mirror of
https://github.com/lvgl/lvgl.git
synced 2024-12-02 22:24:02 +08:00
fix(span): handle trailing newline (#5957)
This commit is contained in:
parent
45e4aa9fc3
commit
03b5f583bc
@ -644,7 +644,7 @@ static bool lv_text_get_snippet(const char * txt, const lv_font_t * font,
|
||||
uint32_t ofs = _lv_text_get_next_line(txt, font, letter_space, real_max_width, use_width, flag);
|
||||
*end_ofs = ofs;
|
||||
|
||||
if(txt[ofs] == '\0' && *use_width < max_width) {
|
||||
if(txt[ofs] == '\0' && *use_width < max_width && !(ofs && (txt[ofs - 1] == '\n' || txt[ofs - 1] == '\r'))) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
|
BIN
tests/ref_imgs/widgets/span_06.png
Normal file
BIN
tests/ref_imgs/widgets/span_06.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
@ -279,4 +279,34 @@ void test_spangroup_get_expand_width(void)
|
||||
lv_spangroup_get_expand_width(spangroup, experimental_size));
|
||||
}
|
||||
|
||||
void test_spangroup_newlines(void)
|
||||
{
|
||||
active_screen = lv_screen_active();
|
||||
spangroup = lv_spangroup_create(active_screen);
|
||||
lv_obj_set_size(spangroup, LV_PCT(100), LV_PCT(100));
|
||||
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "Lorem\n");
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "ipsum");
|
||||
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "\n\n");
|
||||
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "dolor");
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "");
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "\nsit");
|
||||
|
||||
/* carriage return is treated as equivalent to line feed */
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "\r");
|
||||
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "amet,\n consectetur");
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), " adipiscing");
|
||||
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "\n");
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "");
|
||||
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "\relit, sed\n");
|
||||
lv_span_set_text(lv_spangroup_new_span(spangroup), "do eiusmod");
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/span_06.png");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user