pub trait TextBuffer {
Show 22 methods
// Required methods
fn is_mutable(&self) -> bool;
fn as_str(&self) -> &str;
fn insert_text(&mut self, text: &str, char_index: CharIndex) -> usize;
fn delete_char_range(&mut self, char_range: Range<CharIndex>);
fn type_id(&self) -> TypeId;
// Provided methods
fn char_range(&self, char_range: Range<CharIndex>) -> &str { ... }
fn byte_index_from_char_index(&self, char_index: CharIndex) -> ByteIndex { ... }
fn char_index_from_byte_index(&self, byte_index: ByteIndex) -> CharIndex { ... }
fn clear(&mut self) { ... }
fn replace_with(&mut self, text: &str) { ... }
fn take(&mut self) -> String { ... }
fn insert_text_at(
&mut self,
ccursor: &mut CCursor,
text_to_insert: &str,
char_limit: usize,
) { ... }
fn decrease_indentation(&mut self, ccursor: &mut CCursor) { ... }
fn delete_selected(&mut self, cursor_range: &CCursorRange) -> CCursor { ... }
fn delete_selected_ccursor_range(
&mut self,
[min, max]: [CCursor; 2],
) -> CCursor { ... }
fn delete_previous_char(&mut self, ccursor: CCursor) -> CCursor { ... }
fn delete_next_char(&mut self, ccursor: CCursor) -> CCursor { ... }
fn delete_previous_word(&mut self, max_ccursor: CCursor) -> CCursor { ... }
fn delete_next_word(&mut self, min_ccursor: CCursor) -> CCursor { ... }
fn delete_surrounding_chars(
&mut self,
cursor_range: CCursorRange,
before_chars: usize,
after_chars: usize,
) -> CCursorRange { ... }
fn delete_paragraph_before_cursor(
&mut self,
galley: &Galley,
cursor_range: &CCursorRange,
) -> CCursor { ... }
fn delete_paragraph_after_cursor(
&mut self,
galley: &Galley,
cursor_range: &CCursorRange,
) -> CCursor { ... }
}Expand description
Trait constraining what types crate::TextEdit may use as
an underlying buffer.
Most likely you will use a String which implements TextBuffer.
Required Methods§
Sourcefn is_mutable(&self) -> bool
fn is_mutable(&self) -> bool
Can this text be edited?
Sourcefn insert_text(&mut self, text: &str, char_index: CharIndex) -> usize
fn insert_text(&mut self, text: &str, char_index: CharIndex) -> usize
Sourcefn delete_char_range(&mut self, char_range: Range<CharIndex>)
fn delete_char_range(&mut self, char_range: Range<CharIndex>)
Deletes a range of text char_range from this buffer.
§Notes
char_range is a character range, not a byte range.
Sourcefn type_id(&self) -> TypeId
fn type_id(&self) -> TypeId
Returns a unique identifier for the implementing type.
This is useful for downcasting from this trait to the implementing type. Here is an example usage:
use egui::TextBuffer;
use std::any::TypeId;
struct ExampleBuffer {}
impl TextBuffer for ExampleBuffer {
fn is_mutable(&self) -> bool { unimplemented!() }
fn as_str(&self) -> &str { unimplemented!() }
fn insert_text(&mut self, text: &str, char_index: egui::text::CharIndex) -> usize { unimplemented!() }
fn delete_char_range(&mut self, char_range: std::ops::Range<egui::text::CharIndex>) { unimplemented!() }
// Implement it like the following:
fn type_id(&self) -> TypeId {
TypeId::of::<Self>()
}
}
// Example downcast:
pub fn downcast_example(buffer: &dyn TextBuffer) -> Option<&ExampleBuffer> {
if buffer.type_id() == TypeId::of::<ExampleBuffer>() {
unsafe { Some(&*(buffer as *const dyn TextBuffer as *const ExampleBuffer)) }
} else {
None
}
}Provided Methods§
Sourcefn char_range(&self, char_range: Range<CharIndex>) -> &str
fn char_range(&self, char_range: Range<CharIndex>) -> &str
Reads the given character range.
fn byte_index_from_char_index(&self, char_index: CharIndex) -> ByteIndex
fn char_index_from_byte_index(&self, byte_index: ByteIndex) -> CharIndex
Sourcefn replace_with(&mut self, text: &str)
fn replace_with(&mut self, text: &str)
Replaces all contents of this string with text
Sourcefn take(&mut self) -> String
fn take(&mut self) -> String
Clears all characters in this buffer and returns a string of the contents.
fn insert_text_at( &mut self, ccursor: &mut CCursor, text_to_insert: &str, char_limit: usize, )
fn decrease_indentation(&mut self, ccursor: &mut CCursor)
fn delete_selected(&mut self, cursor_range: &CCursorRange) -> CCursor
fn delete_selected_ccursor_range(&mut self, [min, max]: [CCursor; 2]) -> CCursor
fn delete_previous_char(&mut self, ccursor: CCursor) -> CCursor
fn delete_next_char(&mut self, ccursor: CCursor) -> CCursor
fn delete_previous_word(&mut self, max_ccursor: CCursor) -> CCursor
fn delete_next_word(&mut self, min_ccursor: CCursor) -> CCursor
Sourcefn delete_surrounding_chars(
&mut self,
cursor_range: CCursorRange,
before_chars: usize,
after_chars: usize,
) -> CCursorRange
fn delete_surrounding_chars( &mut self, cursor_range: CCursorRange, before_chars: usize, after_chars: usize, ) -> CCursorRange
Deletes characters surrounding the current cursor range.
Removes before_chars characters before the selection start and
after_chars characters after the selection end.
The returned CCursorRange is adjusted to account for the removed
characters before the selection.
fn delete_paragraph_before_cursor( &mut self, galley: &Galley, cursor_range: &CCursorRange, ) -> CCursor
fn delete_paragraph_after_cursor( &mut self, galley: &Galley, cursor_range: &CCursorRange, ) -> CCursor
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl TextBuffer for &str
Immutable view of a &str!
impl TextBuffer for &str
Immutable view of a &str!