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
use crate::resources::{renderables::*, Transform2d};
use oxygengine_core::{
    ecs::{Entity, Universe},
    scripting::intuicio::{core as intuicio_core, data as intuicio_data, derive::*, prelude::*},
    Scalar,
};
use oxygengine_ha_renderer::{
    components::{text_instance::*, transform::*},
    math::*,
};

#[derive(IntuicioStruct, Debug, Default)]
#[intuicio(name = "TextNode", module_name = "renderable")]
pub struct TextNode {
    #[intuicio(ignore)]
    pub content: HaTextContent,
    #[intuicio(ignore)]
    pub font: String,
    #[intuicio(ignore)]
    pub size: Scalar,
    #[intuicio(ignore)]
    pub color: Rgba,
    #[intuicio(ignore)]
    pub alignment: Vec2,
    #[intuicio(ignore)]
    pub bounds_width: Option<Scalar>,
    #[intuicio(ignore)]
    pub bounds_height: Option<Scalar>,
    #[intuicio(ignore)]
    pub wrapping: HaTextWrapping,
}

impl TextNode {
    pub fn install(registry: &mut Registry) {
        registry.add_struct(TextNode::define_struct(registry));
        registry.add_function(TextNode::event_draw__define_function(registry));
    }
}

#[intuicio_methods(module_name = "renderable")]
impl TextNode {
    #[intuicio_method(transformer = "DynamicManagedValueTransformer")]
    pub fn event_draw(
        this: &mut Self,
        transform: &mut HaTransform,
        universe: &Universe,
        _entity: Entity,
    ) {
        let mut renderables = universe.expect_resource_mut::<Renderables>();
        let renderable = TextRenderable {
            transform: Transform2d::default()
                .position(transform.get_world_origin())
                .rotation(transform.get_world_rotation_lossy().eulers().yaw),
            content: this.content.to_owned(),
            font: this.font.to_owned(),
            size: this.size,
            color: this.color,
            alignment: this.alignment,
            bounds_width: this.bounds_width,
            bounds_height: this.bounds_height,
            wrapping: this.wrapping.to_owned(),
        };
        renderables.draw(renderable);
    }
}