Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egui: Fix custom Window Frames #4009

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Changes from all 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
20 changes: 11 additions & 9 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,13 @@ impl<'open> Window<'open> {
with_title_bar,
} = self;

let frame = frame.unwrap_or_else(|| Frame::window(&ctx.style()));
let header_color =
frame.map_or_else(|| ctx.style().visuals.widgets.open.weak_bg_fill, |f| f.fill);
let window_frame = frame.unwrap_or_else(|| Frame::window(&ctx.style()));

let is_explicitly_closed = matches!(open, Some(false));
let is_open = !is_explicitly_closed || ctx.memory(|mem| mem.everything_is_visible());
area.show_open_close_animation(ctx, &frame, is_open);
area.show_open_close_animation(ctx, &window_frame, is_open);

if !is_open {
return None;
Expand All @@ -419,7 +421,7 @@ impl<'open> Window<'open> {
// Calculate roughly how much larger the window size is compared to the inner rect
let (title_bar_height, title_content_spacing) = if with_title_bar {
let style = ctx.style();
let window_margin = style.spacing.window_margin;
let window_margin = window_frame.inner_margin;
let spacing = window_margin.top + window_margin.bottom;
let height = ctx.fonts(|f| title.font_height(f, &style)) + spacing;
(height, spacing)
Expand All @@ -438,8 +440,8 @@ impl<'open> Window<'open> {
last_frame_outer_rect,
)
.and_then(|window_interaction| {
let margins = frame.outer_margin.sum()
+ frame.inner_margin.sum()
let margins = window_frame.outer_margin.sum()
+ window_frame.inner_margin.sum()
+ vec2(0.0, title_bar_height);

interact(
Expand All @@ -460,8 +462,8 @@ impl<'open> Window<'open> {

let content_inner = {
// BEGIN FRAME --------------------------------
let frame_stroke = frame.stroke;
let mut frame = frame.begin(&mut area_content_ui);
let frame_stroke = window_frame.stroke;
let mut frame = window_frame.begin(&mut area_content_ui);

let show_close_button = open.is_some();

Expand Down Expand Up @@ -518,12 +520,12 @@ impl<'open> Window<'open> {
y: title_bar_height,
},
);
let mut round = area_content_ui.visuals().window_rounding;

let mut round = window_frame.rounding;
if !is_collapsed {
round.se = 0.0;
round.sw = 0.0;
}
let header_color = area_content_ui.visuals().widgets.open.weak_bg_fill;

area_content_ui.painter().set(
*where_to_put_header_background,
Expand Down
Loading