Skip to main content

TextFieldLayout

Struct TextFieldLayout 

Source
pub struct TextFieldLayout {
    pub lines: Vec<TextFieldLine>,
    pub line_h: f32,
    pub top_pad: f32,
    pub text_width: f32,
    pub content_height: f32,
    pub viewport_height: f32,
    pub max_scroll: f32,
    pub scroll_y: f32,
}
Expand description

TextField 的可视布局:视觉行 + 行高/滚动几何

Fields§

§lines: Vec<TextFieldLine>§line_h: f32§top_pad: f32§text_width: f32§content_height: f32§viewport_height: f32

文本可视区高度(不含上下 padding)

§max_scroll: f32§scroll_y: f32

已 clamp 的滚动偏移

Implementations§

Source§

impl TextFieldLayout

Source

pub fn cursor_line(&self, cursor: usize) -> usize

光标落在哪个视觉行:边界判给下一行(后行亲和)。

soft wrap 边界那个 byte 同时是上一行的 end 与下一行的 start(中文每字可断、 没有空格可吞时必然相等,英文挂尾空格同样相等)。End / Right / ↓ 与光标绘制、 滚动定位用这个口径 —— 否则光标停在某行行首时按 End 会被判到上一行,行末就走不过去; 绘制按后行也才对得上“在这里输入会落在哪“。Home 用 Self::cursor_line_upstream。

Source

pub fn cursor_line_upstream(&self, cursor: usize) -> usize

光标落在哪个视觉行:边界判给上一行(前行亲和),目前只有 Home 用。

光标停在两行共用的边界 byte 上时(按 End 之后就是这个位置),Home 该回到刚才那一行 的行首;用后行口径会算到下一行,Home 于是“没反应“(Gitee Go 首次 Linux 运行暴露: 英文用例在 Windows 上恰好有空格可吞、边界不共享,本地一直测不出来)。 硬换行不受影响:下一行 start = end + 1,等号取不到。

已知代价:真正的消歧要记住光标是怎么走到边界的(caret affinity 状态), 两条口径各自只在半个场景里对。这里按“按键方向“分,换来的是 Home / End 都不空转; 代价是“点击落在续行左缘再按 Home“会往上跳一行 —— 留着做光标亲和时一并收口。

Source

pub fn line_text<'a>(&self, value: &'a str, index: usize) -> &'a str

Source

pub fn x_at_in_line( &self, value: &str, line_index: usize, byte: usize, font_size: f32, ) -> f32

指定行内 byte 位置相对文本区左缘的 x(未加 PAD_X)

与 Self::cursor_x 的区别:soft wrap 边界处 byte 同时属于两行, 这里强制按调用方指定的行计算(选区逐行高亮必须用这个)。

Source

pub fn single_line_char_positions( &self, value: &str, font_size: f32, ) -> Option<(Vec<f32>, Vec<f32>)>

单行 LTR 文本的逐字符位置/宽度(相对文本区左缘)。

多行、soft wrap 后多行或 RTL 文本返回 None:AccessKit 的 character_positions 是单行标量,跨行/RTL 需要拆成多个 TextRun。

Source

pub fn line_runs(&self, value: &str, font_size: f32) -> Vec<TextFieldLineRun>

所有视觉行的无障碍 TextRun 数据(多行/RTL 支持)。

每个视觉行一个 run;硬换行行尾包含 \n,value 与 character_lengths 的字符数一致。位置相对该行 bounds: LTR 从左边距起算,RTL 从右边距起算(AccessKit 约定)。

Source

pub fn cursor_x(&self, value: &str, cursor: usize, font_size: f32) -> f32

光标相对文本区左缘的 x(未加 PAD_X)

Source

pub fn cursor_y(&self, cursor: usize) -> f32

光标相对 widget 顶部的 y(已含 top_pad 与滚动)

Source

pub fn offset_at(&self, value: &str, x: f32, y: f32, font_size: f32) -> usize

把局部坐标映射为 value 字节偏移

Source

pub fn scroll_to_show(&self, cursor: usize) -> f32

保证 cursor 所在视觉行可见,返回新的 scroll_y

Trait Implementations§

Source§

impl Clone for TextFieldLayout

Source§

fn clone(&self) -> Self

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 TextFieldLayout

Source§

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

Formats the value using the given formatter. 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> ErasedDestructor for T
where T: 'static,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.