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
use dioxus_native_core::node::NodeType;
use dioxus_native_core::prelude::TextNode;
use dioxus_native_core::real_dom::NodeImmutable;
use freya_core::layout::create_text;
use freya_dom::prelude::DioxusNode;
use freya_engine::prelude::*;
use torin::geometry::Area;

/// Render a `label` element
pub fn render_label(
    area: &Area,
    node_ref: &DioxusNode,
    canvas: &Canvas,
    font_collection: &mut FontCollection,
) {
    let node_children = node_ref.children();

    let child = node_children.first();

    let text = if let Some(child) = child {
        if let NodeType::Text(TextNode { text, .. }) = &*child.node_type() {
            Some(text.clone())
        } else {
            None
        }
    } else {
        None
    };

    if let Some(text) = text {
        let paragraph = create_text(node_ref, area, font_collection, &text);

        let x = area.min_x();
        let y = area.min_y();

        paragraph.paint(canvas, (x, y));
    }
}