Remove drag-n-drop thingy

This commit is contained in:
2025-07-24 01:02:17 +02:00
parent 8f16741705
commit 0acab0413c

View File

@ -11,8 +11,7 @@ use std::{
use chrono::{DateTime, Local};
use egui::{
Align, Button, Context, DragAndDrop, Frame, Layout, ScrollArea, Ui, UiBuilder, Vec2,
Widget as _, vec2,
Align, Button, Context, DragAndDrop, Frame, Layout, ScrollArea, Ui, UiBuilder, Vec2, vec2,
};
use eyre::eyre;
use notify::{EventKind, Watcher};
@ -247,25 +246,16 @@ impl FileEditor {
let mut retain = true;
if is_dragging {
let (_, drop) = ui.dnd_drop_zone::<DraggingItem, _>(Frame::NONE, |ui| {
ui.set_min_size(vec2(ui.available_width(), drag_zone_height));
});
if let Some(drop) = drop {
drop_from_to = Some((drop.index, i));
}
} else {
// the dnd_drop_zone adds 3pts work of extra space
ui.add_space(drag_zone_height + 3.0);
}
// Createa horizontal area to draw the buffer item. The three things drawn here are:
// - The controls that exist at the left-size of the buffer item, i.e. "up"/"down".
// - The buffer item.
// - The controls that exist at the right-size of the buffer item, i.e. "delete".
ui.horizontal(|ui| {
// We don't know how tall the buffer item will be, so we'll reserve
// some horizontal space here and come back to drawing the dragger
// later.
let (dragger_id, mut dragger_rect) = ui.allocate_space(Vec2::new(20.0, 1.0));
// At this point, we don't know how tall the buffer item will be, so we'll reserve
// some horizontal space here and come back to drawing the controls later.
let (_id, mut left_controls_rect) = ui.allocate_space(Vec2::new(20.0, 1.0));
// Leave some space at the end for the delete button..
// Leave some space at the end for the delete button.
let w = ui.available_width();
let item_size = Vec2::new(w - 20.0, 0.0);
@ -288,18 +278,17 @@ impl FileEditor {
});
// Delete-button
if ui.button("x").clicked() {
if ui.button("").clicked() {
retain = false;
ui.ctx().request_repaint();
}
// Draw the dragger using the height from the buffer item
dragger_rect.set_height(item_response.response.rect.height());
left_controls_rect.set_height(item_response.response.rect.height());
// Controls for moving the buffer item
ui.scope_builder(
UiBuilder::new()
.max_rect(dragger_rect)
.max_rect(left_controls_rect)
.layout(Layout::top_down(Align::Center)),
|ui| {
let up_button_response = ui.add_enabled(!is_first, Button::new(""));
@ -307,17 +296,12 @@ impl FileEditor {
drop_from_to = Some((i, i - 1));
}
ui.dnd_drag_source(dragger_id, DraggingItem { index: i }, |ui| {
Button::new("")
.min_size(
// Use all available height, save for the height taken up by
// the up/down buttons + padding. Assume down-button is the
// equally tall as the up-button.
dragger_rect.size()
- Vec2::Y * (up_button_response.rect.height() * 2.0 + 4.0),
)
.ui(ui);
});
// Add some space so that the next button is drawn
// at the bottom of the buffer item.
ui.add_space(
left_controls_rect.height()
- (up_button_response.rect.height() * 2.0 + 4.0),
);
if ui.add_enabled(!is_last, Button::new("")).clicked() {
drop_from_to = Some((i, i + 2));