Skip to content

Commit

Permalink
Merge pull request CleverRaven#72797 from katemonster33/imgui_popup_bugs
Browse files Browse the repository at this point in the history
Fixing ImGui popup size issue, and small input bug
  • Loading branch information
Maleclypse authored Apr 3, 2024
2 parents 0e3ed4b + e3443bc commit dee02e4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 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
15 changes: 6 additions & 9 deletions src/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class query_popup_impl : public cataimgui::window
short keyboard_selected_option;

explicit query_popup_impl( query_popup *parent ) : cataimgui::window( "QUERY_POPUP",
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar ) {
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_AlwaysAutoResize ) {
msg_width = 400;
this->parent = parent;
keyboard_selected_option = 0;
Expand All @@ -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 Expand Up @@ -588,10 +581,14 @@ query_popup::result query_popup::query_once_imgui()
} else if( res.action == "LEFT" ) {
if( impl->keyboard_selected_option > 0 ) {
impl->keyboard_selected_option--;
} else {
impl->keyboard_selected_option = short( buttons.size() - 1 );
}
} else if( res.action == "RIGHT" ) {
if( impl->keyboard_selected_option < short( buttons.size() - 1 ) ) {
impl->keyboard_selected_option++;
} else {
impl->keyboard_selected_option = 0;
}
} else if( res.action == "HELP_KEYBINDINGS" ) {
// Keybindings may have changed, regenerate the UI
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 dee02e4

Please sign in to comment.