From 43a4bae010b814089fe96b9c70c30bdf04b697a4 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 15 Dec 2024 10:30:32 +0300 Subject: Extract center_preferring_top_left_in_area() --- src/utils/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/utils/mod.rs') diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e7dff735..7ab89a72 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -284,6 +284,18 @@ pub fn clamp_preferring_top_left_in_area( rect.loc.y = f64::max(rect.loc.y, area.loc.y); } +pub fn center_preferring_top_left_in_area( + area: Rectangle, + size: Size, +) -> Point { + let area_size = area.size.to_point(); + let size = size.to_point(); + let mut offset = (area_size - size).downscale(2.); + offset.x = f64::max(offset.x, 0.); + offset.y = f64::max(offset.y, 0.); + area.loc + offset +} + #[cfg(feature = "dbus")] pub fn show_screenshot_notification(image_path: Option) { let mut notification = notify_rust::Notification::new(); -- cgit