From 4b41590cf1593e33b8a1ae0e86461f3c0046c1cc Mon Sep 17 00:00:00 2001 From: liamHowatt <30486941+liamHowatt@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:31:53 -0400 Subject: [PATCH] fix(flex): LV_FLEX_ALIGN_SPACE_BETWEEN align single item left (#5915) --- src/layouts/flex/lv_flex.c | 3 +- tests/ref_imgs/align_flex_center1.png | Bin 0 -> 2275 bytes tests/ref_imgs/align_flex_center2.png | Bin 0 -> 2279 bytes tests/ref_imgs/align_flex_space_around1.png | Bin 0 -> 2275 bytes tests/ref_imgs/align_flex_space_around2.png | Bin 0 -> 2279 bytes tests/ref_imgs/align_flex_space_between1.png | Bin 0 -> 2272 bytes tests/ref_imgs/align_flex_space_between2.png | Bin 0 -> 2274 bytes tests/ref_imgs/align_flex_space_evenly1.png | Bin 0 -> 2275 bytes tests/ref_imgs/align_flex_space_evenly2.png | Bin 0 -> 2280 bytes tests/src/test_cases/test_align_flex.c | 80 +++++++++++++++++++ 10 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tests/ref_imgs/align_flex_center1.png create mode 100644 tests/ref_imgs/align_flex_center2.png create mode 100644 tests/ref_imgs/align_flex_space_around1.png create mode 100644 tests/ref_imgs/align_flex_space_around2.png create mode 100644 tests/ref_imgs/align_flex_space_between1.png create mode 100644 tests/ref_imgs/align_flex_space_between2.png create mode 100644 tests/ref_imgs/align_flex_space_evenly1.png create mode 100644 tests/ref_imgs/align_flex_space_evenly2.png create mode 100644 tests/src/test_cases/test_align_flex.c diff --git a/src/layouts/flex/lv_flex.c b/src/layouts/flex/lv_flex.c index 168f9de90..65a1d048e 100644 --- a/src/layouts/flex/lv_flex.c +++ b/src/layouts/flex/lv_flex.c @@ -472,7 +472,6 @@ static void place_content(lv_flex_align_t place, int32_t max_size, int32_t conte { if(item_cnt <= 1) { switch(place) { - case LV_FLEX_ALIGN_SPACE_BETWEEN: case LV_FLEX_ALIGN_SPACE_AROUND: case LV_FLEX_ALIGN_SPACE_EVENLY: place = LV_FLEX_ALIGN_CENTER; @@ -492,7 +491,7 @@ static void place_content(lv_flex_align_t place, int32_t max_size, int32_t conte *start_pos += max_size - content_size; break; case LV_FLEX_ALIGN_SPACE_BETWEEN: - *gap = (int32_t)(max_size - content_size) / (int32_t)(item_cnt - 1); + if(item_cnt > 1) *gap = (int32_t)(max_size - content_size) / (int32_t)(item_cnt - 1); break; case LV_FLEX_ALIGN_SPACE_AROUND: *gap += (int32_t)(max_size - content_size) / (int32_t)(item_cnt); diff --git a/tests/ref_imgs/align_flex_center1.png b/tests/ref_imgs/align_flex_center1.png new file mode 100644 index 0000000000000000000000000000000000000000..3e1b373658b69c1fb25442b18a04f19368d2f201 GIT binary patch literal 2275 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV0^&A1QfZHI&TpJ1IH>)7srr_Id5+`@-i{< zxH?WNaAAEH&|)1@psyBpDW&|F!~c&<|^# tVQ83ffQg}lbCfX}2%{-s*yMs6{HEgkyA2|aTLT*~44$rjF6*2UngChCCRP9d literal 0 HcmV?d00001 diff --git a/tests/ref_imgs/align_flex_space_around1.png b/tests/ref_imgs/align_flex_space_around1.png new file mode 100644 index 0000000000000000000000000000000000000000..3e1b373658b69c1fb25442b18a04f19368d2f201 GIT binary patch literal 2275 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV0^&A1QfZHI&TpJ1IH>)7srr_Id5+`@-i{< zxH?WNaAAEH&|)1@psyBpDW&|F!~c& literal 0 HcmV?d00001 diff --git a/tests/ref_imgs/align_flex_space_between2.png b/tests/ref_imgs/align_flex_space_between2.png new file mode 100644 index 0000000000000000000000000000000000000000..79d86bb5a7bca7ae7a94692eeb5d08dae2cb7d68 GIT binary patch literal 2274 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV0^&A1QfZHI&TpJ1IJ2F7srr_Id5+`@-i{< zxH?WNaAAEHu;pFA!M!soJSV3fJMjMF(&K0DFfhEhvz?!TVTV*BD}#V=1OtQNC}T7b zMpMGD$ORjZzy7n1r~cmgsj&T^o__{A6;d=eNLj<5^~#+w;4-%2wu=pAL}W>8Su qz`&5iG|Ctagwd2RY;wUj=3N{4GD1Jk=LEK07(8A5T-G@yGywpQhj73E literal 0 HcmV?d00001 diff --git a/tests/ref_imgs/align_flex_space_evenly1.png b/tests/ref_imgs/align_flex_space_evenly1.png new file mode 100644 index 0000000000000000000000000000000000000000..3e1b373658b69c1fb25442b18a04f19368d2f201 GIT binary patch literal 2275 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV0^&A1QfZHI&TpJ1IH>)7srr_Id5+`@-i{< zxH?WNaAAEH&|)1@psyBpDW&|F!~c&p<=)?T&_@z^~&)i{PcyT9OpMjykl!==`L2UyAL((W? zG!RBp!tlri{a3jUte