No need for manual nul byte
This commit is contained in:
parent
8856b83461
commit
2627911ff6
4 changed files with 16 additions and 16 deletions
|
@ -17,7 +17,7 @@ fn main() -> Result<(), String> {
|
||||||
));
|
));
|
||||||
|
|
||||||
let output_settings = OutputSettingsBuilder::new().scale(4).build();
|
let output_settings = OutputSettingsBuilder::new().scale(4).build();
|
||||||
let mut window = Window::new("Hello World", &output_settings);
|
let mut window = Window::new("PineTime", &output_settings);
|
||||||
|
|
||||||
let mut ui = UI::init().unwrap();
|
let mut ui = UI::init().unwrap();
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ fn main() -> Result<(), String> {
|
||||||
style_time.set_text_color(lvgl::Color::from_rgb((255, 255, 255)));
|
style_time.set_text_color(lvgl::Color::from_rgb((255, 255, 255)));
|
||||||
time.set_style(style_time);
|
time.set_style(style_time);
|
||||||
time.set_align(&mut screen, lvgl::Align::InLeftMid, 20, 0);
|
time.set_align(&mut screen, lvgl::Align::InLeftMid, 20, 0);
|
||||||
time.set_text("20:46\0");
|
time.set_text("20:46");
|
||||||
time.set_width(240);
|
time.set_width(240);
|
||||||
time.set_height(240);
|
time.set_height(240);
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ fn main() -> Result<(), String> {
|
||||||
bt.set_width(50);
|
bt.set_width(50);
|
||||||
bt.set_height(80);
|
bt.set_height(80);
|
||||||
bt.set_recolor(true);
|
bt.set_recolor(true);
|
||||||
bt.set_text("#5794f2 \u{F293}#\0");
|
bt.set_text("#5794f2 \u{F293}#");
|
||||||
bt.set_label_align(lvgl::LabelAlign::Left);
|
bt.set_label_align(lvgl::LabelAlign::Left);
|
||||||
bt.set_align(&mut screen, lvgl::Align::InTopLeft, 0, 0);
|
bt.set_align(&mut screen, lvgl::Align::InTopLeft, 0, 0);
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ fn main() -> Result<(), String> {
|
||||||
power.set_recolor(true);
|
power.set_recolor(true);
|
||||||
power.set_width(80);
|
power.set_width(80);
|
||||||
power.set_height(20);
|
power.set_height(20);
|
||||||
power.set_text("#fade2a 20%#\0");
|
power.set_text("#fade2a 20%#");
|
||||||
power.set_label_align(lvgl::LabelAlign::Right);
|
power.set_label_align(lvgl::LabelAlign::Right);
|
||||||
power.set_align(&mut screen, lvgl::Align::InTopRight, 0, 0);
|
power.set_align(&mut screen, lvgl::Align::InTopRight, 0, 0);
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ fn main() -> Result<(), String> {
|
||||||
if i > 59 {
|
if i > 59 {
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
time.set_text(format!("21:{:02}\0", i).as_str());
|
time.set_text(format!("21:{:02}", i).as_str());
|
||||||
i = 1 + i;
|
i = 1 + i;
|
||||||
|
|
||||||
sleep(Duration::from_millis(
|
sleep(Duration::from_millis(
|
||||||
|
@ -112,6 +112,13 @@ fn main() -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference to native font for LittlevGL, defined in the file: "fonts_noto_sans_numeric_80.c"
|
// Reference to native font for LittlevGL, defined in the file: "fonts_noto_sans_numeric_80.c"
|
||||||
|
// TODO: Create a macro for definiting a safe wrapper for fonts.
|
||||||
|
// Maybe sometihng like:
|
||||||
|
//
|
||||||
|
// font! {
|
||||||
|
// NotoSansNumeric80 = noto_sans_numeric_80;
|
||||||
|
// };
|
||||||
|
//
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub static mut noto_sans_numeric_80: lvgl_sys::lv_font_t;
|
pub static mut noto_sans_numeric_80: lvgl_sys::lv_font_t;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,3 +16,4 @@ keywords = ["littlevgl", "lvgl", "graphical_interfaces"]
|
||||||
lvgl-sys = {path="../lvgl-sys", version="0.1"}
|
lvgl-sys = {path="../lvgl-sys", version="0.1"}
|
||||||
cty = "0.2"
|
cty = "0.2"
|
||||||
embedded-graphics = "0.6"
|
embedded-graphics = "0.6"
|
||||||
|
cstr_core = { version = "0.2", default-features = false, features = ["alloc"] }
|
||||||
|
|
|
@ -15,8 +15,6 @@ pub enum LvError {
|
||||||
AlreadyInUse,
|
AlreadyInUse,
|
||||||
}
|
}
|
||||||
|
|
||||||
type LvResult<T> = Result<T, LvError>;
|
|
||||||
|
|
||||||
pub struct UI {
|
pub struct UI {
|
||||||
// LittlevGL is not thread-safe by default.
|
// LittlevGL is not thread-safe by default.
|
||||||
_not_sync: PhantomData<*mut ()>,
|
_not_sync: PhantomData<*mut ()>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
use cty;
|
use cstr_core::CString;
|
||||||
use embedded_graphics::pixelcolor::{Rgb565, Rgb888};
|
use embedded_graphics::pixelcolor::{Rgb565, Rgb888};
|
||||||
use lvgl_sys;
|
use lvgl_sys;
|
||||||
|
|
||||||
|
@ -170,11 +170,9 @@ impl Label {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_text(&mut self, text: &str) {
|
pub fn set_text(&mut self, text: &str) {
|
||||||
|
let text = CString::new(text).unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
lvgl_sys::lv_label_set_text(
|
lvgl_sys::lv_label_set_text(self.core.raw().as_mut(), text.as_ptr());
|
||||||
self.core.raw().as_mut(),
|
|
||||||
text.as_ptr() as *const cty::c_char,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,10 +232,6 @@ impl Style {
|
||||||
pub fn set_text_font(&mut self, font: &lvgl_sys::lv_font_t) {
|
pub fn set_text_font(&mut self, font: &lvgl_sys::lv_font_t) {
|
||||||
self.raw.text.font = font;
|
self.raw.text.font = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn raw(&mut self) -> *const lvgl_sys::lv_style_t {
|
|
||||||
&mut self.raw
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Style {
|
impl Clone for Style {
|
||||||
|
|
Loading…
Reference in a new issue