cranpose_ui/modifier/
clickable.rs1use std::rc::Rc;
2
3use super::{Modifier, Point, SemanticsConfiguration, inspector_metadata};
4use crate::{Indication, indication::current_indication, modifier_nodes::ClickableElement};
5
6impl Modifier {
7 pub fn clickable(self, handler: impl Fn(Point) + 'static) -> Self {
16 self.clickable_with_indication(current_indication(), handler)
17 }
18
19 pub fn clickable_with_indication(
25 self,
26 indication: Indication,
27 handler: impl Fn(Point) + 'static,
28 ) -> Self {
29 let element = ClickableElement::with_handler(Rc::new(handler)).indication(indication);
30 let modifier = Self::with_element(element).with_inspector_metadata(inspector_metadata(
31 "clickable",
32 |info| {
33 info.add_property("onClick", "provided");
34 },
35 ));
36 self.then(pressable(modifier))
37 }
38
39 pub fn clickable_on_press(
43 self,
44 on_press: impl Fn(Point) + 'static,
45 on_click: impl Fn(Point) + 'static,
46 ) -> Self {
47 let element = ClickableElement::with_handlers(Rc::new(on_press), Rc::new(on_click))
48 .indication(current_indication());
49 let modifier = Self::with_element(element).with_inspector_metadata(inspector_metadata(
50 "clickableOnPress",
51 |info| {
52 info.add_property("onPress", "provided");
53 info.add_property("onClick", "provided");
54 },
55 ));
56 self.then(pressable(modifier))
57 }
58}
59
60fn pressable(modifier: Modifier) -> Modifier {
64 modifier
65 .then(
66 Modifier::empty().stable_semantics(|config: &mut SemanticsConfiguration| {
67 config.is_clickable = true;
68 }),
69 )
70 .focusable()
71}