fission_core/ui/widgets/
video.rs1use crate::lowering::{LoweringContext, NodeBuilder};
2use crate::ui::traits::Lower;
3use fission_ir::{
4 op::{EmbedKind, LayoutOp, Op},
5 NodeId, WidgetNodeId,
6};
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Default, Clone, Serialize, Deserialize)]
29pub struct Video {
30 pub id: Option<WidgetNodeId>,
32 pub source: String,
34 pub width: Option<f32>,
36 pub height: Option<f32>,
38 pub autoplay: bool,
40 pub loop_playback: bool,
42}
43
44impl Video {
45 pub fn into_node(self) -> crate::ui::Node {
46 crate::ui::Node::Video(self)
47 }
48}
49
50impl Lower for Video {
51 fn lower(&self, cx: &mut LoweringContext) -> NodeId {
52 let widget_id = self
53 .id
54 .unwrap_or_else(|| WidgetNodeId::explicit(&self.source));
55 let layout_id = cx.widget_node_id(widget_id);
56
57 let embed_id = NodeBuilder::new(
58 cx.next_node_id(),
59 Op::Layout(LayoutOp::Embed {
60 kind: EmbedKind::Video,
61 widget_id,
62 width: self.width,
63 height: self.height,
64 }),
65 )
66 .build(cx);
67
68 let mut layout_builder = NodeBuilder::new(
69 layout_id,
70 Op::Layout(LayoutOp::Box {
71 width: self.width,
72 height: self.height,
73 min_width: None,
74 max_width: None,
75 min_height: None,
76 max_height: None,
77 padding: [0.0; 4],
78 flex_grow: 0.0,
79 flex_shrink: 0.0,
80 aspect_ratio: None,
81 }),
82 );
83 layout_builder.add_child(embed_id);
84 layout_builder.build(cx)
85 }
86}