From e05e1f3c7ac585f328efc390bb0a1dfed437e39a Mon Sep 17 00:00:00 2001 From: lhdjply Date: Thu, 25 Jan 2024 18:15:13 +0800 Subject: [PATCH] fix(draw_line): fix the issue where dash_dap equals 1 and cannot display properly when the line is a horizontal line (#5473) Signed-off-by: lhdjply --- src/draw/sw/lv_draw_sw_line.c | 2 +- tests/ref_imgs/widgets/line_1.png | Bin 4385 -> 4381 bytes tests/ref_imgs/widgets/line_2.png | Bin 0 -> 2989 bytes tests/src/test_cases/widgets/test_line.c | 35 +++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/ref_imgs/widgets/line_2.png diff --git a/src/draw/sw/lv_draw_sw_line.c b/src/draw/sw/lv_draw_sw_line.c index db1cad6ee..aa5bd622d 100644 --- a/src/draw/sw/lv_draw_sw_line.c +++ b/src/draw/sw/lv_draw_sw_line.c @@ -152,7 +152,7 @@ static void LV_ATTRIBUTE_FAST_MEM draw_line_hor(lv_draw_unit_t * draw_unit, cons i += diff; dash_cnt += diff; } - else if(dash_cnt >= dsc->dash_gap + dsc->dash_width) { + else if(dash_cnt > dsc->dash_gap + dsc->dash_width) { dash_cnt = 0; } else { diff --git a/tests/ref_imgs/widgets/line_1.png b/tests/ref_imgs/widgets/line_1.png index b4510ab1b409c706f972f6eaa6167025e9a66202..60dd85fe265acb24a4b352f387176e676fec4025 100644 GIT binary patch literal 4381 zcmeHL`8$+rAAgL&*cw}P5L1-p5F%O_%ajtrt21LlH7OCr$-WIUIM-2cB`HOgQM?`d zLy56YvJ|o%dt=EqgK#hmX5_u6_kVbQ>i%J_dG6<4zMtj(e(&qK>*R1&T0%(zf*|R0 zHm98-NO(U435}x=pr^+(^CbkyOr1Mz^;=l_!bqDx9*=4H8t0CTPaug{Kf&2qJ!*VT zNop)L($qK^@bZX8b9T(GYx2z+8Xflb3HF_OwN9tu*v4Tw`?jLNPzEpa==4)N-bkcM zXLx2(HKFYJEeo%m{)>?#e14Q9L`nCu)rTP307@64z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DhA(PfWwIGw9 zNHFMkus&@YRTa|O%!QzOgdT(eXdpEm<%LhV^82Fi6nuBV_d@vI3%<9*|NDucfRP;v WHX0>xK7dajkdLR|-f|C8`u_kq6NFFz diff --git a/tests/ref_imgs/widgets/line_2.png b/tests/ref_imgs/widgets/line_2.png new file mode 100644 index 0000000000000000000000000000000000000000..e7c0efa8f0c941bcdae1fbad5bd9e3b539515368 GIT binary patch literal 2989 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV0^&A1QfZHI&TpJ19yq1i(^Q|oVT|O^F+J^ zTmzdU`o8a{a^n5`}g_v@y8Dr_n&lcWL^LGcmMatA1kcu(to^o z{Qu97zuXVj*IYXA>u2>L@qHZoD}H~peylpT-iERMkU#JDno7I*@_%g^8b99;KQRA? z?FPH^jVF)S|6M%Mx_i&J_|^T#onskmg#I%t9^Odt`48Hpe_ zY(5CG=s`;JQQJ|gM+1B`nT=+y(ISNg1?eC5(bm#vlkuDU-3YPi`r@)PfX#3QPgg&e IbxsLQ0Pg)zy#N3J literal 0 HcmV?d00001 diff --git a/tests/src/test_cases/widgets/test_line.c b/tests/src/test_cases/widgets/test_line.c index 24c7a6323..8daa6ea02 100644 --- a/tests/src/test_cases/widgets/test_line.c +++ b/tests/src/test_cases/widgets/test_line.c @@ -110,4 +110,39 @@ void test_line_basic_render(void) TEST_ASSERT_EQUAL_SCREENSHOT("widgets/line_1.png"); } +void test_line_dash_gap(void) +{ + static lv_point_precise_t line_points1[3] = { {50, 50}, {250, 50}, {250, 250} }; + static lv_point_precise_t line_points2[3] = { {50, 250}, {50, 50}, {250, 50} }; + + lv_obj_t * line1; + line1 = lv_line_create(lv_screen_active()); + lv_line_set_points(line1, line_points1, 3); + lv_obj_set_style_line_width(line1, 1, LV_PART_MAIN); + lv_obj_set_style_line_dash_width(line1, 1, LV_PART_MAIN); + lv_obj_set_style_line_dash_gap(line1, 1, LV_PART_MAIN); + + lv_obj_align(line1, LV_ALIGN_LEFT_MID, 0, 0); + + lv_obj_t * line2; + line2 = lv_line_create(lv_screen_active()); + lv_line_set_points(line2, line_points2, 3); + lv_obj_set_style_line_width(line2, 2, LV_PART_MAIN); + lv_obj_set_style_line_dash_width(line2, 2, LV_PART_MAIN); + lv_obj_set_style_line_dash_gap(line2, 2, LV_PART_MAIN); + + lv_obj_center(line2); + + lv_obj_t * line3; + line3 = lv_line_create(lv_screen_active()); + lv_line_set_points(line3, line_points2, 3); + lv_obj_set_style_line_width(line3, 5, LV_PART_MAIN); + lv_obj_set_style_line_dash_width(line3, 3, LV_PART_MAIN); + lv_obj_set_style_line_dash_gap(line3, 1, LV_PART_MAIN); + + lv_obj_align(line3, LV_ALIGN_RIGHT_MID, 0, 0); + + TEST_ASSERT_EQUAL_SCREENSHOT("widgets/line_2.png"); +} + #endif