Skip to content

Commit

Permalink
Fixing the issue where the wrong ImGui window can end up in the front.
Browse files Browse the repository at this point in the history
  • Loading branch information
katemonster33 committed Feb 16, 2024
1 parent 7513513 commit 5acbf0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ cataimgui::window::window( int window_flags )
p_impl = nullptr;

this->window_flags = window_flags | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNavFocus;
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNavFocus |
ImGuiWindowFlags_NoBringToFrontOnFocus;
}

cataimgui::window::window( const std::string &id_, int window_flags ) : window( window_flags )
Expand Down Expand Up @@ -414,7 +415,7 @@ void cataimgui::window::draw()
// we want to make sure is_resized is able to be handled for at least a full frame
handled_resize = true;
}
if( cached_bounds.x == -1 || cached_bounds.y == -1 ) {
if( cached_bounds.x == -1 || cached_bounds.y == -1 ) {
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
if( cached_bounds.x != -1.f ) {
center.x = cached_bounds.x;
Expand All @@ -429,8 +430,11 @@ void cataimgui::window::draw()
if( cached_bounds.h > 0 || cached_bounds.w > 0 ) {
ImGui::SetNextWindowSize( { cached_bounds.w, cached_bounds.h } );
}
if( ImGui::Begin( id.c_str(), &is_open, window_flags ) ) {
if( ImGui::Begin( id.c_str(), &is_open, window_flags) ) {
draw_controls();
if( p_impl->window_adaptor->is_on_top ) {
ImGui::BringWindowToDisplayFront( ImGui::GetCurrentWindow() );
}
}
ImGui::End();
if( handled_resize ) {
Expand Down
6 changes: 2 additions & 4 deletions src/ui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,11 @@ void ui_adaptor::redraw_invalidated( )
ui_stack_orig = &*ui_stack_copy;
}
std::optional<point> cursor_pos;
auto top_ui = std::prev( ui_stack_orig->end() );
for( auto it = first_enabled; !restart_redrawing && it != ui_stack_orig->end(); ++it ) {
ui_adaptor &ui = *it;
ui.is_on_top = it == top_ui;
if( ui.invalidated || ui.is_imgui ) {
if( ui.redraw_cb ) {
ui.redraw_cb( ui );
}
} else if( ui.invalidated ) {
if( ui.redraw_cb ) {
ui.default_cursor();
ui.redraw_cb( ui );
Expand Down
1 change: 1 addition & 0 deletions src/ui_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ui_adaptor
{
public:
bool is_imgui;
bool is_on_top;
using redraw_callback_t = std::function<void( ui_adaptor & )>;
using screen_resize_callback_t = std::function<void( ui_adaptor & )>;

Expand Down

0 comments on commit 5acbf0b

Please sign in to comment.