wgui: video: variable speed control

This commit is contained in:
Aleksander 2026-06-06 14:44:15 +02:00
parent 683b1115ba
commit da9ad32fe4
3 changed files with 35 additions and 7 deletions

View File

@ -1,9 +1,25 @@
<layout>
<theme>
<var key="width" value="426.666" />
<var key="height" value="133.333" />
</theme>
<elements>
<rectangle position="absolute" width="10000" height="10000" color="#112233"/>
<div margin="16" gap="8" flex_direction="column">
<label text="640x200"/>
<Video src="video.ivf" width="640" height="200"/>
<div flex_direction="row">
<div margin="16" gap="8" flex_direction="column" overflow_y="scroll" >
<label text="640x200, looping"/>
<Video src_builtin="video.ivf" width="~width" height="~height" looping="1"/>
<label text="640x200, non-looping "/>
<Video src_builtin="video.ivf" width="~width" height="~height" looping="0"/>
</div>
<div margin="16" gap="8" flex_direction="column" overflow_y="scroll" >
<label text="640x200, looping, speed 2x"/>
<Video src_builtin="video.ivf" width="~width" height="~height" looping="1" speed="2"/>
<label text="640x200, looping, speed 0.5x"/>
<Video src_builtin="video.ivf" width="~width" height="~height" looping="1" speed="0.5"/>
<label text="640x200, looping, speed 4x"/>
<Video src_builtin="video.ivf" width="~width" height="~height" looping="1" speed="4"/>
</div>
</div>
</elements>
</layout>

View File

@ -29,6 +29,7 @@ pub struct Params<'a> {
pub style: taffy::Style,
pub src: Option<AssetPath<'a>>,
pub looping: bool,
pub speed: f32,
}
struct PlayingSource {
@ -50,6 +51,7 @@ struct Data {
id_image: WidgetID,
looping: bool,
speed: f32,
}
#[allow(dead_code)]
@ -104,7 +106,7 @@ impl ComponentVideo {
state.playing = true;
let framerate = source.demuxer.framerate;
let framerate = source.demuxer.framerate * self.data.speed;
let looping = self.data.looping;
let id_image = self.data.id_image;
let start_time = get_millis();
@ -248,6 +250,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
id_container,
id_image: image.id,
looping: params.looping,
speed: params.speed,
});
let state = Rc::new(RefCell::new(State {

View File

@ -3,8 +3,8 @@ use crate::{
components::{self, Component},
layout::WidgetID,
parser::{
AttribPair, ParserContext, ParserFile, get_asset_path_from_kv, parse_children, parse_i32, process_component,
style::parse_style,
AttribPair, ParserContext, ParserFile, get_asset_path_from_kv, parse_children, parse_f32, parse_i32,
process_component, style::parse_style,
},
};
@ -18,12 +18,16 @@ pub fn parse_component_video<'a>(
) -> anyhow::Result<WidgetID> {
let mut src: Option<AssetPath> = None;
let mut looping: bool = false;
let mut speed: f32 = 1.0;
let style = parse_style(ctx, attribs, tag_name);
for pair in attribs {
let (key, value) = (pair.attrib.as_ref(), pair.value.as_ref());
match key {
"speed" => {
speed = parse_f32(value).unwrap_or(speed);
}
"looping" => {
if let Some(v) = parse_i32(value)
&& v != 0
@ -44,7 +48,12 @@ pub fn parse_component_video<'a>(
let (widget, video) = components::video::construct(
&mut ctx.get_construct_essentials(parent_id),
components::video::Params { style, src, looping },
components::video::Params {
style,
src,
looping,
speed,
},
)?;
process_component(ctx, Component(video), widget.id, attribs);