1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use crate::lowering::{LoweringContext, NodeBuilder};
use crate::ui::traits::Lower;
use fission_ir::{
op::{EmbedKind, LayoutOp, Op},
NodeId, WidgetNodeId,
};
use serde::{Deserialize, Serialize};
/// A platform-native video player widget.
///
/// The video is rendered by the platform's native player and embedded into the
/// Fission layout as an opaque surface. Use [`BuildCtx::video_controls`] to
/// create play/pause/seek action envelopes.
///
/// # Example
///
/// ```rust,ignore
/// Video {
/// source: "https://example.com/clip.mp4".into(),
/// width: Some(640.0),
/// height: Some(360.0),
/// autoplay: true,
/// loop_playback: false,
/// ..Default::default()
/// }
/// ```
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Video {
/// Stable widget identity (auto-derived from `source` if `None`).
pub id: Option<WidgetNodeId>,
/// URL or asset path to the video file.
pub source: String,
/// Fixed width in layout points.
pub width: Option<f32>,
/// Fixed height in layout points.
pub height: Option<f32>,
/// Whether to start playing immediately.
pub autoplay: bool,
/// Whether to loop playback when the video ends.
pub loop_playback: bool,
}
impl Video {
pub fn into_node(self) -> crate::ui::Node {
crate::ui::Node::Video(self)
}
}
impl Lower for Video {
fn lower(&self, cx: &mut LoweringContext) -> NodeId {
let widget_id = self
.id
.unwrap_or_else(|| WidgetNodeId::explicit(&self.source));
let layout_id = cx.widget_node_id(widget_id);
let embed_id = NodeBuilder::new(
cx.next_node_id(),
Op::Layout(LayoutOp::Embed {
kind: EmbedKind::Video,
widget_id,
width: self.width,
height: self.height,
}),
)
.build(cx);
let mut layout_builder = NodeBuilder::new(
layout_id,
Op::Layout(LayoutOp::Box {
width: self.width,
height: self.height,
min_width: None,
max_width: None,
min_height: None,
max_height: None,
padding: [0.0; 4],
flex_grow: 0.0,
flex_shrink: 0.0,
aspect_ratio: None,
}),
);
layout_builder.add_child(embed_id);
layout_builder.build(cx)
}
}