lvgl icon indicating copy to clipboard operation
lvgl copied to clipboard

feat(spangroup): add `lv_spangroup_get_span_by_point` in spangroup

Open W-Mai opened this issue 1 year ago • 5 comments

Description of the feature or fix

lv_obj_t* spangroup = lv_spangroup_create(lv_screen_active());
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_BREAK);
lv_obj_set_width(spangroup, 250);

lv_span_t* span1 = lv_spangroup_new_span(spangroup);

lv_span_set_text(span1, "异世相遇,尽享美味!");
lv_spangroup_add_span_event_cb(spangroup, span1, 
    [](lv_event_t* e) {
        auto span = (lv_span_t *)lv_event_get_param(e);
        LV_LOG_USER("EventSay: %s", span->txt); 
    }, 
    LV_EVENT_PRESSED, NULL);

Notes

W-Mai avatar Jul 26 '24 07:07 W-Mai

When testing it with the default span example, the last line is not recognized correctly: image

Also the documentation should be updated.

I fixed the bug, can you test it again? 🙏

W-Mai avatar Aug 09 '24 09:08 W-Mai

I confirm that the spans are not identified correctly now. :slightly_frowning_face:

span

kisvegabor avatar Aug 23 '24 06:08 kisvegabor

I confirm that the spans are not identified correctly now. 🙁

span span

I think maybe the padding calculation affects the result.

Let me correct the calculation.

W-Mai avatar Aug 23 '24 07:08 W-Mai

I fix the bug, and now it shows like this: image

W-Mai avatar Aug 27 '24 10:08 W-Mai

Thanks for trying to fix it. I'm still seeing an issue with lv_example_span_1. Does it work for you?

liamHowatt avatar Aug 28 '24 05:08 liamHowatt

Thanks for trying to fix it. I'm still seeing an issue with lv_example_span_1. Does it work for you?

image

Sure, I reproduce it. Let me try to fix it.

W-Mai avatar Aug 31 '24 12:08 W-Mai

If I comment this line

lv_spangroup_set_indent(spangroup, 20);

Then everything will be fine. 🤷

image

So, there are some calculation problem with span indent property.

W-Mai avatar Aug 31 '24 12:08 W-Mai

@XuNeo I caught a typo of yours. image

image

W-Mai avatar Aug 31 '24 13:08 W-Mai

Almost there :slightly_smiling_face:

I've updated lv_example_span_1() and it works like this now: span

  • There is vertical offset error on the first line
  • The indent in active too

kisvegabor avatar Sep 02 '24 15:09 kisvegabor

Oh sure, I'm really missed something. Let me fix it.

image

W-Mai avatar Sep 03 '24 03:09 W-Mai

image

It should be the reason, but it doesn't seem to be a good solution.

When there is a span of different row heights in a line spangroup, the previous span height will not be refreshed in subsequent span updates.

I think we can record the last span of the current line first, and then update the previous span hight when the line is over.

W-Mai avatar Sep 03 '24 03:09 W-Mai

fixed

/* iterate all the spans in the current line and set the trailing height to the max line height */
for(lv_span_t * tmp_span = prev_span;
    tmp_span && tmp_span != cur_span;
    tmp_span = lv_ll_get_next(&spans->child_ll, tmp_span))
    tmp_span->trailing_height = max_line_h;

W-Mai avatar Sep 03 '24 04:09 W-Mai

Thanks, vertically it's working well now!

The only issue I see is that clicking the space before the first line still returns the first span.

If you have time please add a basic test too.

kisvegabor avatar Sep 03 '24 08:09 kisvegabor

Thanks, vertically it's working well now!

The only issue I see is that clicking the space before the first line still returns the first span.

If you have time please add a basic test too.

  1. Indent problem fixed
  2. Test was added

W-Mai avatar Sep 04 '24 05:09 W-Mai

Perfect! :heart: Just the warning in the test...

kisvegabor avatar Sep 04 '24 10:09 kisvegabor