1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#[allow(unused)]
use crate::*;
use pax_engine::api::{Event, MouseOut};
use pax_engine::api::{MouseOver, Property};
use pax_engine::*;
use pax_runtime::api::NodeContext;

/// A scrolling container for arbitrary content.
#[pax]
#[engine_import_path("pax_engine")]
#[inlined(
    <Group >
        <Rectangle fill=TRANSPARENT/>
        for i in 0..self._slot_children_count {
            slot(0)
        }
    </Group>
    if self._showing {
        <Group x={100% + 5px} y={100% + 5px} anchor_x=0% anchor_y=0% width=200px height=30px>
            <Text x=5px height=100% width={100% -10px} id=text text={self.tip}/>
            <Rectangle corner_radii={RectangleCornerRadii::radii(5.00, 5.00, 5.00, 5.00)} fill=rgb(12.5%, 12.5%, 12.5%)/>
        </Group>
    }
    @settings {
        @mouse_over: self.mouse_over
        @mouse_out: self.mouse_out
        @mount: on_mount
        #text {
            selectable: false,
            style: {
                    font: {Font::Web(
                        "ff-real-headline-pro",
                        "https://use.typekit.net/ivu7epf.css",
                        FontStyle::Normal,
                        FontWeight::ExtraLight,
                    )},
                    font_size: 16px,
                    fill: WHITE,
                    align_vertical: TextAlignVertical::Center,
                    align_horizontal: TextAlignHorizontal::Left,
                    align_multiline: TextAlignHorizontal::Center
            }
    	}
    }

)]
pub struct Tooltip {
    pub tip: Property<String>,
    pub _showing: Property<bool>,
    pub _slot_children_count: Property<usize>,
}

impl Tooltip {
    pub fn on_mount(&mut self, ctx: &NodeContext) {
        let slot_children_count = ctx.slot_children_count.clone();
        let deps = [slot_children_count.untyped()];
        self._slot_children_count
            .replace_with(Property::computed(move || slot_children_count.get(), &deps));
    }

    pub fn mouse_over(&mut self, _ctx: &NodeContext, _event: Event<MouseOver>) {
        self._showing.set(true);
    }

    pub fn mouse_out(&mut self, _ctx: &NodeContext, _event: Event<MouseOut>) {
        self._showing.set(false);
    }
}