pub struct Viewport {
pub top_row: usize,
pub top_col: usize,
pub width: u16,
pub height: u16,
pub wrap: Wrap,
pub text_width: u16,
}Expand description
Where the buffer is scrolled to and how big the visible area is.
Mirrors what tui-textarea exposed today: the host publishes
(width, height) from the render path each frame, and the buffer
uses the cached values to clamp the cursor / scroll offsets when
motions ask for it. top_row and top_col are the first visible
row / column; top_col is a char index, matching Position.
wrap and text_width together drive soft-wrap-aware scrolling
and motion. text_width is the cell width of the text area
(i.e. width minus any gutter the host renders) so the buffer
can compute screen-line splits without duplicating gutter logic.
Fields§
§top_row: usize§top_col: usize§width: u16§height: u16§wrap: WrapSoft-wrap mode the renderer + scroll math is using. Default
is Wrap::None (no wrap, horizontal scroll via top_col).
text_width: u16Cell width of the text area (after the host’s gutter is
subtracted from the editor area). Used by wrap-aware scroll
and motion code; ignored when wrap == Wrap::None. Set to 0
before the first frame; wrap math falls back to no-op then.
Implementations§
Source§impl Viewport
impl Viewport
pub const fn new() -> Self
Sourcepub fn bottom_row(self) -> usize
pub fn bottom_row(self) -> usize
Last document row that’s currently on screen (inclusive).
Returns top_row when height == 0 so callers don’t have
to special-case the pre-first-draw state.
Sourcepub fn contains(self, pos: Position) -> bool
pub fn contains(self, pos: Position) -> bool
True when pos lies inside the current viewport rect.
Sourcepub fn ensure_visible(&mut self, pos: Position)
pub fn ensure_visible(&mut self, pos: Position)
Adjust top_row / top_col so pos is visible, scrolling by
the minimum amount needed. Used after motions and after
content edits that move the cursor.
Trait Implementations§
impl Copy for Viewport
Auto Trait Implementations§
impl Freeze for Viewport
impl RefUnwindSafe for Viewport
impl Send for Viewport
impl Sync for Viewport
impl Unpin for Viewport
impl UnsafeUnpin for Viewport
impl UnwindSafe for Viewport
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> 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