mittens_engine/engine/ecs/component/
layout_bounds.rs1use crate::engine::ecs::ComponentId;
2use crate::engine::ecs::component::Component;
3use crate::engine::graphics::bounds::Aabb;
4
5#[derive(Debug, Clone, Copy)]
10pub struct LayoutBoundsComponent {
11 pub content_local: Aabb,
12 pub padding_local: Aabb,
13}
14
15impl LayoutBoundsComponent {
16 pub fn new(content_local: Aabb, padding_local: Aabb) -> Self {
17 Self {
18 content_local,
19 padding_local,
20 }
21 }
22}
23
24impl Component for LayoutBoundsComponent {
25 fn name(&self) -> &'static str {
26 "layout_bounds"
27 }
28
29 fn set_id(&mut self, _component: ComponentId) {}
30
31 fn as_any(&self) -> &dyn std::any::Any {
32 self
33 }
34
35 fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
36 self
37 }
38
39 fn to_mms_ast(
40 &self,
41 _world: &crate::engine::ecs::World,
42 ) -> crate::scripting::ast::ComponentExpression {
43 use crate::engine::ecs::component::ce_helpers::{CeBuilder, array, ce_call, num};
44
45 let content = vec![
46 array(
47 self.content_local
48 .min
49 .iter()
50 .map(|&value| num(value as f64))
51 .collect(),
52 ),
53 array(
54 self.content_local
55 .max
56 .iter()
57 .map(|&value| num(value as f64))
58 .collect(),
59 ),
60 ];
61 let padding = vec![
62 array(
63 self.padding_local
64 .min
65 .iter()
66 .map(|&value| num(value as f64))
67 .collect(),
68 ),
69 array(
70 self.padding_local
71 .max
72 .iter()
73 .map(|&value| num(value as f64))
74 .collect(),
75 ),
76 ];
77
78 ce_call("LayoutBounds", "content_box", content).with_call("padding_box", padding)
79 }
80}