mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-14 05:03:33 +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.
|
/// Returns `true` if `self` is a subtree.
|
||||||
pub fn is_subtree(&self) -> bool {
|
pub fn is_subtree(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -323,9 +323,30 @@ impl View for Menubar {
|
|||||||
.checked_sub(offset)
|
.checked_sub(offset)
|
||||||
.and_then(|pos| self.child_at(pos.x))
|
.and_then(|pos| self.child_at(pos.x))
|
||||||
{
|
{
|
||||||
self.focus = child;
|
if !self.root.children[child].is_delimiter() {
|
||||||
if btn == MouseButton::Left {
|
self.focus = child;
|
||||||
return self.select_child(false);
|
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