Skip to content

Commit 5581ac4

Browse files
committed
fix examples
1 parent fedc960 commit 5581ac4

File tree

7 files changed

+41
-40
lines changed

7 files changed

+41
-40
lines changed

examples/animation.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use lvgl::input_device::{
1212
};
1313
use lvgl::misc::anim::{AnimRepeatCount, Animation};
1414
use lvgl::style::Style;
15-
use lvgl::widgets::{Btn, Label};
16-
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, Widget};
15+
use lvgl::widgets::{Btn, Label, Widget};
16+
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part};
1717
use std::thread::sleep;
1818
use std::time::Duration;
1919
use std::time::Instant;
@@ -46,18 +46,18 @@ fn main() -> Result<(), LvError> {
4646

4747
let mut screen_style = Style::default();
4848
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
49-
screen.add_style(Part::Main, &mut screen_style);
49+
screen.add_style(screen_style.into_raw(), Part::Main.into());
5050
// Create the button
5151
let mut button = Btn::create(&mut screen)?;
52-
button.set_align(Align::LeftMid, 30, 0);
52+
button.align(Align::LeftMid.into(), 30, 0);
5353
button.set_size(180, 80);
5454
let mut btn_lbl = Label::create(&mut button)?;
5555
btn_lbl.set_text(CString::new("Click me!").unwrap().as_c_str());
5656

5757
let mut btn_state = false;
5858

5959
let mut anim = Animation::new(&mut button, Duration::from_secs(1), 0, 60, |obj, val| {
60-
obj.set_align(Align::LeftMid, val, 0)
60+
obj.align(Align::LeftMid.into(), val as i16, 0)
6161
})?;
6262
anim.set_repeat_count(AnimRepeatCount::Infinite);
6363
anim.start();

examples/arc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use embedded_graphics_simulator::{
66
};
77
use lvgl;
88
use lvgl::style::Style;
9-
use lvgl::widgets::{Arc, Label};
10-
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, Widget};
9+
use lvgl::widgets::{Arc, Label, Widget};
10+
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part};
1111
use lvgl_sys;
1212
use std::thread::sleep;
1313
use std::time::Duration;
@@ -52,23 +52,23 @@ fn main() -> Result<(), LvError> {
5252
let mut screen_style = Style::default();
5353
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
5454
screen_style.set_radius(0);
55-
screen.add_style(Part::Main, &mut screen_style);
55+
screen.add_style(screen_style.into_raw(), Part::Main.into());
5656

5757
// Create the arc object
5858
let mut arc = Arc::create(&mut screen)?;
5959
arc.set_size(150, 150);
60-
arc.set_align(Align::Center, 0, 10);
60+
arc.align(Align::Center.into(), 0, 10);
6161
arc.set_start_angle(135);
6262
arc.set_end_angle(135);
6363

6464
let mut loading_lbl = Label::create(&mut screen)?;
6565
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str());
66-
loading_lbl.set_align(Align::OutTopMid, 0, 0);
66+
loading_lbl.align(Align::OutTopMid.into(), 0, 0);
6767
//loading_lbl.set_label_align(LabelAlign::Center)?;
6868

6969
let mut loading_style = Style::default();
7070
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
71-
loading_lbl.add_style(Part::Main, &mut loading_style);
71+
loading_lbl.add_style(loading_style.into_raw(), Part::Main.into());
7272

7373
let mut angle = 0;
7474
let mut forward = true;

examples/bar.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use embedded_graphics_simulator::{
66
};
77
use lvgl;
88
use lvgl::style::Style;
9-
use lvgl::widgets::{Bar, Label};
10-
use lvgl::{Align, AnimationState, Color, Display, DrawBuffer, Event, LvError, Part, Widget};
9+
use lvgl::widgets::{Bar, Label, Widget};
10+
use lvgl::{Align, AnimationState, Color, Display, DrawBuffer, Event, LvError, Part};
1111
use std::thread::sleep;
1212
use std::time::Duration;
1313
use std::time::Instant;
@@ -33,12 +33,12 @@ fn main() -> Result<(), LvError> {
3333
let mut screen_style = Style::default();
3434
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
3535
screen_style.set_radius(0);
36-
screen.add_style(Part::Main, &mut screen_style);
36+
screen.add_style(screen_style.into_raw(), Part::Main.into());
3737

3838
// Create the bar object
3939
let mut bar = Bar::create(&mut screen)?;
4040
bar.set_size(175, 20);
41-
bar.set_align(Align::Center, 0, 10);
41+
bar.align(Align::Center.into(), 0, 10);
4242
bar.set_range(0, 100);
4343
bar.on_event(|_b, _e| {
4444
println!("Completed!");
@@ -47,15 +47,15 @@ fn main() -> Result<(), LvError> {
4747
// Set the indicator style for the bar object
4848
let mut ind_style = Style::default();
4949
ind_style.set_bg_color(Color::from_rgb((100, 245, 100)));
50-
bar.add_style(Part::Any, &mut ind_style);
50+
bar.add_style(ind_style.into_raw(), Part::Any.into());
5151

5252
let mut loading_lbl = Label::create(&mut screen)?;
5353
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str());
54-
loading_lbl.set_align(Align::OutTopMid, 0, 0);
54+
loading_lbl.align(Align::OutTopMid.into(), 0, 0);
5555

5656
let mut loading_style = Style::default();
5757
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
58-
loading_lbl.add_style(Part::Main, &mut loading_style);
58+
loading_lbl.add_style(loading_style.into_raw(), Part::Main.into());
5959

6060
let mut i = 0;
6161
'running: loop {

examples/button_click.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use lvgl::input_device::{
1111
InputDriver,
1212
};
1313
use lvgl::style::Style;
14-
use lvgl::widgets::{Btn, Label};
15-
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, Widget};
14+
use lvgl::widgets::{Btn, Label, Widget};
15+
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part};
1616
use std::thread::sleep;
1717
use std::time::Duration;
1818
use std::time::Instant;
@@ -45,10 +45,10 @@ fn main() -> Result<(), LvError> {
4545

4646
let mut screen_style = Style::default();
4747
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
48-
screen.add_style(Part::Main, &mut screen_style);
48+
screen.add_style(screen_style.into_raw(), Part::Main.into());
4949
// Create the button
5050
let mut button = Btn::create(&mut screen)?;
51-
button.set_align(Align::LeftMid, 30, 0);
51+
button.align(Align::LeftMid.into(), 30, 0);
5252
button.set_size(180, 80);
5353
let mut btn_lbl = Label::create(&mut button)?;
5454
btn_lbl.set_text(CString::new("Click me!").unwrap().as_c_str());

examples/demo.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use embedded_graphics_simulator::{
77
use lvgl;
88
use lvgl::font::Font;
99
use lvgl::style::Style;
10-
use lvgl::widgets::Label;
11-
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, TextAlign, Widget};
10+
use lvgl::widgets::{Label, Widget};
11+
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, TextAlign};
1212
use lvgl_sys;
1313
use std::thread::sleep;
1414
use std::time::Duration;
@@ -35,14 +35,14 @@ fn main() -> Result<(), LvError> {
3535

3636
// Create screen and widgets
3737
let binding = display?;
38-
let screen = binding.get_scr_act();
38+
let mut screen = binding.get_scr_act()?;
3939

4040
println!("Before all widgets: {:?}", mem_info());
4141

4242
let mut screen_style = Style::default();
4343
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
4444
screen_style.set_radius(0);
45-
screen?.add_style(Part::Main, &mut screen_style);
45+
screen.add_style(screen_style.into_raw(), Part::Main.into());
4646

4747
let mut time = Label::from("20:46");
4848
let mut style_time = Style::default();
@@ -52,22 +52,22 @@ fn main() -> Result<(), LvError> {
5252
// See font module documentation for an explanation of the unsafe block
5353
style_time.set_text_font(unsafe { Font::new_raw(lvgl_sys::noto_sans_numeric_80) });
5454

55-
time.add_style(Part::Main, &mut style_time);
56-
time.set_align(Align::Center, 0, 90);
55+
time.add_style(style_time.into_raw(), Part::Main.into());
56+
time.align(Align::Center.into(), 0, 90);
5757
time.set_width(240);
5858
time.set_height(240);
5959

6060
let mut bt = Label::from("#5794f2 \u{F293}#");
6161
bt.set_width(50);
6262
bt.set_height(80);
6363
let _ = bt.set_recolor(true);
64-
bt.set_align(Align::TopLeft, 0, 0);
64+
bt.align(Align::TopLeft.into(), 0, 0);
6565

6666
let mut power: Label = "#fade2a 20%#".into();
6767
let _ = power.set_recolor(true);
6868
power.set_width(80);
6969
power.set_height(20);
70-
power.set_align(Align::TopRight, 40, 0);
70+
power.align(Align::TopRight.into(), 40, 0);
7171

7272
let mut i = 0;
7373
'running: loop {

examples/rust_timer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use embedded_graphics_simulator::{
66
};
77
use lvgl;
88
use lvgl::style::Style;
9-
use lvgl::widgets::{Bar, Label};
10-
use lvgl::{Align, AnimationState, Color, Display, DrawBuffer, Event, LvError, Part, Widget};
9+
use lvgl::widgets::{Bar, Label, Widget};
10+
use lvgl::{Align, AnimationState, Color, Display, DrawBuffer, Event, LvError, Part};
1111
use std::thread::sleep;
1212
use std::time::Duration;
1313
use std::time::Instant;
@@ -53,12 +53,12 @@ fn main() -> Result<(), LvError> {
5353
let mut screen_style = Style::default();
5454
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
5555
screen_style.set_radius(0);
56-
screen.add_style(Part::Main, &mut screen_style);
56+
screen.add_style(screen_style.into_raw(), Part::Main.into());
5757

5858
// Create the bar object
5959
let mut bar = Bar::create(&mut screen)?;
6060
bar.set_size(175, 20);
61-
bar.set_align(Align::Center, 0, 10);
61+
bar.align(Align::Center.into(), 0, 10);
6262
bar.set_range(0, 100);
6363
bar.on_event(|_b, _e| {
6464
println!("Completed!");
@@ -67,15 +67,15 @@ fn main() -> Result<(), LvError> {
6767
// Set the indicator style for the bar object
6868
let mut ind_style = Style::default();
6969
ind_style.set_bg_color(Color::from_rgb((100, 245, 100)));
70-
bar.add_style(Part::Any, &mut ind_style);
70+
bar.add_style(ind_style.into_raw(), Part::Main.into());
7171

7272
let mut loading_lbl = Label::create(&mut screen)?;
7373
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str());
74-
loading_lbl.set_align(Align::OutTopMid, 0, 0);
74+
loading_lbl.align(Align::OutTopMid.into(), 0, 0);
7575

7676
let mut loading_style = Style::default();
7777
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
78-
loading_lbl.add_style(Part::Main, &mut loading_style);
78+
loading_lbl.add_style(loading_style.into_raw(), Part::Main.into());
7979

8080
let mut i = 0;
8181
let clock = Clock::default();

examples/sdl.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use lvgl::input_device::InputDriver;
88
use lvgl::lv_drv_disp_sdl;
99
use lvgl::lv_drv_input_pointer_sdl;
1010
use lvgl::style::Style;
11+
use lvgl::widgets::Widget;
1112
use lvgl::widgets::{Btn, Label};
1213
use lvgl::LvResult;
13-
use lvgl::{Align, Color, DrawBuffer, Part, Widget};
14+
use lvgl::{Align, Color, DrawBuffer, Part};
1415
use std::thread::sleep;
1516
use std::time::Duration;
1617
use std::time::Instant;
@@ -28,10 +29,10 @@ fn main() -> LvResult<()> {
2829

2930
let mut screen_style = Style::default();
3031
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
31-
screen.add_style(Part::Main, &mut screen_style);
32+
screen.add_style(screen_style.into_raw(), Part::Main.into());
3233
// Create the button
3334
let mut button = Btn::create(&mut screen)?;
34-
button.set_align(Align::LeftMid, 30, 0);
35+
button.align(Align::LeftMid.into(), 30, 0);
3536
button.set_size(180, 80);
3637
let mut btn_lbl = Label::create(&mut button)?;
3738
btn_lbl.set_text(CString::new("Click me!").unwrap().as_c_str());

0 commit comments

Comments
 (0)