1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

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)
This commit is contained in:
n4n5
2026-08-03 14:15:07 +02:00
committed by GitHub
parent eba2780dba
commit fa608a1b40

View File

@@ -84,6 +84,7 @@ pub struct Window<'a> {
open: Option<&'a mut bool>, open: Option<&'a mut bool>,
area: Area, area: Area,
frame: Option<Frame>, frame: Option<Frame>,
title_frame: Option<Frame>,
resize: Resize, resize: Resize,
scroll: ScrollArea, scroll: ScrollArea,
collapsible: bool, collapsible: bool,
@@ -106,6 +107,7 @@ impl<'a> Window<'a> {
open: None, open: None,
area, area,
frame: None, frame: None,
title_frame: None,
resize: Resize::default() resize: Resize::default()
.with_stroke(false) .with_stroke(false)
.min_size([96.0, 32.0]) .min_size([96.0, 32.0])
@@ -265,6 +267,13 @@ impl<'a> Window<'a> {
self 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. /// Set minimum width of the window.
#[inline] #[inline]
pub fn min_width(mut self, min_width: f32) -> Self { pub fn min_width(mut self, min_width: f32) -> Self {
@@ -549,6 +558,7 @@ impl Window<'_> {
mut open, mut open,
area, area,
frame, frame,
title_frame,
resize, resize,
scroll, scroll,
collapsible, collapsible,
@@ -616,10 +626,12 @@ impl Window<'_> {
let style = ctx.global_style(); 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)); let window_frame = frame.unwrap_or_else(|| Frame::window(&style));
// We apply the window margin by using the `ScrollArea::content_margin`. // 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 window_frame = window_frame.inner_margin(0.0);
let is_explicitly_closed = matches!(open, Some(false)); let is_explicitly_closed = matches!(open, Some(false));
@@ -711,7 +723,7 @@ impl Window<'_> {
title_ui( title_ui(
ui, ui,
title, title,
window_frame.inner_margin(window_margin), window_title_frame,
&mut collapsing, &mut collapsing,
collapsible, collapsible,
on_top, on_top,
@@ -725,12 +737,12 @@ impl Window<'_> {
.show_body_unindented(ui, |ui| { .show_body_unindented(ui, |ui| {
if scroll.is_any_scroll_enabled() { if scroll.is_any_scroll_enabled() {
scroll scroll
.content_margin(window_margin) .content_margin(window_content_margin)
.show(ui, add_contents) .show(ui, add_contents)
.inner .inner
} else { } else {
crate::Frame::NONE crate::Frame::NONE
.inner_margin(window_margin) .inner_margin(window_content_margin)
.show(ui, add_contents) .show(ui, add_contents)
.inner .inner
} }