Rename ObjectX to GenericObject
This commit is contained in:
parent
9ec78a70cb
commit
11695e20c1
7 changed files with 19 additions and 24 deletions
|
@ -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
|
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).
|
[`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] 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
|
- [x] Styles: You can set styles in any exposed object. We are still missing the possibility of defining base styles.
|
||||||
possibility of defining base styles.
|
|
||||||
- [ ] Input Devices
|
- [ ] Input Devices
|
||||||
- [ ] Fonts
|
- [ ] Fonts
|
||||||
- [ ] Images
|
- [ ] Images
|
||||||
|
|
|
@ -4,7 +4,7 @@ use embedded_graphics_simulator::{
|
||||||
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
|
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
|
||||||
};
|
};
|
||||||
use lvgl::widgets::{Bar, Button, Label};
|
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 lvgl_sys;
|
||||||
use std::sync::{mpsc, Arc, Mutex};
|
use std::sync::{mpsc, Arc, Mutex};
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{DisplayDriver, Event, Object, ObjectX};
|
use crate::{DisplayDriver, Event, GenericObject, Object};
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
@ -47,10 +47,10 @@ impl UI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scr_act(&self) -> ObjectX {
|
pub fn scr_act(&self) -> GenericObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
let screen = lvgl_sys::lv_disp_get_scr_act(ptr::null_mut());
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,17 +17,13 @@ pub trait NativeObject {
|
||||||
/// Generic LVGL object.
|
/// Generic LVGL object.
|
||||||
///
|
///
|
||||||
/// This is the parent object of all widget types. It stores the native LVGL raw pointer.
|
/// This is the parent object of all widget types. It stores the native LVGL raw pointer.
|
||||||
///
|
pub struct GenericObject {
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// Panics if LVGL internally freed the original object.
|
|
||||||
pub struct ObjectX {
|
|
||||||
// We use a raw pointer here because we do not control this memory address, it is controlled
|
// We use a raw pointer here because we do not control this memory address, it is controlled
|
||||||
// by LVGL's global state.
|
// by LVGL's global state.
|
||||||
raw: *mut lvgl_sys::lv_obj_t,
|
raw: *mut lvgl_sys::lv_obj_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NativeObject for ObjectX {
|
impl NativeObject for GenericObject {
|
||||||
fn raw(&self) -> ptr::NonNull<lvgl_sys::lv_obj_t> {
|
fn raw(&self) -> ptr::NonNull<lvgl_sys::lv_obj_t> {
|
||||||
ptr::NonNull::new(self.raw).expect(PANIC_MESSAGE)
|
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 = ();
|
type SpecialEvent = ();
|
||||||
|
|
||||||
unsafe fn from_raw(raw: ptr::NonNull<lvgl_sys::lv_obj_t>) -> Self {
|
unsafe fn from_raw(raw: ptr::NonNull<lvgl_sys::lv_obj_t>) -> Self {
|
||||||
|
@ -125,7 +121,7 @@ impl Object for ObjectX {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ObjectX {
|
impl Default for GenericObject {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
raw: unsafe { lvgl_sys::lv_obj_create(ptr::null_mut(), ptr::null_mut()) },
|
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 {
|
macro_rules! define_object {
|
||||||
($item:ident) => {
|
($item:ident) => {
|
||||||
pub struct $item {
|
pub struct $item {
|
||||||
core: $crate::support::ObjectX,
|
core: $crate::support::GenericObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $item {
|
impl $item {
|
||||||
|
@ -171,14 +167,14 @@ macro_rules! define_object {
|
||||||
|
|
||||||
unsafe fn from_raw(raw_pointer: core::ptr::NonNull<lvgl_sys::lv_obj_t>) -> Self {
|
unsafe fn from_raw(raw_pointer: core::ptr::NonNull<lvgl_sys::lv_obj_t>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
core: $crate::support::ObjectX::from_raw(raw_pointer),
|
core: $crate::support::GenericObject::from_raw(raw_pointer),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($item:ident, $event_type:ident) => {
|
($item:ident, $event_type:ident) => {
|
||||||
pub struct $item {
|
pub struct $item {
|
||||||
core: $crate::support::ObjectX,
|
core: $crate::support::GenericObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $item {
|
impl $item {
|
||||||
|
@ -213,7 +209,7 @@ macro_rules! define_object {
|
||||||
|
|
||||||
unsafe fn from_raw(raw_pointer: core::ptr::NonNull<lvgl_sys::lv_obj_t>) -> Self {
|
unsafe fn from_raw(raw_pointer: core::ptr::NonNull<lvgl_sys::lv_obj_t>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
core: $crate::support::ObjectX::from_raw(raw_pointer),
|
core: $crate::support::GenericObject::from_raw(raw_pointer),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::support::{Animation, NativeObject, ObjectX, Style};
|
use crate::support::{Animation, GenericObject, NativeObject, Style};
|
||||||
use crate::Object;
|
use crate::Object;
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
@ -14,7 +14,7 @@ impl Bar {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = lvgl_sys::lv_bar_create(parent.raw().as_mut(), ptr::null_mut());
|
let ptr = lvgl_sys::lv_bar_create(parent.raw().as_mut(), ptr::null_mut());
|
||||||
let raw = ptr::NonNull::new_unchecked(ptr);
|
let raw = ptr::NonNull::new_unchecked(ptr);
|
||||||
let core = ObjectX::from_raw(raw);
|
let core = GenericObject::from_raw(raw);
|
||||||
Self { core }
|
Self { core }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{NativeObject, Object, ObjectX};
|
use crate::{GenericObject, NativeObject, Object};
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
|
||||||
define_object!(Button);
|
define_object!(Button);
|
||||||
|
@ -11,7 +11,7 @@ impl Button {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = lvgl_sys::lv_btn_create(parent.raw().as_mut(), ptr::null_mut());
|
let ptr = lvgl_sys::lv_btn_create(parent.raw().as_mut(), ptr::null_mut());
|
||||||
let raw = ptr::NonNull::new_unchecked(ptr);
|
let raw = ptr::NonNull::new_unchecked(ptr);
|
||||||
let core = ObjectX::from_raw(raw);
|
let core = GenericObject::from_raw(raw);
|
||||||
Self { core }
|
Self { core }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{NativeObject, Object, ObjectX};
|
use crate::{GenericObject, NativeObject, Object};
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
use cstr_core::CString;
|
use cstr_core::CString;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ impl Label {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = lvgl_sys::lv_label_create(parent.raw().as_mut(), ptr::null_mut());
|
let ptr = lvgl_sys::lv_label_create(parent.raw().as_mut(), ptr::null_mut());
|
||||||
let raw = ptr::NonNull::new_unchecked(ptr);
|
let raw = ptr::NonNull::new_unchecked(ptr);
|
||||||
let core = ObjectX::from_raw(raw);
|
let core = GenericObject::from_raw(raw);
|
||||||
Self { core }
|
Self { core }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue