cranpose_ui/modifier/
clickable.rs1use super::{inspector_metadata, Modifier, Point, SemanticsConfiguration};
2use crate::modifier_nodes::ClickableElement;
3use std::rc::Rc;
4
5impl Modifier {
6 pub fn clickable(self, handler: impl Fn(Point) + 'static) -> Self {
10 let handler = Rc::new(handler);
11 let modifier = Self::with_element(ClickableElement::with_handler(handler))
12 .with_inspector_metadata(inspector_metadata("clickable", |info| {
13 info.add_property("onClick", "provided");
14 }))
15 .then(
16 Modifier::empty().semantics(|config: &mut SemanticsConfiguration| {
17 config.is_clickable = true;
18 }),
19 );
20 self.then(modifier)
21 }
22
23 pub fn clickable_on_press(
26 self,
27 on_press: impl Fn(Point) + 'static,
28 on_click: impl Fn(Point) + 'static,
29 ) -> Self {
30 let modifier = Self::with_element(ClickableElement::with_handlers(
31 Rc::new(on_press),
32 Rc::new(on_click),
33 ))
34 .with_inspector_metadata(inspector_metadata("clickableOnPress", |info| {
35 info.add_property("onPress", "provided");
36 info.add_property("onClick", "provided");
37 }))
38 .then(
39 Modifier::empty().semantics(|config: &mut SemanticsConfiguration| {
40 config.is_clickable = true;
41 }),
42 );
43 self.then(modifier)
44 }
45}