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