Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/egui/src/containers/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ impl Frame {
Self::new().inner_margin(8).fill(style.visuals.panel_fill)
}

/// Does NOT include margin ([`Window`] applies that manually).
pub fn window(style: &Style) -> Self {
Self::new()
.inner_margin(style.spacing.window_margin)
.corner_radius(style.visuals.window_corner_radius)
.shadow(style.visuals.window_shadow)
.fill(style.visuals.window_fill())
Expand Down
17 changes: 13 additions & 4 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'open> Window<'open> {
.with_stroke(false)
.min_size([96.0, 32.0])
.default_size([340.0, 420.0]), // Default inner size of a window
scroll: ScrollArea::neither().auto_shrink(false),
scroll: ScrollArea::neither().auto_shrink(false).content_margin(0.0),
collapsible: true,
default_open: true,
with_title_bar: true,
Expand Down Expand Up @@ -509,12 +509,15 @@ impl Window<'_> {

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

let window_margin = style.spacing.window_margin;

// Calculate roughly how much larger the full window inner size is compared to the content rect
let (title_bar_height_with_margin, title_content_spacing) = if with_title_bar {
let title_bar_inner_height = ctx
.fonts_mut(|fonts| title.font_height(fonts, &style))
.at_least(style.spacing.interact_size.y);
let title_bar_inner_height = title_bar_inner_height + window_frame.inner_margin.sum().y;
let title_bar_inner_height =
title_bar_inner_height + window_frame.inner_margin.sum().y + window_margin.sum().y;
let half_height = (title_bar_inner_height / 2.0).round() as _;
window_frame.corner_radius.ne = window_frame.corner_radius.ne.clamp(0, half_height);
window_frame.corner_radius.nw = window_frame.corner_radius.nw.clamp(0, half_height);
Expand Down Expand Up @@ -613,9 +616,15 @@ impl Window<'_> {
.show_body_unindented(&mut frame.content_ui, |ui| {
resize.show(ui, |ui| {
if scroll.is_any_scroll_enabled() {
scroll.show(ui, add_contents).inner
scroll
.content_margin(window_margin)
.show(ui, add_contents)
.inner
} else {
add_contents(ui)
crate::Frame::NONE
.inner_margin(window_margin)
.show(ui, add_contents)
.inner
}
})
})
Expand Down
6 changes: 4 additions & 2 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,9 @@ pub struct Visuals {
/// How the text cursor acts.
pub text_cursor: TextCursorStyle,

/// Allow child widgets to be just on the border and still have a stroke with some thickness
/// Allow widgets to paint this much outside the scroll area rect.
///
/// Legacy. Should not be used anymore.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you should say, what to use instead

pub clip_rect_margin: f32,

/// Show a background behind buttons.
Expand Down Expand Up @@ -1456,7 +1458,7 @@ impl Visuals {

text_cursor: Default::default(),

clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion
clip_rect_margin: 0.0,
button_frame: true,
collapsing_header_frame: false,
indent_has_left_vline: true,
Expand Down
Loading