Wrap alloc extension in its own module
This commit is contained in:
parent
f3032c7d17
commit
93c68afc0e
2 changed files with 28 additions and 10 deletions
|
@ -79,7 +79,7 @@ impl<const N: usize> DrawBuffer<N> {
|
||||||
if self.initialized.swap_and_check() {
|
if self.initialized.swap_and_check() {
|
||||||
// TODO: needs to be 'static somehow
|
// TODO: needs to be 'static somehow
|
||||||
// Cannot be in the DrawBuffer struct because the type `lv_disp_buf_t` contains a raw
|
// Cannot be in the DrawBuffer struct because the type `lv_disp_buf_t` contains a raw
|
||||||
// pointer and raw pointers are not Sync and consequently cannot be in `static` variables.
|
// pointer and raw pointers are not Send and consequently cannot be in `static` variables.
|
||||||
let mut inner: MaybeUninit<lvgl_sys::lv_disp_buf_t> = MaybeUninit::uninit();
|
let mut inner: MaybeUninit<lvgl_sys::lv_disp_buf_t> = MaybeUninit::uninit();
|
||||||
let primary_buffer_guard = self.refresh_buffer.lock();
|
let primary_buffer_guard = self.refresh_buffer.lock();
|
||||||
let draw_buf = unsafe {
|
let draw_buf = unsafe {
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::widgets::Label;
|
use crate::widgets::Label;
|
||||||
use crate::{LvResult, NativeObject};
|
use crate::{LvResult, NativeObject};
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
use cstr_core::CString;
|
|
||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
pub fn set_label_align(&mut self, align: LabelAlign) -> LvResult<()> {
|
pub fn set_label_align(&mut self, align: LabelAlign) -> LvResult<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -14,8 +11,15 @@ impl Label {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
|
mod alloc_imp {
|
||||||
|
use crate::widgets::Label;
|
||||||
|
use crate::LvError;
|
||||||
|
use cstr_core::CString;
|
||||||
|
use core::convert::TryFrom;
|
||||||
|
|
||||||
impl<S: AsRef<str>> From<S> for Label {
|
impl<S: AsRef<str>> From<S> for Label {
|
||||||
fn from(text: S) -> Self {
|
fn from(text: S) -> Self {
|
||||||
|
// text.try_into().unwrap()
|
||||||
let text_cstr = CString::new(text.as_ref()).unwrap();
|
let text_cstr = CString::new(text.as_ref()).unwrap();
|
||||||
let mut label = Label::new().unwrap();
|
let mut label = Label::new().unwrap();
|
||||||
label.set_text(text_cstr.as_c_str()).unwrap();
|
label.set_text(text_cstr.as_c_str()).unwrap();
|
||||||
|
@ -23,6 +27,20 @@ impl<S: AsRef<str>> From<S> for Label {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue link: https://github.com/rust-lang/rust/issues/50133
|
||||||
|
//
|
||||||
|
// impl<S: AsRef<str>> TryFrom<S> for Label {
|
||||||
|
// type Error = LvError;
|
||||||
|
// fn try_from(text: S) -> Result<Self, Self::Error> {
|
||||||
|
// let text_cstr = CString::new(text.as_ref())?;
|
||||||
|
// let mut label = Label::new()?;
|
||||||
|
// label.set_text(text_cstr.as_c_str())?;
|
||||||
|
// Ok(label)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum LabelAlign {
|
pub enum LabelAlign {
|
||||||
|
|
Loading…
Reference in a new issue