fission_core/ui/widgets/
positioned.rs1use crate::lowering::{LoweringContext, NodeBuilder};
2use crate::ui::traits::Lower;
3use crate::ui::Node;
4use fission_ir::{
5 op::{LayoutOp, Op},
6 NodeId,
7};
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Default, Clone, Serialize, Deserialize)]
28pub struct Positioned {
29 pub id: Option<NodeId>,
31 pub left: Option<f32>,
33 pub top: Option<f32>,
35 pub right: Option<f32>,
37 pub bottom: Option<f32>,
39 pub width: Option<f32>,
41 pub height: Option<f32>,
43 pub child: Option<Box<Node>>,
45}
46
47impl Positioned {
48 pub fn into_node(self) -> Node {
49 Node::Positioned(self)
50 }
51}
52
53impl Lower for Positioned {
54 fn lower(&self, cx: &mut LoweringContext) -> NodeId {
55 let id = self.id.unwrap_or_else(|| cx.next_node_id());
56 cx.push_scope(id);
57
58 let child_id = if let Some(child) = &self.child {
59 Some(child.lower(cx))
60 } else {
61 None
62 };
63
64 let mut builder = NodeBuilder::new(
65 id,
66 Op::Layout(LayoutOp::Positioned {
67 left: self.left,
68 top: self.top,
69 right: self.right,
70 bottom: self.bottom,
71 width: self.width,
72 height: self.height,
73 }),
74 );
75
76 if let Some(cid) = child_id {
77 builder.add_child(cid);
78 }
79
80 cx.pop_scope();
81 builder.build(cx)
82 }
83}