Skip to content

Commit

Permalink
Another attempt to fix the window size
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Dec 25, 2024
1 parent d2552fb commit ef6c3b7
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions src/window/window_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ use {
#[cfg(target_os = "macos")]
use super::macos::MacosWindowFeature;

const GRID_TOLERANCE: f32 = 0e-6;
const GRID_TOLERANCE: f32 = 1e-3;

fn round_or_op<Op: FnOnce(f32) -> f32>(v: f32, op: Op) -> f32 {
let rounded = v.round();
if v.abs_diff_eq(&rounded, GRID_TOLERANCE) {
rounded
} else {
op(v)
}
}

use approx::AbsDiffEq;
use log::trace;
Expand Down Expand Up @@ -696,15 +705,16 @@ impl WinitWindowWrapper {
window_padding.left + window_padding.right,
window_padding.top + window_padding.bottom,
);
let round_or_ceil = |v: PixelSize<f32>| -> PixelSize<f32> {
PixelSize::new(
round_or_op(v.width, f32::ceil),
round_or_op(v.height, f32::ceil),
)
};

let window_size = *grid_size * self.renderer.grid_renderer.grid_scale;
let window_size = if window_size.abs_diff_eq(&window_size.round(), GRID_TOLERANCE) {
window_size.round()
} else {
window_size.floor()
}
.try_cast()
.unwrap()
let window_size = round_or_ceil(*grid_size * self.renderer.grid_renderer.grid_scale)
.try_cast()
.unwrap()
+ window_padding_size;

log::info!(
Expand Down Expand Up @@ -749,14 +759,16 @@ impl WinitWindowWrapper {
PixelSize::new(self.saved_inner_size.width, self.saved_inner_size.height)
- window_padding_size;

let grid_size = content_size / self.renderer.grid_renderer.grid_scale;
let grid_size = if grid_size.abs_diff_eq(&grid_size.round(), GRID_TOLERANCE) {
grid_size.round()
} else {
grid_size.ceil()
}
.try_cast()
.unwrap();
let round_or_floor = |v: GridSize<f32>| -> GridSize<f32> {
GridSize::new(
round_or_op(v.width, f32::floor),
round_or_op(v.height, f32::floor),
)
};

let grid_size = round_or_floor(content_size / self.renderer.grid_renderer.grid_scale)
.try_cast()
.unwrap();

grid_size.max(min)
}
Expand Down

0 comments on commit ef6c3b7

Please sign in to comment.