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> <layout>
<theme>
<var key="width" value="426.666" />
<var key="height" value="133.333" />
</theme>
<elements> <elements>
<rectangle position="absolute" width="10000" height="10000" color="#112233"/> <rectangle position="absolute" width="10000" height="10000" color="#112233"/>
<div margin="16" gap="8" flex_direction="column"> <div flex_direction="row">
<label text="640x200"/> <div margin="16" gap="8" flex_direction="column" overflow_y="scroll" >
<Video src="video.ivf" width="640" height="200"/> <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> </div>
</elements> </elements>
</layout> </layout>

View File

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

View File

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