Touch input device #27
3 changed files with 7 additions and 11 deletions
|
@ -1,3 +1,4 @@
|
|||
use core::cell::Cell;
|
||||
use cstr_core::CString;
|
||||
use embedded_graphics::pixelcolor::Rgb565;
|
||||
use embedded_graphics::prelude::*;
|
||||
|
@ -8,8 +9,6 @@ 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::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::thread::sleep;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
|
@ -26,13 +25,11 @@ fn main() -> Result<(), LvError> {
|
|||
ui.disp_drv_register(display)?;
|
||||
|
||||
// Initial state of input
|
||||
let latest_touch_status: Rc<RefCell<BufferStatus>> = Rc::new(RefCell::new(
|
||||
InputData::Touch(Point::new(0, 0)).released().once(),
|
||||
));
|
||||
let latest_touch_status: Cell<BufferStatus> =
|
||||
Cell::new(InputData::Touch(Point::new(0, 0)).released().once());
|
||||
|
||||
// Register the input mode
|
||||
let internal = Rc::clone(&latest_touch_status);
|
||||
let mut touch_screen = Pointer::new(move || internal.borrow().clone());
|
||||
let mut touch_screen = Pointer::new(|| latest_touch_status.get());
|
||||
|
||||
ui.indev_drv_register(&mut touch_screen)?;
|
||||
|
||||
|
@ -52,7 +49,7 @@ fn main() -> Result<(), LvError> {
|
|||
|
||||
let mut btn_state = false;
|
||||
button.on_event(|mut btn, event| {
|
||||
println!("Some event! {:?}", event);
|
||||
println!("Button received event: {:?}", event);
|
||||
if let lvgl::Event::Clicked = event {
|
||||
if btn_state {
|
||||
let nt = CString::new("Click me!").unwrap();
|
||||
|
@ -62,7 +59,6 @@ fn main() -> Result<(), LvError> {
|
|||
btn_lbl.set_text(nt.as_c_str()).unwrap();
|
||||
}
|
||||
btn_state = !btn_state;
|
||||
println!("Clicked! Inner..");
|
||||
btn.toggle().unwrap();
|
||||
}
|
||||
})?;
|
||||
|
|
|
@ -47,7 +47,7 @@ pub struct Pointer {
|
|||
}
|
||||
|
||||
impl Pointer {
|
||||
pub fn new<F>(mut handler: F) -> Self
|
||||
pub fn new<F>(handler: F) -> Self
|
||||
where
|
||||
F: Fn() -> BufferStatus,
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::input_device::{BufferStatus, Pointer};
|
||||
use crate::input_device::Pointer;
|
||||
use crate::mem::Box;
|
||||
use crate::{Color, Event, LvError, LvResult, Obj, Widget};
|
||||
use core::marker::PhantomData;
|
||||
|
|
Loading…
Reference in a new issue