From aca11351791218c9822243023bc8e8e049d6d307 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Mon, 24 Jun 2024 13:28:24 +1200 Subject: [PATCH] Debug log hovered node's parent on right click --- packages/blitz/src/render.rs | 13 ++++++++++--- packages/dioxus-blitz/src/window.rs | 9 +++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/blitz/src/render.rs b/packages/blitz/src/render.rs index 1fb70e6b..73e2186b 100644 --- a/packages/blitz/src/render.rs +++ b/packages/blitz/src/render.rs @@ -267,7 +267,7 @@ where .max(-(content_height - viewport_height)); } - pub fn click(&mut self) { + pub fn click(&mut self, button: &str) { let Some(node_id) = self.dom.as_ref().get_hover_node_id() else { return; }; @@ -277,7 +277,14 @@ where }; if self.devtools.highlight_hover { - let node = &self.dom.as_ref().get_node(node_id).unwrap(); + let mut node = self.dom.as_ref().get_node(node_id).unwrap(); + + if button == "right" { + if let Some(parent_id) = node.parent { + node = self.dom.as_ref().get_node(parent_id).unwrap(); + } + } + dbg!(&node.final_layout); dbg!(&node.style); @@ -349,7 +356,7 @@ where // If we hit a node, then we collect the node to its parents, check for listeners, and then // call those listeners - if !self.devtools.highlight_hover { + if !self.devtools.highlight_hover && button == "left" { self.dom.handle_event(RendererEvent { name: "click".to_string(), target: node_id, diff --git a/packages/dioxus-blitz/src/window.rs b/packages/dioxus-blitz/src/window.rs index 3f5f9d0d..56142873 100644 --- a/packages/dioxus-blitz/src/window.rs +++ b/packages/dioxus-blitz/src/window.rs @@ -67,8 +67,13 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> { // modifiers, .. } => { - if state == ElementState::Pressed && button == MouseButton::Left { - self.renderer.click(); + if state == ElementState::Pressed && matches!(button, MouseButton::Left | MouseButton::Right) { + self.renderer.click(match button { + MouseButton::Left => "left", + MouseButton::Right => "right", + _ => unreachable!(), + + }); self.request_redraw(); }