Skip to main content

Virtualized

Struct Virtualized 

Source
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>

Source

pub fn new(capacity: usize) -> Self

Create a new virtualized container with owned storage.

§Arguments
  • capacity - Maximum items to retain in memory.
Source

pub fn external(len: usize, cache_capacity: usize) -> Self

Create with external storage reference.

Source

pub fn with_item_height(self, height: ItemHeight) -> Self

Set item height strategy.

Source

pub fn with_fixed_height(self, height: u16) -> Self

Set fixed item height.

Source

pub fn with_variable_heights_fenwick( self, default_height: u16, capacity: usize, ) -> Self

Set variable heights with O(log n) Fenwick tree tracking.

This is more efficient than Variable(HeightCache) for large lists as scroll-to-index mapping is O(log n) instead of O(visible).

Source

pub fn with_overscan(self, overscan: usize) -> Self

Set overscan amount.

Source

pub fn with_follow(self, follow: bool) -> Self

Enable follow mode.

Source

pub fn len(&self) -> usize

Get total number of items.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn scroll_offset(&self) -> usize

Get current scroll offset.

Source

pub fn visible_count(&self) -> usize

Get current visible count (from last render).

Source

pub fn follow_mode(&self) -> bool

Check if follow mode is enabled.

Source

pub fn visible_range(&self, viewport_height: u16) -> Range<usize>

Calculate visible range for given viewport height.

Source

pub fn render_range(&self, viewport_height: u16) -> Range<usize>

Get render range with overscan for smooth scrolling.

Source

pub fn scroll(&mut self, delta: i32)

Scroll by delta (positive = down/forward).

Source

pub fn scroll_to(&mut self, idx: usize)

Scroll to specific item index.

Source

pub fn scroll_to_bottom(&mut self)

Scroll to bottom.

Source

pub fn scroll_to_top(&mut self)

Scroll to top.

Source

pub fn scroll_to_start(&mut self)

Alias for scroll_to_top (Home key).

Source

pub fn scroll_to_end(&mut self)

Scroll to bottom and enable follow mode (End key).

Source

pub fn page_up(&mut self)

Page up (scroll by visible count - 1).

Source

pub fn page_down(&mut self)

Page down (scroll by visible count - 1).

Source

pub fn set_follow(&mut self, follow: bool)

Set follow mode.

Source

pub fn is_at_bottom(&self) -> bool

Check if scrolled to bottom.

Source

pub fn fling(&mut self, velocity: f32)

Start momentum scroll.

Source

pub fn tick(&mut self, dt: Duration)

Apply momentum scroll tick.

Source

pub fn set_visible_count(&mut self, count: usize)

Update visible count (called during render).

Source§

impl<T> Virtualized<T>

Source

pub fn push(&mut self, item: T)

Push an item (owned storage only).

Source

pub fn get(&self, idx: usize) -> Option<&T>

Get item by index (owned storage only).

Source

pub fn get_mut(&mut self, idx: usize) -> Option<&mut T>

Get mutable item by index (owned storage only).

Source

pub fn clear(&mut self)

Clear all items (owned storage only).

Source

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.

Source

pub fn iter(&self) -> Box<dyn Iterator<Item = &T> + '_>

Iterate over items (owned storage only). Returns empty iterator for external storage.

Source

pub fn set_external_len(&mut self, len: usize)

Update external storage length.

Trait Implementations§

Source§

impl<T: Clone> Clone for Virtualized<T>

Source§

fn clone(&self) -> Virtualized<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Virtualized<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for Virtualized<T>

§

impl<T> !RefUnwindSafe for Virtualized<T>

§

impl<T> Send for Virtualized<T>
where T: Send,

§

impl<T> !Sync for Virtualized<T>

§

impl<T> Unpin for Virtualized<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Virtualized<T>

§

impl<T> UnwindSafe for Virtualized<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more