1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 #include "../../lvgl_private.h"
4 
5 #include "unity/unity.h"
6 
7 static lv_obj_t * active_screen = NULL;
8 
setUp(void)9 void setUp(void)
10 {
11     active_screen = lv_screen_active();
12 }
13 
tearDown(void)14 void tearDown(void)
15 {
16     lv_obj_clean(active_screen);
17 }
18 
obj_create(lv_obj_t * parent,lv_color_t color)19 lv_obj_t * obj_create(lv_obj_t * parent, lv_color_t color)
20 {
21     lv_obj_t * obj = lv_obj_create(parent);
22     lv_obj_set_style_bg_color(obj, color, LV_PART_MAIN);
23     lv_obj_set_width(obj, 150);
24     lv_obj_set_height(obj, 150);
25 
26     return obj;
27 }
28 
obj_set_margin(lv_obj_t * obj,int32_t left,int32_t top,int32_t right,int32_t bottom)29 void obj_set_margin(lv_obj_t * obj, int32_t left, int32_t top, int32_t right, int32_t bottom)
30 {
31     lv_obj_set_style_margin_left(obj, left, LV_PART_MAIN);
32     lv_obj_set_style_margin_top(obj, top, LV_PART_MAIN);
33     lv_obj_set_style_margin_right(obj, right, LV_PART_MAIN);
34     lv_obj_set_style_margin_bottom(obj, bottom, LV_PART_MAIN);
35 }
36 
37 // takes no effect on position but size.
test_align(void)38 void test_align(void)
39 {
40     lv_obj_t * obj0 = active_screen;
41 
42     lv_obj_set_width(obj0, 800);
43     lv_obj_set_height(obj0, 400);
44     lv_obj_center(obj0);
45     lv_obj_set_style_pad_all(obj0, 0, LV_PART_MAIN);
46     lv_obj_set_style_border_width(obj0, 0, LV_PART_MAIN);
47 
48     lv_obj_t * obj0s[] = {
49         obj_create(obj0, lv_palette_main(LV_PALETTE_BLUE)),
50         obj_create(obj0, lv_palette_main(LV_PALETTE_RED)),
51         obj_create(obj0, lv_palette_main(LV_PALETTE_DEEP_PURPLE)),
52         obj_create(obj0, lv_palette_main(LV_PALETTE_GREEN)),
53         obj_create(obj0, lv_palette_main(LV_PALETTE_PINK))
54     };
55 
56     lv_obj_align(obj0s[0], LV_ALIGN_TOP_MID, 0, 0);
57     lv_obj_align_to(obj0s[1], obj0s[0], LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
58     lv_obj_align_to(obj0s[2], obj0s[1], LV_ALIGN_OUT_RIGHT_MID, 0, 0);
59     lv_obj_align_to(obj0s[3], obj0s[2], LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
60     lv_obj_update_layout(obj0);
61 
62     obj_set_margin(obj0s[0], 20, 50, 60, 50);
63     lv_obj_set_style_width(obj0s[0], LV_PCT(60), LV_PART_MAIN);
64     obj_set_margin(obj0s[1], 15, 12, 50, 20);
65     obj_set_margin(obj0s[2], 25, 25, 100, 20);
66     obj_set_margin(obj0s[3], 12, 50, 100, 100);
67     lv_obj_set_style_width(obj0s[3], LV_PCT(100), LV_PART_MAIN);
68     TEST_ASSERT_EQUAL_SCREENSHOT("margin_align_0.png");
69     obj_set_margin(obj0s[4], 6, 100, 100, 100);
70 
71     lv_obj_set_style_radius(obj0s[0], 0, LV_PART_MAIN);
72 
73     lv_obj_align(obj0s[4], LV_ALIGN_LEFT_MID, 0, 0);
74 
75     lv_obj_update_layout(obj0);
76 
77     TEST_ASSERT_EQUAL_SCREENSHOT("margin_align_1.png");
78 }
79 
80 #endif
81