From 0d058feca09c920be69c4fac5013d5fd0fbc0ae6 Mon Sep 17 00:00:00 2001 From: Moritz Moeller Date: Sat, 12 Aug 2023 23:13:35 +0200 Subject: [PATCH] Drag 'n drop UX working as expected. --- Cargo.toml | 1 + src/app.rs | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 429f433..4b4d6c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,6 +58,7 @@ inherits = "release" [patch.crates-io] egui = { git = "https://github.com/emilk/egui", branch = "master" } # rev = "4bd4eca2e4b440ca585d8844740afd8144ba7dbc" } # branch = "master" } +egui_dnd = { git = "https://github.com/lucasmerlin/egui_dnd", branch = "main" } eframe = { git = "https://github.com/emilk/egui", branch = "master" } # rev = "4bd4eca2e4b440ca585d8844740afd8144ba7dbc" } # branch = "master" } unicode_skeleton = { git = "https://github.com/virtualritz/unicode_skeleton.git", branch = "master" } #decancer = { git = "https://github.com/null8626/decancer.git", branch = "main" } diff --git a/src/app.rs b/src/app.rs index 599e399..37bec6e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,7 @@ use ahash::AHashSet as HashSet; use enum_dispatch::enum_dispatch; //use log::info; -use egui_dnd::{utils::shift_vec, DragDropItem, DragDropUi}; +use egui_dnd::{dnd, DragDropItem, DragDropUi}; use serde::{Deserialize, Serialize}; use std::{hash::{Hasher, Hash}, collections::{BTreeMap, VecDeque}}; use unicode_blocks as ub; @@ -586,21 +586,30 @@ impl eframe::App for GlyphanaApp { //ui.end_row(); }*/ - let response = self + dnd(ui, "dnd_example").show_vec(&mut self.categories, |ui, item, handle, state| { + handle + .show_drag_cursor_on_hover(false) + .ui(ui, |ui| {ui.selectable_value(&mut self.selected_category, item.id(), &item.name); }); + }); + + + /*let response = self .categories_ui - .ui::(ui, self.categories.iter_mut(), |item, ui, handle| { - ui.horizontal(|ui| { + .ui::(ui, self.categories.iter(), |item, ui, handle, _pressure| { + /*ui.horizontal(|ui| { // Anything in the handle can be used to drag the item handle.ui(ui, item, |ui| { ui.label("☰"); }); - ui.selectable_value(&mut self.selected_category, item.id(), &item.name); - }); + });*/ + ui.selectable_value(&mut self.selected_category, item.id(), &item.name); }); + + //response.update_vec(&mut self.categories); if let Some(response) = response.completed { shift_vec(response.from, response.to, &mut self.categories); - } + }*/ //}); }); });