1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 #include "../../lvgl_private.h"
4
5 #include "unity/unity.h"
6 #include "lv_test_indev.h"
7
setUp(void)8 void setUp(void)
9 {
10 /* Function run before every test */
11 }
12
tearDown(void)13 void tearDown(void)
14 {
15 /* Function run after every test */
16 lv_obj_clean(lv_screen_active());
17 }
18
ext_draw_size_event_cb(lv_event_t * e)19 static void ext_draw_size_event_cb(lv_event_t * e)
20 {
21 lv_event_set_ext_draw_size(e, 100);
22 }
23
btn_clicked_event_cb(lv_event_t * e)24 static void btn_clicked_event_cb(lv_event_t * e)
25 {
26 uint32_t * cnt = lv_event_get_user_data(e);
27 (*cnt)++;
28 }
29
test_obj_flag_overflow_visible_1(void)30 void test_obj_flag_overflow_visible_1(void)
31 {
32 lv_obj_t * obj_main = lv_obj_create(lv_screen_active());
33 lv_obj_set_size(obj_main, 400, 300);
34 lv_obj_set_style_bg_color(obj_main, lv_palette_main(LV_PALETTE_RED), 0);
35 lv_obj_add_flag(obj_main, LV_OBJ_FLAG_OVERFLOW_VISIBLE);
36 lv_obj_center(obj_main);
37 lv_obj_add_event_cb(obj_main, ext_draw_size_event_cb, LV_EVENT_REFR_EXT_DRAW_SIZE, NULL);
38
39 lv_obj_t * obj_child_1 = lv_obj_create(obj_main);
40 lv_obj_set_size(obj_child_1, 200, 200);
41 lv_obj_set_style_bg_color(obj_child_1, lv_palette_main(LV_PALETTE_PURPLE), 0);
42 lv_obj_align(obj_child_1, LV_ALIGN_LEFT_MID, -100, 0);
43
44 lv_obj_t * btn_1 = lv_button_create(obj_child_1);
45 lv_obj_set_size(btn_1, 100, 100);
46 lv_obj_align(btn_1, LV_ALIGN_LEFT_MID, -75, 0);
47 lv_obj_remove_flag(btn_1, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
48 uint32_t cnt_1;
49 lv_obj_add_event_cb(btn_1, btn_clicked_event_cb, LV_EVENT_CLICKED, &cnt_1);
50
51 lv_obj_t * label_1 = lv_label_create(btn_1);
52 lv_label_set_text(label_1, "Button 1");
53 lv_obj_center(label_1);
54
55 lv_obj_t * obj_child_2 = lv_obj_create(obj_main);
56 lv_obj_set_size(obj_child_2, 200, 200);
57 lv_obj_set_style_bg_color(obj_child_2, lv_palette_main(LV_PALETTE_ORANGE), 0);
58 lv_obj_add_flag(obj_child_2, LV_OBJ_FLAG_OVERFLOW_VISIBLE);
59 lv_obj_align(obj_child_2, LV_ALIGN_RIGHT_MID, 100, 0);
60 lv_obj_add_event_cb(obj_child_2, ext_draw_size_event_cb, LV_EVENT_REFR_EXT_DRAW_SIZE, NULL);
61
62 lv_obj_t * btn_2 = lv_button_create(obj_child_2);
63 lv_obj_set_size(btn_2, 100, 100);
64 lv_obj_align(btn_2, LV_ALIGN_RIGHT_MID, 75, 0);
65 lv_obj_remove_flag(btn_2, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
66 uint32_t cnt_2;
67 lv_obj_add_event_cb(btn_2, btn_clicked_event_cb, LV_EVENT_CLICKED, &cnt_2);
68
69 lv_obj_t * label_2 = lv_label_create(btn_2);
70 lv_label_set_text(label_2, "Button 2");
71 lv_obj_center(label_2);
72
73 cnt_1 = 0;
74 cnt_2 = 0;
75
76 /*The clipped part of the left button (shouldn't trigger click event)*/
77 lv_test_mouse_click_at(100, 220);
78
79 /*The non clipped part of the left button (should trigger click event)*/
80 lv_test_mouse_click_at(140, 220);
81
82 /*The left part of the right button (should trigger click event)*/
83 lv_test_mouse_click_at(650, 220);
84
85 /*The outer part of the right button (should trigger click event as obj_child_2 has LV_OBJ_FLAG_OVERFLOW_VISIBLE)*/
86 lv_test_mouse_click_at(690, 220);
87
88 TEST_ASSERT_EQUAL_UINT32(1, cnt_1);
89 TEST_ASSERT_EQUAL_UINT32(2, cnt_2);
90
91 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/obj_flag_overflow_visible_1_1.png");
92
93 /*Test if the overflowing parts are rendered correctly after scrolling too*/
94 lv_obj_scroll_by_bounded(obj_main, -20, 0, LV_ANIM_OFF);
95 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/obj_flag_overflow_visible_1_2.png");
96
97 lv_obj_scroll_by_bounded(obj_child_2, -30, 0, LV_ANIM_OFF);
98 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/obj_flag_overflow_visible_1_3.png");
99
100 /*Test with rotation*/
101 lv_obj_set_style_transform_rotation(obj_main, 300, 0);
102 lv_obj_set_style_transform_pivot_x(obj_main, 200, 0);
103 lv_obj_set_style_transform_pivot_y(obj_main, 150, 0);
104
105 lv_obj_set_style_transform_rotation(obj_child_1, 300, 0);
106 lv_obj_set_style_transform_pivot_x(obj_child_1, 100, 0);
107 lv_obj_set_style_transform_pivot_y(obj_child_1, 100, 0);
108
109 lv_obj_set_style_transform_rotation(obj_child_2, 300, 0);
110 lv_obj_set_style_transform_pivot_x(obj_child_2, 100, 0);
111 lv_obj_set_style_transform_pivot_y(obj_child_2, 100, 0);
112
113 lv_obj_set_style_transform_rotation(btn_1, 300, 0);
114 lv_obj_set_style_transform_pivot_x(btn_1, 100, 0);
115 lv_obj_set_style_transform_pivot_y(btn_1, 100, 0);
116
117 lv_obj_set_style_transform_rotation(btn_2, 300, 0);
118 lv_obj_set_style_transform_pivot_x(btn_2, 100, 0);
119 lv_obj_set_style_transform_pivot_y(btn_2, 100, 0);
120
121 cnt_1 = 0;
122 cnt_2 = 0;
123
124 /*The clipped part of the left button (shouldn't trigger click event)*/
125 lv_test_mouse_click_at(185, 40);
126
127 /*The non clipped part of the left button (should trigger click event)*/
128 lv_test_mouse_click_at(210, 80);
129
130 /*The left part of the right button (should trigger click event)*/
131 lv_test_mouse_click_at(590, 370);
132
133 /*The outer part of the right button (should trigger click event as obj_child_2 has LV_OBJ_FLAG_OVERFLOW_VISIBLE)*/
134 lv_test_mouse_click_at(600, 430);
135
136 /*The clipped part of the right button (clipped because it's out of the red panel's ext draw size, shouldn't trigger click event)*/
137 lv_test_mouse_click_at(645, 430);
138
139 TEST_ASSERT_EQUAL_UINT32(1, cnt_1);
140 TEST_ASSERT_EQUAL_UINT32(2, cnt_2);
141 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/obj_flag_overflow_visible_1_4.png");
142
143 }
144
145 #endif
146