1 /**
2 * @file lv_win.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_win.h"
10 #if LV_USE_WIN
11
12 /*********************
13 * DEFINES
14 *********************/
15
16 /**********************
17 * TYPEDEFS
18 **********************/
19
20 /**********************
21 * STATIC PROTOTYPES
22 **********************/
23 static void lv_win_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
24
25 /**********************
26 * STATIC VARIABLES
27 **********************/
28 const lv_obj_class_t lv_win_class = {
29 .constructor_cb = lv_win_constructor,
30 .width_def = LV_PCT(100),
31 .height_def = LV_PCT(100),
32 .base_class = &lv_obj_class,
33 .instance_size = sizeof(lv_win_t)
34 };
35 static lv_coord_t create_header_height;
36 /**********************
37 * MACROS
38 **********************/
39
40 /**********************
41 * GLOBAL FUNCTIONS
42 **********************/
43
lv_win_create(lv_obj_t * parent,lv_coord_t header_height)44 lv_obj_t * lv_win_create(lv_obj_t * parent, lv_coord_t header_height)
45 {
46 LV_LOG_INFO("begin");
47 create_header_height = header_height;
48
49 lv_obj_t * obj = lv_obj_class_create_obj(&lv_win_class, parent);
50 lv_obj_class_init_obj(obj);
51 return obj;
52 }
53
lv_win_add_title(lv_obj_t * win,const char * txt)54 lv_obj_t * lv_win_add_title(lv_obj_t * win, const char * txt)
55 {
56 lv_obj_t * header = lv_win_get_header(win);
57 lv_obj_t * title = lv_label_create(header);
58 lv_label_set_long_mode(title, LV_LABEL_LONG_DOT);
59 lv_label_set_text(title, txt);
60 lv_obj_set_flex_grow(title, 1);
61 return title;
62 }
63
lv_win_add_btn(lv_obj_t * win,const void * icon,lv_coord_t btn_w)64 lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w)
65 {
66 lv_obj_t * header = lv_win_get_header(win);
67 lv_obj_t * btn = lv_btn_create(header);
68 lv_obj_set_size(btn, btn_w, LV_PCT(100));
69
70 lv_obj_t * img = lv_img_create(btn);
71 lv_img_set_src(img, icon);
72 lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
73
74 return btn;
75 }
76
lv_win_get_header(lv_obj_t * win)77 lv_obj_t * lv_win_get_header(lv_obj_t * win)
78 {
79 return lv_obj_get_child(win, 0);
80 }
81
lv_win_get_content(lv_obj_t * win)82 lv_obj_t * lv_win_get_content(lv_obj_t * win)
83 {
84 return lv_obj_get_child(win, 1);
85 }
86
87 /**********************
88 * STATIC FUNCTIONS
89 **********************/
90
lv_win_constructor(const lv_obj_class_t * class_p,lv_obj_t * obj)91 static void lv_win_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
92 {
93 LV_UNUSED(class_p);
94 lv_obj_t * parent = lv_obj_get_parent(obj);
95 lv_obj_set_size(obj, lv_obj_get_width(parent), lv_obj_get_height(parent));
96 lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
97
98 lv_obj_t * header = lv_obj_create(obj);
99 lv_obj_set_size(header, LV_PCT(100), create_header_height);
100 lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
101 lv_obj_set_flex_align(header, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
102
103 lv_obj_t * cont = lv_obj_create(obj);
104 lv_obj_set_flex_grow(cont, 1);
105 lv_obj_set_width(cont, LV_PCT(100));
106 }
107
108 #endif
109