From f1bde5df89f047ad2befc79e011489c749c298d4 Mon Sep 17 00:00:00 2001 From: Veneficium <85629831+veneficium42@users.noreply.github.com> Date: Mon, 10 Nov 2025 18:12:41 +0100 Subject: [PATCH] use filename for window title --- src/main.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index d5e622d..b49b113 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::fs::File; -use std::io::BufReader; +use std::io::{BufReader, Read}; use std::num::NonZeroU32; +use std::path::Path; use std::rc::Rc; use std::{env, time::*}; @@ -19,6 +20,8 @@ use softbuffer::Surface; #[derive(Default)] struct App { + file_name: String, + window: Option>, surface: Option>>, image: RgbaImage, @@ -37,7 +40,8 @@ struct Animation { impl ApplicationHandler for App { fn resumed(&mut self, event_loop: &ActiveEventLoop) { - let window_attributes = Window::default_attributes().with_title("A fantastic window!"); + let window_attributes = + Window::default_attributes().with_title(format!("sivi - {}", self.file_name)); let window = Rc::new(event_loop.create_window(window_attributes).unwrap()); let context = softbuffer::Context::new(event_loop.owned_display_handle()).unwrap(); let surface = Surface::new(&context, window.clone()).unwrap(); @@ -164,9 +168,19 @@ fn main() -> anyhow::Result<()> { return Ok(()); }; + let file_path = Path::new(args[1].as_str()); + + if !file_path.is_file() { + println!("The argument provided is not a file path!\n"); + return Ok(()); + } + let mut app = App::default(); - let image = ImageReader::open(args[1].clone()) - .context(format!("Failed to open image at {}", args[1]))?; + let image = + ImageReader::open(file_path).context(format!("Failed to open image at {}", args[1]))?; + + app.file_name = file_path.file_name().unwrap().to_str().unwrap().to_string(); + match image.format().unwrap() { ImageFormat::Gif => { let mut animation = Animation::default();