@@ -416,14 +416,15 @@ impl<'open> Window<'open> {
416
416
let on_top = Some ( area_layer_id) == ctx. top_layer_id ( ) ;
417
417
let mut area = area. begin ( ctx) ;
418
418
419
- let title_content_spacing = 2.0 * ctx. style ( ) . spacing . item_spacing . y ;
420
-
421
419
// Calculate roughly how much larger the window size is compared to the inner rect
422
- let title_bar_height = if with_title_bar {
420
+ let ( title_bar_height, title_content_spacing ) = if with_title_bar {
423
421
let style = ctx. style ( ) ;
424
- ctx. fonts ( |f| title. font_height ( f, & style) ) + title_content_spacing * 2.0
422
+ let window_margin = style. spacing . window_margin ;
423
+ let spacing = window_margin. top + window_margin. bottom ;
424
+ let height = ctx. fonts ( |f| title. font_height ( f, & style) ) + spacing;
425
+ ( height, spacing)
425
426
} else {
426
- 0.0
427
+ ( 0.0 , 0.0 )
427
428
} ;
428
429
429
430
// First interact (move etc) to avoid frame delay:
@@ -466,6 +467,11 @@ impl<'open> Window<'open> {
466
467
467
468
let where_to_put_header_background = & area_content_ui. painter ( ) . add ( Shape :: Noop ) ;
468
469
470
+ // Backup item spacing before the title bar
471
+ let item_spacing = frame. content_ui . spacing ( ) . item_spacing ;
472
+ // Use title bar spacing as the item spacing before the content
473
+ frame. content_ui . spacing_mut ( ) . item_spacing . y = title_content_spacing;
474
+
469
475
let title_bar = if with_title_bar {
470
476
let title_bar = show_title_bar (
471
477
& mut frame. content_ui ,
@@ -480,13 +486,15 @@ impl<'open> Window<'open> {
480
486
None
481
487
} ;
482
488
483
- let ( content_inner, content_response) = collapsing
489
+ // Remove item spacing after the title bar
490
+ frame. content_ui . spacing_mut ( ) . item_spacing . y = 0.0 ;
491
+
492
+ let ( content_inner, mut content_response) = collapsing
484
493
. show_body_unindented ( & mut frame. content_ui , |ui| {
485
- resize. show ( ui, |ui| {
486
- if title_bar. is_some ( ) {
487
- ui. add_space ( title_content_spacing) ;
488
- }
494
+ // Restore item spacing for the content
495
+ ui. spacing_mut ( ) . item_spacing . y = item_spacing. y ;
489
496
497
+ resize. show ( ui, |ui| {
490
498
if scroll. is_any_scroll_enabled ( ) {
491
499
scroll. show ( ui, add_contents) . inner
492
500
} else {
@@ -523,6 +531,11 @@ impl<'open> Window<'open> {
523
531
) ;
524
532
} ;
525
533
534
+ // Fix title bar separator line position
535
+ if let Some ( response) = & mut content_response {
536
+ response. rect . min . y = outer_rect. min . y + title_bar_height;
537
+ }
538
+
526
539
title_bar. ui (
527
540
& mut area_content_ui,
528
541
outer_rect,
@@ -1026,7 +1039,7 @@ impl TitleBar {
1026
1039
1027
1040
if let Some ( content_response) = & content_response {
1028
1041
// paint separator between title and content:
1029
- let y = content_response. rect . top ( ) + ui . spacing ( ) . item_spacing . y * 0.5 ;
1042
+ let y = content_response. rect . top ( ) ;
1030
1043
// let y = lerp(self.rect.bottom()..=content_response.rect.top(), 0.5);
1031
1044
let stroke = ui. visuals ( ) . widgets . noninteractive . bg_stroke ;
1032
1045
ui. painter ( ) . hline ( outer_rect. x_range ( ) , y, stroke) ;
0 commit comments