Skip to main content

text

Macro text 

Source
macro_rules! text {
    (id = $id:expr, $text:expr) => { ... };
    ($text:expr) => { ... };
}
Expand description

Creates a Text element that has an ID, so that screen readers can read it.

Without id = ..., the macro derives the ID from the file, line, and column of the call. Two calls on different lines get different IDs, and the same call produces the same ID every time. With id = ..., you choose the ID, which is useful when the text must keep its ID even if the code moves.

Use Text::new_inaccessible to skip the accessibility node.

ยงExamples

let a = text!("hello");
let b = text!(id = "farewell-message", "hello");
assert_ne!(a.id(), b.id());

See the docs for Text for how the ID affects accessibility updates.