pub fn text_editor(
args: impl Into<TextEditorArgs>,
state: Arc<RwLock<TextEditorState>>,
)
Expand description
A text editor component with two-layer architecture:
- surface layer: provides visual container, minimum size, and click area
- Core layer: handles text rendering and editing logic
This design solves the issue where empty text editors had zero width and couldn’t be clicked.
§Example
use tessera_ui_basic_components::text_editor::{text_editor, TextEditorArgs, TextEditorArgsBuilder, TextEditorState};
use tessera_ui::{Dp, DimensionValue, Px};
use std::sync::Arc;
use parking_lot::RwLock;
let args = TextEditorArgsBuilder::default()
.width(Some(DimensionValue::Fixed(Px(300))))
.height(Some(DimensionValue::Fill { min: Some(Px(50)), max: Some(Px(500)) }))
.build()
.unwrap();
let state = Arc::new(RwLock::new(TextEditorState::new(Dp(12.0), None)));
// text_editor(args, state);
Multi-line text editor component with full state management, cursor, selection, and IME support.
The text_editor
component provides a robust, customizable multi-line text editing area.
It supports keyboard and mouse input, selection, cursor movement, IME/preedit, and scroll handling.
State is managed externally via TextEditorState
(typically wrapped in Arc<RwLock<...>>
).
§Features
- Multi-line text editing with Unicode support
- Full cursor and selection management (mouse, keyboard, drag, double/triple click)
- IME/preedit support for CJK and complex input
- Customizable appearance (background, border, shape, padding, selection color)
- Focus management and event handling
- Scroll via mouse wheel or keyboard
§Parameters
args
: Editor configuration, seeTextEditorArgs
.state
: Shared editor state, seeTextEditorState
.
§Example
use tessera_ui_basic_components::text_editor::{text_editor, TextEditorArgs, TextEditorArgsBuilder, TextEditorState};
use tessera_ui::{Dp, DimensionValue, Px};
use std::sync::Arc;
use parking_lot::RwLock;
let args = TextEditorArgsBuilder::default()
.width(Some(DimensionValue::Fixed(Px(300))))
.height(Some(DimensionValue::Fill { min: Some(Px(50)), max: Some(Px(500)) }))
.build()
.unwrap();
let state = Arc::new(RwLock::new(TextEditorState::new(Dp(12.0), None)));
text_editor(args, state);