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
impl PanelWrap
Sourcepub fn build(source: Arc<str>, width: usize) -> Self
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.
Sourcepub fn build_with(source: Arc<str>, width: usize, mode: WrapMode) -> Self
pub fn build_with(source: Arc<str>, width: usize, mode: WrapMode) -> Self
Build fresh from plain source with an explicit WrapMode.
Sourcepub fn build_with_marker(
source: Arc<str>,
width: usize,
mode: WrapMode,
marker: Option<WrapMarker>,
) -> Self
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).
Sourcepub fn build_styled(lines: &[Line<'_>], width: usize) -> Self
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.
Sourcepub fn build_styled_with_marker(
lines: &[Line<'_>],
width: usize,
mode: WrapMode,
marker: Option<WrapMarker>,
) -> Self
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.
Sourcepub fn rebuild_if_needed(
cache: &mut Option<PanelWrap>,
source: &Arc<str>,
width: usize,
)
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.
Sourcepub fn rebuild_if_needed_with(
cache: &mut Option<PanelWrap>,
source: &Arc<str>,
width: usize,
mode: WrapMode,
)
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.
Sourcepub fn rebuild_if_needed_marker(
cache: &mut Option<PanelWrap>,
source: &Arc<str>,
width: usize,
mode: WrapMode,
marker: Option<WrapMarker>,
)
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).
Sourcepub fn wrap_width(&self) -> usize
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.
Sourcepub fn marker(&self) -> Option<WrapMarker>
pub fn marker(&self) -> Option<WrapMarker>
This panel’s end-of-row wrap marker, if any.
pub fn line_count(&self) -> usize
Sourcepub fn source(&self) -> &str
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).
pub fn line_text(&self, idx: usize) -> &str
pub fn line_char_len(&self, idx: usize) -> usize
pub fn total_rows(&self) -> u32
Sourcepub fn visible_window(&self, scroll: u16, height: u16) -> Vec<Line<'static>>
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.
Sourcepub fn textpos_to_row_col(&self, pos: TextPos) -> (u32, usize)
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.
Sourcepub fn row_col_to_textpos(&self, row: u32, col: usize) -> TextPos
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§
impl !Freeze for PanelWrap
impl !RefUnwindSafe for PanelWrap
impl !Sync for PanelWrap
impl Send for PanelWrap
impl Unpin for PanelWrap
impl UnsafeUnpin for PanelWrap
impl UnwindSafe for PanelWrap
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> 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