From 11695e20c1a73189b80640014b5663b8a9b18603 Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Tue, 2 Jun 2020 19:21:44 +0200 Subject: [PATCH] Rename ObjectX to GenericObject --- README.md | 3 +-- examples/button_click.rs | 2 +- lvgl/src/global.rs | 6 +++--- lvgl/src/support.rs | 20 ++++++++------------ lvgl/src/widgets/bar.rs | 4 ++-- lvgl/src/widgets/button.rs | 4 ++-- lvgl/src/widgets/label.rs | 4 ++-- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8f03677..1c71325 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,7 @@ List of LVGL features that impacts the library usage in general. draw to the display. You can use `lvgl-rs` with any of the [`embedded_graphics` supported displays](https://docs.rs/embedded-graphics/0.6.2/embedded_graphics/#supported-displays). - [x] Events: You can listen and trigger events in widget objects. -- [x] Styles: Partially supported. You can set styles in any exposed object. We are still missing the - possibility of defining base styles. +- [x] Styles: You can set styles in any exposed object. We are still missing the possibility of defining base styles. - [ ] Input Devices - [ ] Fonts - [ ] Images diff --git a/examples/button_click.rs b/examples/button_click.rs index 830e8cc..4836eb2 100644 --- a/examples/button_click.rs +++ b/examples/button_click.rs @@ -4,7 +4,7 @@ use embedded_graphics_simulator::{ OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, }; use lvgl::widgets::{Bar, Button, Label}; -use lvgl::{self, Align, Animation, Color, DisplayDriver, Event, Object, Style, UI}; +use lvgl::{self, Align, Animation, Color, DisplayDriver, Event, NativeObject, Object, Style, UI}; use lvgl_sys; use std::sync::{mpsc, Arc, Mutex}; use std::thread::sleep; diff --git a/lvgl/src/global.rs b/lvgl/src/global.rs index 2d4846c..b1fd638 100644 --- a/lvgl/src/global.rs +++ b/lvgl/src/global.rs @@ -1,4 +1,4 @@ -use crate::{DisplayDriver, Event, Object, ObjectX}; +use crate::{DisplayDriver, Event, GenericObject, Object}; use alloc::boxed::Box; use core::marker::PhantomData; use core::ptr; @@ -47,10 +47,10 @@ impl UI { } } - pub fn scr_act(&self) -> ObjectX { + pub fn scr_act(&self) -> GenericObject { unsafe { let screen = lvgl_sys::lv_disp_get_scr_act(ptr::null_mut()); - ObjectX::from_raw(NonNull::new_unchecked(screen)) + GenericObject::from_raw(NonNull::new_unchecked(screen)) } } diff --git a/lvgl/src/support.rs b/lvgl/src/support.rs index 55eaef0..8d35d2f 100644 --- a/lvgl/src/support.rs +++ b/lvgl/src/support.rs @@ -17,17 +17,13 @@ pub trait NativeObject { /// Generic LVGL object. /// /// This is the parent object of all widget types. It stores the native LVGL raw pointer. -/// -/// # Panics -/// -/// Panics if LVGL internally freed the original object. -pub struct ObjectX { +pub struct GenericObject { // We use a raw pointer here because we do not control this memory address, it is controlled // by LVGL's global state. raw: *mut lvgl_sys::lv_obj_t, } -impl NativeObject for ObjectX { +impl NativeObject for GenericObject { fn raw(&self) -> ptr::NonNull { ptr::NonNull::new(self.raw).expect(PANIC_MESSAGE) } @@ -117,7 +113,7 @@ pub trait Object: NativeObject { } } -impl Object for ObjectX { +impl Object for GenericObject { type SpecialEvent = (); unsafe fn from_raw(raw: ptr::NonNull) -> Self { @@ -125,7 +121,7 @@ impl Object for ObjectX { } } -impl Default for ObjectX { +impl Default for GenericObject { fn default() -> Self { Self { raw: unsafe { lvgl_sys::lv_obj_create(ptr::null_mut(), ptr::null_mut()) }, @@ -136,7 +132,7 @@ impl Default for ObjectX { macro_rules! define_object { ($item:ident) => { pub struct $item { - core: $crate::support::ObjectX, + core: $crate::support::GenericObject, } impl $item { @@ -171,14 +167,14 @@ macro_rules! define_object { unsafe fn from_raw(raw_pointer: core::ptr::NonNull) -> Self { Self { - core: $crate::support::ObjectX::from_raw(raw_pointer), + core: $crate::support::GenericObject::from_raw(raw_pointer), } } } }; ($item:ident, $event_type:ident) => { pub struct $item { - core: $crate::support::ObjectX, + core: $crate::support::GenericObject, } impl $item { @@ -213,7 +209,7 @@ macro_rules! define_object { unsafe fn from_raw(raw_pointer: core::ptr::NonNull) -> Self { Self { - core: $crate::support::ObjectX::from_raw(raw_pointer), + core: $crate::support::GenericObject::from_raw(raw_pointer), } } } diff --git a/lvgl/src/widgets/bar.rs b/lvgl/src/widgets/bar.rs index 7ce3c8e..ab7e809 100644 --- a/lvgl/src/widgets/bar.rs +++ b/lvgl/src/widgets/bar.rs @@ -1,4 +1,4 @@ -use crate::support::{Animation, NativeObject, ObjectX, Style}; +use crate::support::{Animation, GenericObject, NativeObject, Style}; use crate::Object; use alloc::boxed::Box; use core::ptr; @@ -14,7 +14,7 @@ impl Bar { unsafe { let ptr = lvgl_sys::lv_bar_create(parent.raw().as_mut(), ptr::null_mut()); let raw = ptr::NonNull::new_unchecked(ptr); - let core = ObjectX::from_raw(raw); + let core = GenericObject::from_raw(raw); Self { core } } } diff --git a/lvgl/src/widgets/button.rs b/lvgl/src/widgets/button.rs index 6e79071..a447605 100644 --- a/lvgl/src/widgets/button.rs +++ b/lvgl/src/widgets/button.rs @@ -1,4 +1,4 @@ -use crate::{NativeObject, Object, ObjectX}; +use crate::{GenericObject, NativeObject, Object}; use core::ptr; define_object!(Button); @@ -11,7 +11,7 @@ impl Button { unsafe { let ptr = lvgl_sys::lv_btn_create(parent.raw().as_mut(), ptr::null_mut()); let raw = ptr::NonNull::new_unchecked(ptr); - let core = ObjectX::from_raw(raw); + let core = GenericObject::from_raw(raw); Self { core } } } diff --git a/lvgl/src/widgets/label.rs b/lvgl/src/widgets/label.rs index 861d1fe..8090564 100644 --- a/lvgl/src/widgets/label.rs +++ b/lvgl/src/widgets/label.rs @@ -1,4 +1,4 @@ -use crate::{NativeObject, Object, ObjectX}; +use crate::{GenericObject, NativeObject, Object}; use core::ptr; use cstr_core::CString; @@ -19,7 +19,7 @@ impl Label { unsafe { let ptr = lvgl_sys::lv_label_create(parent.raw().as_mut(), ptr::null_mut()); let raw = ptr::NonNull::new_unchecked(ptr); - let core = ObjectX::from_raw(raw); + let core = GenericObject::from_raw(raw); Self { core } } }