mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Round misc things
This commit is contained in:
@@ -261,7 +261,8 @@ impl Resize {
|
|||||||
state.desired_size = state
|
state.desired_size = state
|
||||||
.desired_size
|
.desired_size
|
||||||
.at_least(self.min_size)
|
.at_least(self.min_size)
|
||||||
.at_most(self.max_size);
|
.at_most(self.max_size)
|
||||||
|
.round();
|
||||||
|
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -1046,13 +1046,14 @@ impl TitleBar {
|
|||||||
let inner_response = ui.horizontal(|ui| {
|
let inner_response = ui.horizontal(|ui| {
|
||||||
let height = ui
|
let height = ui
|
||||||
.fonts(|fonts| title.font_height(fonts, ui.style()))
|
.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);
|
ui.set_min_height(height);
|
||||||
|
|
||||||
let item_spacing = ui.spacing().item_spacing;
|
let item_spacing = ui.spacing().item_spacing;
|
||||||
let button_size = Vec2::splat(ui.spacing().icon_width);
|
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 {
|
if collapsible {
|
||||||
ui.add_space(pad);
|
ui.add_space(pad);
|
||||||
|
|||||||
@@ -179,13 +179,15 @@ impl GridLayout {
|
|||||||
let width = self.prev_state.col_width(self.col).unwrap_or(0.0);
|
let width = self.prev_state.col_width(self.col).unwrap_or(0.0);
|
||||||
let height = self.prev_row_height(self.row);
|
let height = self.prev_row_height(self.row);
|
||||||
let size = child_size.max(vec2(width, height));
|
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)]
|
#[allow(clippy::unused_self)]
|
||||||
pub(crate) fn align_size_within_rect(&self, size: Vec2, frame: Rect) -> Rect {
|
pub(crate) fn align_size_within_rect(&self, size: Vec2, frame: Rect) -> Rect {
|
||||||
// TODO(emilk): allow this alignment to be customized
|
// 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 {
|
pub(crate) fn justify_and_align(&self, frame: Rect, size: Vec2) -> Rect {
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ impl Layout {
|
|||||||
pub fn align_size_within_rect(&self, size: Vec2, outer: Rect) -> Rect {
|
pub fn align_size_within_rect(&self, size: Vec2, outer: Rect) -> Rect {
|
||||||
debug_assert!(size.x >= 0.0 && size.y >= 0.0);
|
debug_assert!(size.x >= 0.0 && size.y >= 0.0);
|
||||||
debug_assert!(!outer.is_negative());
|
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 {
|
fn initial_cursor(&self, max_rect: Rect) -> Rect {
|
||||||
@@ -634,7 +634,7 @@ impl Layout {
|
|||||||
debug_assert!(!frame_rect.any_nan());
|
debug_assert!(!frame_rect.any_nan());
|
||||||
debug_assert!(!frame_rect.is_negative());
|
debug_assert!(!frame_rect.is_negative());
|
||||||
|
|
||||||
frame_rect
|
frame_rect.round()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply justify (fill width/height) and/or alignment after calling `next_space`.
|
/// Apply justify (fill width/height) and/or alignment after calling `next_space`.
|
||||||
|
|||||||
@@ -195,10 +195,10 @@ impl Label {
|
|||||||
assert!(!galley.rows.is_empty(), "Galleys are never empty");
|
assert!(!galley.rows.is_empty(), "Galleys are never empty");
|
||||||
// collect a response from many rows:
|
// collect a response from many rows:
|
||||||
let rect = galley.rows[0].rect.translate(vec2(pos.x, pos.y));
|
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) {
|
for row in galley.rows.iter().skip(1) {
|
||||||
let rect = row.rect.translate(vec2(pos.x, pos.y));
|
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)
|
(pos, galley, response)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ impl<'l> StripLayout<'l> {
|
|||||||
|
|
||||||
// Make sure we don't have a gap in the stripe/frame/selection background:
|
// Make sure we don't have a gap in the stripe/frame/selection background:
|
||||||
let item_spacing = self.ui.spacing().item_spacing;
|
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 {
|
if flags.striped {
|
||||||
self.ui.painter().rect_filled(
|
self.ui.painter().rect_filled(
|
||||||
|
|||||||
Reference in New Issue
Block a user