Skip to content

Commit

Permalink
Adding the ability for ui_manager to redraw all windows when an ImGui…
Browse files Browse the repository at this point in the history
… window is shown with auto-sizing enabled
  • Loading branch information
katemonster33 committed Apr 2, 2024
1 parent e53504c commit 76569d4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
1 change: 1 addition & 0 deletions src/cata_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
9 changes: 1 addition & 8 deletions src/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/ui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 76569d4

Please sign in to comment.