Struct egui_dnd::DragDropUi

source ·
pub struct DragDropUi { /* private fields */ }
Expand description

Holds the data needed to draw the floating item while it is being dragged

Implementations§

source§

impl DragDropUi

DragDropUi stores the state of the Drag & Drop list.

Example

use egui_dnd::DragDropUi;
use eframe::App;
use eframe::egui::Context;
use eframe::Frame;
use eframe::egui::CentralPanel;
use egui_dnd::utils::shift_vec;

struct DnDApp {
    items: Vec<String>,
    dnd: DragDropUi,
}


impl App for DnDApp {
    fn update(&mut self, ctx: &Context, frame: &mut Frame) {
        CentralPanel::default().show(ctx, |ui| {
            let response = self.dnd.ui(ui, self.items.iter_mut(), |item, ui, handle| {
                ui.horizontal(|ui| {
                    handle.ui(ui, item, |ui| {
                        ui.label("grab");
                    });
                    ui.label(item.clone());
                });
            });
            if let Some(response) = response.completed {
                shift_vec(response.from, response.to, &mut self.items);
            }
        });
    }
}

use eframe::NativeOptions;
let dnd = DragDropUi::default();
eframe::run_native("DnD Example", NativeOptions::default(), Box::new(|_| {
    Box::new(DnDApp {
        dnd: DragDropUi::default(),
        items: vec!["a", "b", "c"].into_iter().map(|s| s.to_string()).collect(),
    })
}));
source

pub fn ui<'a, T: DragDropItem + 'a>( &mut self, ui: &mut Ui, values: impl Iterator<Item = &'a mut T>, item_ui: impl FnMut(&mut T, &mut Ui, Handle<'_>) ) -> DragDropResponse

Draw the dragged item and check if it has been dropped

Trait Implementations§

source§

impl Clone for DragDropUi

source§

fn clone(&self) -> DragDropUi

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for DragDropUi

source§

fn default() -> DragDropUi

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> SerializableAny for Twhere T: 'static + Any + Clone + Send + Sync,