pub struct SortableList { /* private fields */ }Expand description
A list that reorders by dragging a row, with a line showing where it will land, or with Alt
and the arrows, Home and End. The arrows alone move between rows, and each move is announced to
screen readers. The order belongs to the app, which applies what
on_reorder tells it.
use ravenrs_reactive::State;
use ravenrs_widgets::{SortableList, Text, Ui};
let items = State::new(vec!["Warm", "Cool", "Matte"]);
let shown = items.get();
let moved = items.clone();
let list = SortableList::new(shown.len(), move |i| Text::new(shown[i]))
.on_reorder(move |from, to| moved.update(|v| {
let item = v.remove(from);
v.insert(to, item);
}));
let mut ui = Ui::new(list, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl SortableList
impl SortableList
Sourcepub fn new<V: View + 'static>(
count: usize,
item: impl Fn(usize) -> V + 'static,
) -> Self
pub fn new<V: View + 'static>( count: usize, item: impl Fn(usize) -> V + 'static, ) -> Self
A list of count rows, in the order the app keeps.
Sourcepub fn key(self, key: impl Fn(usize) -> u64 + 'static) -> Self
pub fn key(self, key: impl Fn(usize) -> u64 + 'static) -> Self
What identifies a row, which is its position by default. With it, what a row keeps of its own goes with it when it moves.
Sourcepub fn on_reorder(self, handler: impl Fn(usize, usize) + 'static) -> Self
pub fn on_reorder(self, handler: impl Fn(usize, usize) + 'static) -> Self
Called with where a row was and where it should go.
Sourcepub fn row_name(self, name: impl Fn(usize) -> String + 'static) -> Self
pub fn row_name(self, name: impl Fn(usize) -> String + 'static) -> Self
What screen readers call each row, for rows whose content does not say it.
Trait Implementations§
Source§impl Debug for SortableList
impl Debug for SortableList
Auto Trait Implementations§
impl !RefUnwindSafe for SortableList
impl !Send for SortableList
impl !Sync for SortableList
impl !UnwindSafe for SortableList
impl Freeze for SortableList
impl Unpin for SortableList
impl UnsafeUnpin for SortableList
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Adds padding inside the box, in logical pixels.
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Paints a background behind the content.
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
Fixes the width and/or height in logical pixels;
None keeps the content size.