mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 06:53:19 -10:00
The bar can now drive an interactive example. A row of bench/bevy-parity/runs.tsv may name an input script, in the format `raea play --input-script` takes ({"FRAME": ["Pointer:X:Y:down"]}). The example gets it as RAEA_PARITY_INPUT: systems/parity input.rs writes bevy_picking's PointerInput messages on the picture the cameras draw into. The port's pictures then come from `raea play` under the same script; cost still comes from the render.
Gaps found and patched on the way:
- raea play sent its pointer only to useInput, never to page elements, so a composition's onClick never ran. The live step now hit tests the pointer on the page (BevyPage::hit_path) and sends its React handlers the events a browser fires, in a browser's order: over/out, enter/leave, move, down/up, and click on what both the press and the release were over (runtime/live pointer.rs).
- bevy_ui_widgets' Popover: Node takes `popover` ({positions: [{side, align, gap}], window_margin}). raea's Blitz places the popup after layout beside its parent's box (inside its border), at the first placement the window hides least, as position_popover does (vendor/blitz-dom bevy_popover.rs). It's drawn and hit tested there. Node also takes bevy_picking's handlers (onClick, onPointerDown/Up/Over/Out/Enter/Leave/Move; sdk/render ui-pick.ts). The page bridge keeps data-raea-bevy-popover.
- After any state change in play, bevy text was drawn broken at min-content width: raea's bevy_text min-content measure breaks lines at width 0, and a box whose layout taffy kept from its cache never broke them back. A measure now puts back the lines a laid-out box keeps (blitz-dom inline.rs, TextLayout::performed_width).
The port's Button reads "Hover" and "Press" as set_button_style has it; the menu button toggles spawn_menu's popup of four items, each lit while hovered; activating an item closes the menu. Under a click on Menu, then the pointer on the first item: 0.994691, worst tile 17. Without the toggle, the popover, GlobalZIndex or hover, with the side flipped, a 6 px gap, three items or 90% width, the bar fails; a gray border passes it and the probe catches it (7217 px off against 6465). conformance/ui-pick.test.tsx; blitz-dom bevy_popover tests; runtime/live pointer test.
77 lines
3.6 KiB
Rust
77 lines
3.6 KiB
Rust
//! The play's pointer on the page's elements (docs/control.feature FC0a, FC3c): each frame's pointer, a window's or
|
|
//! `--input-script`'s "Pointer:X:Y[:down]", hit tested on the page as last laid out, its events sent to the React
|
|
//! elements' on* handlers as a browser fires them: pointerOut and pointerOver along the old and new paths when the
|
|
//! element under it changes, pointerLeave and pointerEnter on the elements left and entered (innermost left first,
|
|
//! outermost entered first), pointerMove when it moves, pointerDown and pointerUp on the button's edges, and click on
|
|
//! the elements both the press and the release were over. Each goes to every element up the path (bevy-react runs
|
|
//! the ones that have that handler), as `{"t": "uiEvent"}` (runtime/react pointer.rs), before the frame's step.
|
|
|
|
use serde_json::{Value, json};
|
|
|
|
/// The page pointer as the last frame left it.
|
|
#[derive(Default)]
|
|
pub(crate) struct PagePointer {
|
|
at: Option<(f64, f64)>,
|
|
path: Vec<u64>,
|
|
down: Option<Vec<u64>>,
|
|
}
|
|
|
|
impl PagePointer {
|
|
/// This frame's events for a pointer at `(x, y, down)` over `path` (the elements under it, innermost first).
|
|
pub(crate) fn step(&mut self, (x, y, down): (f64, f64, bool), path: Vec<u64>) -> Vec<Value> {
|
|
let mut out = Vec::new();
|
|
let mut send = |ids: &mut dyn Iterator<Item = &u64>, kind: &str| {
|
|
for id in ids {
|
|
out.push(json!({"t": "uiEvent", "event": {"id": id, "kind": kind, "x": x, "y": y, "button": 0}}));
|
|
}
|
|
};
|
|
if self.path.first() != path.first() {
|
|
send(&mut self.path.iter(), "pointerOut");
|
|
send(&mut self.path.iter().filter(|id| !path.contains(id)), "pointerLeave");
|
|
send(&mut path.iter(), "pointerOver");
|
|
send(&mut path.iter().rev().filter(|id| !self.path.contains(id)), "pointerEnter");
|
|
}
|
|
if self.at.is_some_and(|a| a != (x, y)) {
|
|
send(&mut path.iter(), "pointerMove");
|
|
}
|
|
match (down, self.down.take()) {
|
|
(true, None) => {
|
|
send(&mut path.iter(), "pointerDown");
|
|
self.down = Some(path.clone());
|
|
}
|
|
(true, held) => self.down = held,
|
|
(false, Some(pressed)) => {
|
|
send(&mut path.iter(), "pointerUp");
|
|
send(&mut path.iter().filter(|id| pressed.contains(id)), "click");
|
|
}
|
|
(false, None) => {}
|
|
}
|
|
self.at = Some((x, y));
|
|
self.path = path;
|
|
out
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
fn kinds(v: &[Value]) -> Vec<(String, u64)> {
|
|
v.iter().map(|m| (m["event"]["kind"].as_str().unwrap().to_string(), m["event"]["id"].as_u64().unwrap())).collect()
|
|
}
|
|
|
|
#[test]
|
|
fn a_browsers_order_over_enter_down_up_click() {
|
|
let mut p = PagePointer::default();
|
|
let k = |s: &str, id: u64| (s.to_string(), id);
|
|
// onto a child (5) of 3: over bubbles, enter from the outside in
|
|
assert_eq!(kinds(&p.step((10.0, 10.0, false), vec![5, 3])), vec![k("pointerOver", 5), k("pointerOver", 3), k("pointerEnter", 3), k("pointerEnter", 5)]);
|
|
// pressed on 5, released on its parent 3 alone: the click is 3's
|
|
assert_eq!(kinds(&p.step((10.0, 10.0, true), vec![5, 3])), vec![k("pointerDown", 5), k("pointerDown", 3)]);
|
|
let up = kinds(&p.step((20.0, 10.0, false), vec![3]));
|
|
assert_eq!(up, vec![k("pointerOut", 5), k("pointerOut", 3), k("pointerLeave", 5), k("pointerOver", 3), k("pointerMove", 3), k("pointerUp", 3), k("click", 3)]);
|
|
// still: nothing
|
|
assert!(p.step((20.0, 10.0, false), vec![3]).is_empty());
|
|
}
|
|
}
|