Struct zng_ext_font::SegmentedText

source ·
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

source

pub fn new(text: impl Into<Txt>, base_direction: LayoutDirection) -> Self

New segmented text from any text type.

source

pub fn text(&self) -> &Txt

The text string.

source

pub fn segs(&self) -> &[TextSegment]

The text segments.

source

pub fn seg_from_char(&self, from: usize) -> usize

Get segment index from a char index.

source

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.

source

pub fn is_bidi(&self) -> bool

Gets if the text contains segments not in the base direction.

source

pub fn get(&self, index: usize) -> Option<(&str, TextSegment)>

Returns the text segment if index is in bounds.

source

pub fn get_clone(&self, index: usize) -> Option<SegmentedText>

Returns a clone of the text segment if index is in bounds.

source

pub fn is_empty(&self) -> bool

Returns true if text and segments are empty.

source

pub fn into_parts(self) -> (Txt, Vec<TextSegment>, LayoutDirection)

Destructs self into the text and segments.

source

pub fn from_parts( text: Txt, segments: Vec<TextSegment>, base_direction: LayoutDirection, ) -> Self

New segmented text from parts.

§Panics

Some basic validation is done on the input:

  • If one of the inputs is empty but the other is not.
  • If text is not empty and the last segment does not end with the text.
source

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);
}
source

pub fn text_range(&self, segs_range: Range<usize>) -> Range<usize>

Convert a segments range to a text bytes range.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn backspace_word_range(&self, from: usize, count: u32) -> Range<usize>

Find the range that must be removed to backspace words before from a count number of times.

The character at from is not included, only the previous word is selected.

source

pub fn delete_word_range(&self, from: usize, count: u32) -> Range<usize>

Find the range that must be removed to delete words starting by from a count number of times.

Trait Implementations§

source§

impl Clone for SegmentedText

source§

fn clone(&self) -> SegmentedText

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SegmentedText

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for SegmentedText

source§

fn default() -> SegmentedText

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

impl PartialEq for SegmentedText

source§

fn eq(&self, other: &SegmentedText) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for SegmentedText

source§

impl StructuralPartialEq for SegmentedText

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
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

source§

impl<T> AnyVarValue for T
where T: VarValue,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Access to dyn Any methods.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Access to mut dyn Any methods.
source§

fn clone_boxed(&self) -> Box<dyn AnyVarValue>

Clone the value.
source§

fn clone_boxed_var(&self) -> Box<dyn AnyVar>

Clone the value into a new boxed LocalVar<Self>.
source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Access to Box<dyn Any> methods.
source§

fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool

Gets if self equals other.
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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FsChangeNote for T
where T: Debug + Any + Send + Sync,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Access any.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoVar<T> for T
where T: VarValue,

source§

type Var = LocalVar<T>

Variable type that will wrap the T value. Read more
source§

fn into_var(self) -> <T as IntoVar<T>>::Var

Converts the source value into a var.
source§

fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>
where Self: Sized,

Converts into BoxedVar<T>. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> IntoValue<T> for T
where T: VarValue,

§

impl<T> MaybeSendSync for T

source§

impl<T> StateValue for T
where T: Any + Send + Sync,

source§

impl<T> VarValue for T
where T: Debug + Clone + PartialEq + Any + Send + Sync,