Skip to main content

PanelWrap

Struct PanelWrap 

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

Cached line/wrap structure for one panel’s text, rebuilt only when its content or width actually changes (see PanelWrap::rebuild_if_needed).

Implementations§

Source§

impl PanelWrap

Source

pub fn build(source: Arc<str>, width: usize) -> Self

Build fresh from source at width columns, wrapping long lines (WrapMode::Wrap). O(source length) — call only when content/width has actually changed (see rebuild_if_needed), never unconditionally on every frame.

Source

pub fn build_with(source: Arc<str>, width: usize, mode: WrapMode) -> Self

Build fresh from plain source with an explicit WrapMode.

Source

pub fn build_with_marker( source: Arc<str>, width: usize, mode: WrapMode, marker: Option<WrapMarker>, ) -> Self

Build fresh from plain source with an explicit WrapMode and an optional end-of-row WrapMarker (which reserves the rightmost column, narrowing the wrap width by one).

Source

pub fn build_styled(lines: &[Line<'_>], width: usize) -> Self

Build fresh from pre-styled ratatui Lines — e.g. syntax-highlighted source or a diff — wrapping long lines (WrapMode::Wrap). Each span’s style is recorded as a per-line style run, exactly like the ANSI path, but taking styled Lines directly instead of parsing escape sequences (so no ansi feature is required). All geometry, selection and copy operate on the plain, concatenated text; styling is purely a rendering concern.

The input Lines are consumed only to extract their text and styles — they are not retained — so any lifetime is accepted. As styled content is typically recomputed each frame (there is no stable Arc identity to diff against), call this only when the content actually changed.

Source

pub fn build_styled_with_marker( lines: &[Line<'_>], width: usize, mode: WrapMode, marker: Option<WrapMarker>, ) -> Self

Like build_styled but with an explicit WrapMode and an optional end-of-row WrapMarker.

Source

pub fn rebuild_if_needed( cache: &mut Option<PanelWrap>, source: &Arc<str>, width: usize, )

Rebuild only if source’s identity (by pointer — a new response/edit always produces a fresh allocation) or width differ from what’s cached; otherwise this is a no-op, keeping repeated frames (drags, idle redraws) cheap regardless of how large the content is. Plain text, WrapMode::Wrap.

Source

pub fn rebuild_if_needed_with( cache: &mut Option<PanelWrap>, source: &Arc<str>, width: usize, mode: WrapMode, )

Like rebuild_if_needed but for plain text with an explicit WrapMode. Also rebuilds if the mode changed, or if the cache currently holds ANSI-styled content.

Source

pub fn rebuild_if_needed_marker( cache: &mut Option<PanelWrap>, source: &Arc<str>, width: usize, mode: WrapMode, marker: Option<WrapMarker>, )

Like rebuild_if_needed_with but also carrying an optional end-of-row WrapMarker. Rebuilds if the marker changed (it affects the reserved column and thus the wrap geometry).

Source

pub fn mode(&self) -> WrapMode

This panel’s line-layout mode.

Source

pub fn wrap_width(&self) -> usize

The width lines actually wrap to — the panel’s inner width, less one column when a WrapMarker reserves the rightmost column. Selection and highlight geometry must use this, not the raw panel width, so the reserved marker column is excluded.

Source

pub fn marker(&self) -> Option<WrapMarker>

This panel’s end-of-row wrap marker, if any.

Source

pub fn line_count(&self) -> usize

Source

pub fn source(&self) -> &str

The exact, unmodified text this cache was built from — every line, with its original line endings, not just what’s currently scrolled into view. Used for “copy the whole panel” (no selection needed).

Source

pub fn line_text(&self, idx: usize) -> &str

Source

pub fn line_char_len(&self, idx: usize) -> usize

Source

pub fn total_rows(&self) -> u32

Source

pub fn visible_window(&self, scroll: u16, height: u16) -> Vec<Line<'static>>

The exact wrapped rows visible in a height-row window starting at absolute wrapped-row scroll — the only rows actually wrapped, and only the portion of each raw line that window actually covers (wrap_line_window), regardless of the total content size or how long any single raw line is. Repeated calls with the same (scroll, height) (the common case across idle/unchanged frames) hit last_window and do no wrapping work at all.

Source

pub fn textpos_to_row_col(&self, pos: TextPos) -> (u32, usize)

Convert a logical TextPos into its absolute wrapped-row index and column-within-that-row — the reverse of Self::row_col_to_textpos, used to project a (resize-invariant) selection back onto the current frame’s screen space for highlighting or scroll-into-view.

Source

pub fn row_col_to_textpos(&self, row: u32, col: usize) -> TextPos

Convert an absolute wrapped-row index + column-in-row (screen space) into the logical TextPos it corresponds to — the reverse of Self::textpos_to_row_col, used to map a mouse click/drag onto real content.

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