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(
    node: TreeNode,
    is_selected: bool,
    onselected: EventHandler<TreeNode>,
) -> Element {
    let mut status = use_signal(ButtonStatus::default);

    let onmousedown = {
        to_owned![node];
        move |_| onselected.call(node.clone())
    };

    let onmouseenter = move |_| {
        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.read() {
            ButtonStatus::Idle => "white",
            ButtonStatus::Hovering => "rgb(150, 150, 150)",
        }
    };
    let margin_left = (node.height * 10) as f32 + 16.5;

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