fission_core/ui/widgets/
safe_area.rs1use crate::lowering::{LoweringContext, NodeBuilder};
2use crate::ui::traits::Lower;
3use crate::ui::Node;
4use fission_ir::{LayoutOp, NodeId, Op};
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct SafeArea {
9 pub id: Option<NodeId>,
10 pub child: Box<Node>,
11}
12
13impl Default for SafeArea {
14 fn default() -> Self {
15 Self {
16 id: None,
17 child: Box::new(crate::ui::widgets::spacer::Spacer::default().into_node()),
18 }
19 }
20}
21
22impl SafeArea {
23 pub fn into_node(self) -> Node {
24 Node::SafeArea(self)
25 }
26}
27
28impl Lower for SafeArea {
29 fn lower(&self, cx: &mut LoweringContext) -> NodeId {
30 let id = self.id.unwrap_or_else(|| cx.next_node_id());
31 let insets = &cx.env.window_insets;
32
33 cx.push_scope(id);
34 let child_id = self.child.lower(cx);
35 cx.pop_scope();
36
37 let mut builder = NodeBuilder::new(id, Op::Layout(LayoutOp::Box {
39 width: None,
40 height: None,
41 min_width: None,
42 max_width: None,
43 min_height: None,
44 max_height: None,
45 padding: [insets.left, insets.right, insets.top, insets.bottom],
46 flex_grow: 1.0,
47 flex_shrink: 1.0,
48 aspect_ratio: None,
49 }));
50
51 builder.add_child(child_id);
52 builder.build(cx)
53 }
54}