Skip to content

Commit

Permalink
Fix examples (#183)
Browse files Browse the repository at this point in the history
* Fix arc example compilation

* Fix animation example

* Make bar example compile and run

* Fix button_click example

* bar: Reduce sleep time
  • Loading branch information
C47D authored Dec 22, 2024
1 parent eac71b2 commit 80fd2a7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
8 changes: 4 additions & 4 deletions examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ fn main() -> Result<(), LvError> {

let mut screen_style = Style::default();
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
screen.add_style(Part::Main, &mut screen_style)?;
screen.add_style(Part::Main, &mut screen_style);
// Create the button
let mut button = Btn::create(&mut screen)?;
button.set_align(Align::LeftMid, 30, 0)?;
button.set_size(180, 80)?;
button.set_align(Align::LeftMid, 30, 0);
button.set_size(180, 80);
let mut btn_lbl = Label::create(&mut button)?;
btn_lbl.set_text(CString::new("Click me!").unwrap().as_c_str())?;

let mut btn_state = false;

let mut anim = Animation::new(&mut button, Duration::from_secs(1), 0, 60, |obj, val| {
obj.set_align(Align::LeftMid, val, 0).unwrap()
obj.set_align(Align::LeftMid, val, 0)
})?;
anim.set_repeat_count(AnimRepeatCount::Infinite);
anim.start();
Expand Down
14 changes: 7 additions & 7 deletions examples/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ fn main() -> Result<(), LvError> {
let mut screen_style = Style::default();
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
screen_style.set_radius(0);
screen.add_style(Part::Main, &mut screen_style)?;
screen.add_style(Part::Main, &mut screen_style);

// Create the arc object
let mut arc = Arc::create(&mut screen)?;
arc.set_size(150, 150)?;
arc.set_align(Align::Center, 0, 10)?;
arc.set_start_angle(135)?;
arc.set_end_angle(135)?;
arc.set_size(150, 150);
arc.set_align(Align::Center, 0, 10);
arc.set_start_angle(135);
arc.set_end_angle(135);

let mut loading_lbl = Label::create(&mut screen)?;
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str())?;
loading_lbl.set_align(Align::OutTopMid, 0, 0)?;
loading_lbl.set_align(Align::OutTopMid, 0, 0);
//loading_lbl.set_label_align(LabelAlign::Center)?;

let mut loading_style = Style::default();
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
loading_lbl.add_style(Part::Main, &mut loading_style)?;
loading_lbl.add_style(Part::Main, &mut loading_style);

let mut angle = 0;
let mut forward = true;
Expand Down
19 changes: 11 additions & 8 deletions examples/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ fn main() -> Result<(), LvError> {
let mut screen_style = Style::default();
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
screen_style.set_radius(0);
screen.add_style(Part::Main, &mut screen_style)?;
screen.add_style(Part::Main, &mut screen_style);

// Create the bar object
let mut bar = Bar::create(&mut screen)?;
bar.set_size(175, 20)?;
bar.set_align(Align::Center, 0, 10)?;
bar.set_size(175, 20);
bar.set_align(Align::Center, 0, 10);
bar.set_range(0, 100)?;
bar.on_event(|_b, _e| {
println!("Completed!");
Expand All @@ -47,24 +47,27 @@ fn main() -> Result<(), LvError> {
// Set the indicator style for the bar object
let mut ind_style = Style::default();
ind_style.set_bg_color(Color::from_rgb((100, 245, 100)));
bar.add_style(Part::Any, &mut ind_style)?;
bar.add_style(Part::Any, &mut ind_style);

let mut loading_lbl = Label::create(&mut screen)?;
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str())?;
loading_lbl.set_align(Align::OutTopMid, 0, 0)?;
loading_lbl.set_align(Align::OutTopMid, 0, 0);

let mut loading_style = Style::default();
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
loading_lbl.add_style(Part::Main, &mut loading_style)?;
loading_lbl.add_style(Part::Main, &mut loading_style);

let mut i = 0;
'running: loop {
let start = Instant::now();
if i > 100 {
i = 0;
lvgl::event_send(&mut bar, Event::Clicked)?;
// Enabling this line gives the followong errors:
// - error[E0597]: `ind_style` does not live long enough when adding an style to the bar
// - implementation of `Widget` is not general enough
// lvgl::event_send(&mut bar, Event::Clicked);
}
bar.set_value(i, AnimationState::ON)?;
bar.set_value(i, AnimationState::ON);
i += 1;

lvgl::task_handler();
Expand Down
6 changes: 3 additions & 3 deletions examples/button_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ fn main() -> Result<(), LvError> {

let mut screen_style = Style::default();
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
screen.add_style(Part::Main, &mut screen_style)?;
screen.add_style(Part::Main, &mut screen_style);
// Create the button
let mut button = Btn::create(&mut screen)?;
button.set_align(Align::LeftMid, 30, 0)?;
button.set_size(180, 80)?;
button.set_align(Align::LeftMid, 30, 0);
button.set_size(180, 80);
let mut btn_lbl = Label::create(&mut button)?;
btn_lbl.set_text(CString::new("Click me!").unwrap().as_c_str())?;

Expand Down

0 comments on commit 80fd2a7

Please sign in to comment.