fix(span): handle trailing newline (#5957)

This commit is contained in:
liamHowatt 2024-03-27 01:24:44 -04:00 committed by GitHub
parent 45e4aa9fc3
commit 03b5f583bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 1 deletions

View File

@ -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 {

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@ -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