Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nia-e committed Jun 20, 2023
1 parent 29642c0 commit f358ad0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
23 changes: 13 additions & 10 deletions lvgl/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::Screen;
use crate::{disp_drv_register, disp_get_default, get_str_act, LvResult, NativeObject};
use crate::{Box, Color};
use core::convert::TryInto;
#[cfg(feature = "nightly")]
use core::error::Error;
use core::fmt;
use core::mem::{ManuallyDrop, MaybeUninit};
use core::pin::Pin;
use core::ptr::NonNull;
use core::{ptr, result};
use core::fmt;
#[cfg(feature = "nightly")]
use core::error::Error;

/// Error in interacting with a `Display`.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
Expand All @@ -21,11 +21,15 @@ pub enum DisplayError {

impl fmt::Display for DisplayError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Display {}", match self {
DisplayError::NotAvailable => "not available",
DisplayError::FailedToRegister => "failed to register",
DisplayError::NotRegistered => "not registered",
})
write!(
f,
"Display {}",
match self {
DisplayError::NotAvailable => "not available",
DisplayError::FailedToRegister => "failed to register",
DisplayError::NotRegistered => "not registered",
}
)
}
}

Expand Down Expand Up @@ -396,8 +400,7 @@ mod tests {
let _screen_direct = display
.get_scr_act()
.expect("Return screen directly from the display instance");
let _screen_default =
get_scr_act().expect("Return screen from the default display");
let _screen_default = get_scr_act().expect("Return screen from the default display");
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion lvgl/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ pub fn task_handler() {

/// Directly send an event to a specific widget.
#[inline]
pub fn event_send<W: for<'a> Widget<'a>>(obj: &mut W, event: Event<<W as Widget<'_>>::SpecialEvent>) -> LvResult<()> {
pub fn event_send<W: for<'a> Widget<'a>>(
obj: &mut W,
event: Event<<W as Widget<'_>>::SpecialEvent>,
) -> LvResult<()> {
unsafe {
lvgl_sys::lv_event_send(obj.raw()?.as_mut(), event.into(), ptr::null_mut());
};
Expand Down
14 changes: 11 additions & 3 deletions lvgl/src/lv_core/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ impl Obj<'_> {
let ptr = lvgl_sys::lv_obj_create(parent.raw()?.as_mut());
if ptr::NonNull::new(ptr).is_some() {
//(*ptr).user_data = Box::new(UserDataObj::empty()).into_raw() as *mut _;
Ok(Self { raw: ptr, styles_used: PhantomData })
Ok(Self {
raw: ptr,
styles_used: PhantomData,
})
} else {
Err(LvError::InvalidReference)
}
Expand Down Expand Up @@ -152,7 +155,10 @@ impl<'a> Widget<'a> for Obj<'a> {
type Part = Part;

unsafe fn from_raw(raw: ptr::NonNull<lvgl_sys::lv_obj_t>) -> Option<Self> {
Some(Self { raw: raw.as_ptr(), styles_used: PhantomData })
Some(Self {
raw: raw.as_ptr(),
styles_used: PhantomData,
})
}
}

Expand Down Expand Up @@ -195,7 +201,9 @@ macro_rules! define_object {
obj.user_data = $crate::Box::into_raw($crate::Box::new(f)) as *mut _;
lvgl_sys::lv_obj_add_event_cb(
obj,
lvgl_sys::lv_event_cb_t::Some($crate::support::event_callback::<'a, Self, F>),
lvgl_sys::lv_event_cb_t::Some(
$crate::support::event_callback::<'a, Self, F>,
),
lvgl_sys::lv_event_code_t_LV_EVENT_ALL,
obj.user_data,
);
Expand Down
2 changes: 1 addition & 1 deletion lvgl/src/lv_core/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'a> TryFrom<Obj<'a>> for Screen<'a> {

fn try_from(value: Obj<'a>) -> Result<Self, Self::Error> {
match unsafe { (*value.raw()?.as_mut()).parent } as usize {
0 => Ok(Self { raw: value, }),
0 => Ok(Self { raw: value }),
_ => Err(LvError::InvalidReference),
}
}
Expand Down
20 changes: 12 additions & 8 deletions lvgl/src/support.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::display::DisplayError;
use crate::Widget;
use core::convert::{TryFrom, TryInto};
use core::ptr::NonNull;
use core::fmt;
#[cfg(feature = "nightly")]
use core::error::Error;
use core::fmt;
use core::ptr::NonNull;
#[cfg(feature = "embedded_graphics")]
use embedded_graphics::pixelcolor::{Rgb565, Rgb888};

Expand All @@ -21,12 +21,16 @@ pub enum LvError {

impl fmt::Display for LvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", match self {
LvError::InvalidReference => "Accessed invalid reference or ptr",
LvError::Uninitialized => "LVGL uninitialized",
LvError::LvOOMemory => "LVGL out of memory",
LvError::AlreadyInUse => "Resource already in use",
})
write!(
f,
"{}",
match self {
LvError::InvalidReference => "Accessed invalid reference or ptr",
LvError::Uninitialized => "LVGL uninitialized",
LvError::LvOOMemory => "LVGL out of memory",
LvError::AlreadyInUse => "Resource already in use",
}
)
}
}

Expand Down

0 comments on commit f358ad0

Please sign in to comment.