From fa608a1b40ec9a0683fd9c272828bc10105e164e Mon Sep 17 00:00:00 2001 From: n4n5 Date: Mon, 3 Aug 2026 14:15:07 +0200 Subject: [PATCH] Add `egui::Window::title_frame` (#8353) * [X] I have followed the instructions in the PR template Add a way to set the frame for the content and for the title of the window - `self.frame` will be used for the margins of the body - `self.title_frame` will be used for the margins of the header (title) --- crates/egui/src/containers/window.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index cf6c58f88..b39a6ec3c 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -84,6 +84,7 @@ pub struct Window<'a> { open: Option<&'a mut bool>, area: Area, frame: Option, + title_frame: Option, resize: Resize, scroll: ScrollArea, collapsible: bool, @@ -106,6 +107,7 @@ impl<'a> Window<'a> { open: None, area, frame: None, + title_frame: None, resize: Resize::default() .with_stroke(false) .min_size([96.0, 32.0]) @@ -265,6 +267,13 @@ impl<'a> Window<'a> { self } + /// Change the background color, margins, etc. of the title + #[inline] + pub fn title_frame(mut self, frame: Frame) -> Self { + self.title_frame = Some(frame); + self + } + /// Set minimum width of the window. #[inline] pub fn min_width(mut self, min_width: f32) -> Self { @@ -549,6 +558,7 @@ impl Window<'_> { mut open, area, frame, + title_frame, resize, scroll, collapsible, @@ -616,10 +626,12 @@ impl Window<'_> { let style = ctx.global_style(); + // We get or create the Frame for the title and content + let window_title_frame = title_frame.unwrap_or_else(|| Frame::window(&style)); let window_frame = frame.unwrap_or_else(|| Frame::window(&style)); // We apply the window margin by using the `ScrollArea::content_margin`. - let window_margin = window_frame.inner_margin; + let window_content_margin = window_frame.inner_margin; let window_frame = window_frame.inner_margin(0.0); let is_explicitly_closed = matches!(open, Some(false)); @@ -711,7 +723,7 @@ impl Window<'_> { title_ui( ui, title, - window_frame.inner_margin(window_margin), + window_title_frame, &mut collapsing, collapsible, on_top, @@ -725,12 +737,12 @@ impl Window<'_> { .show_body_unindented(ui, |ui| { if scroll.is_any_scroll_enabled() { scroll - .content_margin(window_margin) + .content_margin(window_content_margin) .show(ui, add_contents) .inner } else { crate::Frame::NONE - .inner_margin(window_margin) + .inner_margin(window_content_margin) .show(ui, add_contents) .inner }