Skip to content

Commit 47ad4d0

Browse files
committed
cleanup examples
1 parent cfb85a4 commit 47ad4d0

18 files changed

+572
-57
lines changed
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<component>
2+
23
<api>
34
<prop name="text" type="string" default="Button"/>
45
</api>
6+
7+
<consts>
8+
<color name="dark_color" value="0x222222"/>
9+
</consts>
10+
511
<styles>
6-
<style name="main" bg_color="0x22222" border_width="2" border_color="0x333333" radius="100"/>
12+
<style name="main" bg_color="#dark_color" border_width="2" border_color="0x555555" radius="100"/>
713
</styles>
8-
<view extends="lv_button" styles="main" width="$my_width">
14+
15+
<view extends="lv_button" styles="main">
916
<h2 text="$text" align="center"/>
1017
</view>
1118
</component>
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<component>
2+
3+
<api>
4+
<prop name="text" type="string" default="Button"/>
5+
</api>
6+
27
<styles>
3-
<style name="main" bg_color="0xff3322" text_color="0xffffff" border_color="0x333333" radius="100"/>
8+
<style name="main" bg_color="0xff3322" border_width="2" border_color="0x555555" radius="100"/>
49
</styles>
5-
<view extends="button_default" styles="main" text="$text">
6-
</view>
7-
</component>
10+
11+
<view extends="lv_button" styles="main">
12+
<h2 text="$text" align="center"/>
13+
</view>
14+
</component>
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<component>
2+
3+
<api>
4+
<prop name="text" type="string" default="Button"/>
5+
</api>
6+
27
<styles>
3-
<style name="main" bg_color="0xffbb44" text_color="0x000000" border_color="0x333333" radius="100"/>
8+
<style name="main" bg_color="0xffbb44" border_width="2" border_color="0x555555" radius="100"/>
49
</styles>
5-
<view extends="button_default" styles="main" text="$text">
10+
11+
<view extends="lv_button" styles="main">
12+
<h2 text="$text" align="center"/>
613
</view>
7-
</component>
14+
</component>

examples/components/headings/h1.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
<component>
1+
<component>
2+
<api>
3+
<prop name="text" type="string" default="Label"/>
4+
</api>
5+
26
<styles>
3-
<style name="main" text_font="lv_montserrat_18" />
7+
<style name="main" text_font="arial_22" />
48
</styles>
5-
<view extends="lv_label" styles="main">
9+
10+
<view extends="lv_label" styles="main" text="$text">
611
</view>
712
</component>

examples/components/headings/h2.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<component>
2+
<api>
3+
<prop name="text" type="string" default="Label"/>
4+
</api>
5+
26
<styles>
3-
<style name="main" text_font="lv_montserrat_16"/>
7+
<style name="main" text_font="arial_18"/>
48
</styles>
9+
510
<view extends="lv_label" styles="main" text="$text">
611
</view>
712
</component>

examples/components/headings/h3.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<component>
2+
<api>
3+
<prop name="text" type="string" default="Label"/>
4+
</api>
5+
26
<styles>
3-
<style name="main" text_font="lv_montserrat_14" />
7+
<style name="main" text_font="arial_14"/>
48
</styles>
5-
<view extends="lv_label" styles="main">
9+
10+
<view extends="lv_label" styles="main" text="$text">
611
</view>
712
</component>

examples/components/home.xml

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,54 @@
11
<component>
2-
<view extends="lv_obj" width="100%" height="100%" style_radius="0" style_border_width="0">
3-
<lv_obj flex_flow="column" width="50%" height="100%">
4-
<slider_box title="First"/>
5-
<slider_box title="Temperature of the Living room"/>
6-
<slider_box title="The last one"/>
7-
</lv_obj>
2+
<styles>
3+
<style name="main"
4+
bg_color="0x000000"
5+
radius="0"
6+
border_width="0"
7+
layout="flex"
8+
flex_flow="row"
9+
width="100%" height="100%"
10+
pad_all="0"
11+
pad_column="0"/>
12+
13+
<style name="cont"
14+
height="100%"
15+
bg_color="0x333333"
16+
flex_flow="column"
17+
layout="flex"
18+
radius="0"
19+
pad_all="0"
20+
border_width="2" />
21+
22+
<style name="left_cont"
23+
width="content"/>
24+
825

9-
<button_error text="Default" align="center"/>
26+
<style name="right_cont"
27+
layout="flex"
28+
bg_opa="130"
29+
border_width="0"
30+
flex_flow="column"
31+
flex_track_place="center"
32+
flex_cross_place="center"
33+
pad_all="16"
34+
/>
35+
</styles>
36+
37+
<view extends="lv_obj" styles="main">
38+
<lv_obj styles="cont left_cont">
39+
<slider_box/>
40+
<slider_box/>
41+
<slider_box/>
42+
</lv_obj>
43+
44+
<lv_obj styles="cont right_cont" flex_grow="1">
45+
<button_default text="First button"/>
46+
<button_default text="Second button"/>
47+
<dark_slider width="100" height="15" color="0xff0000"/>
48+
<button_warning text="Third button"/>
49+
<button_warning text="Forth button"/>
50+
<button_error text="Fifth button"/>
51+
<button_error text="Sixth button"/>
52+
</lv_obj>
1053
</view>
11-
</component>
54+
</component>

examples/widgets/dark_slider/dark_slider.c

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
* GLOBAL FUNCTIONS
3333
**********************/
3434

35+
void dark_slider_set_color(lv_obj_t * obj, lv_color_t c)
36+
{
37+
lv_obj_set_style_bg_color(obj, c, LV_PART_INDICATOR);
38+
lv_obj_set_style_bg_color(obj, lv_color_darken(c, 80), LV_PART_INDICATOR | LV_STATE_PRESSED);
39+
}
40+
3541
void dark_slider_constructor_hook(lv_obj_t * obj)
3642
{
3743

@@ -44,11 +50,57 @@ void dark_slider_destructor_hook(lv_obj_t * obj)
4450

4551
void dark_slider_event_hook(lv_event_t * e)
4652
{
47-
53+
lv_event_code_t code = lv_event_get_code(e);
54+
lv_obj_t * obj = lv_event_get_target(e);
55+
56+
if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
57+
int32_t * s = lv_event_get_param(e);
58+
*s = LV_MAX(*s, 60);
59+
}
60+
else if(code == LV_EVENT_DRAW_TASK_ADDED) {
61+
lv_draw_task_t * draw_task = lv_event_get_param(e);
62+
if(draw_task == NULL || lv_draw_task_get_type(draw_task) != LV_DRAW_TASK_TYPE_FILL) return;
63+
lv_draw_rect_dsc_t * draw_rect_dsc = lv_draw_task_get_draw_dsc(draw_task);
64+
65+
if(draw_rect_dsc->base.part == LV_PART_KNOB && lv_obj_has_state(obj, LV_STATE_PRESSED)) {
66+
char buf[8];
67+
lv_snprintf(buf, sizeof(buf), "%"LV_PRId32, lv_slider_get_value(obj));
68+
69+
lv_point_t text_size;
70+
lv_text_get_size(&text_size, buf, LV_FONT_DEFAULT, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE);
71+
72+
lv_area_t txt_area;
73+
lv_area_t draw_task_area;
74+
lv_draw_task_get_area(draw_task, &draw_task_area);
75+
txt_area.x1 = draw_task_area.x1 + lv_area_get_width(&draw_task_area) / 2 - text_size.x / 2;
76+
txt_area.x2 = txt_area.x1 + text_size.x;
77+
txt_area.y2 = draw_task_area.y1 - 10;
78+
txt_area.y1 = txt_area.y2 - text_size.y;
79+
80+
lv_area_t bg_area;
81+
bg_area.x1 = txt_area.x1 - LV_DPX(8);
82+
bg_area.x2 = txt_area.x2 + LV_DPX(8);
83+
bg_area.y1 = txt_area.y1 - LV_DPX(8);
84+
bg_area.y2 = txt_area.y2 + LV_DPX(8);
85+
86+
lv_draw_rect_dsc_t rect_dsc;
87+
lv_draw_rect_dsc_init(&rect_dsc);
88+
rect_dsc.bg_color = lv_palette_darken(LV_PALETTE_GREY, 3);
89+
rect_dsc.radius = LV_DPX(5);
90+
lv_draw_rect(draw_rect_dsc->base.layer, &rect_dsc, &bg_area);
91+
92+
lv_draw_label_dsc_t label_dsc;
93+
lv_draw_label_dsc_init(&label_dsc);
94+
label_dsc.color = lv_color_white();
95+
label_dsc.text = buf;
96+
label_dsc.text_local = 1;
97+
lv_draw_label(draw_rect_dsc->base.layer, &label_dsc, &txt_area);
98+
}
99+
}
48100
}
49101

50102

51103

52104
/**********************
53105
* STATIC FUNCTIONS
54-
**********************/
106+
**********************/
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
<widget>
2+
<api>
3+
<prop name="color" type="color"/>
4+
</api>
5+
26
<styles>
37
<style name="main"
48
bg_color="0x333333" bg_opa="255"
59
border_width="2" border_color="0xaaaaaa"
610
radius="100"
711
width="120"
8-
pad_all="3"/>
12+
height="16"
13+
pad_all="4"/>
914
<style name="light_knob"
1015
bg_color="0xeeeeee" bg_opa="255"
11-
border_width="2" border_color="0xaaaaaa" pad_all="10"/>
16+
border_width="2" radius="100" border_color="0xaaaaaa" pad_all="5"/>
1217
<style name="blue_indicator"
13-
bg_color="0x0000ff" bg_opa="255"/>
18+
bg_color="0x0000ff" bg_opa="255"
19+
radius="100"/>
1420
</styles>
1521
<view extends="lv_slider"
1622
styles="main light_knob:knob blue_indicator:indicator"
17-
align="center">
23+
align="center" value="30" range="20 40">
1824
</view>
1925
</widget>

examples/widgets/dark_slider/dark_slider_gen.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ static void dark_slider_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
7878

7979
if(!style_main_inited) {
8080
lv_style_init(&style_main);
81-
lv_style_set_bg_color(&style_main, lv_color_hex(0x333333));
81+
lv_style_set_bg_color(&style_main, lv_color_hex(0x333333));
8282
lv_style_set_border_width(&style_main, 2);
83+
lv_style_set_bg_opa(&style_main, 255);
8384
lv_style_set_radius(&style_main, 100);
8485
style_main_inited = true;
8586
}
@@ -91,26 +92,29 @@ static void dark_slider_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
9192

9293
if(!style_light_knob_inited) {
9394
lv_style_init(&style_light_knob);
94-
lv_style_set_bg_color(&style_light_knob, lv_color_hex(0xeeeeee));
95+
lv_style_set_bg_color(&style_light_knob, lv_color_hex(0xeeeeee));
96+
lv_style_set_bg_opa(&style_light_knob, 255);
9597
lv_style_set_border_width(&style_light_knob, 2);
98+
lv_style_set_radius(&style_light_knob, 10);
9699
style_light_knob_inited = true;
97100
}
98101

99-
lv_obj_add_style(obj, &style_light_knob, LV_PART_MAIN | LV_STATE_DEFAULT);
102+
lv_obj_add_style(obj, &style_light_knob, LV_PART_KNOB | LV_STATE_DEFAULT);
100103

101104
static lv_style_t style_blue_indicator;
102105
static bool style_blue_indicator_inited = false;
103106

104107
if(!style_blue_indicator_inited) {
105108
lv_style_init(&style_blue_indicator);
106-
lv_style_set_bg_color(&style_blue_indicator, lv_color_hex(0x0000ff));
109+
lv_style_set_bg_color(&style_blue_indicator, lv_color_hex(0x0000ff));
110+
lv_style_set_bg_opa(&style_blue_indicator, 255);
107111
style_blue_indicator_inited = true;
108112
}
109113

110-
lv_obj_add_style(obj, &style_blue_indicator, LV_PART_MAIN | LV_STATE_DEFAULT);
114+
lv_obj_add_style(obj, &style_blue_indicator, LV_PART_INDICATOR | LV_STATE_DEFAULT);
111115

116+
lv_obj_add_flag(obj, LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS);
112117
dark_slider_t * dark_slider = (dark_slider_t *)obj;
113-
114118

115119
dark_slider_constructor_hook(obj);
116120

0 commit comments

Comments
 (0)