pub struct TextEditorState { /* private fields */ }
Expand description
Core text editing state, shared between components Core state for text editing, including content, selection, cursor, and interaction state.
This struct manages the text buffer, selection, cursor position, focus, and user interaction state.
It is designed to be shared between UI components via an Arc<RwLock<TextEditorState>>
.
§Example
use std::sync::Arc;
use parking_lot::RwLock;
use tessera_ui::Dp;
use tessera_ui_basic_components::text_edit_core::{TextEditorState, text_edit_core};
let state = Arc::new(RwLock::new(TextEditorState::new(Dp(16.0), None)));
// Use `text_edit_core(state.clone())` inside your component tree.
Implementations§
Source§impl TextEditorState
impl TextEditorState
Sourcepub fn new(size: Dp, line_height: Option<Dp>) -> Self
pub fn new(size: Dp, line_height: Option<Dp>) -> Self
Creates a new TextEditorState
with the given font size and optional line height.
§Arguments
size
- Font size in Dp.line_height
- Optional line height in Dp. IfNone
, uses 1.2x the font size.
§Example
use tessera_ui::Dp;
use tessera_ui_basic_components::text_edit_core::TextEditorState;
let state = TextEditorState::new(Dp(16.0), None);
Sourcepub fn with_selection_color(
size: Dp,
line_height: Option<Dp>,
selection_color: Color,
) -> Self
pub fn with_selection_color( size: Dp, line_height: Option<Dp>, selection_color: Color, ) -> Self
Creates a new TextEditorState
with a custom selection highlight color.
§Arguments
size
- Font size in Dp.line_height
- Optional line height in Dp.selection_color
- Color used for selection highlight.
Sourcepub fn line_height(&self) -> Px
pub fn line_height(&self) -> Px
Returns the line height in pixels.
Sourcepub fn text_data(&mut self, constraint: TextConstraint) -> TextData
pub fn text_data(&mut self, constraint: TextConstraint) -> TextData
Returns the current text buffer as TextData
, applying the given layout constraints.
§Arguments
constraint
- Layout constraints for text rendering.
Sourcepub fn focus_handler(&self) -> &Focus
pub fn focus_handler(&self) -> &Focus
Returns a reference to the internal focus handler.
Sourcepub fn focus_handler_mut(&mut self) -> &mut Focus
pub fn focus_handler_mut(&mut self) -> &mut Focus
Returns a mutable reference to the internal focus handler.
Sourcepub fn editor(&self) -> &Editor<'static>
pub fn editor(&self) -> &Editor<'static>
Returns a reference to the underlying glyphon::Editor
.
Sourcepub fn editor_mut(&mut self) -> &mut Editor<'static>
pub fn editor_mut(&mut self) -> &mut Editor<'static>
Returns a mutable reference to the underlying glyphon::Editor
.
Sourcepub fn bink_timer(&self) -> Instant
pub fn bink_timer(&self) -> Instant
Returns the current blink timer instant (for cursor blinking).
Sourcepub fn update_bink_timer(&mut self)
pub fn update_bink_timer(&mut self)
Resets the blink timer to the current instant.
Sourcepub fn selection_color(&self) -> Color
pub fn selection_color(&self) -> Color
Returns the current selection highlight color.
Sourcepub fn current_selection_rects(&self) -> &Vec<RectDef>
pub fn current_selection_rects(&self) -> &Vec<RectDef>
Returns a reference to the current selection rectangles.
Sourcepub fn set_selection_color(&mut self, color: Color)
pub fn set_selection_color(&mut self, color: Color)
Sourcepub fn handle_click(
&mut self,
position: PxPosition,
timestamp: Instant,
) -> ClickType
pub fn handle_click( &mut self, position: PxPosition, timestamp: Instant, ) -> ClickType
Sourcepub fn start_drag(&mut self)
pub fn start_drag(&mut self)
Starts a drag operation (for text selection).
Sourcepub fn is_dragging(&self) -> bool
pub fn is_dragging(&self) -> bool
Returns true
if a drag operation is in progress.
Sourcepub fn last_click_position(&self) -> Option<PxPosition>
pub fn last_click_position(&self) -> Option<PxPosition>
Returns the last click position, if any.
Sourcepub fn update_last_click_position(&mut self, position: PxPosition)
pub fn update_last_click_position(&mut self, position: PxPosition)
Updates the last click position (used for drag tracking).
§Arguments
position
- The new last click position.
Auto Trait Implementations§
impl Freeze for TextEditorState
impl RefUnwindSafe for TextEditorState
impl Send for TextEditorState
impl Sync for TextEditorState
impl Unpin for TextEditorState
impl !UnwindSafe for TextEditorState
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync 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