Skip to content

Commit

Permalink
Round misc things
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 30, 2024
1 parent 1a45dd5 commit 609de0f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion crates/egui/src/containers/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

// ------------------------------

Expand Down
5 changes: 3 additions & 2 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions crates/egui/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/egui/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_extras/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 609de0f

Please sign in to comment.