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