lvgl-rs/lvgl/src/widgets/bar.rs
Kuba Clark 2fae95bdfb
Bar widget (#12)
* Implement simple bar widget

* Make it easier to create new examples

* Add bar example

* Add README to examples

* Remove unnecessary imports
2020-05-31 09:12:37 +02:00

34 lines
841 B
Rust

use crate::support::{NativeObject, ObjectX};
use core::ptr;
use lvgl_sys;
define_object!(Bar);
impl Bar {
pub fn new<C>(parent: &mut C) -> Self
where
C: NativeObject,
{
let raw = unsafe {
let ptr = lvgl_sys::lv_bar_create(parent.raw().as_mut(), ptr::null_mut());
ptr::NonNull::new_unchecked(ptr)
};
let core = ObjectX::from_raw(raw);
Self { core }
}
/// Set minimum and the maximum values of the bar
pub fn set_range(&mut self, min: i16, max: i16) {
unsafe {
lvgl_sys::lv_bar_set_range(self.core.raw().as_mut(), min, max);
}
}
/// Set the value of the bar
pub fn set_value(&mut self, value: i16) {
unsafe {
lvgl_sys::lv_bar_set_value(self.core.raw().as_mut(), value, 0);
}
}
}