pub struct SegmentedText { /* private fields */ }Expand description
A string segmented in sequences of words, spaces, tabs and separated line breaks.
Each segment is tagged with a TextSegmentKind and is defines as
an offset from the last segment.
Implementations§
Source§impl SegmentedText
impl SegmentedText
Sourcepub fn new(text: impl Into<Txt>, base_direction: LayoutDirection) -> Self
pub fn new(text: impl Into<Txt>, base_direction: LayoutDirection) -> Self
New segmented text from any text type.
Sourcepub fn segs(&self) -> &[TextSegment]
pub fn segs(&self) -> &[TextSegment]
The text segments.
Sourcepub fn seg_from_char(&self, from: usize) -> usize
pub fn seg_from_char(&self, from: usize) -> usize
Get segment index from a char index.
Sourcepub fn base_direction(&self) -> LayoutDirection
pub fn base_direction(&self) -> LayoutDirection
Contextual direction.
Note that each segment can override the direction, and even the entire text can be a sequence in the opposite direction.
Sourcepub fn get(&self, index: usize) -> Option<(&str, TextSegment)>
pub fn get(&self, index: usize) -> Option<(&str, TextSegment)>
Returns the text segment if index is in bounds.
Sourcepub fn get_clone(&self, index: usize) -> Option<SegmentedText>
pub fn get_clone(&self, index: usize) -> Option<SegmentedText>
Returns a clone of the text segment if index is in bounds.
Sourcepub fn into_parts(self) -> (Txt, Vec<TextSegment>, LayoutDirection)
pub fn into_parts(self) -> (Txt, Vec<TextSegment>, LayoutDirection)
Destructs self into the text and segments.
Sourcepub fn from_parts(
text: Txt,
segments: Vec<TextSegment>,
base_direction: LayoutDirection,
) -> Self
pub fn from_parts( text: Txt, segments: Vec<TextSegment>, base_direction: LayoutDirection, ) -> Self
Sourcepub fn iter(&self) -> SegmentedTextIter<'_> ⓘ
pub fn iter(&self) -> SegmentedTextIter<'_> ⓘ
Segments iterator.
§Examples
for (sub_str, seg) in SegmentedText::new("Foo bar!\nBaz.", LayoutDirection::LTR).iter() {
println!("s: {sub_str:?} is a `{:?}`", seg.kind);
}Sourcepub fn text_range(&self, segs_range: Range<usize>) -> Range<usize> ⓘ
pub fn text_range(&self, segs_range: Range<usize>) -> Range<usize> ⓘ
Convert a segments range to a text bytes range.
Sourcepub fn reorder_line_to_ltr(&self, segs_range: Range<usize>) -> Vec<usize>
pub fn reorder_line_to_ltr(&self, segs_range: Range<usize>) -> Vec<usize>
Compute a map of segments in segs_range to their final LTR display order.
The segs_range must be the segments of a line after line wrap.
Sourcepub fn snap_char_boundary(&self, i: usize) -> usize
pub fn snap_char_boundary(&self, i: usize) -> usize
Find the nearest next char boundary from the byte index i.
If i is larger than the text length, returns the text length, if i is
already a char boundary, returns i.
Sourcepub fn snap_grapheme_boundary(&self, i: usize) -> usize
pub fn snap_grapheme_boundary(&self, i: usize) -> usize
Find the nearest grapheme cluster boundary from the byte index i.
If i is larger than the text length, returns the text length, if i is
already a grapheme boundary, returns i.
Sourcepub fn next_insert_index(&self, from: usize) -> usize
pub fn next_insert_index(&self, from: usize) -> usize
Find the next grapheme cluster, after from.
The from must be in a grapheme boundary or 0 or len. This operation is saturating.
§Panics
Panics if from is larger than the text length, or is not at a grapheme boundary.
Sourcepub fn prev_insert_index(&self, from: usize) -> usize
pub fn prev_insert_index(&self, from: usize) -> usize
Find the previous grapheme cluster, before from.
The from must be in a grapheme boundary or 0 or len. This operation is saturating.
§Panics
Panics if from is larger than the text length, or is not at a grapheme boundary.
Sourcepub fn next_word_index(&self, from: usize) -> usize
pub fn next_word_index(&self, from: usize) -> usize
Find the start of the next word or the next line-break segment, after from.
This operation is saturating.
Sourcepub fn next_word_end_index(&self, from: usize) -> usize
pub fn next_word_end_index(&self, from: usize) -> usize
Find the next word segment end or the next line-break segment end, after from.
This operation is saturating.
Sourcepub fn prev_word_index(&self, from: usize) -> usize
pub fn prev_word_index(&self, from: usize) -> usize
Find the start of the previous word segment or the previous line-break segment, before from.
This operation is saturating.
Sourcepub fn line_start_index(&self, from: usize) -> usize
pub fn line_start_index(&self, from: usize) -> usize
Find the start of the line that contains from.
§Panics
Panics if from is larger than the text length, or is not a char boundary.
Sourcepub fn line_end_index(&self, from: usize) -> usize
pub fn line_end_index(&self, from: usize) -> usize
Find the end of the line that contains from.
§Panics
Panics if from is larger than the text length, or is not a char boundary.
Sourcepub fn delete_range(&self, from: usize, count: u32) -> Range<usize> ⓘ
pub fn delete_range(&self, from: usize, count: u32) -> Range<usize> ⓘ
Find the range that must be removed to delete starting by from a count number of times.
Delete Del action removes the next grapheme cluster, this is different from
backspace_range that usually only removes one character.
§Panics
Panics if from is larger than the text length, or is not a grapheme boundary.
Sourcepub fn backspace_range(&self, from: usize, count: u32) -> Range<usize> ⓘ
pub fn backspace_range(&self, from: usize, count: u32) -> Range<usize> ⓘ
Find the range that must be removed to backspace before from a count number of times.
The character at from is not included, only the previous char is selected, with some exceptions,
the selection includes any char before zero-width-joiner (ZWJ), it also includes \r before \n
and Emoji char before Emoji modifier or variation selector (VS16).
§Panics
Panics if from is larger than the text length, or is not a char boundary.
Trait Implementations§
Source§impl Clone for SegmentedText
impl Clone for SegmentedText
Source§fn clone(&self) -> SegmentedText
fn clone(&self) -> SegmentedText
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SegmentedText
impl Debug for SegmentedText
Source§impl Default for SegmentedText
impl Default for SegmentedText
Source§fn default() -> SegmentedText
fn default() -> SegmentedText
Source§impl PartialEq for SegmentedText
impl PartialEq for SegmentedText
impl Eq for SegmentedText
impl StructuralPartialEq for SegmentedText
Auto Trait Implementations§
impl Freeze for SegmentedText
impl RefUnwindSafe for SegmentedText
impl Send for SegmentedText
impl Sync for SegmentedText
impl Unpin for SegmentedText
impl UnwindSafe for SegmentedText
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> AnyVarValue for T
impl<T> AnyVarValue for T
Source§fn clone_boxed(&self) -> BoxAnyVarValue
fn clone_boxed(&self) -> BoxAnyVarValue
Source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self and other are equal.Source§fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
other if both are of the same type.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> 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
key and return true if they are equal.Source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§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>
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