From cb8a78137dded24187ef99b1d6a3c421e4c5d90c Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Sun, 31 May 2020 12:07:24 +0200 Subject: [PATCH] Possible to set values in the bar widget with animations --- examples/bar.rs | 6 +++--- lvgl/src/support.rs | 14 ++++++++++++++ lvgl/src/widgets/bar.rs | 7 ++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/bar.rs b/examples/bar.rs index 048e8ee..4d14c29 100644 --- a/examples/bar.rs +++ b/examples/bar.rs @@ -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)); diff --git a/lvgl/src/support.rs b/lvgl/src/support.rs index 5d38236..980d7af 100644 --- a/lvgl/src/support.rs +++ b/lvgl/src/support.rs @@ -325,3 +325,17 @@ pub enum Align { OutRightMid, OutRightBottom, } + +pub enum Animation { + ON, + OFF, +} + +impl From 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, + } + } +} diff --git a/lvgl/src/widgets/bar.rs b/lvgl/src/widgets/bar.rs index 17a1be6..7315efa 100644 --- a/lvgl/src/widgets/bar.rs +++ b/lvgl/src/widgets/bar.rs @@ -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()); } } }