Skip to content

Commit 7477492

Browse files
committed
Change window margins and set clip_rect_margin=0
1 parent 07c5402 commit 7477492

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

crates/egui/src/containers/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ impl Frame {
197197
Self::new().inner_margin(8).fill(style.visuals.panel_fill)
198198
}
199199

200+
/// Does NOT include margin ([`Window`] applies that manually).
200201
pub fn window(style: &Style) -> Self {
201202
Self::new()
202-
.inner_margin(style.spacing.window_margin)
203203
.corner_radius(style.visuals.window_corner_radius)
204204
.shadow(style.visuals.window_shadow)
205205
.fill(style.visuals.window_fill())

crates/egui/src/containers/window.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'open> Window<'open> {
6262
.with_stroke(false)
6363
.min_size([96.0, 32.0])
6464
.default_size([340.0, 420.0]), // Default inner size of a window
65-
scroll: ScrollArea::neither().auto_shrink(false),
65+
scroll: ScrollArea::neither().auto_shrink(false).content_margin(0.0),
6666
collapsible: true,
6767
default_open: true,
6868
with_title_bar: true,
@@ -509,12 +509,15 @@ impl Window<'_> {
509509

510510
area.with_widget_info(|| WidgetInfo::labeled(WidgetType::Window, true, title.text()));
511511

512+
let window_margin = style.spacing.window_margin;
513+
512514
// Calculate roughly how much larger the full window inner size is compared to the content rect
513515
let (title_bar_height_with_margin, title_content_spacing) = if with_title_bar {
514516
let title_bar_inner_height = ctx
515517
.fonts_mut(|fonts| title.font_height(fonts, &style))
516518
.at_least(style.spacing.interact_size.y);
517-
let title_bar_inner_height = title_bar_inner_height + window_frame.inner_margin.sum().y;
519+
let title_bar_inner_height =
520+
title_bar_inner_height + window_frame.inner_margin.sum().y + window_margin.sum().y;
518521
let half_height = (title_bar_inner_height / 2.0).round() as _;
519522
window_frame.corner_radius.ne = window_frame.corner_radius.ne.clamp(0, half_height);
520523
window_frame.corner_radius.nw = window_frame.corner_radius.nw.clamp(0, half_height);
@@ -613,9 +616,15 @@ impl Window<'_> {
613616
.show_body_unindented(&mut frame.content_ui, |ui| {
614617
resize.show(ui, |ui| {
615618
if scroll.is_any_scroll_enabled() {
616-
scroll.show(ui, add_contents).inner
619+
scroll
620+
.content_margin(window_margin)
621+
.show(ui, add_contents)
622+
.inner
617623
} else {
618-
add_contents(ui)
624+
crate::Frame::NONE
625+
.inner_margin(window_margin)
626+
.show(ui, add_contents)
627+
.inner
619628
}
620629
})
621630
})

crates/egui/src/style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ impl Visuals {
14511451

14521452
text_cursor: Default::default(),
14531453

1454-
clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion
1454+
clip_rect_margin: 0.0,
14551455
button_frame: true,
14561456
collapsing_header_frame: false,
14571457
indent_has_left_vline: true,

0 commit comments

Comments
 (0)