lvgl
lvgl copied to clipboard
feat(spangroup): add `lv_spangroup_get_span_by_point` in spangroup
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
- Update the Documentation if needed.
- Add Examples if relevant.
- Add Tests if applicable.
- If you added new options to
lv_conf_template.hrun lv_conf_internal_gen.py and update Kconfig. - Run
scripts/code-format.py(astyle version v3.4.12 needs to be installed) and follow the Code Conventions. - Mark the Pull request as Draft while you are working on the first version, and mark is as Ready when it's ready for review.
- When changes were requested, re-request review to notify the maintainers.
- Help us to review this Pull Request! Anyone can approve or request changes.
When testing it with the default span example, the last line is not recognized correctly:
Also the documentation should be updated.
I fixed the bug, can you test it again? 🙏
I confirm that the spans are not identified correctly now. :slightly_frowning_face:
I confirm that the spans are not identified correctly now. 🙁
I think maybe the padding calculation affects the result.
Let me correct the calculation.
I fix the bug, and now it shows like this:
Thanks for trying to fix it. I'm still seeing an issue with lv_example_span_1. Does it work for you?
Thanks for trying to fix it. I'm still seeing an issue with
lv_example_span_1. Does it work for you?
Sure, I reproduce it. Let me try to fix it.
If I comment this line
lv_spangroup_set_indent(spangroup, 20);
Then everything will be fine. 🤷
So, there are some calculation problem with span indent property.
@XuNeo I caught a typo of yours.
Almost there :slightly_smiling_face:
I've updated lv_example_span_1() and it works like this now:
- There is vertical offset error on the first line
- The indent in active too
Oh sure, I'm really missed something. Let me fix it.
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.
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;
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.
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.
- Indent problem fixed
- Test was added
Perfect! :heart: Just the warning in the test...
