Make it possible to send events
This commit is contained in:
parent
096d175fc0
commit
b8a559a6cf
3 changed files with 35 additions and 4 deletions
|
@ -4,7 +4,7 @@ use embedded_graphics_simulator::{
|
|||
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
|
||||
};
|
||||
use lvgl::widgets::{Bar, Label};
|
||||
use lvgl::{self, Align, Animation, Color, DisplayDriver, Object, Style, UI};
|
||||
use lvgl::{self, Align, Animation, Color, DisplayDriver, Event, Object, Style, UI};
|
||||
use lvgl_sys;
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::thread::sleep;
|
||||
|
@ -45,9 +45,9 @@ fn main() -> Result<(), String> {
|
|||
loading_lbl.set_text("Loading...");
|
||||
loading_lbl.set_align(&mut bar, Align::OutTopMid, 0, -10);
|
||||
|
||||
loading_lbl.on_event(|mut this, event| {
|
||||
loading_lbl.on_event(|_, event| {
|
||||
if let lvgl::Event::Clicked = event {
|
||||
this.set_text("Clicked!");
|
||||
println!("Loaded!");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -73,6 +73,10 @@ fn main() -> Result<(), String> {
|
|||
'running: loop {
|
||||
if i > 100 {
|
||||
i = 0;
|
||||
threaded_ui
|
||||
.lock()
|
||||
.unwrap()
|
||||
.event_send(&mut loading_lbl, Event::Clicked)
|
||||
}
|
||||
bar.set_value(i, Animation::OFF);
|
||||
i += 1;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{DisplayDriver, Object, ObjectX};
|
||||
use crate::{DisplayDriver, Event, Object, ObjectX};
|
||||
use alloc::boxed::Box;
|
||||
use core::marker::PhantomData;
|
||||
use core::ptr;
|
||||
|
@ -54,6 +54,15 @@ impl UI {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn event_send<T>(&mut self, obj: &mut T, event: Event<T::SpecialEvent>)
|
||||
where
|
||||
T: Object,
|
||||
{
|
||||
unsafe {
|
||||
lvgl_sys::lv_event_send(obj.raw().as_mut(), event.into(), ptr::null_mut());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick_inc(&mut self, tick_period: Duration) {
|
||||
unsafe {
|
||||
lvgl_sys::lv_tick_inc(tick_period.as_millis() as u32);
|
||||
|
|
|
@ -374,6 +374,24 @@ impl<S> TryFrom<lvgl_sys::lv_event_t> for Event<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> From<Event<S>> for lvgl_sys::lv_event_t {
|
||||
fn from(event: Event<S>) -> Self {
|
||||
let native_event = match event {
|
||||
Event::Pressed => lvgl_sys::LV_EVENT_PRESSED,
|
||||
Event::Pressing => lvgl_sys::LV_EVENT_PRESSING,
|
||||
Event::PressLost => lvgl_sys::LV_EVENT_PRESS_LOST,
|
||||
Event::ShortClicked => lvgl_sys::LV_EVENT_SHORT_CLICKED,
|
||||
Event::Clicked => lvgl_sys::LV_EVENT_CLICKED,
|
||||
Event::LongPressed => lvgl_sys::LV_EVENT_LONG_PRESSED,
|
||||
Event::LongPressedRepeat => lvgl_sys::LV_EVENT_LONG_PRESSED_REPEAT,
|
||||
Event::Released => lvgl_sys::LV_EVENT_RELEASED,
|
||||
// TODO: handle all types...
|
||||
_ => lvgl_sys::LV_EVENT_CLICKED,
|
||||
};
|
||||
native_event as lvgl_sys::lv_event_t
|
||||
}
|
||||
}
|
||||
|
||||
/// These events are sent only by pointer-like input devices (E.g. mouse or touchpad)
|
||||
pub enum PointerEvent {
|
||||
DragBegin,
|
||||
|
|
Loading…
Reference in a new issue