Skip to main content

SortableList

Struct SortableList 

Source
pub struct SortableList<'a> { /* private fields */ }
Expand description

A vertical list of rows that can be reordered by dragging their grips.

§Interaction

  • Press on a row’s grip to start dragging. The source row collapses out of layout and a ghost copy of the row floats under the cursor.
  • Move the cursor — a sky-tinted slot opens at the predicted drop position, and the surrounding rows shift to reveal it.
  • Release to commit the move. If the slot lands at the source’s own position the order is left untouched.
  • Escape cancels the drag without reordering.

§State

Items are stored in a caller-owned Vec<SortableItem> passed by mutable reference; the widget reorders the vec in place on a successful drop. Transient drag state (origin, target, grab offset) lives in egui memory keyed by the widget’s id_salt.

§Example

let mut items = vec![
    SortableItem::new("api", "api-east-01")
        .subtitle("10.0.1.5 · us-east-1")
        .status("live", BadgeTone::Ok),
    SortableItem::new("worker", "worker-pool-a")
        .subtitle("24 instances · autoscale")
        .status("idle", BadgeTone::Neutral),
];
SortableList::new("deployment-targets", &mut items).show(ui);

Implementations§

Source§

impl<'a> SortableList<'a>

Source

pub fn new(id_salt: impl Hash, items: &'a mut Vec<SortableItem>) -> Self

Create a sortable list.

  • id_salt — stable salt for this widget’s transient drag state. Different SortableList widgets in the same window must use distinct salts.
  • items — caller-owned list of rows. Reordered in place on drop.
Source

pub fn show(self, ui: &mut Ui) -> Response

Render the list and handle drag interaction.

Trait Implementations§

Source§

impl<'a> Debug for SortableList<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SortableList<'a>

§

impl<'a> RefUnwindSafe for SortableList<'a>

§

impl<'a> Send for SortableList<'a>

§

impl<'a> Sync for SortableList<'a>

§

impl<'a> Unpin for SortableList<'a>

§

impl<'a> UnsafeUnpin for SortableList<'a>

§

impl<'a> !UnwindSafe for SortableList<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.