fission_core/ui/widgets/
video.rs1use crate::internal::InternalLower;
2use crate::lowering::{InternalIrBuilder, InternalLoweringCx};
3use fission_ir::{
4 op::{EmbedKind, LayoutOp, Op},
5 WidgetId,
6};
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Default, Clone, Serialize, Deserialize)]
29pub struct Video {
30 pub id: Option<WidgetId>,
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
46impl InternalLower for Video {
47 fn lower(&self, cx: &mut InternalLoweringCx) -> WidgetId {
48 let widget_id = self.id.unwrap_or_else(|| WidgetId::explicit(&self.source));
49 let layout_id = cx.widget_node_id(widget_id);
50
51 let embed_id = InternalIrBuilder::new(
52 cx.next_node_id(),
53 Op::Layout(LayoutOp::Embed {
54 kind: EmbedKind::Video,
55 widget_id,
56 width: self.width,
57 height: self.height,
58 }),
59 )
60 .build(cx);
61
62 let mut layout_builder = InternalIrBuilder::new(
63 layout_id,
64 Op::Layout(LayoutOp::Box {
65 width: self.width,
66 height: self.height,
67 min_width: None,
68 max_width: None,
69 min_height: None,
70 max_height: None,
71 padding: [0.0; 4],
72 flex_grow: 0.0,
73 flex_shrink: 0.0,
74 aspect_ratio: None,
75 }),
76 );
77 layout_builder.add_child(embed_id);
78 layout_builder.build(cx)
79 }
80}