fission_core/ui/widgets/
action_scope.rs1use crate::lowering::{LoweringContext, NodeBuilder};
2use crate::ui::traits::Lower;
3use crate::ui::Node;
4use crate::ActionScopeId;
5use fission_ir::{NodeId, Op, Semantics};
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct ActionScope {
15 pub id: ActionScopeId,
16 pub child: Box<Node>,
17}
18
19impl ActionScope {
20 pub fn new(id: ActionScopeId, child: Node) -> Self {
21 Self {
22 id,
23 child: Box::new(child),
24 }
25 }
26
27 pub fn into_node(self) -> Node {
28 Node::ActionScope(self)
29 }
30}
31
32impl Lower for ActionScope {
33 fn lower(&self, cx: &mut LoweringContext) -> NodeId {
34 let wrapper_id = cx.next_node_id();
35 cx.push_scope(wrapper_id);
36 let child_id = self.child.lower(cx);
37 cx.pop_scope();
38
39 let semantics = Semantics {
40 action_scope_id: Some(self.id.as_u128()),
41 ..Semantics::default()
42 };
43 let mut builder = NodeBuilder::new(wrapper_id, Op::Semantics(semantics));
44 builder.add_child(child_id);
45 builder.build(cx)
46 }
47}