This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
custom_widget.c
202 lines (164 loc) · 5.15 KB
/
custom_widget.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "custom_widget.h"
#include "dataset.h"
#include "setting.h"
#include <stdio.h>
typedef struct
{
lv_cont_ext_t cont;
lv_obj_t * title;
lv_obj_t * ta;
lv_obj_t * lb_plus;
lv_obj_t * lb_minus;
}tbox_ext_t;
lv_obj_t * layerview_base = NULL;
lv_obj_t * scr1 = NULL;
lv_obj_t * sel_layer = NULL;
static void update_sel_cb(lv_obj_t * obj, lv_event_t ev);
lv_obj_t * tbox_create(lv_obj_t * par, char * title)
{
lv_obj_t * cont = lv_cont_create(par, NULL);
lv_cont_set_fit2(cont, LV_FIT_FLOOD, LV_FIT_TIGHT);
lv_cont_set_layout(cont, LV_LAYOUT_ROW_M);
tbox_ext_t * ext = lv_obj_allocate_ext_attr(cont, sizeof(tbox_ext_t));
ext->title = lv_label_create(cont, NULL);
lv_label_set_text(ext->title, title);
ext->ta = lv_ta_create(cont, NULL);
lv_ta_set_one_line(ext->ta, true);
lv_ta_set_text(ext->ta, "");
lv_ta_set_cursor_type(ext->ta, LV_CURSOR_NONE);
lv_ta_set_cursor_blink_time(ext->ta, 0);
ext->lb_plus = lv_label_create(ext->ta, NULL);
lv_label_set_text(ext->lb_plus, LV_SYMBOL_PLUS);
lv_obj_align(ext->lb_plus, ext->ta, LV_ALIGN_IN_RIGHT_MID, 0, 0);
lv_obj_set_click(ext->lb_plus, true);
ext->lb_minus = lv_label_create(ext->ta, ext->lb_plus);
lv_label_set_text(ext->lb_minus, LV_SYMBOL_MINUS" ");
lv_obj_align(ext->lb_minus, ext->lb_plus, LV_ALIGN_OUT_LEFT_MID, 0, 0);
lv_obj_set_click(ext->lb_minus, true);
return cont;
}
lv_obj_t * tbox_get_ta(lv_obj_t * tbox)
{
tbox_ext_t * ext = lv_obj_get_ext_attr(tbox);
return ext->ta;
}
lv_obj_t * layerview_init(lv_obj_t * win) //This is only a layer
{
lv_obj_t * layer_base = lv_cont_create(win, NULL);
lv_cont_set_fit4(layer_base, LV_FIT_FLOOD, LV_FIT_FLOOD, LV_FIT_TIGHT, LV_FIT_TIGHT);
lv_cont_set_layout(layer_base, LV_LAYOUT_PRETTY);
lv_obj_t * title = lv_label_create(layer_base, NULL);
lv_label_set_text(title, "[Layer View]");
layerview_base = layer_base;
return layer_base;
//todo:Del Button
}
//Create a newlayer by a obj on Simulator, use obj's TYPE && ID to set title
lv_obj_t * layerview_add(lv_obj_t * par_layer, lv_obj_t * obj)
{
if(par_layer == NULL)
{
return NULL;
}
lv_obj_t * layer = lv_cont_create(par_layer, NULL);
lv_cont_set_fit4(layer, LV_FIT_FLOOD, LV_FIT_FLOOD, LV_FIT_TIGHT, LV_FIT_TIGHT);
lv_cont_set_layout(layer, LV_LAYOUT_COL_L);
layerview_ext_t * ext = lv_obj_allocate_ext_attr(layer, sizeof(layerview_ext_t));
ext->bind = obj;
ext->title = lv_label_create(layer, NULL);
ext->child = NULL;
ext->left = NULL;
ext->right = NULL;
widget_info_t * info = lv_obj_get_user_data(obj);
// lv_obj_set_click(ext->title, true);
// lv_obj_set_user_data(ext->title, obj); //Bind label with obj by user_data
lv_label_set_text(ext->title, widget_get_type_name(info->type));
layerview_ext_t * par_ext = lv_obj_get_ext_attr(par_layer);
if(par_ext->child == NULL)
{
par_ext->child = layer;
}else
{
layerview_add_bro(layer, par_ext->child);
}
lv_obj_set_event_cb(layer, update_sel_cb);
return layer;
}
lv_obj_t * layerview_get_base(void)
{
return layerview_base;
}
lv_obj_t * layerview_get_sel_obj(void)
{
if (sel_layer)
{
layerview_ext_t * ext = lv_obj_get_ext_attr(sel_layer);
return ext->bind;
}
return NULL;
}
lv_obj_t * layerview_get_sel_layer(void)
{
return sel_layer;
}
void layerview_add_bro(lv_obj_t * left_layer, lv_obj_t * layer)
{
layerview_ext_t * left_ext = lv_obj_get_ext_attr(left_layer);
if(left_ext->right == NULL)
{
layerview_ext_t * ext = lv_obj_get_ext_attr(layer);
ext->left = left_layer;
left_ext->right = layer;
}else
{
layerview_add_bro(left_ext->right, layer);
}
}
void layerview_del(lv_obj_t * layer) //Delete a layer and its child && move its brother layer
{
if(layer == NULL)
{
return;
}
lv_obj_t * par_layer = lv_obj_get_parent(layer);
if(par_layer == layerview_base) //Now we can't delete the screen(TFT Simulator)
{
return;
}
layerview_ext_t * par_ext = lv_obj_get_ext_attr(par_layer);
layerview_ext_t * ext = lv_obj_get_ext_attr(layer);
if(layer == par_ext->child)
{
par_ext->child = ext->right;
if(ext->right != NULL)
{
layerview_ext_t * right_ext = lv_obj_get_ext_attr(ext->right);
right_ext->left = NULL;
}
}else
{
layerview_ext_t * left_ext = lv_obj_get_ext_attr(ext->left);
left_ext->right = ext->right;
if(ext->right != NULL)
{
layerview_ext_t * right_ext = lv_obj_get_ext_attr(ext->right);
right_ext->left = ext->left;
}
}
lv_obj_del(ext->bind);
lv_obj_del(layer);
}
void layerview_del_sel(void) //Delete the selected layer & bind obj
{
layerview_del(sel_layer);
sel_layer = NULL;
}
static void update_sel_cb(lv_obj_t * layer, lv_event_t ev)
{
if(ev == LV_EVENT_CLICKED)
{
sel_layer = layer;
layerview_ext_t * ext = lv_obj_get_ext_attr(layer);
lb_selected_mod(ext->bind);
}
}