fix(segmented_button): close context menu when clicked outside
This commit is contained in:
parent
3f2ba11d56
commit
51ede4bce6
2 changed files with 20 additions and 5 deletions
|
|
@ -579,7 +579,7 @@ where
|
||||||
.merge(menu_status)
|
.merge(menu_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
Mouse(ButtonReleased(Left)) | Touch(FingerLifted { .. }) => {
|
Mouse(ButtonReleased(_)) | Touch(FingerLifted { .. }) => {
|
||||||
let state = self.tree.state.downcast_mut::<MenuBarState>();
|
let state = self.tree.state.downcast_mut::<MenuBarState>();
|
||||||
state.pressed = false;
|
state.pressed = false;
|
||||||
|
|
||||||
|
|
@ -596,7 +596,13 @@ where
|
||||||
.iter()
|
.iter()
|
||||||
.any(|ms| ms.menu_bounds.check_bounds.contains(overlay_cursor));
|
.any(|ms| ms.menu_bounds.check_bounds.contains(overlay_cursor));
|
||||||
|
|
||||||
if self.close_condition.click_inside && is_inside {
|
if self.close_condition.click_inside
|
||||||
|
&& is_inside
|
||||||
|
&& matches!(
|
||||||
|
event,
|
||||||
|
Mouse(ButtonReleased(Left)) | Touch(FingerLifted { .. })
|
||||||
|
)
|
||||||
|
{
|
||||||
state.reset();
|
state.reset();
|
||||||
return Captured;
|
return Captured;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -910,6 +910,13 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Event::Mouse(mouse::Event::ButtonReleased(_))
|
||||||
|
| Event::Touch(touch::Event::FingerLifted { .. }) = event
|
||||||
|
{
|
||||||
|
state.focused = false;
|
||||||
|
state.focused_item = Item::None;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(on_activate) = self.on_activate.as_ref() {
|
if let Some(on_activate) = self.on_activate.as_ref() {
|
||||||
if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
|
if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
|
||||||
| Event::Touch(touch::Event::FingerLifted { .. }) = event
|
| Event::Touch(touch::Event::FingerLifted { .. }) = event
|
||||||
|
|
@ -928,8 +935,6 @@ where
|
||||||
state.show_context = Some(key);
|
state.show_context = Some(key);
|
||||||
state.context_cursor =
|
state.context_cursor =
|
||||||
cursor_position.position().unwrap_or_default();
|
cursor_position.position().unwrap_or_default();
|
||||||
state.focused = true;
|
|
||||||
state.focused_item = Item::Tab(key);
|
|
||||||
|
|
||||||
let menu_state =
|
let menu_state =
|
||||||
tree.children[0].state.downcast_mut::<MenuBarState>();
|
tree.children[0].state.downcast_mut::<MenuBarState>();
|
||||||
|
|
@ -1321,13 +1326,17 @@ where
|
||||||
|
|
||||||
let center_y = bounds.center_y();
|
let center_y = bounds.center_y();
|
||||||
|
|
||||||
|
let menu_open = !tree.children.is_empty()
|
||||||
|
&& tree.children[0].state.downcast_ref::<MenuBarState>().open;
|
||||||
|
|
||||||
let key_is_active = self.model.is_active(key);
|
let key_is_active = self.model.is_active(key);
|
||||||
let key_is_hovered = self.button_is_hovered(state, key);
|
let key_is_hovered = self.button_is_hovered(state, key);
|
||||||
|
let key_has_context_menu_open = menu_open && state.show_context == Some(key);
|
||||||
let status_appearance = if self.button_is_focused(state, key) {
|
let status_appearance = if self.button_is_focused(state, key) {
|
||||||
appearance.focus
|
appearance.focus
|
||||||
} else if key_is_active {
|
} else if key_is_active {
|
||||||
appearance.active
|
appearance.active
|
||||||
} else if key_is_hovered {
|
} else if key_is_hovered || key_has_context_menu_open {
|
||||||
appearance.hover
|
appearance.hover
|
||||||
} else {
|
} else {
|
||||||
appearance.inactive
|
appearance.inactive
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue