1 /**
2  * @file lv_demo_smartwatch.c
3  * Smartwatch general functions.
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_demo_smartwatch.h"
10 #if LV_USE_DEMO_SMARTWATCH
11 
12 #include "lv_demo_smartwatch_private.h"
13 #include "lv_demo_smartwatch_home.h"
14 #include "lv_demo_smartwatch_list.h"
15 #include "lv_demo_smartwatch_notifications.h"
16 #include "lv_demo_smartwatch_settings.h"
17 #include "lv_demo_smartwatch_control.h"
18 #include "lv_demo_smartwatch_weather.h"
19 #include "lv_demo_smartwatch_qr.h"
20 #include "lv_demo_smartwatch_easter_egg.h"
21 
22 /*********************
23  *      DEFINES
24  *********************/
25 
26 /**********************
27  *      TYPEDEFS
28  **********************/
29 
30 /**********************
31  *  STATIC PROTOTYPES
32  **********************/
33 
34 static void create_dialog_window(void);
35 static void create_scroll_hints(void);
36 static void lv_demo_obj_set_hidden(lv_obj_t * obj, bool state);
37 static void dialog_close_event_cb(lv_event_t * e);
38 static void lv_create_home_tile(void);
39 static void home_tileview_event_cb(lv_event_t * e);
40 
41 static lv_anim_t * obj_set_opacity_anim(lv_obj_t * obj);
42 static void anim_set_opacity_cb(lv_anim_t * a, int32_t v);
43 
44 /**********************
45  *  STATIC VARIABLES
46  **********************/
47 
48 static lv_theme_t * theme_original;
49 static bool circular_scroll;
50 static bool show_scroll_hints;
51 static bool load_app_list;
52 static bool first_load;
53 static lv_scrollbar_mode_t scrollbar_mode;
54 
55 static lv_obj_t * home_tile;
56 static lv_obj_t * dialog_parent;
57 static lv_obj_t * dialog_window;
58 static lv_obj_t * dialog_panel;
59 static lv_obj_t * dialog_title;
60 static lv_obj_t * dialog_message;
61 static lv_obj_t * dialog_close;
62 static lv_obj_t * dialog_close_label;
63 static lv_obj_t * hint_panel;
64 static lv_obj_t * hint_up;
65 static lv_obj_t * hint_down;
66 static lv_obj_t * hint_left;
67 static lv_obj_t * hint_right;
68 
69 static lv_anim_t * anim_up;
70 static lv_anim_t * anim_down;
71 static lv_anim_t * anim_left;
72 static lv_anim_t * anim_right;
73 
74 /**********************
75  *  GLOBAL VARIABLES
76  **********************/
77 
78 /**********************
79  *      MACROS
80  **********************/
81 
82 /**********************
83  *   GLOBAL FUNCTIONS
84  **********************/
85 
lv_demo_smartwatch(void)86 void lv_demo_smartwatch(void)
87 {
88 
89     /*Use the simple the to make styling simpler*/
90     lv_display_t * display = lv_display_get_default();
91     theme_original = lv_display_get_theme(display);
92     lv_theme_t * theme = lv_theme_default_init(display, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
93                                                true, LV_FONT_DEFAULT);
94     lv_display_set_theme(display, theme);
95 
96     create_dialog_window();
97 
98     create_scroll_hints();
99 
100     lv_create_home_tile();
101 
102     lv_demo_smartwatch_set_circular_scroll(true);
103 
104     lv_demo_smartwatch_control_create(home_tile);
105 
106     lv_demo_smartwatch_home_create(home_tile);
107 
108     lv_demo_smartwatch_list_create(home_tile);
109 
110     lv_tileview_set_tile_by_index(home_tile, 0, 1, LV_ANIM_OFF);
111 
112     lv_demo_smartwatch_notifications_create();
113 
114     lv_demo_smartwatch_settings_create();
115 
116     lv_demo_smartwatch_weather_create();
117 
118     lv_demo_smartwatch_qr_create();
119 
120     lv_demo_smartwatch_easter_egg_create();
121 
122     lv_demo_smartwatch_set_default_scrollbar_mode(LV_SCROLLBAR_MODE_OFF);
123 
124     lv_demo_smartwatch_set_default_hints_state(true);
125 
126     lv_demo_smartwatch_set_default_brightness(100);
127 
128     /* load the logo screen immediately, more like a boot logo */
129     lv_demo_smartwatch_easter_egg_load(LV_SCR_LOAD_ANIM_FADE_IN, 0, 0);
130 
131     /* load the home screen after 2500ms */
132     lv_demo_smartwatch_home_load(LV_SCR_LOAD_ANIM_FADE_IN, 500, 2500);
133 }
134 
lv_demo_smartwatch_scroll_event(lv_event_t * e)135 void lv_demo_smartwatch_scroll_event(lv_event_t * e)
136 {
137 
138     lv_event_code_t event_code = lv_event_get_code(e);
139     lv_obj_t * list = lv_event_get_target(e);
140     if(event_code == LV_EVENT_SCROLL) {
141         lv_area_t list_a;
142         lv_obj_get_coords(list, &list_a);
143         lv_coord_t list_y_center = list_a.y1 + lv_area_get_height(&list_a) / 2;
144 
145         lv_coord_t r = lv_obj_get_height(list) * 7 / 10;
146         uint32_t i;
147         uint32_t child_cnt = lv_obj_get_child_count(list);
148         for(i = 0; i < child_cnt; i++) {
149             lv_obj_t * child = lv_obj_get_child(list, i);
150             lv_area_t child_a;
151             lv_obj_get_coords(child, &child_a);
152 
153             lv_coord_t child_y_center = child_a.y1 + lv_area_get_height(&child_a) / 2;
154 
155             lv_coord_t diff_y = child_y_center - list_y_center;
156             diff_y = LV_ABS(diff_y);
157 
158             /*Get the x of diff_y on a circle.*/
159             lv_coord_t x;
160             /*If diff_y is out of the circle use the last point of the circle (the radius)*/
161             if(diff_y >= r) {
162                 x = r;
163             }
164             else {
165                 /*Use Pythagoras theorem to get x from radius and y*/
166                 uint32_t x_sqr = r * r - diff_y * diff_y;
167                 lv_sqrt_res_t res;
168                 lv_sqrt(x_sqr, &res, 0x8000); /*Use lvgl's built in sqrt root function*/
169                 x = r - res.i;
170             }
171 
172             /*Translate the item by the calculated X coordinate*/
173             lv_obj_set_style_translate_x(child, circular_scroll ? x : 0, 0);
174 
175         }
176     }
177 }
178 
lv_demo_smartwatch_show_dialog(const char * title,const char * message)179 void lv_demo_smartwatch_show_dialog(const char * title, const char * message)
180 {
181     lv_obj_t * active_screen = lv_screen_active();
182 
183     if(lv_obj_check_type(active_screen, &lv_tileview_class)) {
184         /* attach the dialog window to the current active tile */
185         lv_obj_set_parent(dialog_window, lv_tileview_get_tile_active(active_screen));
186     }
187     else {
188         /*  attach the dialog window to current active screen */
189         lv_obj_set_parent(dialog_window, active_screen);
190     }
191 
192     lv_label_set_text(dialog_title, title);
193     lv_label_set_text(dialog_message, message);
194     lv_obj_remove_flag(dialog_window, LV_OBJ_FLAG_HIDDEN); /* show the dialog */
195     lv_obj_scroll_to_y(dialog_window, 0, LV_ANIM_ON);
196 }
197 
lv_demo_smartwatch_set_load_app_list(bool state)198 void lv_demo_smartwatch_set_load_app_list(bool state)
199 {
200     load_app_list = state;
201 }
202 
lv_demo_smartwatch_get_load_app_list(void)203 bool lv_demo_smartwatch_get_load_app_list(void)
204 {
205     return load_app_list;
206 }
207 
lv_demo_smartwatch_get_tileview(void)208 lv_obj_t * lv_demo_smartwatch_get_tileview(void)
209 {
210     return home_tile;
211 }
212 
lv_demo_smartwatch_home_load(lv_screen_load_anim_t anim_type,uint32_t time,uint32_t delay)213 void lv_demo_smartwatch_home_load(lv_screen_load_anim_t anim_type, uint32_t time, uint32_t delay)
214 {
215     lv_screen_load_anim(home_tile, anim_type, time, delay, false);
216 }
217 
lv_demo_smartwatch_load_home_watchface(void)218 void lv_demo_smartwatch_load_home_watchface(void)
219 {
220     lv_obj_t * active_screen = lv_screen_active();
221     if(active_screen != home_tile) {
222         lv_screen_load_anim(home_tile, LV_SCR_LOAD_ANIM_FADE_IN, 500, 0, false);
223     }
224     if(lv_tileview_get_tile_active(home_tile) != lv_demo_smartwatch_get_tile_home()) {
225         lv_tileview_set_tile_by_index(home_tile, 0, 1, LV_ANIM_OFF);
226     }
227 }
228 
lv_demo_smartwatch_get_scrollbar_mode(void)229 lv_scrollbar_mode_t lv_demo_smartwatch_get_scrollbar_mode(void)
230 {
231     return scrollbar_mode;
232 }
233 
lv_demo_smartwatch_set_scrollbar_mode(lv_scrollbar_mode_t mode)234 void lv_demo_smartwatch_set_scrollbar_mode(lv_scrollbar_mode_t mode)
235 {
236     scrollbar_mode = mode;
237 }
238 
lv_demo_smartwatch_set_circular_scroll(bool state)239 void lv_demo_smartwatch_set_circular_scroll(bool state)
240 {
241     circular_scroll = state;
242 }
243 
lv_demo_smartwatch_set_scroll_hint(bool state)244 void lv_demo_smartwatch_set_scroll_hint(bool state)
245 {
246     show_scroll_hints = state;
247 }
248 
lv_demo_smartwatch_get_scroll_hint(void)249 bool lv_demo_smartwatch_get_scroll_hint(void)
250 {
251     return show_scroll_hints;
252 }
253 
lv_demo_smartwatch_show_scroll_hint(lv_dir_t dir)254 void lv_demo_smartwatch_show_scroll_hint(lv_dir_t dir)
255 {
256 
257     if(!show_scroll_hints) {
258         /* scroll hints are disabled, make sure hint panel is hidden */
259         lv_demo_obj_set_hidden(hint_panel, true);
260         return;
261     }
262 
263     lv_demo_obj_set_hidden(hint_up, (dir & LV_DIR_TOP) != LV_DIR_TOP);
264     lv_demo_obj_set_hidden(hint_down, (dir & LV_DIR_BOTTOM) != LV_DIR_BOTTOM);
265     lv_demo_obj_set_hidden(hint_left, (dir & LV_DIR_LEFT) != LV_DIR_LEFT);
266     lv_demo_obj_set_hidden(hint_right, (dir & LV_DIR_RIGHT) != LV_DIR_RIGHT);
267 
268     lv_obj_t * active_screen = lv_screen_active();
269     if(lv_obj_check_type(active_screen, &lv_tileview_class)) {
270         /* attach the hint panel to the current active tile */
271         lv_obj_set_parent(hint_panel, lv_tileview_get_tile_active(active_screen));
272     }
273     else {
274         /*  attach the hint panel to current active screen */
275         lv_obj_set_parent(hint_panel, active_screen);
276     }
277 
278     lv_demo_obj_set_hidden(hint_panel, dir == LV_DIR_NONE);
279 
280 
281     /* Delete animations if they exist*/
282     lv_anim_delete(hint_up, NULL);
283     lv_anim_delete(hint_down, NULL);
284     lv_anim_delete(hint_left, NULL);
285     lv_anim_delete(hint_right, NULL);
286 
287     /* Set max opacity to make icons visible */
288     lv_obj_set_style_opa(hint_down, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
289     lv_obj_set_style_opa(hint_up, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
290     lv_obj_set_style_opa(hint_left, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
291     lv_obj_set_style_opa(hint_right, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
292 
293     if(dir != LV_DIR_NONE) {
294         anim_up = obj_set_opacity_anim(hint_up);
295         anim_down = obj_set_opacity_anim(hint_down);
296         anim_left = obj_set_opacity_anim(hint_left);
297         anim_right = obj_set_opacity_anim(hint_right);
298     }
299 }
300 
301 
302 /**********************
303  *   STATIC FUNCTIONS
304  **********************/
305 
home_tileview_event_cb(lv_event_t * e)306 static void home_tileview_event_cb(lv_event_t * e)
307 {
308     lv_event_code_t event_code = lv_event_get_code(e);
309     if(event_code == LV_EVENT_SCREEN_LOADED) {
310         if(!first_load) {
311             first_load = true;
312             /* run the analog seconds animation on first load */
313             lv_demo_smartwatch_face_update_seconds(0);
314         }
315 
316         /* show the possible scroll directions hint */
317         if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_home()) {
318             lv_demo_smartwatch_show_home_hint(true);
319         }
320         else if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_app_list()) {
321             lv_demo_smartwatch_show_scroll_hint(LV_DIR_LEFT);
322         }
323         else if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_control()) {
324             lv_demo_smartwatch_show_scroll_hint(LV_DIR_TOP | LV_DIR_BOTTOM);
325         }
326     }
327 
328     if(event_code == LV_EVENT_SCREEN_LOAD_START) {
329         lv_obj_set_scrollbar_mode(home_tile, lv_demo_smartwatch_get_scrollbar_mode());
330         lv_demo_smartwatch_app_list_loading();
331     }
332 
333     if(event_code == LV_EVENT_VALUE_CHANGED) {
334         if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_home()) {
335             lv_demo_smartwatch_show_home_hint(true);
336         }
337         else if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_app_list()) {
338             lv_demo_smartwatch_show_scroll_hint(LV_DIR_LEFT);
339         }
340         else if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_control()) {
341             lv_demo_smartwatch_show_scroll_hint(LV_DIR_TOP | LV_DIR_BOTTOM);
342         }
343     }
344 
345     if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_home() && lv_screen_active() == home_tile) {
346 
347         if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) == LV_DIR_RIGHT) {
348             lv_demo_smartwatch_set_load_app_list(false); /* flag was not open from app list */
349             lv_demo_smartwatch_notifications_load(LV_SCR_LOAD_ANIM_OVER_RIGHT, 500, 0);
350         }
351 
352         if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) == LV_DIR_TOP) {
353             lv_demo_smartwatch_set_load_app_list(false); /* flag was not open from app list */
354             lv_demo_smartwatch_weather_load(LV_SCR_LOAD_ANIM_MOVE_TOP, 500, 0);
355         }
356     }
357 
358     if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_control() && lv_screen_active() == home_tile) {
359         if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) == LV_DIR_BOTTOM) {
360             lv_demo_smartwatch_qr_load(LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 500, 0);
361         }
362         else if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) != LV_DIR_TOP) {
363             lv_demo_smartwatch_show_scroll_hint(LV_DIR_TOP | LV_DIR_BOTTOM);
364         }
365     }
366 
367     if(lv_tileview_get_tile_active(home_tile) == lv_demo_smartwatch_get_tile_app_list() &&
368        lv_screen_active() == home_tile) {
369         if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) != LV_DIR_RIGHT) {
370             lv_demo_smartwatch_show_scroll_hint(LV_DIR_LEFT);
371         }
372     }
373 
374 
375 }
376 
lv_create_home_tile(void)377 static void lv_create_home_tile(void)
378 {
379     home_tile = lv_tileview_create(NULL);
380     lv_obj_set_scrollbar_mode(home_tile, LV_SCROLLBAR_MODE_AUTO);
381     lv_obj_set_style_bg_color(home_tile, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
382     lv_obj_set_style_bg_opa(home_tile, 55, LV_PART_MAIN | LV_STATE_DEFAULT);
383 
384     lv_obj_add_event_cb(home_tile, home_tileview_event_cb, LV_EVENT_ALL, NULL);
385 
386 }
387 
dialog_close_event_cb(lv_event_t * e)388 static void dialog_close_event_cb(lv_event_t * e)
389 {
390     LV_UNUSED(e);
391     lv_obj_add_flag(dialog_window, LV_OBJ_FLAG_HIDDEN);
392 }
393 
create_dialog_window(void)394 static void create_dialog_window(void)
395 {
396     dialog_parent = lv_obj_create(NULL);
397 
398     dialog_window = lv_obj_create(dialog_parent);
399     lv_obj_set_width(dialog_window, lv_pct(100));
400     lv_obj_set_height(dialog_window, lv_pct(100));
401     lv_obj_set_align(dialog_window, LV_ALIGN_CENTER);
402     lv_obj_set_scrollbar_mode(dialog_window, LV_SCROLLBAR_MODE_OFF);
403     lv_obj_add_flag(dialog_window, LV_OBJ_FLAG_HIDDEN);
404     lv_obj_remove_flag(dialog_window, LV_OBJ_FLAG_GESTURE_BUBBLE); /* block gesture events when active */
405     lv_obj_set_scroll_dir(dialog_window, LV_DIR_VER);
406     lv_obj_set_style_radius(dialog_window, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
407     lv_obj_set_style_bg_color(dialog_window, lv_color_hex(0x555555), LV_PART_MAIN | LV_STATE_DEFAULT);
408     lv_obj_set_style_bg_opa(dialog_window, 150, LV_PART_MAIN | LV_STATE_DEFAULT);
409     lv_obj_set_style_border_width(dialog_window, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
410     lv_obj_set_style_pad_left(dialog_window, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
411     lv_obj_set_style_pad_right(dialog_window, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
412     lv_obj_set_style_pad_top(dialog_window, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
413     lv_obj_set_style_pad_bottom(dialog_window, 60, LV_PART_MAIN | LV_STATE_DEFAULT);
414 
415     dialog_panel = lv_obj_create(dialog_window);
416     lv_obj_set_width(dialog_panel, lv_pct(80));
417     lv_obj_set_height(dialog_panel, LV_SIZE_CONTENT);
418     lv_obj_set_x(dialog_panel, 0);
419     lv_obj_set_y(dialog_panel, 60);
420     lv_obj_set_align(dialog_panel, LV_ALIGN_TOP_MID);
421     lv_obj_set_flex_flow(dialog_panel, LV_FLEX_FLOW_COLUMN);
422     lv_obj_set_flex_align(dialog_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
423     lv_obj_remove_flag(dialog_panel, LV_OBJ_FLAG_SCROLLABLE);
424     lv_obj_set_style_bg_color(dialog_panel, lv_color_hex(0x080404), LV_PART_MAIN | LV_STATE_DEFAULT);
425     lv_obj_set_style_bg_opa(dialog_panel, 235, LV_PART_MAIN | LV_STATE_DEFAULT);
426     lv_obj_set_style_border_color(dialog_panel, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
427     lv_obj_set_style_border_opa(dialog_panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
428     lv_obj_set_style_border_width(dialog_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
429     lv_obj_set_style_pad_left(dialog_panel, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
430     lv_obj_set_style_pad_right(dialog_panel, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
431     lv_obj_set_style_pad_top(dialog_panel, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
432     lv_obj_set_style_pad_bottom(dialog_panel, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
433 
434     dialog_title = lv_label_create(dialog_panel);
435     lv_obj_set_width(dialog_title, lv_pct(80));
436     lv_obj_set_height(dialog_title, LV_SIZE_CONTENT);
437     lv_obj_set_align(dialog_title, LV_ALIGN_TOP_MID);
438     lv_label_set_long_mode(dialog_title, LV_LABEL_LONG_SCROLL_CIRCULAR);
439     lv_label_set_text(dialog_title, "Title");
440     lv_obj_set_style_text_align(dialog_title, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
441     lv_obj_set_style_text_font(dialog_title, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT);
442     lv_obj_set_style_border_color(dialog_title, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
443     lv_obj_set_style_border_opa(dialog_title, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
444     lv_obj_set_style_border_width(dialog_title, 1, LV_PART_MAIN | LV_STATE_DEFAULT);
445     lv_obj_set_style_border_side(dialog_title, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT);
446     lv_obj_set_style_pad_left(dialog_title, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
447     lv_obj_set_style_pad_right(dialog_title, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
448     lv_obj_set_style_pad_top(dialog_title, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
449     lv_obj_set_style_pad_bottom(dialog_title, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
450 
451     dialog_message = lv_label_create(dialog_panel);
452     lv_obj_set_width(dialog_message, lv_pct(80));
453     lv_obj_set_height(dialog_message, LV_SIZE_CONTENT);
454     lv_obj_set_align(dialog_message, LV_ALIGN_CENTER);
455     lv_label_set_text(dialog_message, "Dialog message");
456     lv_obj_set_style_text_font(dialog_message, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT);
457 
458     dialog_close = lv_button_create(dialog_panel);
459     lv_obj_set_width(dialog_close, lv_pct(60));
460     lv_obj_set_height(dialog_close, LV_SIZE_CONTENT);
461     lv_obj_set_align(dialog_close, LV_ALIGN_BOTTOM_MID);
462     lv_obj_add_flag(dialog_close, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
463     lv_obj_remove_flag(dialog_close, LV_OBJ_FLAG_SCROLLABLE);
464     lv_obj_set_style_radius(dialog_close, 20, LV_PART_MAIN | LV_STATE_DEFAULT);
465 
466     dialog_close_label = lv_label_create(dialog_close);
467     lv_obj_set_width(dialog_close_label, LV_SIZE_CONTENT);
468     lv_obj_set_height(dialog_close_label, LV_SIZE_CONTENT);
469     lv_obj_set_align(dialog_close_label, LV_ALIGN_CENTER);
470     lv_label_set_text(dialog_close_label, "Close");
471     lv_obj_set_style_text_font(dialog_close_label, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT);
472 
473     lv_obj_add_event_cb(dialog_close, dialog_close_event_cb, LV_EVENT_CLICKED, NULL);
474 }
475 
create_scroll_hints(void)476 static void create_scroll_hints(void)
477 {
478     hint_panel = lv_obj_create(dialog_parent);
479 
480     lv_obj_set_width(hint_panel, lv_pct(100));
481     lv_obj_set_height(hint_panel, lv_pct(100));
482     lv_obj_set_align(hint_panel, LV_ALIGN_CENTER);
483     lv_obj_add_flag(hint_panel, LV_OBJ_FLAG_HIDDEN);
484     lv_obj_remove_flag(hint_panel, LV_OBJ_FLAG_CLICKABLE);
485     lv_obj_set_style_radius(hint_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
486     lv_obj_set_style_bg_color(hint_panel, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
487     lv_obj_set_style_bg_opa(hint_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
488     lv_obj_set_style_border_width(hint_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
489     lv_obj_set_style_pad_left(hint_panel, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
490     lv_obj_set_style_pad_right(hint_panel, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
491     lv_obj_set_style_pad_top(hint_panel, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
492     lv_obj_set_style_pad_bottom(hint_panel, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
493 
494     hint_up = lv_image_create(hint_panel);
495     lv_image_set_src(hint_up, &img_up_arrow_icon);
496     lv_image_set_scale(hint_up, 200);
497     lv_obj_set_width(hint_up, LV_SIZE_CONTENT);
498     lv_obj_set_height(hint_up, LV_SIZE_CONTENT);
499     lv_obj_set_align(hint_up, LV_ALIGN_TOP_MID);
500     lv_obj_remove_flag(hint_up, LV_OBJ_FLAG_SCROLLABLE);
501     lv_obj_remove_flag(hint_up, LV_OBJ_FLAG_CLICKABLE);
502     lv_obj_set_style_radius(hint_up, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
503     lv_obj_set_style_bg_color(hint_up, lv_color_hex(0x333333), LV_PART_MAIN | LV_STATE_DEFAULT);
504     lv_obj_set_style_bg_opa(hint_up, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
505     lv_obj_set_style_pad_left(hint_up, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
506     lv_obj_set_style_pad_right(hint_up, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
507 
508     hint_down = lv_image_create(hint_panel);
509     lv_image_set_src(hint_down, &img_up_arrow_icon);
510     lv_image_set_rotation(hint_down, 1800);
511     lv_image_set_scale(hint_down, 200);
512     lv_obj_set_width(hint_down, LV_SIZE_CONTENT);
513     lv_obj_set_height(hint_down, LV_SIZE_CONTENT);
514     lv_obj_set_align(hint_down, LV_ALIGN_BOTTOM_MID);
515     lv_obj_remove_flag(hint_down, LV_OBJ_FLAG_SCROLLABLE);
516     lv_obj_remove_flag(hint_down, LV_OBJ_FLAG_CLICKABLE);
517     lv_obj_set_style_radius(hint_down, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
518     lv_obj_set_style_bg_color(hint_down, lv_color_hex(0x333333), LV_PART_MAIN | LV_STATE_DEFAULT);
519     lv_obj_set_style_bg_opa(hint_down, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
520     lv_obj_set_style_pad_left(hint_down, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
521     lv_obj_set_style_pad_right(hint_down, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
522 
523     hint_left = lv_image_create(hint_panel);
524     lv_image_set_src(hint_left, &img_up_arrow_icon);
525     lv_image_set_rotation(hint_left, 2700);
526     lv_image_set_scale(hint_left, 200);
527     lv_obj_set_width(hint_left, LV_SIZE_CONTENT);
528     lv_obj_set_height(hint_left, LV_SIZE_CONTENT);
529     lv_obj_set_align(hint_left, LV_ALIGN_LEFT_MID);
530     lv_obj_remove_flag(hint_left, LV_OBJ_FLAG_SCROLLABLE);
531     lv_obj_remove_flag(hint_left, LV_OBJ_FLAG_CLICKABLE);
532     lv_obj_set_style_radius(hint_left, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
533     lv_obj_set_style_bg_color(hint_left, lv_color_hex(0x333333), LV_PART_MAIN | LV_STATE_DEFAULT);
534     lv_obj_set_style_bg_opa(hint_left, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
535     lv_obj_set_style_pad_top(hint_left, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
536     lv_obj_set_style_pad_bottom(hint_left, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
537 
538     hint_right = lv_image_create(hint_panel);
539     lv_image_set_src(hint_right, &img_up_arrow_icon);
540     lv_image_set_rotation(hint_right, 900);
541     lv_image_set_scale(hint_right, 200);
542     lv_obj_set_width(hint_right, LV_SIZE_CONTENT);
543     lv_obj_set_height(hint_right, LV_SIZE_CONTENT);
544     lv_obj_set_align(hint_right, LV_ALIGN_RIGHT_MID);
545     lv_obj_remove_flag(hint_right, LV_OBJ_FLAG_SCROLLABLE);
546     lv_obj_remove_flag(hint_right, LV_OBJ_FLAG_CLICKABLE);
547     lv_obj_set_style_radius(hint_right, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
548     lv_obj_set_style_bg_color(hint_right, lv_color_hex(0x333333), LV_PART_MAIN | LV_STATE_DEFAULT);
549     lv_obj_set_style_bg_opa(hint_right, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
550     lv_obj_set_style_pad_top(hint_right, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
551     lv_obj_set_style_pad_bottom(hint_right, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
552 }
553 
lv_demo_obj_set_hidden(lv_obj_t * obj,bool state)554 static void lv_demo_obj_set_hidden(lv_obj_t * obj, bool state)
555 {
556     if(state) {
557         lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);
558     }
559     else {
560         lv_obj_remove_flag(obj, LV_OBJ_FLAG_HIDDEN);
561     }
562 }
563 
anim_set_opacity_cb(lv_anim_t * a,int32_t v)564 static void anim_set_opacity_cb(lv_anim_t * a, int32_t v)
565 {
566     lv_obj_t * target = (lv_obj_t *)a->user_data;
567     lv_obj_set_style_opa(target, v, 0);
568 }
569 
obj_set_opacity_anim(lv_obj_t * obj)570 static lv_anim_t * obj_set_opacity_anim(lv_obj_t * obj)
571 {
572     lv_anim_t anim_opa;
573     lv_anim_init(&anim_opa);
574     lv_anim_set_var(&anim_opa, obj);
575     lv_anim_set_values(&anim_opa, 255, 0);
576     lv_anim_set_duration(&anim_opa, 1000);
577     lv_anim_set_delay(&anim_opa, 1000);
578     lv_anim_set_user_data(&anim_opa, obj);
579     lv_anim_set_custom_exec_cb(&anim_opa, anim_set_opacity_cb);
580     return lv_anim_start(&anim_opa);
581 }
582 
583 #endif /*LV_USE_DEMO_SMARTWATCH*/
584