pub struct TextFieldState {
pub text: String,
pub selection: Range<usize>,
pub composition: Option<Range<usize>>,
pub scroll_offset: f32,
pub scroll_offset_y: f32,
pub drag_anchor: Option<usize>,
pub blink_start: Instant,
pub inner_width: f32,
pub inner_height: f32,
pub preferred_x_px: Option<f32>,
pub offset_map: Option<Box<dyn OffsetMapping>>,
pub visual_transformation: Option<Rc<dyn VisualTransformation>>,
/* private fields */
}Fields§
§text: String§selection: Range<usize>§composition: Option<Range<usize>>§scroll_offset: f32§scroll_offset_y: f32§drag_anchor: Option<usize>§blink_start: Instant§inner_width: f32§inner_height: f32§preferred_x_px: Option<f32>§offset_map: Option<Box<dyn OffsetMapping>>When a visual transformation is active, this maps offsets in the display text back to offsets in the original text.
visual_transformation: Option<Rc<dyn VisualTransformation>>The active visual transformation, set during layout.
Implementations§
Source§impl TextFieldState
impl TextFieldState
pub fn new() -> Self
Sourcepub fn redo(&mut self) -> bool
pub fn redo(&mut self) -> bool
Re-apply a previously undone edit. Returns true if a redo was performed.
Sourcepub fn clear_undo_history(&mut self)
pub fn clear_undo_history(&mut self)
Clear all undo/redo history.
pub fn insert_text(&mut self, text: &str)
Sourcepub fn insert_text_atomic(&mut self, text: &str)
pub fn insert_text_atomic(&mut self, text: &str)
Like insert_text but marks the operation as unmergeable (for cut/paste).
pub fn delete_backward(&mut self)
pub fn delete_forward(&mut self)
pub fn move_cursor(&mut self, delta: isize, extend_selection: bool)
pub fn selected_text(&self) -> String
pub fn set_composition(&mut self, text: String, cursor: Option<(usize, usize)>)
pub fn commit_composition(&mut self, text: String)
pub fn cancel_composition(&mut self)
pub fn delete_surrounding(&mut self, before_bytes: usize, after_bytes: usize)
pub fn begin_drag(&mut self, idx_byte: usize, extend: bool)
pub fn drag_to(&mut self, idx_byte: usize)
pub fn end_drag(&mut self)
pub fn caret_index(&self) -> usize
Sourcepub fn ensure_caret_visible(
&mut self,
caret_x_px: f32,
inner_width_px: f32,
inset_px: f32,
)
pub fn ensure_caret_visible( &mut self, caret_x_px: f32, inner_width_px: f32, inset_px: f32, )
Keep caret visible inside inner content width (px).
inset_px is a small padding (px) to avoid hugging edges.
Sets the scroll target for smooth animated scrolling.
Sourcepub fn ensure_caret_visible_xy(
&mut self,
caret_x_px: f32,
caret_y_px: f32,
inner_w_px: f32,
inner_h_px: f32,
inset_px: f32,
)
pub fn ensure_caret_visible_xy( &mut self, caret_x_px: f32, caret_y_px: f32, inner_w_px: f32, inner_h_px: f32, inset_px: f32, )
Keep caret visible inside an inner rect (for multiline). Sets the scroll target for smooth animated scrolling.
pub fn clamp_scroll(&mut self, content_h_px: f32)
pub fn reset_caret_blink(&mut self)
pub fn caret_visible(&self) -> bool
pub fn set_inner_width(&mut self, w_px: f32)
pub fn set_inner_height(&mut self, h_px: f32)
Sourcepub fn tick_scroll_animation(&mut self)
pub fn tick_scroll_animation(&mut self)
Advance scroll animation by actual wall-clock dt using spring physics. Call this once per frame before reading [scroll_offset] / [scroll_offset_y]. On the first call after a target change, snaps immediately to avoid 1-frame delay.