Skip to main content

MultiSelectPanel

Struct MultiSelectPanel 

Source
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

Source

pub fn new() -> Self

A panel with no content, no selection and scroll at the top.

Source

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

Source

pub fn wrap_mode(&self) -> WrapMode

This panel’s current WrapMode.

Source

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.

Source

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

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

Source

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.

Source

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.

Source

pub fn has_content(&self) -> bool

Whether any content has been set yet.

Source

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.

Source

pub fn total_rows(&self) -> u32

The total number of wrapped rows the current content occupies.

Source

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.

Source

pub fn scroll(&self) -> u16

This panel’s current scroll offset, in wrapped rows.

Source

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

Source

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)].

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn has_pending_autoscroll(&self) -> bool

Whether a drag is currently held past an edge, waiting for autoscroll_tick to keep scrolling.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn has_selection(&self) -> bool

Whether there is any selection region at all (active or finalized).

Source

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.

Source

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.

Source

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

Source

pub fn finalized_selections(&self) -> Vec<(TextPos, TextPos)>

The finalized regions (those moved aside by finalize_active) as (anchor, cursor) pairs, in insertion order.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source§

fn default() -> MultiSelectPanel

Returns the “default value” for a type. Read more

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.