Skip to content

Commit

Permalink
Round panel bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 26, 2024
1 parent c9dfc42 commit 133ccbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions crates/egui/src/containers/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//!
//! Add your [`crate::Window`]:s after any top-level panels.
use emath::GuiRounding as _;

use crate::{
lerp, vec2, Align, Context, CursorIcon, Frame, Id, InnerResponse, LayerId, Layout, NumExt,
Rangef, Rect, Sense, Stroke, Ui, UiBuilder, UiKind, UiStackInfo, Vec2,
Expand Down Expand Up @@ -264,6 +266,8 @@ impl SidePanel {
}
}

panel_rect = panel_rect.round_point();

let mut panel_ui = ui.new_child(
UiBuilder::new()
.id_salt(id)
Expand Down Expand Up @@ -756,6 +760,8 @@ impl TopBottomPanel {
}
}

panel_rect = panel_rect.round_point();

let mut panel_ui = ui.new_child(
UiBuilder::new()
.id_salt(id)
Expand Down Expand Up @@ -1130,15 +1136,14 @@ impl CentralPanel {
ctx: &Context,
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
) -> InnerResponse<R> {
let available_rect = ctx.available_rect();
let id = Id::new((ctx.viewport_id(), "central_panel"));

let mut panel_ui = Ui::new(
ctx.clone(),
id,
UiBuilder::new()
.layer_id(LayerId::background())
.max_rect(available_rect),
.max_rect(ctx.available_rect().round_point()),
);
panel_ui.set_clip_rect(ctx.screen_rect());

Expand Down
8 changes: 4 additions & 4 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2567,15 +2567,15 @@ impl Context {

/// Position and size of the egui area.
pub fn screen_rect(&self) -> Rect {
self.input(|i| i.screen_rect())
self.input(|i| i.screen_rect()).round_point()
}

/// How much space is still available after panels has been added.
///
/// This is the "background" area, what egui doesn't cover with panels (but may cover with windows).
/// This is also the area to which windows are constrained.
pub fn available_rect(&self) -> Rect {
self.pass_state(|s| s.available_rect())
self.pass_state(|s| s.available_rect()).round_point()
}

/// How much space is used by panels and windows.
Expand All @@ -2585,15 +2585,15 @@ impl Context {
for (_id, window) in ctx.memory.areas().visible_windows() {
used = used.union(window.rect());
}
used
used.round_point()
})
}

/// How much space is used by panels and windows.
///
/// You can shrink your egui area to this size and still fit all egui components.
pub fn used_size(&self) -> Vec2 {
self.used_rect().max - Pos2::ZERO
(self.used_rect().max - Pos2::ZERO).round_point()
}

// ---------------------------------------------------------------------
Expand Down

0 comments on commit 133ccbf

Please sign in to comment.