Skip to main content

TextBox

Struct TextBox 

Source
pub struct TextBox {
    pub text: String,
    pub cursor_pos: usize,
    pub multiline: bool,
}

Fields§

§text: String§cursor_pos: usize§multiline: bool

Implementations§

Source§

impl TextBox

Source

pub fn new() -> Self

Source

pub fn with_text(text: &str) -> Self

Source

pub fn with_text_multiline(text: &str) -> Self

複数行モードを有効にした TextBox を生成します(note エディタ等)。

Source

pub fn set_text(&mut self, text: &str)

Source

pub fn get_text_with_cursor(&self, show_cursor: bool) -> String

カーソルを挿入した表示用の文字列を作成します

Source

pub fn handle_key(&mut self, keycode: u8, ascii: Option<char>) -> bool

キーボード入力を処理します。テキストまたはカーソルが動いた場合は true を返します。

「文字が変わったのか、カーソルが動いただけなのか」を区別したい呼び出し側は TextBox::handle_key_outcome を使うこと。

Source

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_dirtyparse_and_layout が走り、そこで active_text_box が破棄される。次のキーで with_text_multiline により カーソル位置が末尾に戻った TextBox が作り直されるため、 note アプリで「↑を押しても 1 行しか上がらない」症状になっていた。

Trait Implementations§

Source§

impl Clone for TextBox

Source§

fn clone(&self) -> TextBox

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextBox

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextBox

Source§

fn default() -> TextBox

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.