Menubar: trigger leaf nodes on mouse release

Feels more natural
This commit is contained in:
Alexandre Bury 2018-01-09 14:53:55 +01:00
parent d384cbdaf1
commit d41f1e937d
2 changed files with 32 additions and 3 deletions

View File

@ -56,6 +56,14 @@ impl MenuItem {
}
}
/// Returns `true` if `self` is a leaf node.
pub fn is_leaf(&self) -> bool {
match *self {
MenuItem::Leaf(_, _) => true,
_ => false,
}
}
/// Returns `true` if `self` is a subtree.
pub fn is_subtree(&self) -> bool {
match *self {

View File

@ -323,12 +323,33 @@ impl View for Menubar {
.checked_sub(offset)
.and_then(|pos| self.child_at(pos.x))
{
if !self.root.children[child].is_delimiter() {
self.focus = child;
if btn == MouseButton::Left {
return self.select_child(true);
}
}
}
}
Event::Mouse {
event: MouseEvent::Release(btn),
position,
offset,
} if position.fits(offset) && position.y == offset.y =>
{
if let Some(child) = position
.checked_sub(offset)
.and_then(|pos| self.child_at(pos.x))
{
if self.root.children[child].is_leaf() {
if self.focus == child {
if btn == MouseButton::Left {
return self.select_child(false);
}
}
}
}
}
Event::Mouse {
event: MouseEvent::Press(_),
..