cranpose_ui/modifier/pointer_icon.rs
1use cranpose_ui_graphics::{CursorIcon, PointerIcon};
2
3use super::{Modifier, inspector_metadata};
4use crate::modifier_nodes::PointerIconElement;
5
6impl Modifier {
7 /// Names the pointer's appearance while it hovers this node.
8 ///
9 /// The innermost region under the pointer wins, so a control inside a
10 /// window can ask for its own icon without the window's icon overriding it.
11 /// Declaring an icon makes the node a hit target in its own right, which is
12 /// what lets a decorative region — a title bar, a display panel — carry a
13 /// cursor without also handling clicks.
14 ///
15 /// Platforms without a pointing device (Android, iOS) ignore it.
16 ///
17 /// Example: `Modifier::empty().pointer_icon(PointerIcon::POINTER)`
18 pub fn pointer_icon(self, icon: PointerIcon) -> Self {
19 let name = icon
20 .css_keyword()
21 .map_or_else(|| "custom".to_string(), str::to_string);
22 let modifier = Self::with_element(PointerIconElement::new(icon)).with_inspector_metadata(
23 inspector_metadata("pointerIcon", move |info| {
24 info.add_property("pointerIcon", &name);
25 }),
26 );
27 self.then(modifier)
28 }
29
30 /// Names one of the platform's standard pointer shapes while it hovers this
31 /// node, the common case of [`pointer_icon`](Self::pointer_icon).
32 ///
33 /// Example: `Modifier::empty().cursor(CursorIcon::EwResize)`
34 pub fn cursor(self, icon: CursorIcon) -> Self {
35 self.pointer_icon(PointerIcon::System(icon))
36 }
37}