Alt+Click now prevents selection in Tree widget
this allows you to drag'n'drop tree nodes without selecting them
+//! Tree widget allows you to create views for hierarchical data.
+//!
+//! ## Built-in controls
+//!
+//! Selection works on all mouse buttons, not just left.
+//!
+//! `Ctrl+Click` - enables multi-selection.
+//! `Alt+Click` - prevents selection allowing you to use drag'n'drop.
+
use crate::{
border::BorderBuilder,
brush::Brush,
@@ -130,12 +139,16 @@ impl Control for Tree {
}
} else if let Some(WidgetMessage::MouseDown { .. }) = message.data::<WidgetMessage>() {
if !message.handled() {
+ 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 {
if let Some((tree_root_handle, tree_root)) =
ui.try_borrow_by_type_up::<TreeRoot>(self.parent())
{
- let selection = if ui.keyboard_modifiers().control {
+ 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 {
selection.push(self.handle);
@@ -156,6 +169,7 @@ impl Control for Tree {
message.set_handled(true);
}
}
+ }
} else if let Some(msg) = message.data::<TreeMessage>() {
if message.destination() == self.handle() {
match msg {
