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
use dioxus::prelude::*;
use freya_components::ButtonStatus;
use freya_elements::elements as dioxus_elements;

use crate::TreeNode;

#[allow(non_snake_case)]
#[component]
pub fn NodeElement<'a>(
    cx: Scope<'a>,
    node: TreeNode,
    is_selected: bool,
    onselected: EventHandler<'a, &'a TreeNode>,
) -> Element<'a> {
    let status = use_state(cx, ButtonStatus::default);

    let onmousedown = move |_| onselected.call(&cx.props.node);

    let onmouseover = move |_| {
        if *status.get() != ButtonStatus::Hovering {
            status.set(ButtonStatus::Hovering);
        }
    };

    let onmouseleave = move |_| {
        status.set(ButtonStatus::default());
    };

    let background = if *is_selected {
        "rgb(100, 100, 100)"
    } else {
        "transparent"
    };
    let color = if *is_selected {
        "white"
    } else {
        match *status.get() {
            ButtonStatus::Idle => "white",
            ButtonStatus::Hovering => "rgb(150, 150, 150)",
        }
    };
    let margin_left = (node.height * 10) as f32 + 16.5;

    render!(
        rect {
            corner_radius: "7",
            padding: "5",
            background: background,
            width: "100%",
            height: "27",
            offset_x: "{margin_left}",
            onmousedown: onmousedown,
            onmouseover: onmouseover,
            onmouseleave: onmouseleave,
            label {
                font_size: "14",
                color: "{color}",
                "{node.tag} #{node.id:?}"
            }
        }
    )
}