1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use super::{ContextMenuItem, ContextMenuWidget, Response, Tooltip, TooltipWidget, Ui};
use crate::accessibility::{AccessRole, Accessible};
/// An immediate mode component that allocates and paints itself in a UI.
pub trait Widget {
fn ui(self, ui: &mut Ui<'_>) -> Response;
/// Show a tooltip while the widget is hovered, in the same expression:
/// `ui.add(Button::new("Save").tooltip("Write the file"))`.
fn tooltip(self, text: impl Into<String>) -> TooltipWidget<Self>
where
Self: Sized,
{
Tooltip::new(text).wrap(self)
}
/// Open a context menu on secondary click. The chosen item is reported by
/// [`Response::menu_selected`] on the pass it is picked.
fn context_menu(self, items: &[ContextMenuItem]) -> ContextMenuWidget<'_, Self>
where
Self: Sized,
{
ContextMenuWidget::new(self, items)
}
/// The name a screen reader speaks for this widget, replacing the one it derives from
/// its visible text. Required for controls without text: an icon button, a bare
/// switch, a slider without a caption.
fn accessible_label(self, label: impl Into<String>) -> Accessible<Self>
where
Self: Sized,
{
Accessible::new(self).label(label.into())
}
/// Extra detail a screen reader speaks after the name: a hint or the reason for an error.
fn accessible_description(self, description: impl Into<String>) -> Accessible<Self>
where
Self: Sized,
{
Accessible::new(self).description(description.into())
}
/// Present this widget to assistive technology as `role`. A custom widget that does
/// not describe itself becomes a node of this role with the response's bounds.
fn accessible_role(self, role: AccessRole) -> Accessible<Self>
where
Self: Sized,
{
Accessible::new(self).role(role)
}
/// Leave this widget and everything in it out of the accessibility tree: decoration
/// that says nothing a screen reader user needs.
fn accessibility_hidden(self) -> Accessible<Self>
where
Self: Sized,
{
Accessible::new(self).hidden()
}
}