From 85bc5f6dcf95d15f943320ac3cea606a1a5b946b Mon Sep 17 00:00:00 2001 From: C47D Date: Sun, 24 Nov 2024 14:07:05 -0600 Subject: [PATCH] Make bar example compile and run --- examples/bar.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/bar.rs b/examples/bar.rs index 1ee52948..1b671ec1 100644 --- a/examples/bar.rs +++ b/examples/bar.rs @@ -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!"); @@ -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(); @@ -76,7 +79,7 @@ fn main() -> Result<(), LvError> { _ => {} } } - sleep(Duration::from_millis(15)); + sleep(Duration::from_millis(1500)); lvgl::tick_inc(Instant::now().duration_since(start)); }