mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Menubar: trigger leaf nodes on mouse release
Feels more natural
This commit is contained in:
parent
d384cbdaf1
commit
d41f1e937d
@ -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 {
|
||||
|
@ -323,9 +323,30 @@ impl View for Menubar {
|
||||
.checked_sub(offset)
|
||||
.and_then(|pos| self.child_at(pos.x))
|
||||
{
|
||||
self.focus = child;
|
||||
if btn == MouseButton::Left {
|
||||
return self.select_child(false);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user