garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

cartopolis-agent · 2026-11-26T18:34:07Z

fix(mithril_bevy): pointer-events: none lets a press through

Bevy's picking stops at the first node under the pointer, and the
renderer never read pointer-events, so a full-window layer that does not
listen (the map chrome's frame, the Midas link's) covered every screen
under it: on the phone only the topmost screen's buttons answered.
pointer-events is now inherited as in CSS and none becomes
Pickable::IGNORE.
crates/mithril_bevy/src/tree.rs | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/crates/mithril_bevy/src/tree.rs b/crates/mithril_bevy/src/tree.rs
index 8e03391e..3bebef2f 100644
--- a/crates/mithril_bevy/src/tree.rs
+++ b/crates/mithril_bevy/src/tree.rs
@@ -740,6 +740,7 @@ fn style_node(
         };
         with_host(|host| host.stylist.compute(&chain, parent_computed, &host.env))
     };
+    let computed = inherit_pointer_events(computed, parent_computed);
     let opacity = parent.opacity * computed.opacity;
     Some((computed, opacity, states, node.entity))
 }
@@ -762,6 +763,31 @@ fn inherit_only(parent: &Computed) -> Computed {
     }
 }
 
+/// `pointer-events` is inherited in CSS, and the cascade keeps it in
+/// `other`, which is not: a node that does not say takes its parent's.
+fn inherit_pointer_events(mut c: Computed, parent: &Computed) -> Computed {
+    if !c.other.contains_key(POINTER_EVENTS) {
+        if let Some(v) = parent.other.get(POINTER_EVENTS) {
+            c.other.insert(POINTER_EVENTS.into(), v.clone());
+        }
+    }
+    c
+}
+
+const POINTER_EVENTS: &str = "pointer-events";
+
+/// What a press does over the node. Bevy's picking stops at the first node
+/// under the pointer, so a full-window layer that does not listen covers
+/// every screen under it unless `pointer-events: none` lets the press
+/// through, as a browser does.
+fn pickable(c: &Computed) -> Pickable {
+    if c.other.get(POINTER_EVENTS).is_some_and(|v| v == "none") {
+        Pickable::IGNORE
+    } else {
+        Pickable::default()
+    }
+}
+
 fn element_of(n: &ShadowNode) -> Element {
     match &n.kind {
         NodeKind::Element {
@@ -869,6 +895,7 @@ fn write_components(
     fonts: Option<&FontMap>,
 ) {
     let is_text = world.get::<Text>(e).is_some();
+    world.entity_mut(e).insert(pickable(c));
     let (tag, classes, props, states) = {
         let tree = world.resource::<UiTree>();
         match tree.nodes.get(&id).map(|n| &n.kind) {