1#[allow(unused)]
2use crate::*;
3use pax_engine::api::{Click, Event, MouseOut, MouseOver, Property};
4use pax_engine::*;
5use pax_runtime::api::NodeContext;
6use pax_runtime::{
7 bind_content_measurement_effect, resolve_axis_autosize, sync_content_autosize_with_axes,
8 ContentMeasurementGeometry,
9};
10
11#[pax]
13#[engine_import_path("pax_engine")]
14#[inlined(
15 <Group>
16 <Rectangle width=100% height=100% fill=TRANSPARENT/>
19 for i in 0..self._projected_children_count {
20 slot(i)
21 }
22 </Group>
23 if self._showing {
24 <Frame x=0px y={100% + 8px} anchor_x=0% anchor_y=0% width=220px autosize_y=true corner_radius=8.0 layout_role=LayoutRole::Breakout>
25 <Text x=12px y=10px width={100% - 24px} id=text text={self.tip}/>
26 <Rectangle
27 width=100%
28 height=100%
29 fill=rgb(12.5%, 12.5%, 12.5%)
30 corner_radius=8.00/>
31 </Frame>
32 }
33 @settings {
34 @click: self.toggle
35 @mouse_over: self.mouse_over
36 @mouse_out: self.mouse_out
37 @mount: on_mount
38 #text {
39 selectable: false,
40 style: {
41 font: {
42 family: "ff-real-headline-pro"
43 url: "https://use.typekit.net/ivu7epf.css"
44 weight: 200
45 },
46 font_size: 16px,
47 fill: WHITE,
48 align_vertical: TextAlignVertical::Top,
49 align_horizontal: TextAlignHorizontal::Left,
50 align_multiline: TextAlignHorizontal::Left
51 }
52 }
53 }
54
55)]
56pub struct Tooltip {
57 pub tip: Property<String>,
59 pub autosize: Property<bool>,
61 pub autosize_x: Property<Option<bool>>,
63 pub autosize_y: Property<Option<bool>>,
65 pub _showing: Property<bool>,
67 pub _projected_children_count: Property<usize>,
69}
70
71impl Tooltip {
72 pub fn on_mount(&mut self, ctx: &NodeContext) {
74 let projected_children_count = ctx.projected_children_count.clone();
75 let deps = [projected_children_count.untyped()];
76 self._projected_children_count
77 .replace_with(Property::computed(
78 move || projected_children_count.get(),
79 &deps,
80 ));
81 let Some(expanded_node) = ctx.expanded_node.upgrade() else {
82 return;
83 };
84 let autosize = self.autosize.clone();
85 let autosize_x = self.autosize_x.clone();
86 let autosize_y = self.autosize_y.clone();
87 let deps = [
88 autosize.untyped(),
89 autosize_x.untyped(),
90 autosize_y.untyped(),
91 ];
92 bind_content_measurement_effect(
93 &expanded_node,
94 ctx,
95 "tooltip autosize",
96 ContentMeasurementGeometry::Placed,
97 &deps,
98 move |node, node_ctx| {
99 sync_content_autosize_with_axes(
100 node,
101 node_ctx,
102 resolve_axis_autosize(autosize.get(), autosize_x.get(), true),
103 resolve_axis_autosize(autosize.get(), autosize_y.get(), true),
104 );
105 },
106 );
107 }
108
109 pub fn toggle(&mut self, _ctx: &NodeContext, _event: Event<Click>) {
111 self._showing.set(!self._showing.get());
112 }
113
114 pub fn mouse_over(&mut self, _ctx: &NodeContext, _event: Event<MouseOver>) {
116 self._showing.set(true);
117 }
118
119 pub fn mouse_out(&mut self, _ctx: &NodeContext, _event: Event<MouseOut>) {
121 self._showing.set(false);
122 }
123}