From 643accfc92e10e4ca5d7c36db42e656111e7674c Mon Sep 17 00:00:00 2001 From: accusys Date: Thu, 19 Mar 2026 01:47:24 +0800 Subject: [PATCH] feat(player): add click-to-seek on progress bar --- src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main.rs b/src/main.rs index 3342d96..bd29fff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -257,6 +257,34 @@ fn run(config: &Config) -> Result<()> { } } } + sdl2::event::Event::MouseButtonDown { x, y, .. } => { + let progress_y = config.height as i32 - progress_height + 5; + let bar_height = 20i32; + if y >= progress_y + && y <= progress_y + bar_height + && player_state.total_frames > 0 + { + let bar_x_start = 10i32; + let bar_width = config.width as i32 - 20; + if x >= bar_x_start && x <= bar_x_start + bar_width { + let ratio = (x - bar_x_start) as f64 / bar_width as f64; + let target_frame = (player_state.total_frames as f64 * ratio) as u64; + if let Some(ref mut dec) = decoder { + let time_ms = + ((target_frame as f64 / player_state.fps) * 1000.0) as u64; + if dec.seek(time_ms).is_ok() { + player_state.current_frame = target_frame; + player_state.current_time_ms = time_ms; + info!( + "Seeked to frame {} ({:.1}%)", + target_frame, + ratio * 100.0 + ); + } + } + } + } + } _ => {} } }