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