Thank you @kisvegabor, hadn’t thought about just moving the label in x. I may have to think a little more on this, because the text length will change, so some text would be long enough to trigger the built in scroll and some not. So would have to calulcate if the scroll is triggered or not as to whether to run the animation.
It may be easier to just stick with padding the text to force it into scrolling.
Would LVGL be open to having a LV_LABEL_AWLAYS_SCROLL_CIRCULAR, or something of that nature to scroll any text regardless of length?
So I have done this, feels hacky, but it works. Is there somewhere we can add a feature request for a foreced scroll?
// calculate size of text to be set
lv_point_t size;
lv_txt_get_size(&size, headerCharArray, lv_obj_get_style_text_font(headerText, LV_PART_MAIN),
lv_obj_get_style_text_letter_space(headerText, LV_PART_MAIN),
lv_obj_get_style_text_line_space(headerText, LV_PART_MAIN),
LV_COORD_MAX,
headerText->flags);
//get the actual size of header text
lv_area_t txt_coords;
lv_obj_get_content_coords(headerText, &txt_coords);
//determine if we need padding
int16_t padSize = lv_area_get_width(&txt_coords) - size.x;
char textBuf[255] = "";
LV_LOG_USER("Label size %d, textSize %d, padSize %d\n", lv_area_get_width(&txt_coords), size.x, padSize);
if(padSize > -1){
//if the text needs padding, grab the width of a blank space
lv_txt_get_size(&size, " ", lv_obj_get_style_text_font(headerText, LV_PART_MAIN),
lv_obj_get_style_text_letter_space(headerText, LV_PART_MAIN),
lv_obj_get_style_text_line_space(headerText, LV_PART_MAIN),
LV_COORD_MAX,
headerText->flags);
//lets left pad the incoing text into a new buffer
sprintf(textBuf,"%*s%s", (padSize / size.x) + 1, "", headerCharArray);
} else {
// no padding, copy text into buffer
sprintf(textBuf,"%s", headerCharArray);
}
// set text, and set to scroll
lv_label_set_text(headerText, textBuf);
lv_label_set_long_mode(headerText, LV_LABEL_LONG_SCROLL_CIRCULAR);
I guess I don’t NEED to have scrolling text, but I have implemented a screen header which has the time, some icons (SD Card, USB connected etc…) and a screen title.
When the device has an alarm, in this case it could be a high temperature alarm or something of that nature, I wish to flash the header background red and scroll the text which will describes the alarm details.
Sometimes this text, is smaller than the label, does not scroll and therfore does not have the same impact as a longer alarm text that scrolls.
As a feature, I just thought if it is easy to implement in LVGL it would be cleaner than the fancy use of sprintf.
with latest lvgl 9.02 Version would you guide , how to print , scroll vertically up consciously receiving metadata ( Song info) in player /internet radio and free up once it go out of sight (screen ) as meta data is fed continually like serial.print () in arduino in loop
It requires a little bit of extra coding. I suggest creating 2 labels: one for the current data one for the new one. Place them on top of each other and use lv_anim to handle the animations. In the animations ready callback you can delete or hide the label which was scrolled out.