Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto wrap text function #89

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jamesSaporito
Copy link

@jamesSaporito jamesSaporito commented Oct 29, 2022

Overview

Added a function hagl_put_wrap_text that will automatically wrap the text to the next line, but without splitting a word into multiple lines. Only full words will be printed on a single line, unless the word is too long to fit. In the scenario where it is too long to fit, it will wrap around mid-word for that word only.

As of now, this was only tested using a small 160x80 ST7735S display with an ESP32 development board.

Testing

Sample program for testing a few scenarios:

hagl_backend_t *display = hagl_init();
hagl_clear(display);

// Text color
color_t color = hagl_color(display, 255, 255, 255);

// Text to display
char text[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
    "do eiusmod tempor incididunt ut labore et dolore magna aliqua."
    "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.";

hagl_set_clip(display, 0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1);
uint8_t result = hagl_put_wrap_text(display, text, color, font6x9);

/**
 * Testing a word that is longer than the window/screen width. This will be forced to
 * wrap around.
 */
// char long_word[] = "thisisjustaverylongwordthatwillwraparound";
// uint8_t result = hagl_put_wrap_text(display, long_word, color, font6x9);

/**
 * Narrower bounds
 */
// hagl_set_clip(display, 50, 0, 100, 80);
// uint8_t result = hagl_put_wrap_text(display, text, color, font6x9);

if (result > 0) {
    ESP_LOGI(TAG, "Success");
} else {
    ESP_LOGI(TAG, "Window Error");
}

hagl_flush(display);

@jamesSaporito
Copy link
Author

@tuupola Hey there, just wanted to ask if you'd like me to close this PR? No worries if this functionality isn't needed!

@tuupola tuupola added the enhancement New feature or request label May 29, 2023
@tuupola
Copy link
Owner

tuupola commented May 29, 2023

@jamesSaporito Sorry I did not mean to ignore you. I have the usual usual "started to work for my own company and much less time for open source" thing going on.

I want to add something like this but I also have not decided how the text styling API would look. @CHiPs44 has created one idea about this #96. There is also couple of related issues #39 and #42.

Main problem for me is that I do not want to open a can of worms and bloat the core library. I want to keep it reasonably small and there can be endless font styling options. So either have to choose a core set of styling rules or make an easily extendable styling API. One option could also be to make the font rendering an external library and core library would only have the 8 bit rendering style.

Lets keeps this open for now so it also works as a TODO list entry for me.

@jamesSaporito
Copy link
Author

@tuupola Oh no worries at all, just wanted to follow up!

Yep I totally get not wanting the bloat. Sounds good to me, I will leave it open. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants