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. O(source length) — call only when content/width has actually changed (see rebuild_if_needed), never unconditionally on every frame.

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.

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.