pub struct TerminalSelection {
pub anchor: TerminalPosition,
pub focus: TerminalPosition,
}Expand description
Direction-preserving anchor/focus text selection.
§Examples
use ailloli_ui_widgets::controls::{TerminalPosition, TerminalSelection};
let selection = TerminalSelection::new(TerminalPosition::new(0, 1), TerminalPosition::new(2, 3));
assert_eq!(selection.anchor.line, 0);Fields§
§anchor: TerminalPositionPosition where dragging began.
focus: TerminalPositionCurrent drag position.
Implementations§
Source§impl TerminalSelection
impl TerminalSelection
Sourcepub const fn new(anchor: TerminalPosition, focus: TerminalPosition) -> Self
pub const fn new(anchor: TerminalPosition, focus: TerminalPosition) -> Self
Creates a selection without ordering or bounds normalization.
§Examples
use ailloli_ui_widgets::controls::{TerminalPosition, TerminalSelection};
let selection = TerminalSelection::new(TerminalPosition::new(3, 2), TerminalPosition::new(1, 0));
assert_eq!(selection.normalized().0.line, 1);Sourcepub const fn lines(start: usize, end: usize) -> Self
pub const fn lines(start: usize, end: usize) -> Self
Selects from column zero of start through the end of end.
usize::MAX is used as the end-of-line sentinel and is clamped during
painting; line indices are not validated here.
§Examples
use ailloli_ui_widgets::controls::TerminalSelection;
let selection = TerminalSelection::lines(2, 4);
assert_eq!((selection.anchor.column, selection.focus.column), (0, usize::MAX));Sourcepub fn normalized(self) -> (TerminalPosition, TerminalPosition)
pub fn normalized(self) -> (TerminalPosition, TerminalPosition)
Returns endpoints in lexicographic (line, column) order.
§Examples
use ailloli_ui_widgets::controls::{TerminalPosition, TerminalSelection};
let (start, end) = TerminalSelection::new(TerminalPosition::new(2, 0), TerminalPosition::new(1, 9)).normalized();
assert_eq!((start.line, end.line), (1, 2));Sourcepub fn clamp(self, line_count: usize) -> Option<Self>
pub fn clamp(self, line_count: usize) -> Option<Self>
Clamps both line indices to an available buffer.
Returns None for an empty buffer. Columns are retained verbatim and are
clamped against line text only when rendered.
§Examples
use ailloli_ui_widgets::controls::TerminalSelection;
assert!(TerminalSelection::lines(1, 4).clamp(0).is_none());
assert_eq!(TerminalSelection::lines(1, 4).clamp(3).unwrap().focus.line, 2);Trait Implementations§
Source§impl Clone for TerminalSelection
impl Clone for TerminalSelection
Source§fn clone(&self) -> TerminalSelection
fn clone(&self) -> TerminalSelection
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TerminalSelection
impl Debug for TerminalSelection
Source§impl Default for TerminalSelection
impl Default for TerminalSelection
Source§fn default() -> TerminalSelection
fn default() -> TerminalSelection
Returns the “default value” for a type. Read more
Source§impl PartialEq for TerminalSelection
impl PartialEq for TerminalSelection
impl Copy for TerminalSelection
impl Eq for TerminalSelection
impl StructuralPartialEq for TerminalSelection
Auto Trait Implementations§
impl Freeze for TerminalSelection
impl RefUnwindSafe for TerminalSelection
impl Send for TerminalSelection
impl Sync for TerminalSelection
impl Unpin for TerminalSelection
impl UnwindSafe for TerminalSelection
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.