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<bool>,
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: String§role: Option<SemanticsWidgetRole>§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
clickable: bool§selected: Option<bool>Compose’s selected, for Role.RadioButton/Role.Tab.
toggled: Option<bool>Compose’s toggleableState, for Role.Switch/Role.Checkbox.
enabled: bool§custom_actions: Vec<SemanticsCustomAction>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.
pub fn with_role(self, role: SemanticsWidgetRole) -> Self
pub fn with_state_description(self, state: impl Into<String>) -> Self
pub fn with_click_label(self, label: impl Into<String>) -> Self
pub fn with_selected(self, selected: bool) -> Self
pub fn with_toggled(self, toggled: bool) -> Self
pub fn with_enabled(self, enabled: bool) -> Self
pub fn with_custom_action(self, action: SemanticsCustomAction) -> Self
Trait Implementations§
Source§impl Clone for CanvasSemanticsNode
impl Clone for CanvasSemanticsNode
Source§fn clone(&self) -> CanvasSemanticsNode
fn clone(&self) -> CanvasSemanticsNode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more