Possible to set values in the bar widget with animations
This commit is contained in:
parent
e0e3924789
commit
cb8a78137d
3 changed files with 21 additions and 6 deletions
|
@ -3,7 +3,7 @@ use embedded_graphics::prelude::*;
|
|||
use embedded_graphics_simulator::{
|
||||
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
|
||||
};
|
||||
use lvgl::{self, widgets::Bar, Align, Color, DisplayDriver, Label, Object, Style, UI};
|
||||
use lvgl::{self, widgets::Bar, Align, Animation, Color, DisplayDriver, Label, Object, Style, UI};
|
||||
use lvgl_sys;
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::thread::sleep;
|
||||
|
@ -38,7 +38,7 @@ fn main() -> Result<(), String> {
|
|||
bar.set_size(175, 50);
|
||||
bar.set_align(&mut screen, Align::Center, 0, 0);
|
||||
bar.set_range(0, 100);
|
||||
bar.set_value(0);
|
||||
bar.set_value(0, Animation::OFF);
|
||||
|
||||
let mut loading_lbl = Label::new(&mut screen);
|
||||
loading_lbl.set_text("Loading...");
|
||||
|
@ -67,7 +67,7 @@ fn main() -> Result<(), String> {
|
|||
if i > 100 {
|
||||
i = 0;
|
||||
}
|
||||
bar.set_value(i);
|
||||
bar.set_value(i, Animation::OFF);
|
||||
i += 1;
|
||||
|
||||
sleep(Duration::from_millis(25));
|
||||
|
|
|
@ -325,3 +325,17 @@ pub enum Align {
|
|||
OutRightMid,
|
||||
OutRightBottom,
|
||||
}
|
||||
|
||||
pub enum Animation {
|
||||
ON,
|
||||
OFF,
|
||||
}
|
||||
|
||||
impl From<Animation> for lvgl_sys::lv_anim_enable_t {
|
||||
fn from(anim: Animation) -> Self {
|
||||
match anim {
|
||||
Animation::ON => lvgl_sys::LV_ANIM_ON as u8,
|
||||
Animation::OFF => lvgl_sys::LV_ANIM_OFF as u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::support::Animation;
|
||||
use crate::support::{NativeObject, ObjectX};
|
||||
use core::ptr;
|
||||
use lvgl_sys;
|
||||
|
@ -24,10 +25,10 @@ impl Bar {
|
|||
}
|
||||
}
|
||||
|
||||
/// Set the value of the bar
|
||||
pub fn set_value(&mut self, value: i16) {
|
||||
/// Set a new value on the bar
|
||||
pub fn set_value(&mut self, value: i16, anim: Animation) {
|
||||
unsafe {
|
||||
lvgl_sys::lv_bar_set_value(self.core.raw().as_mut(), value, 0);
|
||||
lvgl_sys::lv_bar_set_value(self.core.raw().as_mut(), value, anim.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue