From 76569d4074f5365fc5dbcc3fa80a8314de5e9d37 Mon Sep 17 00:00:00 2001 From: Katie M Date: Tue, 2 Apr 2024 15:19:28 -0400 Subject: [PATCH] Adding the ability for ui_manager to redraw all windows when an ImGui window is shown with auto-sizing enabled --- src/cata_imgui.cpp | 10 ++++++++++ src/cata_imgui.h | 1 + src/popup.cpp | 9 +-------- src/ui_manager.cpp | 6 ++++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index a090b75ff23c4..40439cb2b087e 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -266,6 +266,16 @@ void cataimgui::client::process_input( void *input ) #endif +bool cataimgui::client::auto_size_frame_active() +{ + for( const ImGuiWindow *window : GImGui->Windows ) { + if( window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0 ) { + return true; + } + } + return false; +} + static ImGuiKey cata_key_to_imgui( int cata_key ) { switch( cata_key ) { diff --git a/src/cata_imgui.h b/src/cata_imgui.h index a299e35b60c5c..9f5e2b077ad37 100644 --- a/src/cata_imgui.h +++ b/src/cata_imgui.h @@ -68,6 +68,7 @@ class client const SDL_Window_Ptr &sdl_window; const GeometryRenderer_Ptr &sdl_geometry; #endif + bool auto_size_frame_active(); }; void point_to_imvec2( point *src, ImVec2 *dest ); diff --git a/src/popup.cpp b/src/popup.cpp index b8841f0276f18..9880ba1da1ef8 100644 --- a/src/popup.cpp +++ b/src/popup.cpp @@ -38,14 +38,7 @@ class query_popup_impl : public cataimgui::window protected: void draw_controls() override; cataimgui::bounds get_bounds() override { - float height = float( str_height_to_pixels( parent->folded_msg.size() ) ) + - ( ImGui::GetStyle().ItemSpacing.y * 2 ); - if( !parent->buttons.empty() ) { - height += float( str_height_to_pixels( 1 ) ) + ( ImGui::GetStyle().ItemInnerSpacing.y * 2 ) + - ( ImGui::GetStyle().ItemSpacing.y * 2 ); - } - return { -1.f, parent->ontop ? 0 : -1.f, - float( msg_width ) + ( ImGui::GetStyle().WindowBorderSize * 2 ), height }; + return { -1.f, parent->ontop ? 0 : -1.f, -1.f, -1.f }; } }; diff --git a/src/ui_manager.cpp b/src/ui_manager.cpp index 66f9e3623f3d4..ec7cea68e0dab 100644 --- a/src/ui_manager.cpp +++ b/src/ui_manager.cpp @@ -453,6 +453,12 @@ void ui_adaptor::redraw_invalidated( ) imclient->end_frame(); imgui_frame_started = false; + + // if any ImGui window needed to calculate the size of its contents, + // it needs an extra frame to draw. We do that here. + if( imclient->auto_size_frame_active() ) { + redraw_invalidated(); + } } void ui_adaptor::screen_resized()