From f5d894a27ff94337fd57fd689e343f5c8ef66c98 Mon Sep 17 00:00:00 2001 From: talwat <83217276+talwat@users.noreply.github.com> Date: Fri, 30 Oct 2026 07:40:48 +0100 Subject: [PATCH] fix: small bug with progress bar --- data/sfx.txt | 7 +++++++ src/ui/init.rs | 2 +- src/ui/interface/components.rs | 8 ++++++-- src/ui/media_controls.rs | 10 ++++------ 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 data/sfx.txt diff --git a/data/sfx.txt b/data/sfx.txt new file mode 100644 index 0000000..6fc43a5 --- /dev/null +++ b/data/sfx.txt @@ -0,0 +1,7 @@ +noheader +https://sfxmint.com/dl/door-open-50.mp3 +https://sfxmint.com/dl/door-open-10.mp3 +https://sfxmint.com/dl/feedback-buzzer-20.mp3 +https://sfxmint.com/dl/retro-game-explosion-54.mp3 +https://sfxmint.com/dl/retro-game-explosion-51.mp3 +https://sfxmint.com/dl/gore-squish-02.mp3 \ No newline at end of file diff --git a/src/ui/init.rs b/src/ui/init.rs index 6b327b2..985d662 100644 --- a/src/ui/init.rs +++ b/src/ui/init.rs @@ -34,4 +34,4 @@ impl crate::Tasks { media_controls, }) } -} \ No newline at end of file +} diff --git a/src/ui/interface/components.rs b/src/ui/interface/components.rs index 6dc14c1..63321dc 100644 --- a/src/ui/interface/components.rs +++ b/src/ui/interface/components.rs @@ -30,8 +30,12 @@ pub fn progress_bar(state: &ui::State, width: usize) -> String { if let Some(x) = current.duration { duration = x; - let elapsed = elapsed.as_secs() as f32 / duration.as_secs() as f32; - filled = (elapsed * width as f32).round() as usize; + let elapsed = elapsed + .as_secs_f32() + .round() + .clamp(0.0, duration.as_secs_f32()); + let ratio = (elapsed / duration.as_secs_f32()).clamp(0.0, 1.0); + filled = (ratio * width as f32).round() as usize; } } diff --git a/src/ui/media_controls.rs b/src/ui/media_controls.rs index 2c72117..e8046cf 100644 --- a/src/ui/media_controls.rs +++ b/src/ui/media_controls.rs @@ -4,9 +4,7 @@ use std::sync::Arc; use std::time::Duration; -use souvlaki::{ - MediaControlEvent, MediaControls, MediaMetadata, MediaPlayback, PlatformConfig, -}; +use souvlaki::{MediaControlEvent, MediaControls, MediaMetadata, MediaPlayback, PlatformConfig}; use tokio::sync::{broadcast, mpsc}; use crate::player::Current; @@ -164,8 +162,8 @@ mod windows { use ::windows::Win32::System::LibraryLoader::GetModuleHandleW; use ::windows::Win32::UI::WindowsAndMessaging::{ CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, PeekMessageW, - RegisterClassExW, TranslateMessage, MSG, PM_REMOVE, WINDOW_EX_STYLE, WINDOW_STYLE, - WM_QUIT, WNDCLASSEXW, + RegisterClassExW, TranslateMessage, MSG, PM_REMOVE, WINDOW_EX_STYLE, WINDOW_STYLE, WM_QUIT, + WNDCLASSEXW, }; pub struct DummyWindow { @@ -242,4 +240,4 @@ mod windows { } } } -} \ No newline at end of file +}