Long mode crop crops the start of text

Description

I am trying to have three labels on the screen, the center label is supposed use long mode break, the labels above and below it will use long mode crop. Here is the issue:

The labels could have variable sizes, sometimes they will need to break/crop, sometimes they may be very short. When I set long mode crop for the bottom and top label as well as center align them, the long mode crops the start of the text label, which isnt ideal. When I set the text to left align, the crop mode crops the end of the label, however when the label is short, they no longer align with the center label which is center aligned and uses long mode break.

What MCU/Processor/Board and compiler are you using?

Irrelevant for this

What LVGL version are you using?

v7

What do you want to achieve?

All three labels should be aligned to the center of the screen. When the top and bottom labels are too long, they should crop the end of the text label but leave the start intact. The center label should go into long mode break.

What have you tried so far?

I tried to left align the labels, but that results in short labels no longer being aligned to the center of the screen.

Code to reproduce

lv_label_set_long_mode(top, LV_LABEL_LONG_CROP);
lv_label_set_long_mode(center, LV_LABEL_LONG_BREAK);
lv_label_set_long_mode(bottom, LV_LABEL_LONG_CROP);

lv_obj_set_width(top, 150);
lv_obj_set_width(center, 150);
lv_obj_set_width(bottom, 150);

lv_label_set_align(top, LV_LABEL_ALIGN_CENTER);
lv_label_set_align(center, LV_LABEL_ALIGN_CENTER);
lv_label_set_align(bottom, LV_LABEL_ALIGN_CENTER);

Lastly I just set the text using *set_text and align the object itself which should not make a difference

Screenshot and/or video

NA

Update:

We have found an intermediate solution in which we set the label long mode to expand, set the text, get the size and if its above a specific width we use long mode crop, left align the text in the label and set the text again. It works but surely there is a simpler way of doing this?

Hi,

I’ve tested like this and seemingly it produces correct result:

  lv_obj_t * top = lv_label_create(lv_scr_act(), NULL);
  lv_obj_t * center = lv_label_create(lv_scr_act(), NULL);
  lv_obj_t * bottom = lv_label_create(lv_scr_act(), NULL);

  lv_label_set_text(top, "Some text");
  lv_label_set_text(center, "Some text");
  lv_label_set_text(bottom, "Some text to see the crop");

  lv_label_set_long_mode(top, LV_LABEL_LONG_CROP);
  lv_label_set_long_mode(center, LV_LABEL_LONG_BREAK);
  lv_label_set_long_mode(bottom, LV_LABEL_LONG_CROP);

  lv_obj_set_width(top, 150);
  lv_obj_set_width(center, 150);
  lv_obj_set_width(bottom, 150);

  lv_label_set_align(top, LV_LABEL_ALIGN_CENTER);
  lv_label_set_align(center, LV_LABEL_ALIGN_CENTER);
  lv_label_set_align(bottom, LV_LABEL_ALIGN_CENTER);

  lv_obj_set_pos(top, 10, 10);
  lv_obj_set_pos(center, 10, 60);
  lv_obj_set_pos(bottom, 10, 110);

image

Correct me if I am wrong, but the “correct result” would not mean that the bottom most text is cropped on both sides of it? Of your bottom label the first two letters are cropped, which makes the label hard to read/ ambiguous to understand what its supposed to say. Surely this is not intentional behavior by LVGL?

The original code uses this:

lv_label_set_long_mode(bottom, LV_LABEL_LONG_CROP);

I think if you change the long mode that will not be an issue.

I want the text to be cropped at the end, what long mode would I set it to, if not long mode crop, in order to have it cropped? My question is in regards to cropping text and center aligning it, without cropping off both ends

So you want the text to be center-aligned but if it’s too long align it to the left and crop only the right side?

Well, I want the text to be center aligned regardless of its length and crop it if its too long. But since that is currently not possible as it seems, yes I want to left align and crop the text if its too long, otherwise center align. So in theory I have a screen like

    Short Text
      Middle
   Very Long Te