pub struct TextCore<Store> { /* private fields */ }Expand description
Core for text editing.
Implementations§
Source§impl<Store> TextCore<Store>
impl<Store> TextCore<Store>
pub fn new( undo: Option<Box<dyn UndoBuffer>>, clip: Option<Box<dyn Clipboard>>, ) -> TextCore<Store>
Sourcepub fn set_glyph_ctrl(&mut self, show_ctrl: bool)
pub fn set_glyph_ctrl(&mut self, show_ctrl: bool)
Show control characters when iterating glyphs.
Sourcepub fn glyph_ctrl(&self) -> bool
pub fn glyph_ctrl(&self) -> bool
Show glyphs for text-wrap.
Sourcepub fn set_wrap_ctrl(&mut self, wrap_ctrl: bool)
pub fn set_wrap_ctrl(&mut self, wrap_ctrl: bool)
Show glyphs for text-wrap.
Source§impl<Store> TextCore<Store>
impl<Store> TextCore<Store>
Sourcepub fn set_undo_buffer(&mut self, undo: Option<Box<dyn UndoBuffer>>)
pub fn set_undo_buffer(&mut self, undo: Option<Box<dyn UndoBuffer>>)
Undo
Sourcepub fn set_undo_count(&mut self, n: u32)
pub fn set_undo_count(&mut self, n: u32)
Set undo count
Sourcepub fn begin_undo_seq(&mut self)
pub fn begin_undo_seq(&mut self)
Begin a sequence of changes that should be undone in one go.
Sourcepub fn end_undo_seq(&mut self)
pub fn end_undo_seq(&mut self)
End a sequence of changes that should be undone in one go.
Sourcepub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>
pub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>
Undo
Sourcepub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>
pub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>
Undo
Sourcepub fn recent_replay_log(&mut self) -> Vec<UndoEntry>
pub fn recent_replay_log(&mut self) -> Vec<UndoEntry>
Get last replay recording.
Sourcepub fn replay_log(&mut self, replay: &[UndoEntry])
pub fn replay_log(&mut self, replay: &[UndoEntry])
Replay a recording of changes.
Source§impl<Store> TextCore<Store>
impl<Store> TextCore<Store>
Sourcepub fn set_styles(&mut self, new_styles: Vec<(Range<usize>, usize)>)
pub fn set_styles(&mut self, new_styles: Vec<(Range<usize>, usize)>)
Set all styles.
The ranges are byte-ranges. The usize value is the index of the actual style. Those are set with the widget.
Sourcepub fn add_style(&mut self, range: Range<usize>, style: usize)
pub fn add_style(&mut self, range: Range<usize>, style: usize)
Add a style for the given byte-range.
The usize value is the index of the actual style. Those are set at the widget.
Sourcepub fn remove_style(&mut self, range: Range<usize>, style: usize)
pub fn remove_style(&mut self, range: Range<usize>, style: usize)
Remove a style for the given byte-range.
Range and style must match to be removed.
Sourcepub fn remove_style_fully(&mut self, style: usize)
pub fn remove_style_fully(&mut self, style: usize)
Remove all ranges for the given style.
Sourcepub fn styles_in(
&self,
range: Range<usize>,
buf: &mut Vec<(Range<usize>, usize)>,
)
pub fn styles_in( &self, range: Range<usize>, buf: &mut Vec<(Range<usize>, usize)>, )
Find all styles that touch the given range.
Sourcepub fn styles_in_match(
&self,
range: Range<usize>,
style: usize,
buf: &mut Vec<(Range<usize>, usize)>,
)
pub fn styles_in_match( &self, range: Range<usize>, style: usize, buf: &mut Vec<(Range<usize>, usize)>, )
Find all styles that touch the given range.
Sourcepub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)
pub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)
Finds all styles for the given position.
Source§impl<Store> TextCore<Store>
impl<Store> TextCore<Store>
Sourcepub fn set_cursor(
&mut self,
cursor: TextPosition,
extend_selection: bool,
) -> bool
pub fn set_cursor( &mut self, cursor: TextPosition, extend_selection: bool, ) -> bool
Set the cursor position. The value is capped to the number of text lines and the line-width for the given line.
Returns true, if the cursor actually changed.
Sourcepub fn cursor(&self) -> TextPosition
pub fn cursor(&self) -> TextPosition
Cursor position as grapheme-idx.
Sourcepub fn anchor(&self) -> TextPosition
pub fn anchor(&self) -> TextPosition
Selection anchor
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Any text selection.
Sourcepub fn set_selection(
&mut self,
anchor: TextPosition,
cursor: TextPosition,
) -> bool
pub fn set_selection( &mut self, anchor: TextPosition, cursor: TextPosition, ) -> bool
Select text. Anchor and cursor are capped to a valid value.
Sourcepub fn select_all(&mut self) -> bool
pub fn select_all(&mut self) -> bool
Select all text.
Source§impl<Store> TextCore<Store>
impl<Store> TextCore<Store>
Sourcepub fn byte_at(&self, pos: TextPosition) -> Result<Range<usize>, TextError>
pub fn byte_at(&self, pos: TextPosition) -> Result<Range<usize>, TextError>
Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.
Sourcepub fn bytes_at_range(
&self,
range: TextRange,
) -> Result<Range<usize>, TextError>
pub fn bytes_at_range( &self, range: TextRange, ) -> Result<Range<usize>, TextError>
Grapheme range to byte range.
Sourcepub fn byte_pos(&self, byte: usize) -> Result<TextPosition, TextError>
pub fn byte_pos(&self, byte: usize) -> Result<TextPosition, TextError>
Byte position to grapheme position. Returns the position that contains the given byte index.
Sourcepub fn byte_range(&self, bytes: Range<usize>) -> Result<TextRange, TextError>
pub fn byte_range(&self, bytes: Range<usize>) -> Result<TextRange, TextError>
Byte range to grapheme range.
Sourcepub fn str_slice(&self, range: TextRange) -> Result<Cow<'_, str>, TextError>
pub fn str_slice(&self, range: TextRange) -> Result<Cow<'_, str>, TextError>
A range of the text as Cow<str>
Sourcepub fn str_slice_byte(
&self,
range: Range<usize>,
) -> Result<Cow<'_, str>, TextError>
pub fn str_slice_byte( &self, range: Range<usize>, ) -> Result<Cow<'_, str>, TextError>
A range of the text as Cow<str>
Sourcepub fn grapheme_at(
&self,
pos: TextPosition,
) -> Result<Option<Grapheme<'_>>, TextError>
pub fn grapheme_at( &self, pos: TextPosition, ) -> Result<Option<Grapheme<'_>>, TextError>
Get the grapheme at the given position.
Sourcepub fn text_graphemes(
&self,
pos: TextPosition,
) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
pub fn text_graphemes( &self, pos: TextPosition, ) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
Get a cursor over all the text with the current position set at pos.
Sourcepub fn graphemes(
&self,
range: TextRange,
pos: TextPosition,
) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
pub fn graphemes( &self, range: TextRange, pos: TextPosition, ) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
Get a cursor over the text-range the current position set at pos.
Sourcepub fn graphemes_byte(
&self,
range: Range<usize>,
pos: usize,
) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
pub fn graphemes_byte( &self, range: Range<usize>, pos: usize, ) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
Get a cursor over the text-range with the current position set at pos.
Sourcepub fn line_at(&self, row: u32) -> Result<Cow<'_, str>, TextError>
pub fn line_at(&self, row: u32) -> Result<Cow<'_, str>, TextError>
Line as str.
- row must be <= len_lines
Sourcepub fn lines_at(
&self,
row: u32,
) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>
pub fn lines_at( &self, row: u32, ) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>
Iterate over text-lines, starting at row.
- row must be <= len_lines
Sourcepub fn line_graphemes(
&self,
row: u32,
) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
pub fn line_graphemes( &self, row: u32, ) -> Result<<Store as TextStore>::GraphemeIter<'_>, TextError>
Get the text for a line as iterator over the graphemes.
Source§impl<Store> TextCore<Store>
impl<Store> TextCore<Store>
Sourcepub fn set_text(&mut self, t: Store) -> bool
pub fn set_text(&mut self, t: Store) -> bool
Set the text as a TextStore. Clears the styles, cursor and anchor.
Sourcepub fn insert_char(
&mut self,
pos: TextPosition,
c: char,
) -> Result<bool, TextError>
pub fn insert_char( &mut self, pos: TextPosition, c: char, ) -> Result<bool, TextError>
Insert a character.
Has no special handling for ‘\n’ and ‘\t’ and just adds them as they are. ‘\n’ is treated as line-break, but it might not be the correct byte-sequence for your platform.
Sourcepub fn insert_str(
&mut self,
pos: TextPosition,
t: &str,
) -> Result<bool, TextError>
pub fn insert_str( &mut self, pos: TextPosition, t: &str, ) -> Result<bool, TextError>
Insert a string at position.
Trait Implementations§
Auto Trait Implementations§
impl<Store> !Freeze for TextCore<Store>
impl<Store> !RefUnwindSafe for TextCore<Store>
impl<Store> !Send for TextCore<Store>
impl<Store> !Sync for TextCore<Store>
impl<Store> Unpin for TextCore<Store>where
Store: Unpin,
impl<Store> !UnwindSafe for TextCore<Store>
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more