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
use freya_engine::prelude::{
    Canvas,
    FontCollection,
    FontMgr,
};
use freya_native_core::tags::TagName;
use torin::prelude::{
    CursorPoint,
    LayoutNode,
};

use super::*;
use crate::dom::DioxusNode;

pub trait ElementUtils {
    fn is_point_inside_area(
        &self,
        point: &CursorPoint,
        _node_ref: &DioxusNode,
        layout_node: &LayoutNode,
        _scale_factor: f32,
    ) -> bool {
        layout_node.area.contains(point.to_f32())
    }

    fn clip(
        &self,
        _layout_node: &LayoutNode,
        _node_ref: &DioxusNode,
        _canvas: &Canvas,
        _scale_factor: f32,
    ) {
    }

    #[allow(clippy::too_many_arguments)]
    fn render(
        self: Box<Self>,
        layout_node: &LayoutNode,
        node_ref: &DioxusNode,
        canvas: &Canvas,
        font_collection: &mut FontCollection,
        font_manager: &FontMgr,
        default_fonts: &[String],
        scale_factor: f32,
    );
}

pub trait ElementUtilsResolver {
    fn utils(&self) -> Option<Box<dyn ElementUtils>>;
}

impl ElementUtilsResolver for TagName {
    fn utils(&self) -> Option<Box<dyn ElementUtils>> {
        match self {
            TagName::Rect => Some(Box::new(RectElement)),
            TagName::Svg => Some(Box::new(SvgElement)),
            TagName::Paragraph => Some(Box::new(ParagraphElement)),
            TagName::Image => Some(Box::new(ImageElement)),
            TagName::Label => Some(Box::new(LabelElement)),
            _ => None,
        }
    }
}