mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
can't size too small
This commit is contained in:
1 parent
16c14a49b4
commit
44889e735b
2 files changed
+29
-2
No files matched your search
@@ -16,6 +16,8 @@ pub fn position_main_window(
|
||||
// On Mac, this prevents the windows from being positioned off to the top-left,
|
||||
// as (0,0) is the top left directly under the top menu bar.
|
||||
if position.x < 0 {
|
||||
// TODO(bt,2025-07-16): just in the case of x/width, allow slight placement off
|
||||
// screen as long as the app is wide enough.
|
||||
return Err(anyhow::anyhow!("X position must be non-negative"));
|
||||
} else if position.y < 0 {
|
||||
return Err(anyhow::anyhow!("Y position must be non-negative"));
|
||||
@@ -37,8 +39,8 @@ pub fn position_main_window(
|
||||
println!("Current monitor - scale factor: {:?}", monitor.scale_factor());
|
||||
println!("Current monitor - position: {:?}", monitor.position());
|
||||
|
||||
let width_padding = monitor_size.width.div_ceil(4);
|
||||
let height_padding = monitor_size.height.div_ceil(4);
|
||||
let width_padding = monitor_size.width.div_ceil(6);
|
||||
let height_padding = monitor_size.height.div_ceil(6);
|
||||
|
||||
let max_width = monitor_size.width.saturating_sub(width_padding);
|
||||
let max_height = monitor_size.height.saturating_sub(height_padding);
|
||||
@@ -46,6 +48,8 @@ pub fn position_main_window(
|
||||
let max_width = i32::try_from(max_width)?;
|
||||
let max_height = i32::try_from(max_height)?;
|
||||
|
||||
// Prevent the window from being positioned off the screen to the bottom, right, and bottom right.
|
||||
// This works on MacBook (single screen), but should be tested on Windows, Linux, and multiscreen setups.
|
||||
if position.x > max_width {
|
||||
return Err(anyhow::anyhow!("X position must be less than or equal to {} (monitor width {})",
|
||||
max_width, monitor_size.width));
|
||||
|
||||
@@ -20,6 +20,29 @@ pub fn resize_main_window(
|
||||
let window = windows.get(MAIN_WINDOW_NAME)
|
||||
.ok_or_else(|| anyhow::anyhow!("Main window not found"))?;
|
||||
|
||||
|
||||
if let Ok(Some(monitor)) = window.current_monitor() {
|
||||
let scale_factor = monitor.scale_factor();
|
||||
|
||||
if scale_factor > 1.0 {
|
||||
|
||||
let min_width = MAIN_WINDOW_MIN_WIDTH as f64 * scale_factor;
|
||||
let min_height = MAIN_WINDOW_MIN_HEIGHT as f64 * scale_factor;
|
||||
|
||||
// Is this safe? https://users.rust-lang.org/t/convert-an-f64-to-an-i32/50991/4
|
||||
let min_width = min_width as u32;
|
||||
let min_height = min_height as u32;
|
||||
|
||||
if size.width < min_width {
|
||||
return Err(anyhow::anyhow!("Width must be at least {} (given scale factor {})",
|
||||
min_width, scale_factor));
|
||||
} else if size.height < min_height {
|
||||
return Err(anyhow::anyhow!("Height must be at least {} (given scale factor {})",
|
||||
min_height, scale_factor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.set_size(PhysicalSize::new(size.width, size.height))?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user