Skip to content

Commit

Permalink
Merge pull request #187 from Remmirad/context-menu-release-event-hand…
Browse files Browse the repository at this point in the history
…ling

Update event handling for context_menu overlay
  • Loading branch information
Andrew Wheeler(Genusis) authored Sep 30, 2023
2 parents fe20800 + e19c67c commit b71f220
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 b71f220

Please sign in to comment.