@@ -11,22 +11,21 @@ use lvgl::input_device::{
11
11
InputDriver ,
12
12
} ;
13
13
use lvgl:: misc:: anim:: { AnimRepeatCount , Animation } ;
14
- use lvgl:: misc:: area:: LV_SIZE_CONTENT ;
14
+ use lvgl:: misc:: area:: { pct , LV_SIZE_CONTENT } ;
15
15
use lvgl:: style:: { Opacity , Style } ;
16
- use lvgl:: widgets:: { Btn , Btnmatrix , Canvas , Chart , Dropdown , Label } ;
16
+ use lvgl:: widgets:: { Btn , Btnmatrix , Canvas , Chart , Dropdown , Label , Widget } ;
17
17
use lvgl:: { self , NativeObject , Obj } ;
18
- use lvgl:: { Align , Color , Display , DrawBuffer , LvError , Part , Widget } ;
18
+ use lvgl:: { Align , Color , Display , DrawBuffer , LvError , Part } ;
19
19
use lvgl_sys:: {
20
- lv_chart_add_series, lv_chart_type_t, lv_coord_t,
21
- lv_flex_flow_t_LV_FLEX_FLOW_COLUMN, lv_grid_align_t_LV_GRID_ALIGN_CENTER,
22
- lv_grid_align_t_LV_GRID_ALIGN_START, lv_grid_align_t_LV_GRID_ALIGN_STRETCH, lv_label_set_text,
23
- lv_obj_set_grid_cell, lv_obj_set_style_opa, lv_obj_set_width, lv_opa_t,
24
- lv_palette_t_LV_PALETTE_AMBER, lv_palette_t_LV_PALETTE_BLUE, lv_palette_t_LV_PALETTE_BLUE_GREY,
25
- lv_palette_t_LV_PALETTE_BROWN, lv_palette_t_LV_PALETTE_DEEP_ORANGE,
26
- lv_palette_t_LV_PALETTE_DEEP_PURPLE, lv_palette_t_LV_PALETTE_GREY,
27
- lv_palette_t_LV_PALETTE_PURPLE, lv_palette_t_LV_PALETTE_RED, lv_palette_t_LV_PALETTE_TEAL,
28
- LV_CHART_AXIS_PRIMARY_X , LV_CHART_TYPE_BAR , LV_GRID_CONTENT , LV_GRID_TEMPLATE_LAST ,
29
- LV_OBJ_FLAG_HIDDEN , LV_OPA_50 , LV_OPA_70 , LV_OPA_COVER , LV_PART_MAIN ,
20
+ lv_chart_add_series, lv_chart_type_t, lv_coord_t, lv_flex_flow_t_LV_FLEX_FLOW_COLUMN,
21
+ lv_grid_align_t_LV_GRID_ALIGN_CENTER, lv_grid_align_t_LV_GRID_ALIGN_START,
22
+ lv_grid_align_t_LV_GRID_ALIGN_STRETCH, lv_label_set_text, lv_obj_set_grid_cell,
23
+ lv_obj_set_style_opa, lv_obj_set_width, lv_opa_t, lv_palette_t_LV_PALETTE_AMBER,
24
+ lv_palette_t_LV_PALETTE_BLUE, lv_palette_t_LV_PALETTE_BLUE_GREY, lv_palette_t_LV_PALETTE_BROWN,
25
+ lv_palette_t_LV_PALETTE_DEEP_ORANGE, lv_palette_t_LV_PALETTE_DEEP_PURPLE,
26
+ lv_palette_t_LV_PALETTE_GREY, lv_palette_t_LV_PALETTE_PURPLE, lv_palette_t_LV_PALETTE_RED,
27
+ lv_palette_t_LV_PALETTE_TEAL, LV_CHART_AXIS_PRIMARY_X , LV_CHART_TYPE_BAR , LV_GRID_CONTENT ,
28
+ LV_GRID_TEMPLATE_LAST , LV_OBJ_FLAG_HIDDEN , LV_OPA_50 , LV_OPA_70 , LV_OPA_COVER , LV_PART_MAIN ,
30
29
} ;
31
30
use std:: thread:: sleep;
32
31
use std:: time:: Duration ;
@@ -38,27 +37,6 @@ macro_rules! lv_grid_fr {
38
37
lvgl_sys:: LV_COORD_MAX - 100 + $x
39
38
} ;
40
39
}
41
-
42
- // #define _LV_COORD_TYPE_SHIFT (13U)
43
- // #define _LV_COORD_TYPE_SPEC (1 << _LV_COORD_TYPE_SHIFT)
44
- // #define LV_COORD_SET_SPEC(x) ((x) | _LV_COORD_TYPE_SPEC)
45
- macro_rules! lv_coord_set_spec {
46
- ( $x: expr) => {
47
- ( $x) | ( 1 << 13u32 )
48
- } ;
49
- }
50
-
51
- // #define LV_PCT(x) (x < 0 ? LV_COORD_SET_SPEC(1000 - (x)) : LV_COORD_SET_SPEC(x))
52
- macro_rules! lv_pct {
53
- ( $x: literal) => {
54
- if $x < 0 {
55
- lv_coord_set_spec!( 1000 - ( $x) )
56
- } else {
57
- lv_coord_set_spec!( $x)
58
- }
59
- } ;
60
- }
61
-
62
40
macro_rules! lv_canvas_buf_size_indexed_2bit {
63
41
( $w: literal, $h: literal) => {
64
42
( ( ( $w / 4 ) + 1 ) * $h)
@@ -114,53 +92,41 @@ fn main() -> Result<(), LvError> {
114
92
LV_GRID_CONTENT as i16 ,
115
93
LV_GRID_TEMPLATE_LAST as i16 ,
116
94
] ;
117
- unsafe {
118
- lvgl_sys:: lv_obj_set_grid_dsc_array (
119
- screen. raw ( ) . as_ptr ( ) ,
120
- grid_cols. as_ptr ( ) ,
121
- grid_rows. as_ptr ( ) ,
122
- ) ;
123
- }
95
+ screen. set_grid_dsc_array ( & grid_cols[ 0 ] , & grid_rows[ 0 ] ) ;
124
96
125
97
//let chart_type_subject = Subject::new()?;
126
98
//lv_subject_init_int(&chart_type_subject, 0);
127
99
128
100
let mut dropdown = Dropdown :: create ( & mut screen) ?;
129
101
dropdown. set_options ( cstr_core:: cstr!( "Lines\n Bars" ) ) ;
130
- unsafe {
131
- lvgl_sys:: lv_obj_set_grid_cell (
132
- dropdown. raw ( ) . as_ptr ( ) ,
133
- lv_grid_align_t_LV_GRID_ALIGN_CENTER,
134
- 0 ,
135
- 1 ,
136
- lv_grid_align_t_LV_GRID_ALIGN_CENTER,
137
- 0 ,
138
- 1 ,
139
- ) ;
140
- //dropdown.bind_value(&mut chart_type_subject);
141
- dropdown. set_selected ( 1 ) ;
142
- }
102
+ dropdown. set_grid_cell (
103
+ lv_grid_align_t_LV_GRID_ALIGN_CENTER,
104
+ 0 ,
105
+ 1 ,
106
+ lv_grid_align_t_LV_GRID_ALIGN_CENTER,
107
+ 0 ,
108
+ 1 ,
109
+ ) ;
110
+ dropdown. set_selected ( 1 ) ;
143
111
144
112
/*Create a chart with an external array of points*/
113
+ let mut chart = Chart :: create ( & mut screen) ?;
114
+ chart. set_grid_cell (
115
+ lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
116
+ 0 ,
117
+ 1 ,
118
+ lv_grid_align_t_LV_GRID_ALIGN_CENTER,
119
+ 1 ,
120
+ 1 ,
121
+ ) ;
145
122
unsafe {
146
- let mut chart = Chart :: create ( & mut screen) ?;
147
- lvgl_sys:: lv_obj_set_grid_cell (
148
- chart. raw ( ) . as_ptr ( ) ,
149
- lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
150
- 0 ,
151
- 1 ,
152
- lv_grid_align_t_LV_GRID_ALIGN_CENTER,
153
- 1 ,
154
- 1 ,
155
- ) ;
156
-
157
123
let series =
158
124
lvgl_sys:: lv_chart_add_series ( chart. raw ( ) . as_ptr ( ) , c3, LV_CHART_AXIS_PRIMARY_X as u8 ) ;
159
125
160
126
let mut chart_y_array = [ 10 , 25 , 50 , 40 , 30 , 35 , 60 , 65 , 70 , 75 ] ;
161
127
chart. set_ext_y_array ( series. as_mut ( ) . unwrap ( ) , & mut chart_y_array[ 0 ] ) ;
162
- chart. set_type ( LV_CHART_TYPE_BAR as lv_chart_type_t ) ;
163
128
}
129
+ chart. set_type ( LV_CHART_TYPE_BAR as lv_chart_type_t ) ;
164
130
165
131
/*Add custom observer callback*/
166
132
//lv_subject_add_observer_obj(&chart_type_subject, chart_type_observer_cb, chart, NULL);
@@ -169,24 +135,21 @@ fn main() -> Result<(), LvError> {
169
135
//lv_subject_set_int(&chart_type_subject, 1);
170
136
171
137
let mut label = Label :: create ( & mut screen) ?;
172
- unsafe {
173
- lvgl_sys:: lv_obj_set_grid_cell (
174
- label. raw ( ) . as_ptr ( ) ,
175
- lv_grid_align_t_LV_GRID_ALIGN_START,
176
- 1 ,
177
- 1 ,
178
- lv_grid_align_t_LV_GRID_ALIGN_CENTER,
179
- 0 ,
180
- 1 ,
181
- ) ;
182
- }
138
+ label. set_grid_cell (
139
+ lv_grid_align_t_LV_GRID_ALIGN_START,
140
+ 1 ,
141
+ 1 ,
142
+ lv_grid_align_t_LV_GRID_ALIGN_CENTER,
143
+ 0 ,
144
+ 1 ,
145
+ ) ;
183
146
184
147
let mut label_style = Style :: default ( ) ;
185
148
label_style. set_bg_opa ( Opacity :: OPA_70 ) ;
186
149
label_style. set_bg_color ( Color :: from_raw ( c1) ) ;
187
150
label_style. set_text_color ( Color :: from_raw ( c2) ) ;
188
- label. add_style ( Part :: Main , & mut label_style ) ;
189
- label. add_style ( Part :: Main , & mut style_big_font ) ;
151
+ label. add_style ( label_style . into_raw ( ) , Part :: Main . into ( ) ) ;
152
+ label. add_style ( style_big_font . into_raw ( ) , Part :: Main . into ( ) ) ;
190
153
191
154
let mut btnmatrix_options = [
192
155
cstr ! ( "First" ) . as_ptr ( ) ,
@@ -203,33 +166,29 @@ fn main() -> Result<(), LvError> {
203
166
] ;
204
167
205
168
let mut btnmatrix = Btnmatrix :: create ( & mut screen) ?;
169
+ btnmatrix. set_grid_cell (
170
+ lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
171
+ 1 ,
172
+ 1 ,
173
+ lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
174
+ 1 ,
175
+ 1 ,
176
+ ) ;
206
177
unsafe {
207
- lvgl_sys:: lv_obj_set_grid_cell (
208
- btnmatrix. raw ( ) . as_ptr ( ) ,
209
- lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
210
- 1 ,
211
- 1 ,
212
- lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
213
- 1 ,
214
- 1 ,
215
- ) ;
216
178
lvgl_sys:: lv_btnmatrix_set_map ( btnmatrix. raw ( ) . as_ptr ( ) , btnmatrix_options. as_mut_ptr ( ) ) ;
217
- lvgl_sys:: lv_btnmatrix_set_ctrl_map ( btnmatrix. raw ( ) . as_ptr ( ) , btnmatrix_ctrl. as_ptr ( ) ) ;
218
179
}
180
+ btnmatrix. set_ctrl_map ( & btnmatrix_ctrl[ 0 ] ) ;
219
181
220
182
let mut cont = Obj :: create ( & mut screen) ?;
221
- unsafe {
222
- lvgl_sys:: lv_obj_set_grid_cell (
223
- cont. raw ( ) . as_ptr ( ) ,
224
- lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
225
- 2 ,
226
- 1 ,
227
- lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
228
- 0 ,
229
- 2 ,
230
- ) ;
231
- lvgl_sys:: lv_obj_set_flex_flow ( cont. raw ( ) . as_ptr ( ) , lv_flex_flow_t_LV_FLEX_FLOW_COLUMN) ;
232
- }
183
+ cont. set_grid_cell (
184
+ lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
185
+ 2 ,
186
+ 1 ,
187
+ lv_grid_align_t_LV_GRID_ALIGN_STRETCH,
188
+ 0 ,
189
+ 2 ,
190
+ ) ;
191
+ cont. set_flex_flow ( lv_flex_flow_t_LV_FLEX_FLOW_COLUMN) ;
233
192
234
193
let mut btns: Vec < Btn > = Vec :: with_capacity ( 10 ) ;
235
194
let mut labels: Vec < Label > = Vec :: new ( ) ;
@@ -240,11 +199,11 @@ fn main() -> Result<(), LvError> {
240
199
if i == 0 {
241
200
/*let mut a = Animation::new(
242
201
&mut btn,
243
- Duration::from_secs(1 ),
202
+ Duration::from_secs(5 ),
244
203
LV_OPA_COVER as i32,
245
204
LV_OPA_50 as i32,
246
- |obj, val| unsafe {
247
- lv_obj_set_style_opa( obj.raw().as_ptr(), val as lv_opa_t, LV_PART_MAIN );
205
+ |obj, val| {
206
+ obj.set_style_opa( val as lv_opa_t, Part::Main.into() );
248
207
},
249
208
)?;
250
209
a.start();
@@ -258,13 +217,14 @@ fn main() -> Result<(), LvError> {
258
217
}
259
218
260
219
if i == 2 {
261
- // unsafe {
262
- // let mut label = lvgl_sys::lv_obj_get_child(btn.raw().as_ptr(), 0);
263
- // lv_label_set_text(label, cstr!("A multi-line text with a ° symbol").as_ptr());
264
- // lv_obj_set_width(label, lv_pct!(100));
265
- // }
266
- label. set_text ( cstr ! ( "A multi-line text with a ° symbol" ) ) ;
267
- label. set_width ( lv_pct ! ( 100 ) ) ;
220
+ unsafe {
221
+ let mut label = lvgl_sys:: lv_obj_get_child ( btn. raw ( ) . as_ptr ( ) , 0 ) ;
222
+ lv_label_set_text ( label, cstr ! ( "A multi-line text with a ° symbol" ) . as_ptr ( ) ) ;
223
+ lv_obj_set_width ( label, pct ( 100 ) ) ;
224
+ }
225
+ // safe version
226
+ // label.set_text(cstr!("A multi-line text with a ° symbol"));
227
+ // label.set_width(lv_pct!(100));
268
228
}
269
229
270
230
if i == 4 {
@@ -289,17 +249,15 @@ fn main() -> Result<(), LvError> {
289
249
290
250
let mut canvas = Canvas :: create ( & mut screen) ?;
291
251
canvas. set_size ( 400 , 100 ) ;
252
+ canvas. set_grid_cell (
253
+ lv_grid_align_t_LV_GRID_ALIGN_START,
254
+ 0 ,
255
+ 2 ,
256
+ lv_grid_align_t_LV_GRID_ALIGN_START,
257
+ 2 ,
258
+ 1 ,
259
+ ) ;
292
260
unsafe {
293
- let canvas = canvas. raw ( ) . as_ptr ( ) ;
294
- lvgl_sys:: lv_obj_set_grid_cell (
295
- canvas,
296
- lv_grid_align_t_LV_GRID_ALIGN_START,
297
- 0 ,
298
- 2 ,
299
- lv_grid_align_t_LV_GRID_ALIGN_START,
300
- 2 ,
301
- 1 ,
302
- ) ;
303
261
/*lvgl_sys::lv_canvas_set_buffer(
304
262
canvas,
305
263
lvgl_sys::lv_draw_buf_align(canvas_buf, LV_COLOR_FORMAT_RGB565),
@@ -353,7 +311,7 @@ fn main() -> Result<(), LvError> {
353
311
354
312
fn list_button_create < ' a > ( parent : & mut impl NativeObject ) -> Result < ( Btn < ' a > , Label < ' a > ) , LvError > {
355
313
let mut btn = Btn :: create ( parent) ?;
356
- btn. set_size ( lv_pct ! ( 100 ) , LV_SIZE_CONTENT as i16 ) ;
314
+ btn. set_size ( pct ( 100 ) , LV_SIZE_CONTENT as i16 ) ;
357
315
let idx;
358
316
unsafe {
359
317
idx = lvgl_sys:: lv_obj_get_index ( btn. raw ( ) . as_ptr ( ) ) ;
0 commit comments