dioxus/packages/desktop/src/events.rs

89 lines
1.6 KiB
Rust
Raw Normal View History

//! Convert a serialized event to an event Trigger
//!
use std::rc::Rc;
use dioxus_core::{
events::{
on::{MouseEvent, MouseEventInner},
2021-08-25 20:40:18 +00:00
SyntheticEvent,
},
2021-08-31 16:28:57 +00:00
ElementId, EventPriority, ScopeId, UiEvent,
};
#[derive(serde::Serialize, serde::Deserialize)]
struct ImEvent {
event: String,
mounted_dom_id: u64,
scope: u64,
}
2021-08-31 16:28:57 +00:00
pub fn trigger_from_serialized(val: serde_json::Value) -> UiEvent {
let mut data: Vec<ImEvent> = serde_json::from_value(val).unwrap();
let data = data.drain(..).next().unwrap();
2021-08-25 20:40:18 +00:00
let event = SyntheticEvent::MouseEvent(MouseEvent(Rc::new(WebviewMouseEvent)));
let scope = ScopeId(data.scope as usize);
let mounted_dom_id = Some(ElementId(data.mounted_dom_id as usize));
2021-08-31 16:28:57 +00:00
UiEvent {
2021-08-27 02:05:09 +00:00
event,
scope,
mounted_dom_id,
}
}
#[derive(Debug)]
struct WebviewMouseEvent;
impl MouseEventInner for WebviewMouseEvent {
fn alt_key(&self) -> bool {
todo!()
}
fn button(&self) -> i16 {
todo!()
}
fn buttons(&self) -> u16 {
todo!()
}
fn client_x(&self) -> i32 {
todo!()
}
fn client_y(&self) -> i32 {
todo!()
}
fn ctrl_key(&self) -> bool {
todo!()
}
fn meta_key(&self) -> bool {
todo!()
}
fn page_x(&self) -> i32 {
todo!()
}
fn page_y(&self) -> i32 {
todo!()
}
fn screen_x(&self) -> i32 {
todo!()
}
fn screen_y(&self) -> i32 {
todo!()
}
fn shift_key(&self) -> bool {
todo!()
}
fn get_modifier_state(&self, key_code: &str) -> bool {
todo!()
}
}