pub struct IconData { /* private fields */ }Expand description
Which icon — one of the bundled set, or a path of the caller’s own.
It is Copy and cheap to pass around; the path behind it is built only when
IconData::path or IconData::placed is called.
An icon also says whether it carries a direction. An arrow, an indent, a reply
and a chevron all point somewhere, and where they point is relative to the reading
order: in a right-to-left order, back is to the right. A tick, a star and a
magnifying glass point nowhere and must not be touched. Which is which is not a
judgement a widget can make, so it is a property of the icon —
IconData::matches_text_direction — and 76 of the bundled 2 233 carry it.
Implementations§
Source§impl IconData
impl IconData
Sourcepub const fn custom(draw: fn() -> Path) -> Self
pub const fn custom(draw: fn() -> Path) -> Self
An icon of the caller’s own, drawn by draw on the same 24 × 24 grid, y
downwards, and filled by the non-zero rule.
A function pointer and not a Path, so that an icon stays a const — a caller’s
icon is declared exactly where a bundled one would be, and costs nothing until it
is painted.
Sourcepub const fn mirrored(self) -> Self
pub const fn mirrored(self) -> Self
The same icon, declared to carry a direction: IconData::placed mirrors it
when the reading order is right-to-left.
const, so a caller’s directional icon is still a constant:
const BACK: IconData = IconData::custom(arrow).mirrored();
assert!(BACK.matches_text_direction());Sourcepub const fn matches_text_direction(self) -> bool
pub const fn matches_text_direction(self) -> bool
Whether this icon is turned round for a right-to-left reading order.
Sourcepub fn path(self) -> Path
pub fn path(self) -> Path
The icon’s outline on the 24 × 24 grid, ready to be scaled and filled.
The raw artwork, in the direction it was drawn. IconData::placed is what a
widget wants: it is this, sized, positioned, and turned round where it should be.
Sourcepub fn style(self) -> Option<IconStyle>
pub fn style(self) -> Option<IconStyle>
How this icon is drawn, or None for a caller’s own — which is drawn however its
function draws it.
Sourcepub fn placed(self, side: f32, x: f32, y: f32, direction: TextDirection) -> Path
pub fn placed(self, side: f32, x: f32, y: f32, direction: TextDirection) -> Path
The icon’s outline scaled to side and placed at (x, y) — the top-left of
the square it occupies — and mirrored within that square when it carries a
direction and direction is right-to-left.
Every widget that paints an icon goes through here. That is the point: the rule about which icons turn round is stated once, in the icon, and applied once, here, rather than remembered at each of the sixteen places that fill an icon’s path.
Sourcepub fn is_bundled(self) -> bool
pub fn is_bundled(self) -> bool
Whether this icon comes from the bundled set rather than from a caller.