From 43ba09531b084c0021f4414623d5822abc32a373 Mon Sep 17 00:00:00 2001 From: Konkitoman Date: Sun, 30 Jul 2023 21:49:08 +0300 Subject: [PATCH] Fix window draging --- crates/egui/src/containers/window.rs | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 4da358c2a..00be41152 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -669,7 +669,7 @@ impl<'open> Window<'open> { // END FRAME -------------------------------- if let Some(title_bar) = title_bar { - title_bar.ui( + let res = title_bar.ui( &mut area_content_ui, outer_rect, &content_response, @@ -677,6 +677,9 @@ impl<'open> Window<'open> { &mut collapsing, collapsible, ); + if res.is_pointer_button_down_on() { + ctx.viewport_command(viewport_id, ViewportCommand::Drag); + } } collapsing.store(ctx); @@ -711,18 +714,6 @@ impl<'open> Window<'open> { ); } - if ctx.input(|i| i.pointer.any_pressed()) { - if let Some(interaction) = interaction { - if !interaction.is_resize() { - ctx.viewport_command(viewport_id, ViewportCommand::Drag); - println!("Drag"); - } else { - println!("Is resize") - } - } else { - println!("No interaction") - } - } // let size = ctx.round_vec_to_pixels(full_response.rect.size()); if win_size.x < size.x { println!("Set size!"); @@ -1338,7 +1329,7 @@ impl TitleBar { open: Option<&mut bool>, collapsing: &mut CollapsingState, collapsible: bool, - ) { + ) -> Response { if let Some(content_response) = &content_response { // Now we know how large we got to be: self.rect.max.x = self.rect.max.x.max(content_response.rect.max.x); @@ -1373,13 +1364,12 @@ impl TitleBar { // Don't cover the close- and collapse buttons: let double_click_rect = self.rect.shrink2(vec2(32.0, 0.0)); - if ui - .interact(double_click_rect, self.id, Sense::click()) - .double_clicked() - && collapsible - { + let res = ui.interact(double_click_rect, self.id, Sense::click()); + + if res.double_clicked() && collapsible { collapsing.toggle(ui); } + res } /// Paints the "Close" button at the right side of the title bar