Skip to content

Commit

Permalink
Added IsWindowAppearing().
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Sep 1, 2017
1 parent fd684ba commit 804ee78
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
22 changes: 17 additions & 5 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@ ImGuiWindow::ImGuiWindow(const char* name)
Accessed = false;
Collapsed = false;
SkipItems = false;
Appearing = false;
BeginCount = 0;
PopupId = 0;
AutoFitFramesX = AutoFitFramesY = -1;
Expand Down Expand Up @@ -3976,13 +3977,15 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
}

const bool window_appearing_after_being_hidden = (window->HiddenFrames == 1);
window->Appearing = (!window_was_active || window_appearing_after_being_hidden);

// Process SetNextWindow***() calls
bool window_pos_set_by_api = false, window_size_set_by_api = false;
if (g.SetNextWindowPosCond)
{
const ImVec2 backup_cursor_pos = window->DC.CursorPos; // FIXME: not sure of the exact reason of this saving/restore anymore :( need to look into that.
if (!window_was_active || window_appearing_after_being_hidden) window->SetWindowPosAllowFlags |= ImGuiCond_Appearing;
if (window->Appearing)
window->SetWindowPosAllowFlags |= ImGuiCond_Appearing;
window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.SetNextWindowPosCond) != 0;
if (window_pos_set_by_api && ImLengthSqr(g.SetNextWindowPosVal - ImVec2(-FLT_MAX,-FLT_MAX)) < 0.001f)
{
Expand All @@ -3998,7 +4001,8 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
}
if (g.SetNextWindowSizeCond)
{
if (!window_was_active || window_appearing_after_being_hidden) window->SetWindowSizeAllowFlags |= ImGuiCond_Appearing;
if (window->Appearing)
window->SetWindowSizeAllowFlags |= ImGuiCond_Appearing;
window_size_set_by_api = (window->SetWindowSizeAllowFlags & g.SetNextWindowSizeCond) != 0;
SetWindowSize(window, g.SetNextWindowSizeVal, g.SetNextWindowSizeCond);
g.SetNextWindowSizeCond = 0;
Expand All @@ -4014,13 +4018,14 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
}
if (g.SetNextWindowCollapsedCond)
{
if (!window_was_active || window_appearing_after_being_hidden) window->SetWindowCollapsedAllowFlags |= ImGuiCond_Appearing;
if (window->Appearing)
window->SetWindowCollapsedAllowFlags |= ImGuiCond_Appearing;
SetWindowCollapsed(window, g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond);
g.SetNextWindowCollapsedCond = 0;
}
if (g.SetNextWindowFocus)
{
ImGui::SetWindowFocus();
SetWindowFocus();
g.SetNextWindowFocus = false;
}

Expand Down Expand Up @@ -5073,7 +5078,14 @@ void ImGui::SetWindowCollapsed(bool collapsed, ImGuiCond cond)

bool ImGui::IsWindowCollapsed()
{
return GImGui->CurrentWindow->Collapsed;
ImGuiWindow* window = GetCurrentWindowRead();
return window->Collapsed;
}

bool ImGui::IsWindowAppearing()
{
ImGuiWindow* window = GetCurrentWindowRead();
return window->Appearing;
}

void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiCond cond)
Expand Down
1 change: 1 addition & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ namespace ImGui
IMGUI_API float GetWindowWidth();
IMGUI_API float GetWindowHeight();
IMGUI_API bool IsWindowCollapsed();
IMGUI_API bool IsWindowAppearing();
IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows

IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiCond cond = 0); // set next window position. call before Begin()
Expand Down
4 changes: 2 additions & 2 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ struct IMGUI_API ImGuiWindow
bool WasActive;
bool Accessed; // Set to true when any widget access the current window
bool Collapsed; // Set when collapsing window to become only title-bar
bool SkipItems; // == Visible && !Collapsed
bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed)
bool Appearing; // Set during the frame where the window is appearing (or re-appearing)
int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs)
ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling)
int AutoFitFramesX, AutoFitFramesY;
Expand All @@ -701,7 +702,6 @@ struct IMGUI_API ImGuiWindow
ImGuiWindow* RootWindow; // Generally point to ourself. If we are a child window, this is pointing to the first non-child parent window.
ImGuiWindow* RootNonPopupWindow; // Generally point to ourself. Used to display TitleBgActive color and for selecting which window to use for NavWindowing


// Navigation / Focus
int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
Expand Down

0 comments on commit 804ee78

Please sign in to comment.