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
impl TextFieldLayout
Sourcepub fn cursor_line(&self, cursor: usize) -> usize
pub fn cursor_line(&self, cursor: usize) -> usize
光标所在视觉行(软换行边界取下一行,便于继续输入)
pub fn line_text<'a>(&self, value: &'a str, index: usize) -> &'a str
Sourcepub fn x_at_in_line(
&self,
value: &str,
line_index: usize,
byte: usize,
font_size: f32,
) -> f32
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 同时属于两行,
这里强制按调用方指定的行计算(选区逐行高亮必须用这个)。
Sourcepub fn single_line_char_positions(
&self,
value: &str,
font_size: f32,
) -> Option<(Vec<f32>, Vec<f32>)>
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。
Sourcepub fn line_runs(&self, value: &str, font_size: f32) -> Vec<TextFieldLineRun>
pub fn line_runs(&self, value: &str, font_size: f32) -> Vec<TextFieldLineRun>
所有视觉行的无障碍 TextRun 数据(多行/RTL 支持)。
每个视觉行一个 run;硬换行行尾包含 \n,value 与
character_lengths 的字符数一致。位置相对该行 bounds:
LTR 从左边距起算,RTL 从右边距起算(AccessKit 约定)。
Sourcepub fn cursor_x(&self, value: &str, cursor: usize, font_size: f32) -> f32
pub fn cursor_x(&self, value: &str, cursor: usize, font_size: f32) -> f32
光标相对文本区左缘的 x(未加 PAD_X)
Sourcepub fn offset_at(&self, value: &str, x: f32, y: f32, font_size: f32) -> usize
pub fn offset_at(&self, value: &str, x: f32, y: f32, font_size: f32) -> usize
把局部坐标映射为 value 字节偏移
Sourcepub fn scroll_to_show(&self, cursor: usize) -> f32
pub fn scroll_to_show(&self, cursor: usize) -> f32
保证 cursor 所在视觉行可见,返回新的 scroll_y
Trait Implementations§
Source§impl Clone for TextFieldLayout
impl Clone for TextFieldLayout
Auto Trait Implementations§
impl Freeze for TextFieldLayout
impl RefUnwindSafe for TextFieldLayout
impl Send for TextFieldLayout
impl Sync for TextFieldLayout
impl Unpin for TextFieldLayout
impl UnsafeUnpin for TextFieldLayout
impl UnwindSafe for TextFieldLayout
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