pub struct WidgetSemantics {Show 14 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 enabled: bool,
pub focusable: bool,
pub numeric: Option<SemanticsNumericValue>,
pub modal: bool,
pub live: Option<LiveRegion>,
pub virtual_items: Vec<VirtualSemanticItem>,
pub text_selection: Option<(usize, usize)>,
pub read_only: bool,
}Expand description
Widget 声明的语义快照(不含 bounds/children — 由 ElementTree 在构建时填入)
这是 Widget trait semantics() 钩子的返回值。
Widget 声明“我是什么、叫什么、值是什么“,ElementTree 负责在遍历 Element 树时
填入 layout bounds / children 列表来组装完整的 SemanticsData。
Fields§
§role: SemanticsRole无障碍角色
label: Option<String>可读标签(SR 读取的文字)
value: Option<String>当前值(对有状态控件)
- CheckBox → “checked” / “unchecked”
- Slider → 0.0 ~ 1.0
- TextInput → 占位符(编辑中 value 由 state override)
toggled: Option<bool>选中/勾选状态
expanded: Option<bool>展开/收起状态(TreeItem / 折叠面板)
selected: Option<bool>列表项/Tab 选中状态
enabled: bool是否可交互
focusable: bool焦点行为(true = Tab 焦点链节点 + 可接受 Action::Focus)
numeric: Option<SemanticsNumericValue>数值控件的值域(Slider / Progress 等);None = 非数值控件
modal: bool模态对话框(焦点/读屏限制在子树内)
live: Option<LiveRegion>动态内容播报级别(Toast / 状态栏)
virtual_items: Vec<VirtualSemanticItem>虚拟子项(单 RO 虚拟列表/菜单的行语义,不进入元素树)
text_selection: Option<(usize, usize)>文本选区(宿主文本中的全局字符索引,anchor/focus);None = 无选区
read_only: bool只读文本控件:可聚焦/选择/复制,但不暴露 SetValue 编辑动作
Implementations§
Source§impl WidgetSemantics
impl WidgetSemantics
pub fn new(role: SemanticsRole) -> Self
pub fn with_read_only(self, read_only: bool) -> Self
pub fn with_label(self, label: impl Into<String>) -> 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_focusable(self, focusable: bool) -> Self
pub fn with_modal(self, modal: bool) -> Self
pub fn with_live(self, live: LiveRegion) -> Self
Sourcepub fn with_virtual_items(self, items: Vec<VirtualSemanticItem>) -> Self
pub fn with_virtual_items(self, items: Vec<VirtualSemanticItem>) -> Self
虚拟子项(TreeView 行 / 菜单项等单 RO 组件的子语义)
Sourcepub fn with_text_selection(self, anchor: usize, focus: usize) -> Self
pub fn with_text_selection(self, anchor: usize, focus: usize) -> Self
文本选区(全局字符索引;anchor == focus 表示仅光标)
Sourcepub fn with_enabled(self, enabled: bool) -> Self
pub fn with_enabled(self, enabled: bool) -> Self
禁用时同时退出焦点链:屏幕阅读器不应把焦点移到不可交互控件上。
pub fn with_numeric_value( self, value: f64, min: f64, max: f64, step: f64, ) -> Self
pub fn non_focusable(self) -> Self
Trait Implementations§
Source§impl Clone for WidgetSemantics
impl Clone for WidgetSemantics
Auto Trait Implementations§
impl Forget for WidgetSemantics
impl Freeze for WidgetSemantics
impl Move for WidgetSemantics
impl RefUnwindSafe for WidgetSemantics
impl Send for WidgetSemantics
impl Sync for WidgetSemantics
impl Unpin for WidgetSemantics
impl UnsafeUnpin for WidgetSemantics
impl UnwindSafe for WidgetSemantics
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