pub struct VirtualList { /* private fields */ }Expand description
A list of any length that builds only the rows that show, with rows of any height. They
are laid out and measured as they appear, and what was measured is kept by key, so going
back finds them at the right size. It can jump to a row, stay at the end as a chat does,
and keep what is on screen still when rows come in above it. With nothing to select, the
arrows, Page Up, Page Down, Home and End scroll; with a selection or
on_activate, they move between rows, and Enter or Space activates.
Rows of the same height, told with row_height, need no measuring.
use ravenrs_reactive::State;
use ravenrs_widgets::{Text, Ui, VirtualList};
let chosen = State::new(None::<usize>);
let list = VirtualList::new(10_000, |index| Text::new(format!("Row {index}")))
.key(|index| index as u64)
.selection(chosen.binding())
.height(320.0);
let mut ui = Ui::new(list, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl VirtualList
impl VirtualList
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, with item making the view of each one when it shows.
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, a row keeps its measured height and what is on screen stays still when rows come in above. It is asked for every row on each build, so it should only read a value.
Sourcepub fn estimated_height(self, height: f32) -> Self
pub fn estimated_height(self, height: f32) -> Self
How tall a row probably is until it has been measured (40 by default).
Sourcepub fn row_height(self, height: f32) -> Self
pub fn row_height(self, height: f32) -> Self
Every row has this height, and nothing has to be measured.
Sourcepub fn row_heights(self, height: impl Fn(usize) -> f32 + 'static) -> Self
pub fn row_heights(self, height: impl Fn(usize) -> f32 + 'static) -> Self
The height of each row is known, as with the pages of a document. It is asked for every row on each build.
Sourcepub fn follow_end(self, follow: bool) -> Self
pub fn follow_end(self, follow: bool) -> Self
Starts at the end and stays there as rows arrive, as a chat does, until the user scrolls away; coming back to the end takes it up again.
Sourcepub fn scroll_to(self, index: Binding<Option<usize>>) -> Self
pub fn scroll_to(self, index: Binding<Option<usize>>) -> Self
Set it to a row to bring that row to the start of the view. It goes back to None.
Sourcepub fn selection(self, selected: Binding<Option<usize>>) -> Self
pub fn selection(self, selected: Binding<Option<usize>>) -> Self
Makes the rows selectable, one at a time, with the pointer and the arrows.
Sourcepub fn on_activate(self, handler: impl Fn(usize) + 'static) -> Self
pub fn on_activate(self, handler: impl Fn(usize) + 'static) -> Self
Called with a row on a double click, or on Enter or Space.
Sourcepub fn on_visible(self, handler: impl Fn(Range<usize>) + 'static) -> Self
pub fn on_visible(self, handler: impl Fn(Range<usize>) + 'static) -> Self
Called with the rows that show whenever they change, as for loading what comes next.
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.
Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
What screen readers call the list, instead of the name in Labels.
Sourcepub fn height(self, height: f32) -> Self
pub fn height(self, height: f32) -> Self
A fixed height. It takes the height its parent gives it by default.
Sourcepub fn horizontal(self) -> Self
pub fn horizontal(self) -> Self
Runs from left to right; the sizes above are then widths, and the height is across.
Trait Implementations§
Source§impl Debug for VirtualList
impl Debug for VirtualList
Auto Trait Implementations§
impl !RefUnwindSafe for VirtualList
impl !Send for VirtualList
impl !Sync for VirtualList
impl !UnwindSafe for VirtualList
impl Freeze for VirtualList
impl Unpin for VirtualList
impl UnsafeUnpin for VirtualList
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
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>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.