diff --git a/src/app.rs b/src/app.rs index b053000..0554734 100644 --- a/src/app.rs +++ b/src/app.rs @@ -49,9 +49,9 @@ impl eframe::App for Roseate { if window_rect.width() != self.last_window_rect.width() || window_rect.height() != self.last_window_rect.height() { if !self.zoom_pan.has_been_messed_with() { - self.window_scaling.schedule_image_scale_to_window_size(); + self.window_scaling.schedule_scale_image_to_window_size(); + self.last_window_rect = window_rect; } - self.last_window_rect = window_rect; } if self.image.is_none() { @@ -83,32 +83,29 @@ impl eframe::App for Roseate { self.window_scaling.update(&window_rect, &image.image_size); ui.centered_and_justified(|ui| { - let (scaled_image_width, scaled_image_height) = self.window_scaling.get_scaled_image_size( - image.image_size + let scaled_image_size = self.window_scaling.relative_image_size( + Vec2::new(image.image_size.width as f32, image.image_size.height as f32) ); - if self.zoom_pan.is_pan_out_of_bounds([scaled_image_width, scaled_image_height].into()) { + if self.zoom_pan.is_pan_out_of_bounds(scaled_image_size) { self.zoom_pan.schedule_pan_reset(Duration::from_millis(300)); }; // NOTE: umm do we move this to window scaling... *probably* if we // want to stay consistent with zoom_pan but this isn't important right now. let scaled_image_width_animated = egui_animation::animate_eased( - ctx, "image_scale_width", scaled_image_width, 1.5, simple_easing::cubic_in_out - ) as u32; + ctx, "image_scale_width", scaled_image_size.x, 1.5, simple_easing::cubic_in_out + ) as u32 as f32; let scaled_image_height_animated = egui_animation::animate_eased( - ctx, "image_scale_height", scaled_image_height, 1.5, simple_easing::cubic_in_out - ) as u32; + ctx, "image_scale_height", scaled_image_size.y, 1.5, simple_easing::cubic_in_out + ) as u32 as f32; - let image_size = Vec2::new( - scaled_image_width_animated as f32, - scaled_image_height_animated as f32 - ); + let scaled_image_size = Vec2::new(scaled_image_width_animated, scaled_image_height_animated); - let zoom_scaled_size = image_size * self.zoom_pan.zoom_factor; - let image_position = ui.max_rect().center() - zoom_scaled_size * 0.5 + self.zoom_pan.pan_offset; + let zoom_scaled_image_size = self.zoom_pan.relative_image_size(scaled_image_size); + let image_position = ui.max_rect().center() - zoom_scaled_image_size * 0.5 + self.zoom_pan.pan_offset; - let zoom_pan_rect = Rect::from_min_size(image_position, zoom_scaled_size); + let zoom_pan_rect = Rect::from_min_size(image_position, zoom_scaled_image_size); let response = ui.allocate_rect(zoom_pan_rect, egui::Sense::hover()); diff --git a/src/image.rs b/src/image.rs index ef2a2af..2e4813b 100644 --- a/src/image.rs +++ b/src/image.rs @@ -109,7 +109,7 @@ pub fn apply_image_optimizations(mut optimizations: Vec, imag "Uhhhhh, you don't have a monitor. WHAT!" ); - let marginal_allowance: f32 = 1.2; + let marginal_allowance: f32 = 1.3; // TODO: Make this adjustable in the config too as down sample strength. let (width, height) = ( primary_display_maybe.width as f32 * marginal_allowance, diff --git a/src/window_scaling.rs b/src/window_scaling.rs index 8806727..5d08635 100644 --- a/src/window_scaling.rs +++ b/src/window_scaling.rs @@ -1,6 +1,6 @@ use std::time::{Duration, Instant}; -use eframe::egui::Rect; +use eframe::egui::{Rect, Vec2}; use imagesize::ImageSize; use log::debug; @@ -20,7 +20,7 @@ impl WindowScaling { /// Resizes the image to the window size after a short delay /// or later in the update loop (hence being named 'schedule_'). - pub fn schedule_image_scale_to_window_size(&mut self) { + pub fn schedule_scale_image_to_window_size(&mut self) { debug!("The image has been scheduled to resize to the window size."); self.resize_to_window_timer = Some(Instant::now()); } @@ -46,10 +46,10 @@ impl WindowScaling { } } - pub fn get_scaled_image_size(&self, actual_image_size: ImageSize) -> (f32, f32) { - ( - actual_image_size.width as f32 * self.scale_factor, - actual_image_size.height as f32 * self.scale_factor + pub fn relative_image_size(&self, image_size: Vec2) -> Vec2 { + Vec2::new( + image_size.x as f32 * self.scale_factor, + image_size.y as f32 * self.scale_factor ) } } \ No newline at end of file diff --git a/src/zoom_pan.rs b/src/zoom_pan.rs index e2c7f0e..b932fca 100644 --- a/src/zoom_pan.rs +++ b/src/zoom_pan.rs @@ -132,6 +132,10 @@ impl ZoomPan { false } } + + pub fn relative_image_size(&self, image_size: Vec2) -> Vec2 { + image_size * self.zoom_factor + } } impl ZoomPan { @@ -148,6 +152,10 @@ impl ZoomPan { ); debug!("Pan offset reset has been scheduled."); + + // As resetting the pan will just snap us back to the center + // of the image we might as well schedule a reset for image scale too. + self.schedule_scale_reset(delay); } }