expand trees by double click
@@ -19,8 +19,8 @@ use crate::{
stack_panel::StackPanelBuilder,
utils::{make_arrow, ArrowDirection},
widget::{Widget, WidgetBuilder, WidgetMessage},
- BuildContext, Control, NodeHandleMapping, Thickness, UiNode, UserInterface, VerticalAlignment,
- BRUSH_DARK, BRUSH_DARKEST,
+ BuildContext, Control, MouseButton, NodeHandleMapping, Thickness, UiNode, UserInterface,
+ VerticalAlignment, BRUSH_DARK, BRUSH_DARKEST,
};
use std::{
any::{Any, TypeId},
@@ -140,8 +140,10 @@ impl Control for Tree {
TreeExpansionStrategy::Direct,
));
}
- } else if let Some(WidgetMessage::MouseDown { .. }) = message.data::<WidgetMessage>() {
+ } else if let Some(msg) = message.data::<WidgetMessage>() {
if !message.handled() {
+ match msg {
+ WidgetMessage::MouseDown { .. } => {
let keyboard_modifiers = ui.keyboard_modifiers();
// Prevent selection changes by Alt+Click to be able to drag'n'drop tree items.
if !keyboard_modifiers.alt {
@@ -150,7 +152,8 @@ impl Control for Tree {
{
let selection = if keyboard_modifiers.control {
let mut selection = tree_root.selected.clone();
- if let Some(existing) = selection.iter().position(|&h| h == self.handle)
+ if let Some(existing) =
+ selection.iter().position(|&h| h == self.handle)
{
selection.remove(existing);
} else {
@@ -173,6 +176,21 @@ impl Control for Tree {
}
}
}
+ WidgetMessage::DoubleClick { button } => {
+ if *button == MouseButton::Left {
+ ui.send_message(TreeMessage::expand(
+ self.handle(),
+ MessageDirection::ToWidget,
+ !self.is_expanded,
+ TreeExpansionStrategy::Direct,
+ ));
+
+ message.set_handled(true);
+ }
+ }
+ _ => (),
+ }
+ }
} else if let Some(msg) = message.data::<TreeMessage>() {
if message.destination() == self.handle() {
match msg {
