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
impl RowViewport
Sourcepub const fn new(row_height: u16) -> Self
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.
Sourcepub const fn rows_per_item(&self) -> u16
pub const fn rows_per_item(&self) -> u16
Terminal rows each item occupies. Never 0.
Sourcepub const fn painted_offset(&self) -> usize
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.
Sourcepub const fn record_painted_offset(&mut self, offset: usize)
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.
Sourcepub const fn visible_items(&self, area: Rect) -> usize
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.
Sourcepub fn row_at(
&self,
area: Rect,
len: usize,
column: u16,
row: u16,
) -> Option<usize>
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.
Sourcepub fn cursor_visible_offset(
&self,
area: Rect,
len: usize,
requested: usize,
cursor: Option<usize>,
) -> usize
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
impl Clone for RowViewport
Source§fn clone(&self) -> RowViewport
fn clone(&self) -> RowViewport
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RowViewport
Source§impl Debug for RowViewport
impl Debug for RowViewport
impl Eq for RowViewport
Source§impl PartialEq for RowViewport
impl PartialEq for RowViewport
impl StructuralPartialEq for RowViewport
Auto Trait Implementations§
impl Freeze for RowViewport
impl RefUnwindSafe for RowViewport
impl Send for RowViewport
impl Sync for RowViewport
impl Unpin for RowViewport
impl UnsafeUnpin for RowViewport
impl UnwindSafe for RowViewport
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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