Add click out handler
Make all context menus on button click toggles instead of re-shows
This commit is contained in:
parent
18dd3102bf
commit
e0d618862c
4 changed files with 30 additions and 21 deletions
|
@ -301,23 +301,18 @@ impl ContextMenu {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let mut items = items.into_iter().peekable();
|
||||
dbg!(self.visible);
|
||||
if (self.visible) {
|
||||
self.visible = false;
|
||||
} else {
|
||||
if items.peek().is_some() {
|
||||
self.items = items.collect();
|
||||
self.anchor_position = anchor_position;
|
||||
self.anchor_corner = anchor_corner;
|
||||
self.visible = true;
|
||||
self.show_count += 1;
|
||||
if !cx.is_self_focused() {
|
||||
self.previously_focused_view_id = cx.focused_view_id();
|
||||
}
|
||||
cx.focus_self();
|
||||
} else {
|
||||
self.visible = false;
|
||||
if items.peek().is_some() {
|
||||
self.items = items.collect();
|
||||
self.anchor_position = anchor_position;
|
||||
self.anchor_corner = anchor_corner;
|
||||
self.visible = true;
|
||||
self.show_count += 1;
|
||||
if !cx.is_self_focused() {
|
||||
self.previously_focused_view_id = cx.focused_view_id();
|
||||
}
|
||||
cx.focus_self();
|
||||
} else {
|
||||
self.visible = false;
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
@ -482,10 +477,10 @@ impl ContextMenu {
|
|||
.contained()
|
||||
.with_style(style.container)
|
||||
})
|
||||
.on_down_out(MouseButton::Left, |_, this, cx| {
|
||||
.on_click_out(MouseButton::Left, |_, this, cx| {
|
||||
this.cancel(&Default::default(), cx);
|
||||
})
|
||||
.on_down_out(MouseButton::Right, |_, this, cx| {
|
||||
.on_click_out(MouseButton::Right, |_, this, cx| {
|
||||
this.cancel(&Default::default(), cx);
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue