From 60717d639cce85395fc7a9e06f057a92ef0adcc3 Mon Sep 17 00:00:00 2001 From: electria Date: Mon, 27 Jul 2026 21:14:22 -0700 Subject: [PATCH 1/3] fix: hidden error --- src/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index a691062..b9c862e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,13 +145,13 @@ impl State { } #[must_use] fn pick_and_load_image(&mut self) -> Task { - let task; - (self.error, task) = match utils::pick_image() { - Ok(path) => (None, self.load_image(path)), - Err(e) => (Some(e), Task::none()), - }; - - task + match utils::pick_image() { + Ok(path) => self.load_image(path), + Err(e) => { + self.error = Some(e); + Task::none() + } + } } fn save_image(&mut self) { From e32c18e304dacf22d11828b36faf42eda71310e9 Mon Sep 17 00:00:00 2001 From: electria Date: Mon, 27 Jul 2026 21:23:59 -0700 Subject: [PATCH 2/3] refactor: improve helper function sanity pure(er) functions are so much easier to work with (see the bug fix in the pior commit) there's a bit of duplicate code introduced but it's worth it --- src/main.rs | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index b9c862e..59b4151 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,9 +79,13 @@ impl State { } } - Key::Character("o") => { - return self.pick_and_load_image(); - } + Key::Character("o") => match self.pick_and_load_image() { + Ok(task) => { + self.error = None; + return task; + } + Err(e) => self.error = Some(e), + }, Key::Character("r") => { match self.image.as_ref() { @@ -115,9 +119,13 @@ impl State { }, Message::Event(iced::Event::Window(window_event)) => match window_event { - window::Event::FileDropped(file) => { - return self.load_image(file); - } + window::Event::FileDropped(file) => match self.load_image(file) { + Ok(task) => { + self.error = None; + return task; + } + Err(e) => self.error = Some(e), + }, // ignore unused window events _ => {} @@ -130,28 +138,14 @@ impl State { Task::none() } - #[must_use] - fn load_image(&mut self, path: impl AsRef) -> Task { - let task; - (self.error, task) = match utils::load_image(path) { - Ok(image) => { - self.image = Some(image); - (None, self.allocate_image()) - } - Err(e) => (Some(e), Task::none()), - }; - - task + fn load_image(&mut self, path: impl AsRef) -> Result, String> { + utils::load_image(path).and_then(|image| { + self.image = Some(image); + Ok(self.allocate_image()) + }) } - #[must_use] - fn pick_and_load_image(&mut self) -> Task { - match utils::pick_image() { - Ok(path) => self.load_image(path), - Err(e) => { - self.error = Some(e); - Task::none() - } - } + fn pick_and_load_image(&mut self) -> Result, String> { + utils::pick_image().and_then(|path| self.load_image(path)) } fn save_image(&mut self) { From c4738ad2c852b9191d83ac36003429bd2beff74e Mon Sep 17 00:00:00 2001 From: electria Date: Mon, 27 Jul 2026 21:37:00 -0700 Subject: [PATCH 3/3] feat: display image dimensions in title --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.rs b/src/main.rs index 59b4151..62f5087 100644 --- a/src/main.rs +++ b/src/main.rs @@ -170,11 +170,18 @@ impl State { fn subscription(&self) -> Subscription { event::listen().map(Message::Event) } + fn title(&self) -> String { + match self.image.as_ref() { + Some(image) => format!("imagey {}x{}", image.width(), image.height()), + None => format!("imagey"), + } + } } fn main() -> Result<(), iced::Error> { iced::application(State::new, State::update, State::view) .subscription(State::subscription) + .title(State::title) .theme(Theme::custom( "custom", theme::Palette {