use filename for window title

This commit is contained in:
Veneficium 2025-11-10 18:12:41 +01:00
parent 538ce6f79f
commit f1bde5df89

View file

@ -1,6 +1,7 @@
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::{BufReader, Read};
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::path::Path;
use std::rc::Rc; use std::rc::Rc;
use std::{env, time::*}; use std::{env, time::*};
@ -19,6 +20,8 @@ use softbuffer::Surface;
#[derive(Default)] #[derive(Default)]
struct App { struct App {
file_name: String,
window: Option<Rc<Window>>, window: Option<Rc<Window>>,
surface: Option<Surface<OwnedDisplayHandle, Rc<Window>>>, surface: Option<Surface<OwnedDisplayHandle, Rc<Window>>>,
image: RgbaImage, image: RgbaImage,
@ -37,7 +40,8 @@ struct Animation {
impl ApplicationHandler for App { impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &ActiveEventLoop) { 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 window = Rc::new(event_loop.create_window(window_attributes).unwrap());
let context = softbuffer::Context::new(event_loop.owned_display_handle()).unwrap(); let context = softbuffer::Context::new(event_loop.owned_display_handle()).unwrap();
let surface = Surface::new(&context, window.clone()).unwrap(); let surface = Surface::new(&context, window.clone()).unwrap();
@ -164,9 +168,19 @@ fn main() -> anyhow::Result<()> {
return Ok(()); 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 mut app = App::default();
let image = ImageReader::open(args[1].clone()) let image =
.context(format!("Failed to open image at {}", args[1]))?; 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() { match image.format().unwrap() {
ImageFormat::Gif => { ImageFormat::Gif => {
let mut animation = Animation::default(); let mut animation = Animation::default();