Skip to main content

mittens_engine/engine/ecs/component/
inspect_layout.rs

1use crate::engine::ecs::ComponentId;
2use crate::engine::ecs::component::Component;
3
4/// Marks a [`LayoutComponent`] subtree as wanting box-model visualisation.
5///
6/// When attached as a child of a TC that also carries a `LayoutComponent`, the
7/// layout pass over that subtree spawns box-model viz quads (`__box_padding_*`,
8/// `__box_content`, `__box_margin_*`) per styled item. Without this component,
9/// layout skips viz and tears down any pre-existing viz subtrees so the panel
10/// renders clean.
11///
12/// Per-LayoutRoot, not global: each layout tree opts in independently.
13///
14/// [`LayoutComponent`]: crate::engine::ecs::component::LayoutComponent
15#[derive(Debug, Default, Clone, Copy)]
16pub struct InspectLayoutComponent {
17    component: Option<ComponentId>,
18}
19
20impl InspectLayoutComponent {
21    pub fn new() -> Self {
22        Self { component: None }
23    }
24
25    pub fn id(&self) -> Option<ComponentId> {
26        self.component
27    }
28}
29
30impl Component for InspectLayoutComponent {
31    fn set_id(&mut self, component: ComponentId) {
32        self.component = Some(component);
33    }
34
35    fn name(&self) -> &'static str {
36        "inspect_layout"
37    }
38
39    fn as_any(&self) -> &dyn std::any::Any {
40        self
41    }
42
43    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
44        self
45    }
46}