Skip to main content

RowViewport

Struct RowViewport 

Source
pub struct RowViewport { /* private fields */ }
Expand description

A viewport of uniform-height rows: which item is on top, and how pointer rows map back to items.

List-shaped components scroll by item, not by screen row, and hit-test a click by pure arithmetic: divide the pointer’s row by the per-item height, add the offset that was painted. That only works when two things hold — every item is the same height, and the offset used for hit-testing is the one actually painted. This type holds both: the per-item height, and the painted offset — the top-item index the last render actually drew, recorded with record_painted_offset so event-time arithmetic works against what is on screen rather than against app state that may be one frame newer.

The viewport is render-derived runtime state, not a second copy of app-owned scroll: a component that binds scroll still reads the requested offset from app state each frame and resolves it through cursor_visible_offset.

Implementations§

Source§

impl RowViewport

Source

pub const fn new(row_height: u16) -> Self

A viewport whose items each occupy row_height terminal rows. A height of 0 is treated as 1, so the divisions below stay safe.

Source

pub const fn rows_per_item(&self) -> u16

Terminal rows each item occupies. Never 0.

Source

pub const fn painted_offset(&self) -> usize

The top-item index the last render drew, as recorded by record_painted_offset. 0 before the first render.

Source

pub const fn record_painted_offset(&mut self, offset: usize)

Record the offset this frame is about to paint, so later events hit-test against it.

Source

pub const fn visible_items(&self, area: Rect) -> usize

How many whole items fit in area. This is the unit paging and scrolling work in — screen rows are only a paint concern.

Source

pub fn row_at( &self, area: Rect, len: usize, column: u16, row: u16, ) -> Option<usize>

The item index under the pointer at (column, row), using the painted offset, or None outside area or past the last of len items.

Several screen rows can belong to one item, so the pointer row is divided by the per-item height before the lookup — otherwise a click on an item’s second line would hit the wrong item.

Source

pub fn cursor_visible_offset( &self, area: Rect, len: usize, requested: usize, cursor: Option<usize>, ) -> usize

The offset that keeps cursor visible in area, starting from a requested offset — linear_nav::cursor_visible_offset measured in this viewport’s items.

Trait Implementations§

Source§

impl Clone for RowViewport

Source§

fn clone(&self) -> RowViewport

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for RowViewport

Source§

impl Debug for RowViewport

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for RowViewport

Source§

impl PartialEq for RowViewport

Source§

fn eq(&self, other: &RowViewport) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RowViewport

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.