Fix examples

This commit is contained in:
Rafael Caricio 2020-06-07 20:47:49 +02:00 committed by Rafael Carício
parent 36bae837f8
commit 335261ed6e
4 changed files with 65 additions and 65 deletions

View file

@ -5,13 +5,13 @@ use embedded_graphics_simulator::{
};
use lvgl::style::Style;
use lvgl::widgets::{Bar, BarPart, Label, LabelAlign};
use lvgl::{self, Align, Animation, Color, DisplayDriver, Event, Part, State, Widget, UI};
use lvgl::{self, Align, Animation, Color, DisplayDriver, Event, LvError, Part, State, Widget, UI};
use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
fn main() -> Result<(), String> {
fn main() -> Result<(), LvError> {
let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
lvgl_sys::LV_HOR_RES_MAX,
lvgl_sys::LV_VER_RES_MAX,
@ -20,39 +20,39 @@ fn main() -> Result<(), String> {
let output_settings = OutputSettingsBuilder::new().scale(2).build();
let mut window = Window::new("Bar Example", &output_settings);
let mut ui = UI::init().unwrap();
let mut ui = UI::init()?;
// Implement and register your display:
let display_driver = DisplayDriver::new(&mut display);
ui.disp_drv_register(display_driver);
// Create screen and widgets
let mut screen = ui.scr_act();
let mut screen = ui.scr_act()?;
let mut screen_style = Style::default();
screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((255, 255, 255)));
screen_style.set_radius(State::DEFAULT, 0);
screen.add_style(Part::Main, screen_style);
screen.add_style(Part::Main, screen_style)?;
// Create the bar object
let mut bar = Bar::new(&mut screen);
bar.set_size(175, 20);
bar.set_align(&mut screen, Align::Center, 0, 10);
bar.set_range(0, 100);
let mut bar = Bar::new(&mut screen)?;
bar.set_size(175, 20)?;
bar.set_align(&mut screen, Align::Center, 0, 10)?;
bar.set_range(0, 100)?;
// // Set the indicator style for the bar object
let mut ind_style = Style::default();
ind_style.set_bg_color(State::DEFAULT, Color::from_rgb((100, 245, 100)));
bar.add_style(BarPart::Indicator, ind_style);
bar.add_style(BarPart::Indicator, ind_style)?;
let mut loading_lbl = Label::new(&mut screen);
loading_lbl.set_text("Loading...");
loading_lbl.set_align(&mut bar, Align::OutTopMid, 0, -10);
loading_lbl.set_label_align(LabelAlign::Center);
let mut loading_lbl = Label::new(&mut screen)?;
loading_lbl.set_text("Loading...")?;
loading_lbl.set_align(&mut bar, Align::OutTopMid, 0, -10)?;
loading_lbl.set_label_align(LabelAlign::Center)?;
let mut loading_style = Style::default();
loading_style.set_text_color(State::DEFAULT, Color::from_rgb((0, 0, 0)));
loading_lbl.add_style(Part::Main, loading_style);
loading_lbl.add_style(Part::Main, loading_style)?;
let threaded_ui = Arc::new(Mutex::new(ui));
@ -75,9 +75,9 @@ fn main() -> Result<(), String> {
threaded_ui
.lock()
.unwrap()
.event_send(&mut loading_lbl, Event::Clicked)
.event_send(&mut loading_lbl, Event::Clicked)?
}
bar.set_value(i, Animation::OFF);
bar.set_value(i, Animation::OFF)?;
i += 1;
sleep(Duration::from_millis(25));

View file

@ -5,13 +5,13 @@ use embedded_graphics_simulator::{
};
use lvgl::style::Style;
use lvgl::widgets::{Btn, Label};
use lvgl::{self, Align, Color, DisplayDriver, Event, Part, State, Widget, UI};
use lvgl::{self, Align, Color, DisplayDriver, Event, LvError, Part, State, Widget, UI};
use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
fn main() -> Result<(), String> {
fn main() -> Result<(), LvError> {
let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
lvgl_sys::LV_HOR_RES_MAX,
lvgl_sys::LV_VER_RES_MAX,
@ -20,30 +20,30 @@ fn main() -> Result<(), String> {
let output_settings = OutputSettingsBuilder::new().scale(2).build();
let mut window = Window::new("Bar Example", &output_settings);
let mut ui = UI::init().unwrap();
let mut ui = UI::init()?;
// Implement and register your display:
let display_driver = DisplayDriver::new(&mut display);
ui.disp_drv_register(display_driver);
// Create screen and widgets
let mut screen = ui.scr_act();
let mut screen = ui.scr_act()?;
let mut screen_style = Style::default();
screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((0, 0, 0)));
screen.add_style(Part::Main, screen_style);
screen.add_style(Part::Main, screen_style)?;
// Create the button
let mut button = Btn::new(&mut screen);
button.set_align(&mut screen, Align::InLeftMid, 30, 0);
button.set_size(180, 80);
let mut btn_lbl = Label::new(&mut button);
btn_lbl.set_text("Click me!");
let mut button = Btn::new(&mut screen)?;
button.set_align(&mut screen, Align::InLeftMid, 30, 0)?;
button.set_size(180, 80)?;
let mut btn_lbl = Label::new(&mut button)?;
btn_lbl.set_text("Click me!")?;
button.on_event(|_, event| {
if let lvgl::Event::Clicked = event {
println!("Clicked!");
}
});
})?;
let threaded_ui = Arc::new(Mutex::new(ui));
@ -76,7 +76,7 @@ fn main() -> Result<(), String> {
threaded_ui
.lock()
.unwrap()
.event_send(&mut button, Event::Clicked);
.event_send(&mut button, Event::Clicked)?;
}
SimulatorEvent::Quit => break 'running,
_ => {}

View file

@ -6,13 +6,13 @@ use embedded_graphics_simulator::{
use lvgl;
use lvgl::style::Style;
use lvgl::widgets::{Label, LabelAlign};
use lvgl::{Align, Color, Part, State, Widget, UI};
use lvgl::{Align, Color, LvError, Part, State, Widget, UI};
use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
fn main() -> Result<(), String> {
fn main() -> Result<(), LvError> {
let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
lvgl_sys::LV_HOR_RES_MAX,
lvgl_sys::LV_VER_RES_MAX,
@ -21,14 +21,14 @@ fn main() -> Result<(), String> {
let output_settings = OutputSettingsBuilder::new().scale(2).build();
let mut window = Window::new("PineTime", &output_settings);
let mut ui = UI::init().unwrap();
let mut ui = UI::init()?;
// Implement and register your display:
let display_driver = lvgl::DisplayDriver::new(&mut display);
ui.disp_drv_register(display_driver);
// Create screen and widgets
let mut screen = ui.scr_act();
let mut screen = ui.scr_act()?;
let font_roboto_28 = unsafe { &lvgl_sys::lv_theme_get_font_normal() };
let font_noto_sans_numeric_28 = unsafe { &noto_sans_numeric_80 };
@ -36,33 +36,33 @@ fn main() -> Result<(), String> {
let mut screen_style = Style::default();
screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((0, 0, 0)));
screen_style.set_radius(State::DEFAULT, 0);
screen.add_style(Part::Main, screen_style);
screen.add_style(Part::Main, screen_style)?;
let mut time = Label::new(&mut screen);
let mut time = Label::new(&mut screen)?;
let mut style_time = Style::default();
//style_time.set_text_font(font_noto_sans_numeric_28);
style_time.set_text_color(State::DEFAULT, Color::from_rgb((255, 255, 255)));
time.add_style(Part::Main, style_time);
time.set_align(&mut screen, Align::Center, 0, 0);
time.set_text("20:46");
time.set_width(240);
time.set_height(240);
time.add_style(Part::Main, style_time)?;
time.set_align(&mut screen, Align::Center, 0, 0)?;
time.set_text("20:46")?;
time.set_width(240)?;
time.set_height(240)?;
let mut bt = Label::new(&mut screen);
bt.set_width(50);
bt.set_height(80);
bt.set_recolor(true);
bt.set_text("#5794f2 \u{F293}#");
bt.set_label_align(LabelAlign::Left);
bt.set_align(&mut screen, Align::InTopLeft, 0, 0);
let mut bt = Label::new(&mut screen)?;
bt.set_width(50)?;
bt.set_height(80)?;
bt.set_recolor(true)?;
bt.set_text("#5794f2 \u{F293}#")?;
bt.set_label_align(LabelAlign::Left)?;
bt.set_align(&mut screen, Align::InTopLeft, 0, 0)?;
let mut power = Label::new(&mut screen);
power.set_recolor(true);
power.set_width(80);
power.set_height(20);
power.set_text("#fade2a 20%#");
power.set_label_align(LabelAlign::Right);
power.set_align(&mut screen, Align::InTopRight, 0, 0);
let mut power = Label::new(&mut screen)?;
power.set_recolor(true)?;
power.set_width(80)?;
power.set_height(20)?;
power.set_text("#fade2a 20%#")?;
power.set_label_align(LabelAlign::Right)?;
power.set_align(&mut screen, Align::InTopRight, 0, 0)?;
let threaded_ui = Arc::new(Mutex::new(ui));
@ -83,7 +83,7 @@ fn main() -> Result<(), String> {
if i > 59 {
i = 0;
}
time.set_text(format!("21:{:02}", i).as_str());
time.set_text(format!("21:{:02}", i).as_str())?;
i = 1 + i;
sleep(Duration::from_secs(1));

View file

@ -5,13 +5,13 @@ use embedded_graphics_simulator::{
};
use lvgl::style::{Opacity, Style};
use lvgl::widgets::{Gauge, GaugePart};
use lvgl::{self, Align, Color, DisplayDriver, Part, State, Widget, UI};
use lvgl::{self, Align, Color, DisplayDriver, LvError, Part, State, Widget, UI};
use lvgl_sys;
use std::sync::{mpsc, Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
fn main() -> Result<(), String> {
fn main() -> Result<(), LvError> {
let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
lvgl_sys::LV_HOR_RES_MAX,
lvgl_sys::LV_VER_RES_MAX,
@ -20,18 +20,18 @@ fn main() -> Result<(), String> {
let output_settings = OutputSettingsBuilder::new().scale(2).build();
let mut window = Window::new("Gauge Example", &output_settings);
let mut ui = UI::init().unwrap();
let mut ui = UI::init()?;
// Implement and register your display:
let display_driver = DisplayDriver::new(&mut display);
ui.disp_drv_register(display_driver);
// Create screen and widgets
let mut screen = ui.scr_act();
let mut screen = ui.scr_act()?;
let mut screen_style = Style::default();
screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((0, 0, 0)));
screen.add_style(Part::Main, screen_style);
screen.add_style(Part::Main, screen_style)?;
// Create the gauge
let mut gauge_style = Style::default();
@ -52,10 +52,10 @@ fn main() -> Result<(), String> {
gauge_style.set_scale_end_line_width(State::DEFAULT, 4);
gauge_style.set_scale_end_border_width(State::DEFAULT, 4);
let mut gauge = Gauge::new(&mut screen);
gauge.add_style(GaugePart::Main, gauge_style);
gauge.set_align(&mut screen, Align::Center, 0, 0);
gauge.set_value(0, 50);
let mut gauge = Gauge::new(&mut screen)?;
gauge.add_style(GaugePart::Main, gauge_style)?;
gauge.set_align(&mut screen, Align::Center, 0, 0)?;
gauge.set_value(0, 50)?;
let threaded_ui = Arc::new(Mutex::new(ui));
@ -92,7 +92,7 @@ fn main() -> Result<(), String> {
}
sleep(Duration::from_millis(25));
gauge.set_value(0, i);
gauge.set_value(0, i)?;
if i > 99 {
i = 0;