pub struct Virtualized<T> { /* private fields */ }Expand description
A virtualized content container that tracks scroll state and computes visible ranges.
§Design Rationale
- Generic over item type for flexibility
- Supports both owned storage and external data sources
- Computes visible ranges for O(visible) rendering
- Optional overscan for smooth scrolling
- Momentum scrolling support
Implementations§
Source§impl<T> Virtualized<T>
impl<T> Virtualized<T>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new virtualized container with owned storage.
§Arguments
capacity- Maximum items to retain in memory.
Sourcepub fn external(len: usize, cache_capacity: usize) -> Self
pub fn external(len: usize, cache_capacity: usize) -> Self
Create with external storage reference.
Sourcepub fn with_item_height(self, height: ItemHeight) -> Self
pub fn with_item_height(self, height: ItemHeight) -> Self
Set item height strategy.
Sourcepub fn with_fixed_height(self, height: u16) -> Self
pub fn with_fixed_height(self, height: u16) -> Self
Set fixed item height.
Sourcepub fn with_height_prediction(self, config: PredictorConfig) -> Self
pub fn with_height_prediction(self, config: PredictorConfig) -> Self
Predict the heights of unmeasured items with a Bayesian model instead
of a constant default (see VariableHeightsFenwick::with_predictor).
Switches the height strategy to the Fenwick tracker when it is not one
already (a fixed height becomes the tracker’s default; a linear
HeightCache is replaced, dropping its cached measurements). Heights
recorded through Virtualized::observe_height train the model.
Sourcepub fn observe_height(&mut self, idx: usize, height: u16)
pub fn observe_height(&mut self, idx: usize, height: u16)
Record the measured height of item idx.
A no-op for the fixed-height strategy. With a predictor attached this also trains the height model, so unmeasured items follow what has been measured instead of a constant guess.
Sourcepub fn unmeasured_item_height(&self) -> u16
pub fn unmeasured_item_height(&self) -> u16
Height assumed for items that have not been measured yet: the predictor’s current point estimate when one is attached, otherwise the strategy’s default (or the fixed height).
Sourcepub fn with_variable_heights(self, default_height: u16) -> Self
pub fn with_variable_heights(self, default_height: u16) -> Self
Use variable item heights (Fenwick-tracked, the default strategy):
unmeasured rows count default_height, observe_height records
real ones, and offsets, scroll_to and visible_range stay
O(log n). The tracker is sized to the current length and follows the
items: it grows with push (a tracker pre-filled with more heights
than items keeps them), shifts on trim_front, clears on clear
and matches set_external_len exactly.
Sourcepub fn with_variable_heights_fenwick(
self,
default_height: u16,
capacity: usize,
) -> Self
pub fn with_variable_heights_fenwick( self, default_height: u16, capacity: usize, ) -> Self
Variable heights with an explicit initial tracker capacity (the
tracker still follows the item count afterwards). Prefer
Self::with_variable_heights unless the list is filled in bulk
after construction.
Sourcepub fn with_overscan(self, overscan: usize) -> Self
pub fn with_overscan(self, overscan: usize) -> Self
Set overscan amount.
Sourcepub fn with_follow(self, follow: bool) -> Self
pub fn with_follow(self, follow: bool) -> Self
Enable follow mode.
Sourcepub fn scroll_offset(&self) -> usize
pub fn scroll_offset(&self) -> usize
Get current scroll offset.
The internal sentinel value (usize::MAX, used for lazy scroll-to-bottom)
is clamped to the actual item count so callers never see it.
Sourcepub fn visible_count(&self) -> usize
pub fn visible_count(&self) -> usize
Get current visible count (from last render).
Sourcepub fn follow_mode(&self) -> bool
pub fn follow_mode(&self) -> bool
Check if follow mode is enabled.
Sourcepub fn visible_range(&self, viewport_height: u16) -> Range<usize> ⓘ
pub fn visible_range(&self, viewport_height: u16) -> Range<usize> ⓘ
Calculate visible range for given viewport height.
Sourcepub fn render_range(&self, viewport_height: u16) -> Range<usize> ⓘ
pub fn render_range(&self, viewport_height: u16) -> Range<usize> ⓘ
Get render range with overscan for smooth scrolling.
Sourcepub fn scroll_to_bottom(&mut self)
pub fn scroll_to_bottom(&mut self)
Scroll to bottom.
Sourcepub fn scroll_to_top(&mut self)
pub fn scroll_to_top(&mut self)
Scroll to top.
Sourcepub fn scroll_to_start(&mut self)
pub fn scroll_to_start(&mut self)
Alias for scroll_to_top (Home key).
Sourcepub fn scroll_to_end(&mut self)
pub fn scroll_to_end(&mut self)
Scroll to bottom and enable follow mode (End key).
Sourcepub fn set_follow(&mut self, follow: bool)
pub fn set_follow(&mut self, follow: bool)
Set follow mode.
Sourcepub fn is_at_bottom(&self) -> bool
pub fn is_at_bottom(&self) -> bool
Check if scrolled to bottom.
Sourcepub fn set_visible_count(&self, count: usize)
pub fn set_visible_count(&self, count: usize)
Update visible count (called during render).
Sourcepub fn item_height(&self) -> &ItemHeight
pub fn item_height(&self) -> &ItemHeight
Get reference to the item height strategy.
Sourcepub fn item_height_mut(&mut self) -> &mut ItemHeight
pub fn item_height_mut(&mut self) -> &mut ItemHeight
Get mutable reference to the item height strategy.
Useful for updating variable height trackers (e.g. resizing Fenwick tree) when items are added.
Source§impl<T> Virtualized<T>
impl<T> Virtualized<T>
Sourcepub fn get_mut(&mut self, idx: usize) -> Option<&mut T>
pub fn get_mut(&mut self, idx: usize) -> Option<&mut T>
Get mutable item by index (owned storage only).
Sourcepub fn trim_front(&mut self, max: usize) -> usize
pub fn trim_front(&mut self, max: usize) -> usize
Trim items from the front to keep at most max items (owned storage only).
Returns the number of items removed.
Sourcepub fn iter(&self) -> Box<dyn Iterator<Item = &T> + '_>
pub fn iter(&self) -> Box<dyn Iterator<Item = &T> + '_>
Iterate over items (owned storage only). Returns empty iterator for external storage.
Sourcepub fn set_external_len(&mut self, len: usize)
pub fn set_external_len(&mut self, len: usize)
Update external storage length.
Trait Implementations§
Source§impl<T: Clone> Clone for Virtualized<T>
impl<T: Clone> Clone for Virtualized<T>
Source§fn clone(&self) -> Virtualized<T>
fn clone(&self) -> Virtualized<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more