Refactor: add `TitleBar::new` in `window.rs`

This commit is contained in:
Emil Ernerfeldt 2024-07-31 18:44:05 +02:00
parent dfbc7f0d19
commit 8dc2ba2fe9
1 changed files with 54 additions and 54 deletions

View File

@ -528,7 +528,7 @@ impl<'open> Window<'open> {
frame.content_ui.spacing_mut().item_spacing.y = title_content_spacing; frame.content_ui.spacing_mut().item_spacing.y = title_content_spacing;
let title_bar = if with_title_bar { let title_bar = if with_title_bar {
let title_bar = show_title_bar( let title_bar = TitleBar::new(
&mut frame.content_ui, &mut frame.content_ui,
title, title,
show_close_button, show_close_button,
@ -1040,13 +1040,14 @@ struct TitleBar {
rect: Rect, rect: Rect,
} }
fn show_title_bar( impl TitleBar {
fn new(
ui: &mut Ui, ui: &mut Ui,
title: WidgetText, title: WidgetText,
show_close_button: bool, show_close_button: bool,
collapsing: &mut CollapsingState, collapsing: &mut CollapsingState,
collapsible: bool, collapsible: bool,
) -> TitleBar { ) -> Self {
let inner_response = ui.horizontal(|ui| { let inner_response = ui.horizontal(|ui| {
let height = ui let height = ui
.fonts(|fonts| title.font_height(fonts, ui.style())) .fonts(|fonts| title.font_height(fonts, ui.style()))
@ -1079,7 +1080,7 @@ fn show_title_bar(
let min_rect = Rect::from_min_size(ui.min_rect().min, vec2(minimum_width, height)); let min_rect = Rect::from_min_size(ui.min_rect().min, vec2(minimum_width, height));
let id = ui.advance_cursor_after_rect(min_rect); let id = ui.advance_cursor_after_rect(min_rect);
TitleBar { Self {
id, id,
title_galley, title_galley,
min_rect, min_rect,
@ -1090,10 +1091,9 @@ fn show_title_bar(
let title_bar = inner_response.inner; let title_bar = inner_response.inner;
let rect = inner_response.response.rect; let rect = inner_response.response.rect;
TitleBar { rect, ..title_bar } Self { rect, ..title_bar }
} }
impl TitleBar {
/// Finishes painting of the title bar when the window content size already known. /// Finishes painting of the title bar when the window content size already known.
/// ///
/// # Parameters /// # Parameters