Skip to content

Commit

Permalink
Debug log hovered node's parent on right click
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jun 24, 2024
1 parent 3618b22 commit aca1135
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/blitz/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions packages/dioxus-blitz/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit aca1135

Please sign in to comment.