pub struct SelectionHelper { /* private fields */ }
Expand description
Text-selection logic
This struct holds the index of the edit cursor and selection position, which together form a range. There is no requirement on the order of these two positions. Each may be adjusted independently.
Additionally, this struct holds the selection anchor index. This usually equals the selection index, but when using double-click or triple-click selection, the anchor represents the initially-clicked position while the selection index represents the expanded position.
Implementations§
Source§impl SelectionHelper
impl SelectionHelper
Sourcepub fn new(edit: usize, selection: usize) -> Self
pub fn new(edit: usize, selection: usize) -> Self
Construct from (edit, selection)
positions
The anchor position is set to the selection position.
Sourcepub fn edit_index(&self) -> usize
pub fn edit_index(&self) -> usize
Get the cursor index
Sourcepub fn set_edit_index(&mut self, index: usize)
pub fn set_edit_index(&mut self, index: usize)
Set the cursor index without adjusting the selection index
Sourcepub fn set_sel_index(&mut self, index: usize)
pub fn set_sel_index(&mut self, index: usize)
Set the selection index without adjusting the edit index
The anchor index is also set to the selection index.
Sourcepub fn set_sel_index_only(&mut self, index: usize)
pub fn set_sel_index_only(&mut self, index: usize)
Set the selection index only
Prefer Self::set_sel_index
unless you know you don’t want to set the anchor.
Sourcepub fn set_max_len(&mut self, len: usize)
pub fn set_max_len(&mut self, len: usize)
Apply new limit to the maximum length
Call this method if the string changes under the selection to ensure that the selection does not exceed the length of the new string.
Sourcepub fn range(&self) -> Range<usize>
pub fn range(&self) -> Range<usize>
Get the selection range
This range is from the edit index to the selection index or reversed, whichever is increasing.
Sourcepub fn set_anchor_to_range_start(&mut self)
pub fn set_anchor_to_range_start(&mut self)
Set the anchor position to the start of the selection range
Sourcepub fn anchor_to_edit_range(&self) -> Range<usize>
pub fn anchor_to_edit_range(&self) -> Range<usize>
Get the range from the anchor position to the edit position
This is used following Self::set_anchor_to_range_start
to get the
IME pre-edit range.
Sourcepub fn action<T: FormattableText>(
&mut self,
text: &Text<T>,
action: SelectionAction,
)
pub fn action<T: FormattableText>( &mut self, text: &Text<T>, action: SelectionAction, )
Handle an action
Sourcepub fn cursor_rect(&self, text: &TextDisplay) -> Option<Rect>
pub fn cursor_rect(&self, text: &TextDisplay) -> Option<Rect>
Return a Rect
encompassing the cursor(s) and selection
Trait Implementations§
Source§impl Clone for SelectionHelper
impl Clone for SelectionHelper
Source§fn clone(&self) -> SelectionHelper
fn clone(&self) -> SelectionHelper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SelectionHelper
impl Debug for SelectionHelper
Source§impl Default for SelectionHelper
impl Default for SelectionHelper
Source§fn default() -> SelectionHelper
fn default() -> SelectionHelper
Auto Trait Implementations§
impl Freeze for SelectionHelper
impl RefUnwindSafe for SelectionHelper
impl Send for SelectionHelper
impl Sync for SelectionHelper
impl Unpin for SelectionHelper
impl UnwindSafe for SelectionHelper
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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.