Simplify example

This commit is contained in:
Rafael Caricio 2020-06-20 18:46:36 +02:00
parent 7781c12809
commit 30c5d87bb3

View file

@ -1,14 +1,15 @@
use core::cell::Cell;
use cstr_core::CString;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
};
use lvgl::input_device::{BufferStatus, InputData, Pointer};
use lvgl::style::Style;
use lvgl::widgets::{Btn, Label};
use lvgl::{self, Align, Color, LvError, Part, State, Widget, UI};
use std::thread::sleep;
use std::time::{Duration, Instant};
@ -25,11 +26,10 @@ fn main() -> Result<(), LvError> {
ui.disp_drv_register(display)?;
// Define the initial state of your input
let latest_touch_status: Cell<BufferStatus> =
Cell::new(InputData::Touch(Point::new(0, 0)).released().once());
let mut latest_touch_status = InputData::Touch(Point::new(0, 0)).released().once();
// Register a new input device that's capable of reading the current state of the input
let mut touch_screen = Pointer::new(|| latest_touch_status.get());
let mut touch_screen = Pointer::new(|| latest_touch_status);
ui.indev_drv_register(&mut touch_screen)?;
// Create screen and widgets
@ -71,11 +71,9 @@ fn main() -> Result<(), LvError> {
let mut events = window.events().peekable();
if events.peek().is_none() {
latest_touch_status.replace(
InputData::Touch(latest_touch_point.clone())
.released()
.once(),
);
latest_touch_status = InputData::Touch(latest_touch_point.clone())
.released()
.once();
}
for event in events {
@ -87,7 +85,7 @@ fn main() -> Result<(), LvError> {
println!("Clicked on: {:?}", point);
// Send a event to the button directly
latest_touch_point = point.clone();
latest_touch_status.replace(InputData::Touch(point).pressed().once());
latest_touch_status = InputData::Touch(point).pressed().once();
}
SimulatorEvent::Quit => break 'running,
_ => {}