From 609de0fb58f59ef19b40c971f020b90a5d044c24 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 30 Sep 2024 16:48:07 +0200 Subject: [PATCH] Round misc things --- crates/egui/src/containers/resize.rs | 3 ++- crates/egui/src/containers/window.rs | 5 +++-- crates/egui/src/grid.rs | 6 ++++-- crates/egui/src/layout.rs | 4 ++-- crates/egui/src/widgets/label.rs | 4 ++-- crates/egui_extras/src/layout.rs | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index 458bf1122..ea8d8776f 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -261,7 +261,8 @@ impl Resize { state.desired_size = state .desired_size .at_least(self.min_size) - .at_most(self.max_size); + .at_most(self.max_size) + .round(); // ------------------------------ diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 1f99b7c72..58059b5f7 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -1046,13 +1046,14 @@ impl TitleBar { let inner_response = ui.horizontal(|ui| { let height = ui .fonts(|fonts| title.font_height(fonts, ui.style())) - .max(ui.spacing().interact_size.y); + .max(ui.spacing().interact_size.y) + .round(); ui.set_min_height(height); let item_spacing = ui.spacing().item_spacing; let button_size = Vec2::splat(ui.spacing().icon_width); - let pad = (height - button_size.y) / 2.0; // calculated so that the icon is on the diagonal (if window padding is symmetrical) + let pad = ((height - button_size.y) / 2.0).round(); // calculated so that the icon is on the diagonal (if window padding is symmetrical) if collapsible { ui.add_space(pad); diff --git a/crates/egui/src/grid.rs b/crates/egui/src/grid.rs index 3c4986fca..9c8464738 100644 --- a/crates/egui/src/grid.rs +++ b/crates/egui/src/grid.rs @@ -179,13 +179,15 @@ impl GridLayout { let width = self.prev_state.col_width(self.col).unwrap_or(0.0); let height = self.prev_row_height(self.row); let size = child_size.max(vec2(width, height)); - Rect::from_min_size(cursor.min, size) + Rect::from_min_size(cursor.min, size).round() } #[allow(clippy::unused_self)] pub(crate) fn align_size_within_rect(&self, size: Vec2, frame: Rect) -> Rect { // TODO(emilk): allow this alignment to be customized - Align2::LEFT_CENTER.align_size_within_rect(size, frame) + Align2::LEFT_CENTER + .align_size_within_rect(size, frame) + .round() } pub(crate) fn justify_and_align(&self, frame: Rect, size: Vec2) -> Rect { diff --git a/crates/egui/src/layout.rs b/crates/egui/src/layout.rs index 32fd0d03a..41630802c 100644 --- a/crates/egui/src/layout.rs +++ b/crates/egui/src/layout.rs @@ -394,7 +394,7 @@ impl Layout { pub fn align_size_within_rect(&self, size: Vec2, outer: Rect) -> Rect { debug_assert!(size.x >= 0.0 && size.y >= 0.0); debug_assert!(!outer.is_negative()); - self.align2().align_size_within_rect(size, outer) + self.align2().align_size_within_rect(size, outer).round() } fn initial_cursor(&self, max_rect: Rect) -> Rect { @@ -634,7 +634,7 @@ impl Layout { debug_assert!(!frame_rect.any_nan()); debug_assert!(!frame_rect.is_negative()); - frame_rect + frame_rect.round() } /// Apply justify (fill width/height) and/or alignment after calling `next_space`. diff --git a/crates/egui/src/widgets/label.rs b/crates/egui/src/widgets/label.rs index b6ade45ae..b5c750b79 100644 --- a/crates/egui/src/widgets/label.rs +++ b/crates/egui/src/widgets/label.rs @@ -195,10 +195,10 @@ impl Label { assert!(!galley.rows.is_empty(), "Galleys are never empty"); // collect a response from many rows: let rect = galley.rows[0].rect.translate(vec2(pos.x, pos.y)); - let mut response = ui.allocate_rect(rect, sense); + let mut response = ui.allocate_rect(rect.round(), sense); for row in galley.rows.iter().skip(1) { let rect = row.rect.translate(vec2(pos.x, pos.y)); - response |= ui.allocate_rect(rect, sense); + response |= ui.allocate_rect(rect.round(), sense); } (pos, galley, response) } else { diff --git a/crates/egui_extras/src/layout.rs b/crates/egui_extras/src/layout.rs index 239e7b1d2..83f05ffd2 100644 --- a/crates/egui_extras/src/layout.rs +++ b/crates/egui_extras/src/layout.rs @@ -123,7 +123,7 @@ impl<'l> StripLayout<'l> { // Make sure we don't have a gap in the stripe/frame/selection background: let item_spacing = self.ui.spacing().item_spacing; - let gapless_rect = max_rect.expand2(0.5 * item_spacing); + let gapless_rect = max_rect.expand2(0.5 * item_spacing).round(); if flags.striped { self.ui.painter().rect_filled(