Feat: yeet, synthetic somewhat wired up
This commit is contained in:
1 parent
3087813570
commit
d9598066c2
7 files changed
+79
-47
No files matched your search
@@ -342,6 +342,7 @@ impl Parse for Attr {
|
|||||||
impl ToTokens for ToToksCtx<&Attr> {
|
impl ToTokens for ToToksCtx<&Attr> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let name = self.inner.name.to_string();
|
let name = self.inner.name.to_string();
|
||||||
|
let nameident = &self.inner.name;
|
||||||
let mut attr_stream = TokenStream2::new();
|
let mut attr_stream = TokenStream2::new();
|
||||||
match &self.inner.ty {
|
match &self.inner.ty {
|
||||||
AttrType::Value(value) => {
|
AttrType::Value(value) => {
|
||||||
@@ -352,13 +353,15 @@ impl ToTokens for ToToksCtx<&Attr> {
|
|||||||
}
|
}
|
||||||
AttrType::Event(event) => {
|
AttrType::Event(event) => {
|
||||||
tokens.append_all(quote! {
|
tokens.append_all(quote! {
|
||||||
.on(#name, #event)
|
.add_listener(dioxus::events::on::#nameident(ctx, #event))
|
||||||
});
|
});
|
||||||
|
// .on(#name, #event)
|
||||||
}
|
}
|
||||||
AttrType::Tok(exp) => {
|
AttrType::Tok(exp) => {
|
||||||
tokens.append_all(quote! {
|
tokens.append_all(quote! {
|
||||||
.on(#name, #exp)
|
.add_listener(dioxus::events::on::#nameident(ctx, #exp))
|
||||||
});
|
});
|
||||||
|
// .on(#name, #exp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -93,7 +93,7 @@ pub mod on {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GetModifierKey(Box<dyn Fn(usize) -> bool>);
|
pub struct GetModifierKey(pub Box<dyn Fn(usize) -> bool>);
|
||||||
impl std::fmt::Debug for GetModifierKey {
|
impl std::fmt::Debug for GetModifierKey {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
// just skip for now
|
// just skip for now
|
||||||
@@ -159,7 +159,7 @@ pub mod on {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MouseEvent(Box<RawMouseEvent>);
|
pub struct MouseEvent(pub Box<RawMouseEvent>);
|
||||||
impl Deref for MouseEvent {
|
impl Deref for MouseEvent {
|
||||||
type Target = RawMouseEvent;
|
type Target = RawMouseEvent;
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
@@ -168,19 +168,19 @@ pub mod on {
|
|||||||
}
|
}
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RawMouseEvent {
|
pub struct RawMouseEvent {
|
||||||
alt_key: bool,
|
pub alt_key: bool,
|
||||||
button: usize,
|
pub button: i32,
|
||||||
buttons: usize,
|
pub buttons: i32,
|
||||||
client_x: i32,
|
pub client_x: i32,
|
||||||
client_y: i32,
|
pub client_y: i32,
|
||||||
ctrl_key: bool,
|
pub ctrl_key: bool,
|
||||||
meta_key: bool,
|
pub meta_key: bool,
|
||||||
page_x: i32,
|
pub page_x: i32,
|
||||||
page_y: i32,
|
pub page_y: i32,
|
||||||
screen_x: i32,
|
pub screen_x: i32,
|
||||||
screen_y: i32,
|
pub screen_y: i32,
|
||||||
shift_key: bool,
|
pub shift_key: bool,
|
||||||
get_modifier_state: GetModifierKey,
|
pub get_modifier_state: GetModifierKey,
|
||||||
// relatedTarget: DOMEventTarget,
|
// relatedTarget: DOMEventTarget,
|
||||||
}
|
}
|
||||||
event_builder! {
|
event_builder! {
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ mod use_reducer_def {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
|
|
||||||
enum Actions {
|
enum Actions {
|
||||||
Incr,
|
Incr,
|
||||||
Decr,
|
Decr,
|
||||||
|
|||||||
@@ -339,18 +339,18 @@ where
|
|||||||
/// })
|
/// })
|
||||||
/// .finish();
|
/// .finish();
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
|
||||||
pub fn on(mut self, event: &'static str, callback: impl Fn(VirtualEvent) + 'a) -> Self {
|
pub fn on(mut self, event: &'static str, callback: impl Fn(VirtualEvent) + 'a) -> Self {
|
||||||
// todo:
|
let listener = Listener {
|
||||||
// increment listner id from nodectx ref
|
|
||||||
// add listener attrs here instead of later?
|
|
||||||
|
|
||||||
self.listeners.push(Listener {
|
|
||||||
event,
|
event,
|
||||||
callback: self.ctx.bump.alloc(callback),
|
callback: self.ctx.bump.alloc(callback),
|
||||||
id: *self.ctx.idx.borrow(),
|
id: *self.ctx.idx.borrow(),
|
||||||
scope: self.ctx.scope,
|
scope: self.ctx.scope,
|
||||||
});
|
};
|
||||||
|
self.add_listener(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_listener(mut self, listener: Listener<'a>) -> Self {
|
||||||
|
self.listeners.push(listener);
|
||||||
|
|
||||||
// bump the context id forward
|
// bump the context id forward
|
||||||
*self.ctx.idx.borrow_mut() += 1;
|
*self.ctx.idx.borrow_mut() += 1;
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
use dioxus_core::{events::on::MouseEvent, prelude::*};
|
||||||
|
use dioxus_web::WebsysRenderer;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Setup logging
|
||||||
|
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
|
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(Example));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Example: FC<()> = |ctx, _props| {
|
||||||
|
let handler = move |evt: MouseEvent| {
|
||||||
|
// Awesome!
|
||||||
|
// We get type inference with events
|
||||||
|
dbg!(evt.alt_key);
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.render(rsx! {
|
||||||
|
button {
|
||||||
|
"Hello"
|
||||||
|
onclick: {handler}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
@@ -16,6 +16,7 @@ fn main() {
|
|||||||
static Example: FC<()> = |ctx, props| {
|
static Example: FC<()> = |ctx, props| {
|
||||||
let (name, set_name) = use_state(&ctx, || "...?");
|
let (name, set_name) = use_state(&ctx, || "...?");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ctx.render(rsx! {
|
ctx.render(rsx! {
|
||||||
div {
|
div {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{borrow::Borrow, fmt::Debug, sync::Arc};
|
use std::{borrow::Borrow, convert::TryInto, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use dioxus_core::{
|
use dioxus_core::{
|
||||||
events::{EventTrigger, MouseEvent, VirtualEvent},
|
events::{EventTrigger, VirtualEvent},
|
||||||
patch::Edit,
|
patch::Edit,
|
||||||
prelude::ScopeIdx,
|
prelude::ScopeIdx,
|
||||||
};
|
};
|
||||||
@@ -481,30 +481,34 @@ impl PatchMachine {
|
|||||||
Edit::RemoveKnown => {}
|
Edit::RemoveKnown => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 24
|
|
||||||
// pub fn save_template(&mut self, id: CacheId) {
|
|
||||||
// let template = self.stack.top();
|
|
||||||
// let t = template.clone_node_with_deep(true).unwrap();
|
|
||||||
// // self.templates.insert(id, t);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 25
|
|
||||||
// pub fn push_template(&mut self, id: CacheId) {
|
|
||||||
// let template = self.get_template(id).unwrap();
|
|
||||||
// let t = template.clone_node_with_deep(true).unwrap();
|
|
||||||
// self.stack.push(t);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn has_template(&self, id: CacheId) -> bool {
|
|
||||||
// todo!()
|
|
||||||
// // self.templates.contains_key(&id)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent {
|
fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent {
|
||||||
|
use dioxus_core::events::on::*;
|
||||||
match event.type_().as_str() {
|
match event.type_().as_str() {
|
||||||
"click" => VirtualEvent::MouseEvent(MouseEvent {}),
|
"click" | "contextmenu" | "doubleclick" | "drag" | "dragend" | "dragenter" | "dragexit"
|
||||||
|
| "dragleave" | "dragover" | "dragstart" | "drop" | "mousedown" | "mouseenter"
|
||||||
|
| "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => {
|
||||||
|
let evt: web_sys::MouseEvent = event.clone().dyn_into().unwrap();
|
||||||
|
VirtualEvent::MouseEvent(MouseEvent(Box::new(RawMouseEvent {
|
||||||
|
alt_key: evt.alt_key(),
|
||||||
|
button: evt.button() as i32,
|
||||||
|
buttons: evt.buttons() as i32,
|
||||||
|
client_x: evt.client_x(),
|
||||||
|
client_y: evt.client_y(),
|
||||||
|
ctrl_key: evt.ctrl_key(),
|
||||||
|
meta_key: evt.meta_key(),
|
||||||
|
page_x: evt.page_x(),
|
||||||
|
page_y: evt.page_y(),
|
||||||
|
screen_x: evt.screen_x(),
|
||||||
|
screen_y: evt.screen_y(),
|
||||||
|
shift_key: evt.shift_key(),
|
||||||
|
get_modifier_state: GetModifierKey(Box::new(|f| {
|
||||||
|
// evt.get_modifier_state(f)
|
||||||
|
todo!("This is not yet implemented properly, sorry :(");
|
||||||
|
})),
|
||||||
|
})))
|
||||||
|
}
|
||||||
_ => VirtualEvent::OtherEvent,
|
_ => VirtualEvent::OtherEvent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user