Skip to main content

WidgetSemantics

Struct WidgetSemantics 

Source
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

Source

pub fn new(role: SemanticsRole) -> Self

Source

pub fn with_read_only(self, read_only: bool) -> Self

Source

pub fn with_label(self, label: impl Into<String>) -> Self

Source

pub fn with_value(self, value: impl Into<String>) -> Self

Source

pub fn with_toggled(self, v: bool) -> Self

Source

pub fn with_expanded(self, expanded: bool) -> Self

Source

pub fn with_selected(self, selected: bool) -> Self

Source

pub fn with_focusable(self, focusable: bool) -> Self

Source

pub fn with_modal(self, modal: bool) -> Self

Source

pub fn with_live(self, live: LiveRegion) -> Self

Source

pub fn with_virtual_items(self, items: Vec<VirtualSemanticItem>) -> Self

虚拟子项(TreeView 行 / 菜单项等单 RO 组件的子语义)

Source

pub fn with_text_selection(self, anchor: usize, focus: usize) -> Self

文本选区(全局字符索引;anchor == focus 表示仅光标)

Source

pub fn with_enabled(self, enabled: bool) -> Self

禁用时同时退出焦点链:屏幕阅读器不应把焦点移到不可交互控件上。

Source

pub fn with_numeric_value( self, value: f64, min: f64, max: f64, step: f64, ) -> Self

Source

pub fn non_focusable(self) -> Self

Trait Implementations§

Source§

impl Clone for WidgetSemantics

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 WidgetSemantics

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> 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.