pub struct TextBox {
pub text: String,
pub cursor_pos: usize,
pub multiline: bool,
}Fields§
§text: String§cursor_pos: usize§multiline: boolImplementations§
Source§impl TextBox
impl TextBox
pub fn new() -> Self
pub fn with_text(text: &str) -> Self
Sourcepub fn with_text_multiline(text: &str) -> Self
pub fn with_text_multiline(text: &str) -> Self
複数行モードを有効にした TextBox を生成します(note エディタ等)。
pub fn set_text(&mut self, text: &str)
Sourcepub fn get_text_with_cursor(&self, show_cursor: bool) -> String
pub fn get_text_with_cursor(&self, show_cursor: bool) -> String
カーソルを挿入した表示用の文字列を作成します
Sourcepub fn handle_key(&mut self, keycode: u8, ascii: Option<char>) -> bool
pub fn handle_key(&mut self, keycode: u8, ascii: Option<char>) -> bool
キーボード入力を処理します。テキストまたはカーソルが動いた場合は true を返します。
「文字が変わったのか、カーソルが動いただけなのか」を区別したい呼び出し側は
TextBox::handle_key_outcome を使うこと。
Sourcepub fn handle_key_outcome(
&mut self,
keycode: u8,
ascii: Option<char>,
) -> KeyOutcome
pub fn handle_key_outcome( &mut self, keycode: u8, ascii: Option<char>, ) -> KeyOutcome
TextBox::handle_key の詳細版。矢印キー等のカーソル移動と、
実際にテキストを書き換えた編集を区別して返す。
【2026-09-08 バグ修正】この区別が無かったため、Web エンジン側は
矢印キーでも「値が変わった」とみなして DOM の value を書き換え
input イベントを発火していた。DOM が dirty になると
relayout_if_dom_dirty → parse_and_layout が走り、そこで
active_text_box が破棄される。次のキーで with_text_multiline により
カーソル位置が末尾に戻った TextBox が作り直されるため、
note アプリで「↑を押しても 1 行しか上がらない」症状になっていた。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TextBox
impl RefUnwindSafe for TextBox
impl Send for TextBox
impl Sync for TextBox
impl Unpin for TextBox
impl UnsafeUnpin for TextBox
impl UnwindSafe for TextBox
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
Mutably borrows from an owned value. Read more