pub struct SemanticsData {Show 16 fields
pub role: SemanticsRole,
pub label: Option<String>,
pub value: Option<String>,
pub toggled: Option<bool>,
pub expanded: Option<bool>,
pub selected: Option<bool>,
pub modal: bool,
pub live: Option<LiveRegion>,
pub virtual_items: Vec<VirtualSemanticItem>,
pub text_selection: Option<(usize, usize)>,
pub read_only: bool,
pub enabled: bool,
pub bounds: Rect,
pub children: Vec<ElementId>,
pub focusable: bool,
pub numeric: Option<SemanticsNumericValue>,
}Expand description
单个节点的语义快照(与 Element 1:1 关联)
runtime crate 从 ElementTree 遍历收集 Vec<(ElementId, SemanticsData),
然后翻译成 Vec<(accesskit::NodeId, accesskit::Node)> 构建 TreeUpdate。
bounds 单位:逻辑像素(同 Element.origin + RO layout size)。 runtime 在推送 TreeUpdate 前乘 DPR 转物理像素。
Fields§
§role: SemanticsRole无障碍角色
label: Option<String>可读标签(SR 读取的文字,优先于子节点文字)
- Button: 通常来自
.labelTextWidget 的内容 - TextInput: placeholder 或当前 value
- 纯视觉节点: None(由子节点聚合)
value: Option<String>当前值(对有状态控件)
- CheckBox → “checked” / “unchecked”
- Slider → 0.0 ~ 1.0
- TextInput → 输入文字
toggled: Option<bool>是否当前处于激活/选中状态(CheckBox checked, Slider enabled 等)
expanded: Option<bool>展开/收起状态(TreeItem / 折叠面板)
selected: Option<bool>列表项/Tab 选中状态
modal: bool是否模态对话框
live: Option<LiveRegion>动态内容播报级别(Toast 等)
virtual_items: Vec<VirtualSemanticItem>虚拟子项(单 RO 列表/菜单的行语义)
text_selection: Option<(usize, usize)>文本选区(宿主文本中的全局字符索引);None = 无选区
read_only: bool只读文本控件(不暴露 SetValue)
enabled: bool控件是否可交互(禁用状态时 SR 应告知用户)
bounds: Rect逻辑像素 bounds(位置 + 尺寸),runtime 乘 DPR 送 AccessKit
children: Vec<ElementId>子节点 ElementId 列表(用于构建无障碍树结构)
focusable: bool是否是焦点目标(默认 role 推断;显式覆盖)
numeric: Option<SemanticsNumericValue>数值控件的值域(Slider 等);runtime 转成 AccessKit 的 numeric_value 系列属性
Implementations§
Source§impl SemanticsData
impl SemanticsData
Sourcepub fn new(role: SemanticsRole, bounds: Rect) -> Self
pub fn new(role: SemanticsRole, bounds: Rect) -> Self
最简构造:只给 role 和 bounds,其他用合理默认
pub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_numeric_value( self, value: f64, min: f64, max: f64, step: f64, ) -> Self
pub fn with_value(self, value: impl Into<String>) -> Self
pub fn with_toggled(self, v: bool) -> Self
pub fn with_expanded(self, expanded: bool) -> Self
pub fn with_selected(self, selected: bool) -> Self
pub fn with_modal(self, modal: bool) -> Self
pub fn with_live(self, live: LiveRegion) -> Self
pub fn with_children(self, children: Vec<ElementId>) -> Self
Sourcepub fn with_text_selection(self, anchor: usize, focus: usize) -> Self
pub fn with_text_selection(self, anchor: usize, focus: usize) -> Self
文本选区(全局字符索引;anchor == focus 表示仅光标)
Trait Implementations§
Source§impl Clone for SemanticsData
impl Clone for SemanticsData
Auto Trait Implementations§
impl Forget for SemanticsData
impl Freeze for SemanticsDatawhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<VirtualSemanticItem>: Freeze,
PhantomData<ElementId>: Freeze,
impl Move for SemanticsData
impl RefUnwindSafe for SemanticsData
impl Send for SemanticsData
impl Sync for SemanticsData
impl Unpin for SemanticsData
impl UnsafeUnpin for SemanticsDatawhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<VirtualSemanticItem>: UnsafeUnpin,
PhantomData<ElementId>: UnsafeUnpin,
impl UnwindSafe for SemanticsData
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