widget event handling into macro
This commit is contained in:
@@ -17,19 +17,19 @@
|
||||
</theme>
|
||||
|
||||
<template name="Device">
|
||||
<sprite color="~device_color" width="48" height="48" src="${src}" />
|
||||
<sprite color="~device_color" width="${size}" height="${size}" src="${src}" />
|
||||
</template>
|
||||
|
||||
<elements>
|
||||
<div width="400" height="200">
|
||||
<rectangle width="100%" height="100%" padding="4" box_sizing="content_box" flex_wrap="wrap" gap="16" color="~bg_color">
|
||||
<div width="100%" flex_direction="row">
|
||||
<Device src="watch/hmd.svg" />
|
||||
<Device src="watch/controller.svg" />
|
||||
<Device src="watch/controller.svg" />
|
||||
<Device src="watch/track3.svg" />
|
||||
<Device src="watch/track3.svg" />
|
||||
<Device src="watch/track3.svg" />
|
||||
<Device src="watch/hmd.svg" size="40" />
|
||||
<Device src="watch/controller_l.svg" size="36" />
|
||||
<Device src="watch/controller_r.svg" size="36" />
|
||||
<Device src="watch/track3.svg" size="40" />
|
||||
<Device src="watch/track3.svg" size="40" />
|
||||
<Device src="watch/track3.svg" size="40" />
|
||||
</div>
|
||||
<div flex_direction="row">
|
||||
<div id="clock_main" flex_direction="column" padding="4">
|
||||
@@ -51,4 +51,4 @@
|
||||
</rectangle>
|
||||
</div>
|
||||
</elements>
|
||||
</layout>
|
||||
</layout>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><!-- Icon from Material Symbols by Google - https://github.com/google/material-design-icons/blob/master/LICENSE --><path fill="white" d="M11 18q-1.65 0-2.825-1.175T7 14q-2.5.025-4.25-1.737T1 8q0-.825.588-1.412T3 6h4V5H5V3h6v2H9v1h3.175q.4 0 .763.15t.637.425l8.375 8.375Q23 16 23 17.45t-1.05 2.5t-2.5 1.05t-2.5-1.05L15 18zm0-4H8.975q0 .825.588 1.413T11 16h2z"/></svg>
|
||||
|
Before Width: | Height: | Size: 450 B |
@@ -183,7 +183,7 @@ where
|
||||
*widget_id,
|
||||
EventListener::MouseEnter(Box::new({
|
||||
let (k, kb) = (key_state.clone(), state.clone());
|
||||
move |data| {
|
||||
move |data, ()| {
|
||||
data.trigger_haptics = true;
|
||||
on_enter_anim(k.clone(), kb.clone(), data);
|
||||
}
|
||||
@@ -193,7 +193,7 @@ where
|
||||
*widget_id,
|
||||
EventListener::MouseLeave(Box::new({
|
||||
let (k, kb) = (key_state.clone(), state.clone());
|
||||
move |data| {
|
||||
move |data, ()| {
|
||||
data.trigger_haptics = true;
|
||||
on_leave_anim(k.clone(), kb.clone(), data);
|
||||
}
|
||||
@@ -235,7 +235,7 @@ where
|
||||
*widget_id,
|
||||
EventListener::InternalStateChange(Box::new({
|
||||
let (k, kb) = (key_state.clone(), state.clone());
|
||||
move |data| {
|
||||
move |data, _| {
|
||||
if (kb.borrow().modifiers & modifier) != 0 {
|
||||
on_press_anim(k.clone(), data);
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,10 @@ use std::{
|
||||
};
|
||||
|
||||
use vulkano::image::view::ImageView;
|
||||
use wgui::{drawing, event::MouseButton};
|
||||
use wgui::{
|
||||
drawing,
|
||||
event::{InternalStateChangeEvent, MouseButton},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
backend::{
|
||||
@@ -57,11 +60,13 @@ impl OverlayBackend for KeyboardBackend {
|
||||
impl InteractionHandler for KeyboardBackend {
|
||||
fn on_pointer(&mut self, app: &mut AppState, hit: &PointerHit, pressed: bool) {
|
||||
self.panel.on_pointer(app, hit, pressed);
|
||||
self.handle_invoke(app);
|
||||
let _ = self
|
||||
.panel
|
||||
.layout
|
||||
.push_event(&wgui::event::Event::InternalStateChange);
|
||||
self.handle_invoke(app);
|
||||
.push_event(&wgui::event::Event::InternalStateChange(
|
||||
InternalStateChangeEvent { metadata: 0 },
|
||||
));
|
||||
}
|
||||
fn on_scroll(&mut self, app: &mut AppState, hit: &PointerHit, delta_y: f32, delta_x: f32) {
|
||||
self.panel.on_scroll(app, hit, delta_y, delta_x);
|
||||
@@ -102,7 +107,9 @@ impl OverlayRenderer for KeyboardBackend {
|
||||
self.panel.resume(app)?;
|
||||
self.panel
|
||||
.layout
|
||||
.push_event(&wgui::event::Event::InternalStateChange)?;
|
||||
.push_event(&wgui::event::Event::InternalStateChange(
|
||||
InternalStateChangeEvent { metadata: 0 },
|
||||
))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user