Implement simple bar widget

This commit is contained in:
Jakub Clark 2020-05-31 02:15:24 +02:00
parent 81d924e854
commit 4b4021e982
5 changed files with 47 additions and 8 deletions

View file

@ -2,11 +2,12 @@
extern crate alloc;
mod global;
mod display;
mod global;
#[macro_use]
mod support;
mod widgets;
pub mod widgets;
pub use global::{UI, LvError};
pub use display::DisplayDriver;
pub use global::{LvError, UI};
pub use support::*;

View file

@ -111,17 +111,17 @@ impl Object for ObjectX {
macro_rules! define_object {
($item:ident) => {
pub struct $item {
core: ObjectX,
core: $crate::support::ObjectX,
}
impl NativeObject for $item {
impl $crate::support::NativeObject for $item {
fn raw(&self) -> ptr::NonNull<lvgl_sys::lv_obj_t> {
self.core.raw()
}
}
impl Object for $item {
fn set_style(&mut self, style: Style) {
impl $crate::support::Object for $item {
fn set_style(&mut self, style: $crate::support::Style) {
unsafe {
let boxed = Box::new(style.raw);
lvgl_sys::lv_obj_set_style(self.raw().as_mut(), Box::into_raw(boxed));
@ -200,7 +200,7 @@ pub enum Themes {
}
pub struct Style {
raw: lvgl_sys::lv_style_t,
pub(crate) raw: lvgl_sys::lv_style_t,
}
impl Style {

View file

35
lvgl/src/widgets/bar.rs Normal file
View file

@ -0,0 +1,35 @@
// use crate::define_object;
use crate::support::{NativeObject, ObjectX};
use alloc::boxed::Box;
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);
}
}
}

3
lvgl/src/widgets/mod.rs Normal file
View file

@ -0,0 +1,3 @@
mod bar;
pub use self::bar::Bar;