Skip to main content

mittens_engine/engine/ecs/component/
selectable.rs

1use crate::engine::ecs::ComponentId;
2use crate::engine::ecs::component::Component;
3
4/// Selection opt-out marker.
5///
6/// Everything in an editor subtree is selectable by default. Wrapping a subtree in
7/// `SelectableComponent::off()` excludes it from editor selection — clicking a descendant
8/// will not move the gizmo, update the inspector context, or trigger `SelectionChanged`.
9///
10/// Used by editor-owned helper subtrees to self-exclude UI from scene picking.
11#[derive(Debug, Clone, Copy)]
12pub struct SelectableComponent {
13    pub enabled: bool,
14    component: Option<ComponentId>,
15}
16
17impl SelectableComponent {
18    pub fn on() -> Self {
19        Self {
20            enabled: true,
21            component: None,
22        }
23    }
24
25    pub fn off() -> Self {
26        Self {
27            enabled: false,
28            component: None,
29        }
30    }
31}
32
33impl Default for SelectableComponent {
34    fn default() -> Self {
35        Self::on()
36    }
37}
38
39impl Component for SelectableComponent {
40    fn set_id(&mut self, id: ComponentId) {
41        self.component = Some(id);
42    }
43
44    fn name(&self) -> &'static str {
45        "selectable"
46    }
47
48    fn as_any(&self) -> &dyn std::any::Any {
49        self
50    }
51
52    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
53        self
54    }
55
56    fn to_mms_ast(
57        &self,
58        _world: &crate::engine::ecs::World,
59    ) -> crate::scripting::ast::ComponentExpression {
60        use crate::engine::ecs::component::ce_helpers::*;
61        let ctor = if self.enabled { "on" } else { "off" };
62        ce_call("Selectable", ctor, vec![])
63    }
64}