pub struct ListState(/* private fields */);Expand description
The list state that views must hold on behalf of the list element.
Implementations§
Source§impl ListState
impl ListState
Sourcepub fn new(
item_count: usize,
alignment: ListAlignment,
overdraw: Pixels,
) -> Self
pub fn new( item_count: usize, alignment: ListAlignment, overdraw: Pixels, ) -> Self
Construct a new list state, for storage on a view.
The overdraw parameter controls how much extra space is rendered above and below the visible area. Elements within this area will be measured even though they are not visible. This can help ensure that the list doesn’t flicker or pop in when scrolling.
Sourcepub fn measure_all(self) -> Self
pub fn measure_all(self) -> Self
Set the list to measure all items in the list in the first layout phase.
This is useful for ensuring that the scrollbar size is correct instead of based on only rendered elements.
Sourcepub fn reset(&self, element_count: usize)
pub fn reset(&self, element_count: usize)
Reset this instantiation of the list state.
Note that this will cause scroll events to be dropped until the next paint.
Sourcepub fn item_count(&self) -> usize
pub fn item_count(&self) -> usize
The number of items in this list.
Sourcepub fn splice(&self, old_range: Range<usize>, count: usize)
pub fn splice(&self, old_range: Range<usize>, count: usize)
Inform the list state that the items in old_range have been replaced
by count new items that must be recalculated.
Sourcepub fn splice_focusable(
&self,
old_range: Range<usize>,
focus_handles: impl IntoIterator<Item = Option<FocusHandle>>,
)
pub fn splice_focusable( &self, old_range: Range<usize>, focus_handles: impl IntoIterator<Item = Option<FocusHandle>>, )
Register with the list state that the items in old_range have been replaced
by new items. As opposed to Self::splice, this method allows an iterator of optional focus handles
to be supplied to properly integrate with items in the list that can be focused. If a focused item
is scrolled out of view, the list will continue to render it to allow keyboard interaction.
Sourcepub fn set_scroll_handler(
&self,
handler: impl FnMut(&ListScrollEvent, &mut Window, &mut App) + 'static,
)
pub fn set_scroll_handler( &self, handler: impl FnMut(&ListScrollEvent, &mut Window, &mut App) + 'static, )
Set a handler that will be called when the list is scrolled.
Sourcepub fn logical_scroll_top(&self) -> ListOffset
pub fn logical_scroll_top(&self) -> ListOffset
Get the current scroll offset, in terms of the list’s items.
Sourcepub fn scroll_to(&self, scroll_top: ListOffset)
pub fn scroll_to(&self, scroll_top: ListOffset)
Scroll the list to the given offset
Sourcepub fn scroll_to_reveal_item(&self, ix: usize)
pub fn scroll_to_reveal_item(&self, ix: usize)
Scroll the list to the given item, such that the item is fully visible.
Sourcepub fn bounds_for_item(&self, ix: usize) -> Option<Bounds<Pixels>>
pub fn bounds_for_item(&self, ix: usize) -> Option<Bounds<Pixels>>
Get the bounds for the given item in window coordinates, if it’s been rendered.
Sourcepub fn scrollbar_drag_started(&self)
pub fn scrollbar_drag_started(&self)
Call this method when the user starts dragging the scrollbar.
This will prevent the height reported to the scrollbar from changing during the drag as items in the overdraw get measured, and help offset scroll position changes accordingly.
Sourcepub fn scrollbar_drag_ended(&self)
pub fn scrollbar_drag_ended(&self)
Called when the user stops dragging the scrollbar.
See scrollbar_drag_started.
Sourcepub fn set_offset_from_scrollbar(&self, point: Point<Pixels>)
pub fn set_offset_from_scrollbar(&self, point: Point<Pixels>)
Set the offset from the scrollbar
Sourcepub fn max_offset_for_scrollbar(&self) -> Size<Pixels>
pub fn max_offset_for_scrollbar(&self) -> Size<Pixels>
Returns the maximum scroll offset according to the items we have measured. This value remains constant while dragging to prevent the scrollbar from moving away unexpectedly.
Sourcepub fn scroll_px_offset_for_scrollbar(&self) -> Point<Pixels>
pub fn scroll_px_offset_for_scrollbar(&self) -> Point<Pixels>
Returns the current scroll offset adjusted for the scrollbar
Sourcepub fn viewport_bounds(&self) -> Bounds<Pixels>
pub fn viewport_bounds(&self) -> Bounds<Pixels>
Return the bounds of the viewport in pixels.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ListState
impl !RefUnwindSafe for ListState
impl !Send for ListState
impl !Sync for ListState
impl Unpin for ListState
impl !UnwindSafe for ListState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more