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::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<Rc<Window>>,
surface: Option<Surface<OwnedDisplayHandle, Rc<Window>>>,
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();