Skip to main content

CanvasSemanticsNode

Struct CanvasSemanticsNode 

Source
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: u64

Identity 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: Rect

Where 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

Source

pub fn control( key: u64, bounds: Rect, label: impl Into<String>, ) -> CanvasSemanticsNode

A clickable control drawn at bounds.

Source

pub fn text( key: u64, bounds: Rect, label: impl Into<String>, ) -> CanvasSemanticsNode

A drawn label that is read but not activated.

Source

pub fn with_role(self, role: SemanticsWidgetRole) -> CanvasSemanticsNode

Source

pub fn with_state_description( self, state: impl Into<String>, ) -> CanvasSemanticsNode

Source

pub fn with_click_label(self, label: impl Into<String>) -> CanvasSemanticsNode

Source

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

Source

pub fn with_toggled(self, toggled: bool) -> CanvasSemanticsNode

Source

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

Source

pub fn with_custom_action( self, action: SemanticsCustomAction, ) -> CanvasSemanticsNode

Trait Implementations§

Source§

impl Clone for CanvasSemanticsNode

Source§

fn clone(&self) -> CanvasSemanticsNode

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 CanvasSemanticsNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for CanvasSemanticsNode

Source§

fn default() -> CanvasSemanticsNode

Returns the “default value” for a type. Read more
Source§

impl PartialEq for CanvasSemanticsNode

Source§

fn eq(&self, other: &CanvasSemanticsNode) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CanvasSemanticsNode

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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.