Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nia-e committed Jun 20, 2023
1 parent 6de2028 commit 3c7eb81
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 38 deletions.
4 changes: 2 additions & 2 deletions lvgl-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ mod tests {
lv_init();

let horizontal_resolution = lv_disp_get_hor_res(core::ptr::null_mut());
assert_eq!(horizontal_resolution, 0 as i16);
assert_eq!(horizontal_resolution, 0);

let vertical_resolution = lv_disp_get_ver_res(core::ptr::null_mut());
assert_eq!(vertical_resolution, 0 as i16);
assert_eq!(vertical_resolution, 0);
}
}
}
3 changes: 1 addition & 2 deletions lvgl/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ impl<'a> Display {
let disp_p = &mut display_diver.disp_drv;
disp_p.hor_res = hor_res.try_into().unwrap_or(240);
disp_p.ver_res = ver_res.try_into().unwrap_or(240);
let ret = Ok(disp_drv_register(&mut display_diver, None)?);
Ok(disp_drv_register(&mut display_diver, None)?)
//display_diver.disp_drv.leak();
ret
}

/// Returns the current active screen.
Expand Down
2 changes: 1 addition & 1 deletion lvgl/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) fn disp_get_default() -> Result<Display> {
))
}

pub(crate) fn get_str_act<'a>(disp: Option<&'a Display>) -> Result<Obj<'a>> {
pub(crate) fn get_str_act(disp: Option<&Display>) -> Result<Obj> {
let scr_ptr = unsafe {
lvgl_sys::lv_disp_get_scr_act(
disp.map(|d| d.disp.as_ptr())
Expand Down
12 changes: 10 additions & 2 deletions lvgl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ fn once_init() {
}
}

/// Initializes LVGL. Unless `unsafe_no_autoinit` is enabled, do not call
/// without first calling `deinit()` and dropping all old values.
/// Initializes LVGL.
///
/// # Safety
///
/// Unless `unsafe_no_autoinit` is enabled, do not call this function without
/// first calling `deinit()` and dropping all old values.
#[cfg(not(feature = "unsafe_no_autoinit"))]
pub unsafe fn init() {
unsafe {
Expand All @@ -119,6 +123,10 @@ pub unsafe fn init() {
}

/// Uninitializes LVGL. Make sure to reinitialize it before reusing it.
///
/// # Safety
///
/// This function should not be called if LVGL is already uninitialized.
pub unsafe fn deinit() {
unsafe { lvgl_sys::lv_deinit() }
}
Expand Down
12 changes: 2 additions & 10 deletions lvgl/src/lv_core/screen.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
use crate::{LvError, NativeObject, Obj, Part, Widget};

/// An LVGL screen.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Screen<'a> {
raw: Obj<'a>,
}

impl Default for Screen<'_> {
fn default() -> Self {
Self {
raw: Obj::default(),
}
}
}

impl NativeObject for Screen<'_> {
fn raw(&self) -> crate::LvResult<core::ptr::NonNull<lvgl_sys::lv_obj_t>> {
self.raw.raw()
Expand All @@ -36,7 +28,7 @@ impl<'a> TryFrom<Obj<'a>> for Screen<'a> {
type Error = LvError;

fn try_from(value: Obj<'a>) -> Result<Self, Self::Error> {
match unsafe { (*value.raw()?.as_mut()).parent } as usize {
match unsafe { value.raw()?.as_mut().parent } as usize {
0 => Ok(Self { raw: value }),
_ => Err(LvError::InvalidReference),
}
Expand Down
5 changes: 1 addition & 4 deletions lvgl/src/lv_core/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ pub enum StyleValues {

impl StyleValues {
pub fn is_some(&self) -> bool {
match self {
StyleValues::None => false,
_ => true,
}
!matches!(self, StyleValues::None)
}
}

Expand Down
24 changes: 12 additions & 12 deletions lvgl/src/misc/anim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ impl Animation {
},
};

(*anim.raw).time = duration.as_millis().try_into().unwrap_or(0);
(*anim.raw).start_value = start;
(*anim.raw).current_value = start;
(*anim.raw).end_value = end;
(*anim.raw).user_data = Box::<F>::into_raw(Box::new(animator)) as *mut _;
(*anim.raw).var = target as *mut _ as *mut _;
(*anim.raw).exec_cb = Some(animator_trampoline::<'a, 'b, T, F>);
anim.raw.time = duration.as_millis().try_into().unwrap_or(0);
anim.raw.start_value = start;
anim.raw.current_value = start;
anim.raw.end_value = end;
anim.raw.user_data = Box::<F>::into_raw(Box::new(animator)) as *mut _;
anim.raw.var = target as *mut _ as *mut _;
anim.raw.exec_cb = Some(animator_trampoline::<'a, 'b, T, F>);

Ok(anim)
}
Expand All @@ -64,32 +64,32 @@ impl Animation {

/// Sets the delay before starting the animation.
pub fn set_delay(&mut self, delay: Duration) -> Result<(), TryFromIntError> {
(*self.raw).act_time = -(delay.as_millis().try_into()?);
self.raw.act_time = -(delay.as_millis().try_into()?);
Ok(())
}

/// Sets the delay before playback.
pub fn set_playback_delay(&mut self, delay: Duration) -> Result<(), TryFromIntError> {
(*self.raw).playback_delay = delay.as_millis().try_into()?;
self.raw.playback_delay = delay.as_millis().try_into()?;
Ok(())
}

/// Sets the total playback time.
pub fn set_playback_time(&mut self, time: Duration) -> Result<(), TryFromIntError> {
(*self.raw).playback_time = time.as_millis().try_into()?;
self.raw.playback_time = time.as_millis().try_into()?;
Ok(())
}

/// Sets the delay before repeating the animation.
pub fn set_repeat_delay(&mut self, delay: Duration) -> Result<(), TryFromIntError> {
(*self.raw).repeat_delay = delay.as_millis().try_into()?;
self.raw.repeat_delay = delay.as_millis().try_into()?;
Ok(())
}

/// Sets how many times the animation repeats.
pub fn set_repeat_count(&mut self, count: AnimRepeatCount) {
unsafe {
(*self.raw).repeat_cnt = match count {
self.raw.repeat_cnt = match count {
AnimRepeatCount::Finite(c) => c,
AnimRepeatCount::Infinite => lvgl_sys::LV_ANIM_REPEAT_INFINITE
.try_into()
Expand Down
6 changes: 3 additions & 3 deletions lvgl/src/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ pub enum LabelLongMode {
Wrap = lvgl_sys::LV_LABEL_LONG_WRAP,
}

impl Into<u8> for LabelLongMode {
fn into(self) -> u8 {
unsafe { (self as u32).try_into().unwrap_unchecked() }
impl From<LabelLongMode> for u8 {
fn from(value: LabelLongMode) -> Self {
unsafe { (value as u32).try_into().unwrap_unchecked() }
}
}

Expand Down
5 changes: 3 additions & 2 deletions lvgl/src/widgets/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ mod alloc_imp {
impl Label<'_> {
pub fn set_long_mode(&mut self, long_mode: LabelLongMode) -> LvResult<()> {
unsafe {
Ok(lvgl_sys::lv_label_set_long_mode(
lvgl_sys::lv_label_set_long_mode(
self.raw()?.as_mut(),
long_mode.into(),
))
);
Ok(())
}
}

Expand Down

0 comments on commit 3c7eb81

Please sign in to comment.