pub struct CanvasSemanticsNode {
pub key: u64,
pub bounds: Rect,
pub label: String,
pub role: Option<SemanticsWidgetRole>,
pub state_description: Option<String>,
pub on_click_label: Option<String>,
pub clickable: bool,
pub selected: Option<bool>,
pub toggled: Option<ToggleableState>,
pub enabled: bool,
pub custom_actions: Vec<SemanticsCustomAction>,
}Expand description
A semantics node for content that is drawn rather than laid out.
An immediate-mode surface — one Canvas that paints a whole screen — has
exactly one layout node, so the semantics tree built from layout has exactly
one node to offer a screen reader. This is the escape hatch: the drawing
code already knows where it put every control, so it publishes those
rectangles as semantics directly. Android’s own answer for a canvas-drawn
View is the same shape (ExploreByTouchHelper feeding virtual view ids
into an AccessibilityNodeProvider), and Cranpose’s Android bridge is
already an AccessibilityNodeProvider, so these land as first-class
virtual views next to the ones layout produces.
bounds is in the publishing node’s own coordinates (logical px, origin at
that node’s top-left), because that is what a draw scope works in.
Fields§
§key: u64Identity that must survive a redraw.
A screen reader parks its cursor on a virtual view id; if the id for “the Haptics switch” changes when the list scrolls, the cursor jumps. Derive this from what the control is (a row index, an enum discriminant), never from where it currently sits.
bounds: RectWhere the control was drawn, relative to the publishing node.
label: StringWhat the screen reader reads for the control.
role: Option<SemanticsWidgetRole>What kind of control it is, as the screen reader announces it.
state_description: Option<String>Compose’s stateDescription — what the control currently reads as
(“CAMPAIGN”, “3 of 18 gold”), spoken after the label and re-spoken on
its own when only the state changed.
on_click_label: Option<String>Compose’s onClick(label = …). TalkBack reads it as “double tap to
<label>”, so it is a verb phrase, not a repeat of the label.
clickable: boolWhether the control can be activated.
selected: Option<bool>Compose’s selected, for Role.RadioButton/Role.Tab.
toggled: Option<ToggleableState>Compose’s toggleableState, for Role.Switch/Role.Checkbox.
enabled: boolWhether the control accepts input. A disabled control is announced as such.
custom_actions: Vec<SemanticsCustomAction>Named actions that the screen reader lists in its actions menu for the control.
Implementations§
Source§impl CanvasSemanticsNode
impl CanvasSemanticsNode
Sourcepub fn control(key: u64, bounds: Rect, label: impl Into<String>) -> Self
pub fn control(key: u64, bounds: Rect, label: impl Into<String>) -> Self
A clickable control drawn at bounds.
Sourcepub fn text(key: u64, bounds: Rect, label: impl Into<String>) -> Self
pub fn text(key: u64, bounds: Rect, label: impl Into<String>) -> Self
A drawn label that is read but not activated.
Sourcepub fn with_role(self, role: SemanticsWidgetRole) -> Self
pub fn with_role(self, role: SemanticsWidgetRole) -> Self
Returns the node with role set.
Sourcepub fn with_state_description(self, state: impl Into<String>) -> Self
pub fn with_state_description(self, state: impl Into<String>) -> Self
Returns the node with the state description state set. Compose’s stateDescription.
Sourcepub fn with_click_label(self, label: impl Into<String>) -> Self
pub fn with_click_label(self, label: impl Into<String>) -> Self
Returns the node with label set as the verb phrase for activation. The node becomes
clickable.
Sourcepub fn with_selected(self, selected: bool) -> Self
pub fn with_selected(self, selected: bool) -> Self
Returns the node with its selected state set to selected.
Sourcepub fn with_toggled(self, toggled: impl Into<ToggleableState>) -> Self
pub fn with_toggled(self, toggled: impl Into<ToggleableState>) -> Self
Returns the node with its toggle state set to toggled. A bool converts to On or Off.
Sourcepub fn with_enabled(self, enabled: bool) -> Self
pub fn with_enabled(self, enabled: bool) -> Self
Returns the node with enabled set. A disabled node is announced as such.
Sourcepub fn with_custom_action(self, action: SemanticsCustomAction) -> Self
pub fn with_custom_action(self, action: SemanticsCustomAction) -> Self
Returns the node with action added to its custom actions.