pub struct MultiSelectPanel { /* private fields */ }Expand description
One scrollable text panel that owns its scroll offset and one-or-more selection regions.
Cheap to keep across frames: the content setters only rebuild the wrap cache when the content or width actually changed, and selections are logical positions that are unaffected by rewrapping. See the module docs for the feature set.
Implementations§
Source§impl MultiSelectPanel
impl MultiSelectPanel
Sourcepub fn set_wrap_mode(&mut self, mode: WrapMode)
pub fn set_wrap_mode(&mut self, mode: WrapMode)
Choose how raw lines wider than the panel are laid out. Takes effect on the next content set (which apps do every frame).
Sourcepub fn set_wrap_marker(&mut self, marker: Option<WrapMarker>)
pub fn set_wrap_marker(&mut self, marker: Option<WrapMarker>)
Enable/disable the end-of-row wrap marker (see WrapMarker). Takes
effect on the next content set.
Sourcepub fn wrap_marker(&self) -> Option<WrapMarker>
pub fn wrap_marker(&self) -> Option<WrapMarker>
This panel’s current end-of-row wrap marker, if any.
Sourcepub fn set_content(&mut self, text: Arc<str>, width: usize)
pub fn set_content(&mut self, text: Arc<str>, width: usize)
Set (or update) the panel’s plain text and inner wrap width. A no-op
when neither the text (by Arc identity) nor the width nor the mode /
marker changed — safe, and intended, to call every frame.
Sourcepub fn set_styled_content(&mut self, lines: &[Line<'_>], width: usize)
pub fn set_styled_content(&mut self, lines: &[Line<'_>], width: usize)
Set the panel’s content from pre-styled Lines (e.g.
syntax-highlighted source). Rendered rows keep their per-span styling
while selection/copy/geometry operate on the plain text. Styled content
has no stable identity to diff against, so this rebuilds every call —
call it only when the content actually changed.
Sourcepub fn has_content(&self) -> bool
pub fn has_content(&self) -> bool
Whether any content has been set yet.
Sourcepub fn whole_text(&self) -> Option<&str>
pub fn whole_text(&self) -> Option<&str>
The exact, unmodified source text the panel was built from — for a
“copy the whole panel” action that needs no selection. None before any
content is set.
Sourcepub fn total_rows(&self) -> u32
pub fn total_rows(&self) -> u32
The total number of wrapped rows the current content occupies.
Sourcepub fn max_scroll(&self, viewport_height: u16) -> u16
pub fn max_scroll(&self, viewport_height: u16) -> u16
The largest in-bounds scroll offset for a viewport_height-row window
(content rows − height, floored at 0) — for sizing a scrollbar or
clamping a scroll.
Sourcepub fn set_scroll(&mut self, scroll: u16)
pub fn set_scroll(&mut self, scroll: u16)
Set the scroll offset directly (e.g. from a scrollbar drag). Not
clamped here — call clamp_scroll once the
viewport height is known (at draw time).
Sourcepub fn scroll_by(&mut self, delta: i32, viewport_height: u16)
pub fn scroll_by(&mut self, delta: i32, viewport_height: u16)
Move the scroll offset by delta rows (negative = up), clamped to
[0, max_scroll(viewport_height)].
Sourcepub fn clamp_scroll(&mut self, viewport_height: u16) -> u16
pub fn clamp_scroll(&mut self, viewport_height: u16) -> u16
Clamp the scroll offset into range for a viewport_height-row window
and return that window’s max_scroll (for the scrollbar). Call once per
frame at draw time, after setting content.
Sourcepub fn visible_rows(&self, height: u16) -> Vec<Line<'static>>
pub fn visible_rows(&self, height: u16) -> Vec<Line<'static>>
The visible wrapped rows for a height-row window at the current
scroll — ready to render. Only on-screen rows are wrapped, regardless of
total content size.
Sourcepub fn highlight_regions(&self, area: Rect) -> Vec<(u16, u16, u16)>
pub fn highlight_regions(&self, area: Rect) -> Vec<(u16, u16, u16)>
Every selection region’s on-screen cells to highlight, as (row, col_from, col_to_exclusive) in absolute terminal coordinates, bounded
to the visible window. Covers the active region and all finalized ones.
Sourcepub fn begin(&mut self, area: Rect, point: (u16, u16))
pub fn begin(&mut self, area: Rect, point: (u16, u16))
Begin a new active selection region at terminal point, given the
panel’s inner area. Leaves any finalized (finalize_active) regions
intact — call clear first for a fresh, single-region
selection. No-op without content.
Sourcepub fn drag(&mut self, area: Rect, point: (u16, u16))
pub fn drag(&mut self, area: Rect, point: (u16, u16))
Continue the active selection’s drag to terminal point. When the drag
moves past the panel’s top/bottom edge this begins auto-scrolling in
that direction (extending the selection a whole line at a time) and
advances it once immediately; call
autoscroll_tick from an idle loop to keep it
going while the mouse is still. No-op without an active region.
Sourcepub fn end_drag(&mut self)
pub fn end_drag(&mut self)
End the current drag (a mouse-up): stops any pending auto-scroll. The
selection itself is kept — read it with
selected_parts / copy it as the host sees fit.
Sourcepub fn has_pending_autoscroll(&self) -> bool
pub fn has_pending_autoscroll(&self) -> bool
Whether a drag is currently held past an edge, waiting for
autoscroll_tick to keep scrolling.
Sourcepub fn autoscroll_tick(&mut self, area: Rect)
pub fn autoscroll_tick(&mut self, area: Rect)
One “tick” of auto-scrolling a drag held past the panel’s vertical
bounds: scroll one row in the pending direction and extend the active
region’s live end to the newly revealed edge line. Once the content’s
own top/bottom is reached but the drag is still held past the edge, the
cursor snaps to the very first/last line’s full extent instead, so that
boundary line ends up entirely highlighted. No-op when nothing is
pending. area is the panel’s inner rectangle.
Sourcepub fn extend(&mut self, motion: Motion, area: Rect)
pub fn extend(&mut self, motion: Motion, area: Rect)
Move the active region’s live end by one character (Motion::Left /
Motion::Right, crossing line boundaries) or one logical line
(Motion::Up / Motion::Down, keeping the column where possible),
then scroll the panel so that end stays visible. No-op without an active
region or content. area is the panel’s inner rectangle.
Sourcepub fn finalize_active(&mut self)
pub fn finalize_active(&mut self)
Finalize the active region: move it into the set of kept regions and
clear the live one, so a subsequent begin starts a new
region alongside it. No-op when there’s no active region.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drop every selection region (active and finalized) and stop any pending auto-scroll. Call whenever the underlying content is about to change so a highlight never lingers over stale text.
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Whether there is any selection region at all (active or finalized).
Sourcepub fn wrap(&self) -> Option<&PanelWrap>
pub fn wrap(&self) -> Option<&PanelWrap>
The panel’s wrap cache, if content has been set. Exposed so a host can
run its own geometry queries (row/column ↔ TextPos mapping, line
text, hit-testing) against the exact layout the panel is rendering.
Sourcepub fn active_selection(&self) -> Option<(TextPos, TextPos)>
pub fn active_selection(&self) -> Option<(TextPos, TextPos)>
The live (active) region as (anchor, cursor) logical positions, or
None when nothing is being dragged / keyboard-extended. anchor is
where the region began; cursor is its live end.
Sourcepub fn set_active_selection(&mut self, anchor: TextPos, cursor: TextPos)
pub fn set_active_selection(&mut self, anchor: TextPos, cursor: TextPos)
Replace the live (active) region with one spanning anchor..cursor,
without touching any finalized regions. Lets a host restore or script a
selection (the positions are logical, so they survive rewraps).
Sourcepub fn finalized_selections(&self) -> Vec<(TextPos, TextPos)>
pub fn finalized_selections(&self) -> Vec<(TextPos, TextPos)>
The finalized regions (those moved aside by
finalize_active) as (anchor, cursor) pairs,
in insertion order.
Sourcepub fn push_finalized(&mut self, anchor: TextPos, cursor: TextPos)
pub fn push_finalized(&mut self, anchor: TextPos, cursor: TextPos)
Append a finalized region spanning anchor..cursor, as though it had
been dragged and then finalize_actived. Lets
a host restore several kept regions.
Sourcepub fn start_autoscroll(&mut self, dir: AutoScroll)
pub fn start_autoscroll(&mut self, dir: AutoScroll)
Begin auto-scrolling in dir on the next
autoscroll_tick, as though a drag were being
held past that edge. Mainly for hosts/tests that drive auto-scroll
without simulating exact drag geometry.
Sourcepub fn selected_parts(&self, exclude: Option<&HashSet<TextPos>>) -> Vec<String>
pub fn selected_parts(&self, exclude: Option<&HashSet<TextPos>>) -> Vec<String>
The extracted text of every selection region, ordered by where each
region starts in the content (not by draw order), each as one element.
Empty (whitespace-only) regions are skipped. exclude drops individual
character positions from the copied text (e.g. app-specific annotation
glyphs). The host joins these — possibly across several panels — however
it wants (see selected_text for the common
single-panel join).
Sourcepub fn selected_text(
&self,
exclude: Option<&HashSet<TextPos>>,
) -> Option<String>
pub fn selected_text( &self, exclude: Option<&HashSet<TextPos>>, ) -> Option<String>
The whole selection as a single string: every region’s text (ordered by
start) joined by a blank line, or None when nothing is selected. A
convenience over selected_parts for the common
single-panel case.
Source§impl MultiSelectPanel
Scrollbar conveniences (default-on scrollbar feature): thin wrappers that
plumb the panel’s own geometry into the panel-agnostic
crate::scrollbar helpers.
impl MultiSelectPanel
Scrollbar conveniences (default-on scrollbar feature): thin wrappers that
plumb the panel’s own geometry into the panel-agnostic
crate::scrollbar helpers.
Sourcepub fn scroll_to_track_row(&mut self, track: Rect, row: u16)
pub fn scroll_to_track_row(&mut self, track: Rect, row: u16)
Jump/scroll to the position a scrollbar-track click or drag at terminal
row maps to, given the track Rect (the panel’s scrollbar column).
The track’s height doubles as the viewport height for computing the
scrollable extent, so this stays correct between frames without any
cached max_scroll.
Sourcepub fn render_scrollbar(
&self,
area: Rect,
buf: &mut Buffer,
style: &ScrollbarStyle,
)
pub fn render_scrollbar( &self, area: Rect, buf: &mut Buffer, style: &ScrollbarStyle, )
Render this panel’s vertical scrollbar into area (its scrollbar
column) with style. A no-op when the content already fits, so it’s
safe to call every frame; area.height is taken as the visible row
capacity.
Trait Implementations§
Source§impl Default for MultiSelectPanel
impl Default for MultiSelectPanel
Source§fn default() -> MultiSelectPanel
fn default() -> MultiSelectPanel
Auto Trait Implementations§
impl !Freeze for MultiSelectPanel
impl !RefUnwindSafe for MultiSelectPanel
impl !Sync for MultiSelectPanel
impl Send for MultiSelectPanel
impl Unpin for MultiSelectPanel
impl UnsafeUnpin for MultiSelectPanel
impl UnwindSafe for MultiSelectPanel
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