lucasmerlin / hello_egui Goto Github PK
View Code? Open in Web Editor NEWA collection of useful crates for egui
Home Page: https://lucasmerlin.github.io/hello_egui/
License: MIT License
A collection of useful crates for egui
Home Page: https://lucasmerlin.github.io/hello_egui/
License: MIT License
Hi,
Would it be possible for InfiniteScroll
to expose its VirtualList
? I want to flip scroll_position_sync_on_resize
.
Thanks!
I have an interface very similar to the nested
example and would like to be able to drag items between layers. I'm imagining creating a dnd
widget over an iterator that returns a flattened version of the tree, but there would need to be a way to indicate which elements fall inside a nested a container.
Are there any existing ideas or plans to add this functionality? I might take a swing at it but would have to familiarize myself with the crate internals.
376242b seems to have introduced some rather significant jitter, espectially when dragging near the top of a scroll area.
Here's the example script using cargo-script-mvs:
#!/usr/bin/env cargo-eval
//! ```cargo
//! [dependencies]
//! eframe = "0.22.0"
//! #egui_dnd = { git = "https://github.com/lucasmerlin/egui_dnd.git", rev = "e9043021e101fb42fc6ce70e508da857cb7ee263" } # good
//! egui_dnd = { git = "https://github.com/lucasmerlin/egui_dnd.git", rev = "376242b3cc6bed14a93880edb5d5aa46f2fc3b9a" } # bad
//!
//! [profile.dev]
//! opt-level = 3
//! ```
use eframe::egui::{Button, CentralPanel, Frame, ScrollArea};
use eframe::NativeOptions;
use std::hash::{Hash, Hasher};
struct ItemType {
number: u32,
}
impl Hash for ItemType {
fn hash<H: Hasher>(&self, state: &mut H) {
self.number.hash(state);
}
}
fn main() -> eframe::Result<()> {
let mut items: Vec<_> = (0..100).map(|number| ItemType { number }).collect();
eframe::run_simple_native(
"dnd scroll demo",
NativeOptions::default(),
move |ctx, _| {
CentralPanel::default().show(ctx, |ui| {
ui.label("some stuff above");
ui.label("some stuff above");
ui.label("some stuff above");
ui.label("some stuff above");
ui.with_layout(ui.layout().with_cross_justify(true), |ui| {
ScrollArea::vertical().show(ui, |ui| {
let res = egui_dnd::dnd(ui, ui.id()).show(
items.iter_mut().enumerate(),
|ui, (_index, item), handle, state| {
let mut frame = Frame::none();
if state.dragged {
frame.fill = ui.visuals().extreme_bg_color
} else if state.index % 2 == 1 {
frame.fill = ui.visuals().faint_bg_color
}
frame.show(ui, |ui| {
ui.horizontal(|ui| {
handle.ui(ui, |ui| {
ui.label(" ☰ ");
});
for i in 0..(item.number % 3) + 10 {
ui.add_enabled(
false,
Button::new(format!("button {i}")),
);
}
});
});
},
);
if res.final_update().is_some() {
res.update_vec(&mut items);
}
})
})
});
},
)
}
How to get the item index in show_vec?
I would like to make a list of egui::selectable_value()
s reorderable. See my app, Glyphana.
On the left panel there is a list of categories, one of which (and maybe later several) can be selected but which I also want to be reordeable using drag 'n drop.
Think of the list of favorite folders in macOS Finder or Dolphin on KDE. You can click to select a folder but you can also drag 'n drop to reorder your favorites.
I added support for this in the dnd
branch of Glyphana.
But I can only reorder categories, I can't select one any more. I.e. hovering immediately causes the drag 'n drop cursor to appear.
Instead drag 'n drop should only happen when the user presses the mouse button and starts dragging (i.e. some time passed so this is not confused with accidentally moving the mouse while clicking).
Is it possible to drag an item between two separate dnd ui's ?
When indices (enumerate) is used as ID for a list with duplicate items, there is a weird snapping animation when dropping an item on a different position.
Here is a modified update_on_drop
example to illustrate the issue.
use eframe::egui;
use egui::CentralPanel;
use egui_dnd::{dnd, DragDropItem};
use egui::Id;
struct DragWrapper<T>(usize, T);
impl<T> DragDropItem for DragWrapper<T> {
fn id(&self) -> Id {
Id::new(self.0)
}
}
pub fn main() -> eframe::Result<()> {
let mut items = vec!["alfred", "bernhard", "christian", "christian", "christian"];
eframe::run_simple_native(
"DnD Simple Example",
Default::default(),
move |ctx, _frame| {
CentralPanel::default().show(ctx, |ui| {
ui.label("Drag and drop the items below");
ui.style_mut().animation_time = 0.5;
let response =
dnd(ui, "dnd_example").show(items.iter().enumerate().map(|(i,e)| DragWrapper(i,e)), |ui, item, handle, state| {
handle.ui(ui, |ui| {
if state.dragged {
ui.label("dragging");
} else {
ui.label("drag");
}
});
ui.label(*item.1);
});
if response.is_drag_finished() {
response.update_vec(&mut items);
}
ui.label("Another label");
});
},
)
}
Unlike this example, in my actual app, there is no sane way to pre-index the Vec, like what is done in sort_words
example. I only get &mut Vec<T>
and I can't ensure that T is unique in any way.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.