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(str::to_string)
22 .unwrap_or_else(|| "custom".to_string());
23 let modifier = Self::with_element(PointerIconElement::new(icon)).with_inspector_metadata(
24 inspector_metadata("pointerIcon", move |info| {
25 info.add_property("pointerIcon", &name);
26 }),
27 );
28 self.then(modifier)
29 }
30
31 /// Names one of the platform's standard pointer shapes while it hovers this
32 /// node, the common case of [`pointer_icon`](Self::pointer_icon).
33 ///
34 /// Example: `Modifier::empty().cursor(CursorIcon::EwResize)`
35 pub fn cursor(self, icon: CursorIcon) -> Self {
36 self.pointer_icon(PointerIcon::System(icon))
37 }
38}