1 /**
2  * @file lv_win.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_win_private.h"
10 #include "../../core/lv_obj_class_private.h"
11 #include "../../lvgl.h"
12 #if LV_USE_WIN
13 
14 /*********************
15  *      DEFINES
16  *********************/
17 
18 /**********************
19  *      TYPEDEFS
20  **********************/
21 
22 /**********************
23  *  STATIC PROTOTYPES
24  **********************/
25 static void lv_win_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
26 
27 /**********************
28  *  STATIC VARIABLES
29  **********************/
30 const lv_obj_class_t lv_win_class = {
31     .constructor_cb = lv_win_constructor,
32     .width_def = LV_PCT(100),
33     .height_def = LV_PCT(100),
34     .base_class = &lv_obj_class,
35     .instance_size = sizeof(lv_win_t),
36     .name = "win",
37 };
38 /**********************
39  *      MACROS
40  **********************/
41 
42 /**********************
43  *   GLOBAL FUNCTIONS
44  **********************/
45 
lv_win_create(lv_obj_t * parent)46 lv_obj_t * lv_win_create(lv_obj_t * parent)
47 {
48     LV_LOG_INFO("begin");
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_MODE_DOTS);
59     lv_label_set_text(title, txt);
60     lv_obj_set_flex_grow(title, 1);
61     return title;
62 }
63 
lv_win_add_button(lv_obj_t * win,const void * icon,int32_t btn_w)64 lv_obj_t * lv_win_add_button(lv_obj_t * win, const void * icon, int32_t btn_w)
65 {
66     lv_obj_t * header = lv_win_get_header(win);
67     lv_obj_t * btn = lv_button_create(header);
68     lv_obj_set_size(btn, btn_w, LV_PCT(100));
69 
70     if(icon) {
71         lv_obj_t * img = lv_image_create(btn);
72         lv_image_set_src(img, icon);
73         lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
74     }
75 
76     return btn;
77 }
78 
lv_win_get_header(lv_obj_t * win)79 lv_obj_t * lv_win_get_header(lv_obj_t * win)
80 {
81     return lv_obj_get_child(win, 0);
82 }
83 
lv_win_get_content(lv_obj_t * win)84 lv_obj_t * lv_win_get_content(lv_obj_t * win)
85 {
86     return lv_obj_get_child(win, 1);
87 }
88 
89 /**********************
90  *   STATIC FUNCTIONS
91  **********************/
92 
lv_win_constructor(const lv_obj_class_t * class_p,lv_obj_t * obj)93 static void lv_win_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
94 {
95     LV_UNUSED(class_p);
96     lv_obj_t * parent = lv_obj_get_parent(obj);
97     lv_obj_set_size(obj, lv_obj_get_width(parent), lv_obj_get_height(parent));
98     lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
99 
100     lv_obj_t * header = lv_obj_create(obj);
101     lv_obj_set_size(header, LV_PCT(100), lv_display_get_dpi(lv_obj_get_display(obj)) / 2);
102     lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
103     lv_obj_set_flex_align(header, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
104 
105     lv_obj_t * cont = lv_obj_create(obj);
106     lv_obj_set_flex_grow(cont, 1);
107     lv_obj_set_width(cont, LV_PCT(100));
108 }
109 
110 #endif
111