Skip to content

Commit

Permalink
Update event handling for context-menu overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Aschmann committed Sep 30, 2023
1 parent fe20800 commit e19c67c
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/native/overlay/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ where
.next()
.expect("Native: Layout should have a content layout.");

let mut forward_event_to_children = true;

let status = match event {
Event::Keyboard(keyboard::Event::KeyPressed { key_code, .. }) => {
if key_code == keyboard::KeyCode::Escape {
self.state.show = false;
forward_event_to_children = false;
Status::Captured
} else {
Status::Ignored
Expand All @@ -158,34 +161,30 @@ where
mouse::Button::Left | mouse::Button::Right,
))
| Event::Touch(touch::Event::FingerPressed { .. }) => {
if cursor.is_over(layout_children.bounds()) {
Status::Ignored
} else {
if !cursor.is_over(layout_children.bounds()) {
self.state.show = false;
Status::Captured
forward_event_to_children = false;
}
Status::Captured
}

Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) => {
// close when released because because button send message on release
self.state.show = false;
if cursor.is_over(layout_children.bounds()) {
Status::Ignored
} else {
Status::Captured
}
Status::Captured
}

Event::Window(window::Event::Resized { .. }) => {
self.state.show = false;
forward_event_to_children = false;
Status::Captured
}

_ => Status::Ignored,
};

match status {
Status::Ignored => self.content.as_widget_mut().on_event(
let child_status = if forward_event_to_children {
self.content.as_widget_mut().on_event(
self.tree,
event,
layout_children,
Expand All @@ -194,7 +193,13 @@ where
clipboard,
shell,
&layout.bounds(),
),
)
} else {
Status::Ignored
};

match child_status {
Status::Ignored => status,
Status::Captured => Status::Captured,
}
}
Expand Down

0 comments on commit e19c67c

Please sign in to comment.