From 856ee17ed8f73023701cb9642bfe02902be1777a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 2 Jan 2018 16:20:51 -0800 Subject: [PATCH 1/5] Fixed Android clang warning. --- imgui_draw.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 3de85da86..c7232af8f 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -42,7 +42,9 @@ #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it. #pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness // +#if __has_warning("-Wcomma") #pragma clang diagnostic ignored "-Wcomma" // warning : possible misuse of comma operator here // +#endif #if __has_warning("-Wreserved-id-macro") #pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier // #endif From 04b44398eb2602d40c5688c1f092b7340bf30f82 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 12:12:41 +0100 Subject: [PATCH 2/5] Internals: refactored g.SetNextWindow fields into g.NextWindow. structure (so it can be more easily transported/copied) --- imgui.cpp | 116 +++++++++++++++++++++++------------------------ imgui_internal.h | 69 +++++++++++++++------------- 2 files changed, 95 insertions(+), 90 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2b6b699a7..1e257e0da 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2632,8 +2632,8 @@ void ImGui::Shutdown() g.FontStack.clear(); g.OpenPopupStack.clear(); g.CurrentPopupStack.clear(); - g.SetNextWindowSizeConstraintCallback = NULL; - g.SetNextWindowSizeConstraintCallbackUserData = NULL; + g.NextWindow.SizeConstraintCallback = NULL; + g.NextWindow.SizeConstraintCallbackUserData = NULL; for (int i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) g.RenderDrawLists[i].clear(); g.OverlayDrawList.ClearFreeMemory(); @@ -3820,8 +3820,8 @@ static inline void ClearSetNextWindowData() { // FIXME-OPT ImGuiContext& g = *GImGui; - g.SetNextWindowPosCond = g.SetNextWindowSizeCond = g.SetNextWindowContentSizeCond = g.SetNextWindowCollapsedCond = 0; - g.SetNextWindowSizeConstraint = g.SetNextWindowFocus = false; + g.NextWindow.PosCond = g.NextWindow.SizeCond = g.NextWindow.ContentSizeCond = g.NextWindow.CollapsedCond = 0; + g.NextWindow.SizeConstraint = g.NextWindow.Focus = false; } bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags) @@ -3881,7 +3881,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags ext } // Center modal windows by default - if (g.SetNextWindowPosCond == 0) + if (g.NextWindow.PosCond == 0) SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoSavedSettings; @@ -4193,20 +4193,20 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size) { ImGuiContext& g = *GImGui; - if (g.SetNextWindowSizeConstraint) + if (g.NextWindow.SizeConstraint) { // Using -1,-1 on either X/Y axis to preserve the current size. - ImRect cr = g.SetNextWindowSizeConstraintRect; + ImRect cr = g.NextWindow.SizeConstraintRect; new_size.x = (cr.Min.x >= 0 && cr.Max.x >= 0) ? ImClamp(new_size.x, cr.Min.x, cr.Max.x) : window->SizeFull.x; new_size.y = (cr.Min.y >= 0 && cr.Max.y >= 0) ? ImClamp(new_size.y, cr.Min.y, cr.Max.y) : window->SizeFull.y; - if (g.SetNextWindowSizeConstraintCallback) + if (g.NextWindow.SizeConstraintCallback) { ImGuiSizeConstraintCallbackData data; - data.UserData = g.SetNextWindowSizeConstraintCallbackUserData; + data.UserData = g.NextWindow.SizeConstraintCallbackUserData; data.Pos = window->Pos; data.CurrentSize = window->SizeFull; data.DesiredSize = new_size; - g.SetNextWindowSizeConstraintCallback(&data); + g.NextWindow.SizeConstraintCallback(&data); new_size = data.DesiredSize; } } @@ -4352,7 +4352,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) ImGuiWindow* window = FindWindowByName(name); if (!window) { - ImVec2 size_on_first_use = (g.SetNextWindowSizeCond != 0) ? g.SetNextWindowSizeVal : ImVec2(0.0f, 0.0f); // Any condition flag will do since we are creating a new window here. + ImVec2 size_on_first_use = (g.NextWindow.SizeCond != 0) ? g.NextWindow.SizeVal : ImVec2(0.0f, 0.0f); // Any condition flag will do since we are creating a new window here. window = CreateNewWindow(name, size_on_first_use, flags); } @@ -4397,50 +4397,50 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Process SetNextWindow***() calls bool window_pos_set_by_api = false; bool window_size_x_set_by_api = false, window_size_y_set_by_api = false; - if (g.SetNextWindowPosCond) + if (g.NextWindow.PosCond) { - window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.SetNextWindowPosCond) != 0; - if (window_pos_set_by_api && ImLengthSqr(g.SetNextWindowPosPivot) > 0.00001f) + window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.NextWindow.PosCond) != 0; + if (window_pos_set_by_api && ImLengthSqr(g.NextWindow.PosPivotVal) > 0.00001f) { // May be processed on the next frame if this is our first frame and we are measuring size // FIXME: Look into removing the branch so everything can go through this same code path for consistency. - window->SetWindowPosVal = g.SetNextWindowPosVal; - window->SetWindowPosPivot = g.SetNextWindowPosPivot; + window->SetWindowPosVal = g.NextWindow.PosVal; + window->SetWindowPosPivot = g.NextWindow.PosPivotVal; window->SetWindowPosAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); } else { - SetWindowPos(window, g.SetNextWindowPosVal, g.SetNextWindowPosCond); + SetWindowPos(window, g.NextWindow.PosVal, g.NextWindow.PosCond); } - g.SetNextWindowPosCond = 0; + g.NextWindow.PosCond = 0; } - if (g.SetNextWindowSizeCond) + if (g.NextWindow.SizeCond) { - window_size_x_set_by_api = (window->SetWindowSizeAllowFlags & g.SetNextWindowSizeCond) != 0 && (g.SetNextWindowSizeVal.x > 0.0f); - window_size_y_set_by_api = (window->SetWindowSizeAllowFlags & g.SetNextWindowSizeCond) != 0 && (g.SetNextWindowSizeVal.y > 0.0f); - SetWindowSize(window, g.SetNextWindowSizeVal, g.SetNextWindowSizeCond); - g.SetNextWindowSizeCond = 0; + window_size_x_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindow.SizeCond) != 0 && (g.NextWindow.SizeVal.x > 0.0f); + window_size_y_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindow.SizeCond) != 0 && (g.NextWindow.SizeVal.y > 0.0f); + SetWindowSize(window, g.NextWindow.SizeVal, g.NextWindow.SizeCond); + g.NextWindow.SizeCond = 0; } - if (g.SetNextWindowContentSizeCond) + if (g.NextWindow.ContentSizeCond) { // Adjust passed "client size" to become a "window size" - window->SizeContentsExplicit = g.SetNextWindowContentSizeVal; + window->SizeContentsExplicit = g.NextWindow.ContentSizeVal; window->SizeContentsExplicit.y += window->TitleBarHeight() + window->MenuBarHeight(); - g.SetNextWindowContentSizeCond = 0; + g.NextWindow.ContentSizeCond = 0; } else if (first_begin_of_the_frame) { window->SizeContentsExplicit = ImVec2(0.0f, 0.0f); } - if (g.SetNextWindowCollapsedCond) + if (g.NextWindow.CollapsedCond) { - SetWindowCollapsed(window, g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond); - g.SetNextWindowCollapsedCond = 0; + SetWindowCollapsed(window, g.NextWindow.CollapsedVal, g.NextWindow.CollapsedCond); + g.NextWindow.CollapsedCond = 0; } - if (g.SetNextWindowFocus) + if (g.NextWindow.Focus) { SetWindowFocus(); - g.SetNextWindowFocus = false; + g.NextWindow.Focus = false; } if (window->Appearing) SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, false); @@ -4940,7 +4940,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->WriteAccessed = false; window->BeginCount++; - g.SetNextWindowSizeConstraint = false; + g.NextWindow.SizeConstraint = false; // Child window can be out of sight and have "negative" clip windows. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar). @@ -5702,45 +5702,45 @@ void ImGui::SetWindowFocus(const char* name) void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiCond cond, const ImVec2& pivot) { ImGuiContext& g = *GImGui; - g.SetNextWindowPosVal = pos; - g.SetNextWindowPosPivot = pivot; - g.SetNextWindowPosCond = cond ? cond : ImGuiCond_Always; + g.NextWindow.PosVal = pos; + g.NextWindow.PosPivotVal = pivot; + g.NextWindow.PosCond = cond ? cond : ImGuiCond_Always; } void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond) { ImGuiContext& g = *GImGui; - g.SetNextWindowSizeVal = size; - g.SetNextWindowSizeCond = cond ? cond : ImGuiCond_Always; + g.NextWindow.SizeVal = size; + g.NextWindow.SizeCond = cond ? cond : ImGuiCond_Always; } void ImGui::SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback, void* custom_callback_user_data) { ImGuiContext& g = *GImGui; - g.SetNextWindowSizeConstraint = true; - g.SetNextWindowSizeConstraintRect = ImRect(size_min, size_max); - g.SetNextWindowSizeConstraintCallback = custom_callback; - g.SetNextWindowSizeConstraintCallbackUserData = custom_callback_user_data; + g.NextWindow.SizeConstraint = true; + g.NextWindow.SizeConstraintRect = ImRect(size_min, size_max); + g.NextWindow.SizeConstraintCallback = custom_callback; + g.NextWindow.SizeConstraintCallbackUserData = custom_callback_user_data; } void ImGui::SetNextWindowContentSize(const ImVec2& size) { ImGuiContext& g = *GImGui; - g.SetNextWindowContentSizeVal = size; // In Begin() we will add the size of window decorations (title bar, menu etc.) to that to form a SizeContents value. - g.SetNextWindowContentSizeCond = ImGuiCond_Always; + g.NextWindow.ContentSizeVal = size; // In Begin() we will add the size of window decorations (title bar, menu etc.) to that to form a SizeContents value. + g.NextWindow.ContentSizeCond = ImGuiCond_Always; } void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiCond cond) { ImGuiContext& g = *GImGui; - g.SetNextWindowCollapsedVal = collapsed; - g.SetNextWindowCollapsedCond = cond ? cond : ImGuiCond_Always; + g.NextWindow.CollapsedVal = collapsed; + g.NextWindow.CollapsedCond = cond ? cond : ImGuiCond_Always; } void ImGui::SetNextWindowFocus() { ImGuiContext& g = *GImGui; - g.SetNextWindowFocus = true; + g.NextWindow.Focus = true; } // In window space (not screen space!) @@ -6615,11 +6615,11 @@ bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) ImGuiStorage* storage = window->DC.StateStorage; bool is_open; - if (g.SetNextTreeNodeOpenCond != 0) + if (g.NextTreeNodeOpenCond != 0) { - if (g.SetNextTreeNodeOpenCond & ImGuiCond_Always) + if (g.NextTreeNodeOpenCond & ImGuiCond_Always) { - is_open = g.SetNextTreeNodeOpenVal; + is_open = g.NextTreeNodeOpenVal; storage->SetInt(id, is_open); } else @@ -6628,7 +6628,7 @@ bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) const int stored_value = storage->GetInt(id, -1); if (stored_value == -1) { - is_open = g.SetNextTreeNodeOpenVal; + is_open = g.NextTreeNodeOpenVal; storage->SetInt(id, is_open); } else @@ -6636,7 +6636,7 @@ bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) is_open = stored_value != 0; } } - g.SetNextTreeNodeOpenCond = 0; + g.NextTreeNodeOpenCond = 0; } else { @@ -6903,8 +6903,8 @@ void ImGui::SetNextTreeNodeOpen(bool is_open, ImGuiCond cond) ImGuiContext& g = *GImGui; if (g.CurrentWindow->SkipItems) return; - g.SetNextTreeNodeOpenVal = is_open; - g.SetNextTreeNodeOpenCond = cond ? cond : ImGuiCond_Always; + g.NextTreeNodeOpenVal = is_open; + g.NextTreeNodeOpenCond = cond ? cond : ImGuiCond_Always; } void ImGui::PushID(const char* str_id) @@ -9163,8 +9163,8 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF { // Always consume the SetNextWindowSizeConstraint() call in our early return paths ImGuiContext& g = *GImGui; - bool backup_has_next_window_size_constraint = g.SetNextWindowSizeConstraint; - g.SetNextWindowSizeConstraint = false; + bool backup_has_next_window_size_constraint = g.NextWindow.SizeConstraint; + g.NextWindow.SizeConstraint = false; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -9206,8 +9206,8 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF if (backup_has_next_window_size_constraint) { - g.SetNextWindowSizeConstraint = true; - g.SetNextWindowSizeConstraintRect.Min.x = ImMax(g.SetNextWindowSizeConstraintRect.Min.x, w); + g.NextWindow.SizeConstraint = true; + g.NextWindow.SizeConstraintRect.Min.x = ImMax(g.NextWindow.SizeConstraintRect.Min.x, w); } else { @@ -9269,7 +9269,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi items_getter(data, *current_item, &preview_text); // The old Combo() API exposed "popup_max_height_in_items", however the new more general BeginCombo() API doesn't, so we emulate it here. - if (popup_max_height_in_items != -1 && !g.SetNextWindowSizeConstraint) + if (popup_max_height_in_items != -1 && !g.NextWindow.SizeConstraint) { float popup_max_height = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items); SetNextWindowSizeConstraints(ImVec2(0,0), ImVec2(FLT_MAX, popup_max_height)); diff --git a/imgui_internal.h b/imgui_internal.h index 7f538adec..7877e3ffe 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -459,6 +459,38 @@ struct ImDrawListSharedData ImDrawListSharedData(); }; +// Storage for SetNexWindow** functions +struct ImGuiNextWindowData +{ + ImGuiCond PosCond; + ImGuiCond SizeCond; + ImGuiCond ContentSizeCond; + ImGuiCond CollapsedCond; + ImVec2 PosVal; + ImVec2 PosPivotVal; + ImVec2 SizeVal; + ImVec2 ContentSizeVal; + bool CollapsedVal; + ImRect SizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true + ImGuiSizeConstraintCallback SizeConstraintCallback; + void* SizeConstraintCallbackUserData; + bool SizeConstraint; + bool Focus; + + ImGuiNextWindowData() + { + PosCond = SizeCond = ContentSizeCond = CollapsedCond = 0; + PosVal = PosPivotVal = SizeVal = ImVec2(0.0f, 0.0f); + ContentSizeVal = ImVec2(0.0f, 0.0f); + CollapsedVal = false; + SizeConstraintRect = ImRect(); + SizeConstraintCallback = NULL; + SizeConstraintCallbackUserData = NULL; + SizeConstraint = false; + Focus = false; + } +}; + // Main state for ImGui struct ImGuiContext { @@ -502,24 +534,9 @@ struct ImGuiContext ImVector FontStack; // Stack for PushFont()/PopFont() ImVector OpenPopupStack; // Which popups are open (persistent) ImVector CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame) - - // Storage for SetNexWindow** and SetNextTreeNode*** functions - ImVec2 SetNextWindowPosVal; - ImVec2 SetNextWindowPosPivot; - ImVec2 SetNextWindowSizeVal; - ImVec2 SetNextWindowContentSizeVal; - bool SetNextWindowCollapsedVal; - ImGuiCond SetNextWindowPosCond; - ImGuiCond SetNextWindowSizeCond; - ImGuiCond SetNextWindowContentSizeCond; - ImGuiCond SetNextWindowCollapsedCond; - ImRect SetNextWindowSizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true - ImGuiSizeConstraintCallback SetNextWindowSizeConstraintCallback; - void* SetNextWindowSizeConstraintCallbackUserData; - bool SetNextWindowSizeConstraint; - bool SetNextWindowFocus; - bool SetNextTreeNodeOpenVal; - ImGuiCond SetNextTreeNodeOpenCond; + ImGuiNextWindowData NextWindow; // Storage for SetNextWindow** functions + bool NextTreeNodeOpenVal; // Storage for SetNextTreeNode** functions + ImGuiCond NextTreeNodeOpenCond; // Render ImDrawData RenderDrawData; // Main ImDrawData instance to pass render information to the user @@ -609,20 +626,8 @@ struct ImGuiContext MovingWindow = NULL; MovingWindowMoveId = 0; - SetNextWindowPosVal = ImVec2(0.0f, 0.0f); - SetNextWindowSizeVal = ImVec2(0.0f, 0.0f); - SetNextWindowCollapsedVal = false; - SetNextWindowPosCond = 0; - SetNextWindowSizeCond = 0; - SetNextWindowContentSizeCond = 0; - SetNextWindowCollapsedCond = 0; - SetNextWindowSizeConstraintRect = ImRect(); - SetNextWindowSizeConstraintCallback = NULL; - SetNextWindowSizeConstraintCallbackUserData = NULL; - SetNextWindowSizeConstraint = false; - SetNextWindowFocus = false; - SetNextTreeNodeOpenVal = false; - SetNextTreeNodeOpenCond = 0; + NextTreeNodeOpenVal = false; + NextTreeNodeOpenCond = 0; DragDropActive = false; DragDropSourceFlags = 0; From e339949de1c01f3eb2f2d4815f5e8f0f44287229 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 12:22:02 +0100 Subject: [PATCH 3/5] Internals: NextWindow: Using ImGuiCond for consistency. --- imgui.cpp | 25 ++++++++++++------------- imgui_internal.h | 8 +++----- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1e257e0da..b303170e5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3820,8 +3820,7 @@ static inline void ClearSetNextWindowData() { // FIXME-OPT ImGuiContext& g = *GImGui; - g.NextWindow.PosCond = g.NextWindow.SizeCond = g.NextWindow.ContentSizeCond = g.NextWindow.CollapsedCond = 0; - g.NextWindow.SizeConstraint = g.NextWindow.Focus = false; + g.NextWindow.PosCond = g.NextWindow.SizeCond = g.NextWindow.ContentSizeCond = g.NextWindow.CollapsedCond = g.NextWindow.SizeConstraintCond = g.NextWindow.FocusCond = 0; } bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags) @@ -4193,7 +4192,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size) { ImGuiContext& g = *GImGui; - if (g.NextWindow.SizeConstraint) + if (g.NextWindow.SizeConstraintCond != 0) { // Using -1,-1 on either X/Y axis to preserve the current size. ImRect cr = g.NextWindow.SizeConstraintRect; @@ -4437,10 +4436,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) SetWindowCollapsed(window, g.NextWindow.CollapsedVal, g.NextWindow.CollapsedCond); g.NextWindow.CollapsedCond = 0; } - if (g.NextWindow.Focus) + if (g.NextWindow.FocusCond) { SetWindowFocus(); - g.NextWindow.Focus = false; + g.NextWindow.FocusCond = 0; } if (window->Appearing) SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, false); @@ -4940,7 +4939,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->WriteAccessed = false; window->BeginCount++; - g.NextWindow.SizeConstraint = false; + g.NextWindow.SizeConstraintCond = 0; // Child window can be out of sight and have "negative" clip windows. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar). @@ -5717,7 +5716,7 @@ void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond) void ImGui::SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback, void* custom_callback_user_data) { ImGuiContext& g = *GImGui; - g.NextWindow.SizeConstraint = true; + g.NextWindow.SizeConstraintCond = ImGuiCond_Always; g.NextWindow.SizeConstraintRect = ImRect(size_min, size_max); g.NextWindow.SizeConstraintCallback = custom_callback; g.NextWindow.SizeConstraintCallbackUserData = custom_callback_user_data; @@ -5740,7 +5739,7 @@ void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiCond cond) void ImGui::SetNextWindowFocus() { ImGuiContext& g = *GImGui; - g.NextWindow.Focus = true; + g.NextWindow.FocusCond = ImGuiCond_Always; } // In window space (not screen space!) @@ -9163,8 +9162,8 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF { // Always consume the SetNextWindowSizeConstraint() call in our early return paths ImGuiContext& g = *GImGui; - bool backup_has_next_window_size_constraint = g.NextWindow.SizeConstraint; - g.NextWindow.SizeConstraint = false; + ImGuiCond backup_next_window_size_constraint = g.NextWindow.SizeConstraintCond; + g.NextWindow.SizeConstraintCond = 0; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -9204,9 +9203,9 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF if (!popup_open) return false; - if (backup_has_next_window_size_constraint) + if (backup_next_window_size_constraint) { - g.NextWindow.SizeConstraint = true; + g.NextWindow.SizeConstraintCond = backup_next_window_size_constraint; g.NextWindow.SizeConstraintRect.Min.x = ImMax(g.NextWindow.SizeConstraintRect.Min.x, w); } else @@ -9269,7 +9268,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi items_getter(data, *current_item, &preview_text); // The old Combo() API exposed "popup_max_height_in_items", however the new more general BeginCombo() API doesn't, so we emulate it here. - if (popup_max_height_in_items != -1 && !g.NextWindow.SizeConstraint) + if (popup_max_height_in_items != -1 && !g.NextWindow.SizeConstraintCond) { float popup_max_height = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items); SetNextWindowSizeConstraints(ImVec2(0,0), ImVec2(FLT_MAX, popup_max_height)); diff --git a/imgui_internal.h b/imgui_internal.h index 7877e3ffe..f66e99eb2 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -466,6 +466,8 @@ struct ImGuiNextWindowData ImGuiCond SizeCond; ImGuiCond ContentSizeCond; ImGuiCond CollapsedCond; + ImGuiCond SizeConstraintCond; + ImGuiCond FocusCond; ImVec2 PosVal; ImVec2 PosPivotVal; ImVec2 SizeVal; @@ -474,20 +476,16 @@ struct ImGuiNextWindowData ImRect SizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true ImGuiSizeConstraintCallback SizeConstraintCallback; void* SizeConstraintCallbackUserData; - bool SizeConstraint; - bool Focus; ImGuiNextWindowData() { - PosCond = SizeCond = ContentSizeCond = CollapsedCond = 0; + PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = 0; PosVal = PosPivotVal = SizeVal = ImVec2(0.0f, 0.0f); ContentSizeVal = ImVec2(0.0f, 0.0f); CollapsedVal = false; SizeConstraintRect = ImRect(); SizeConstraintCallback = NULL; SizeConstraintCallbackUserData = NULL; - SizeConstraint = false; - Focus = false; } }; From 7fcbd4550010d53ec294fc7aa239ea97f76dfdf4 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 12:28:16 +0100 Subject: [PATCH 4/5] Internals: NextWindow: Renamed, moved functions to member. --- imgui.cpp | 110 +++++++++++++++++++++-------------------------- imgui_internal.h | 7 ++- 2 files changed, 56 insertions(+), 61 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b303170e5..ae85abf06 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -642,7 +642,6 @@ static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, I static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond); static ImGuiWindow* FindHoveredWindow(ImVec2 pos); static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags); -static void ClearSetNextWindowData(); static void CheckStacksSize(ImGuiWindow* window, bool write); static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window); @@ -2632,8 +2631,6 @@ void ImGui::Shutdown() g.FontStack.clear(); g.OpenPopupStack.clear(); g.CurrentPopupStack.clear(); - g.NextWindow.SizeConstraintCallback = NULL; - g.NextWindow.SizeConstraintCallbackUserData = NULL; for (int i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) g.RenderDrawLists[i].clear(); g.OverlayDrawList.ClearFreeMemory(); @@ -3816,19 +3813,12 @@ void ImGui::CloseCurrentPopup() ClosePopupToLevel(popup_idx); } -static inline void ClearSetNextWindowData() -{ - // FIXME-OPT - ImGuiContext& g = *GImGui; - g.NextWindow.PosCond = g.NextWindow.SizeCond = g.NextWindow.ContentSizeCond = g.NextWindow.CollapsedCond = g.NextWindow.SizeConstraintCond = g.NextWindow.FocusCond = 0; -} - bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags) { ImGuiContext& g = *GImGui; if (!IsPopupOpen(id)) { - ClearSetNextWindowData(); // We behave like Begin() and need to consume those values + g.NextWindowData.Clear(); // We behave like Begin() and need to consume those values return false; } @@ -3850,7 +3840,7 @@ bool ImGui::BeginPopup(const char* str_id) ImGuiContext& g = *GImGui; if (g.OpenPopupStack.Size <= g.CurrentPopupStack.Size) // Early out for performance { - ClearSetNextWindowData(); // We behave like Begin() and need to consume those values + g.NextWindowData.Clear(); // We behave like Begin() and need to consume those values return false; } return BeginPopupEx(g.CurrentWindow->GetID(str_id), ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings); @@ -3875,12 +3865,12 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags ext const ImGuiID id = window->GetID(name); if (!IsPopupOpen(id)) { - ClearSetNextWindowData(); // We behave like Begin() and need to consume those values + g.NextWindowData.Clear(); // We behave like Begin() and need to consume those values return false; } // Center modal windows by default - if (g.NextWindow.PosCond == 0) + if (g.NextWindowData.PosCond == 0) SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoSavedSettings; @@ -4192,20 +4182,20 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size) { ImGuiContext& g = *GImGui; - if (g.NextWindow.SizeConstraintCond != 0) + if (g.NextWindowData.SizeConstraintCond != 0) { // Using -1,-1 on either X/Y axis to preserve the current size. - ImRect cr = g.NextWindow.SizeConstraintRect; + ImRect cr = g.NextWindowData.SizeConstraintRect; new_size.x = (cr.Min.x >= 0 && cr.Max.x >= 0) ? ImClamp(new_size.x, cr.Min.x, cr.Max.x) : window->SizeFull.x; new_size.y = (cr.Min.y >= 0 && cr.Max.y >= 0) ? ImClamp(new_size.y, cr.Min.y, cr.Max.y) : window->SizeFull.y; - if (g.NextWindow.SizeConstraintCallback) + if (g.NextWindowData.SizeConstraintCallback) { ImGuiSizeConstraintCallbackData data; - data.UserData = g.NextWindow.SizeConstraintCallbackUserData; + data.UserData = g.NextWindowData.SizeConstraintCallbackUserData; data.Pos = window->Pos; data.CurrentSize = window->SizeFull; data.DesiredSize = new_size; - g.NextWindow.SizeConstraintCallback(&data); + g.NextWindowData.SizeConstraintCallback(&data); new_size = data.DesiredSize; } } @@ -4351,7 +4341,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) ImGuiWindow* window = FindWindowByName(name); if (!window) { - ImVec2 size_on_first_use = (g.NextWindow.SizeCond != 0) ? g.NextWindow.SizeVal : ImVec2(0.0f, 0.0f); // Any condition flag will do since we are creating a new window here. + ImVec2 size_on_first_use = (g.NextWindowData.SizeCond != 0) ? g.NextWindowData.SizeVal : ImVec2(0.0f, 0.0f); // Any condition flag will do since we are creating a new window here. window = CreateNewWindow(name, size_on_first_use, flags); } @@ -4396,50 +4386,50 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Process SetNextWindow***() calls bool window_pos_set_by_api = false; bool window_size_x_set_by_api = false, window_size_y_set_by_api = false; - if (g.NextWindow.PosCond) + if (g.NextWindowData.PosCond) { - window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.NextWindow.PosCond) != 0; - if (window_pos_set_by_api && ImLengthSqr(g.NextWindow.PosPivotVal) > 0.00001f) + window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.NextWindowData.PosCond) != 0; + if (window_pos_set_by_api && ImLengthSqr(g.NextWindowData.PosPivotVal) > 0.00001f) { // May be processed on the next frame if this is our first frame and we are measuring size // FIXME: Look into removing the branch so everything can go through this same code path for consistency. - window->SetWindowPosVal = g.NextWindow.PosVal; - window->SetWindowPosPivot = g.NextWindow.PosPivotVal; + window->SetWindowPosVal = g.NextWindowData.PosVal; + window->SetWindowPosPivot = g.NextWindowData.PosPivotVal; window->SetWindowPosAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); } else { - SetWindowPos(window, g.NextWindow.PosVal, g.NextWindow.PosCond); + SetWindowPos(window, g.NextWindowData.PosVal, g.NextWindowData.PosCond); } - g.NextWindow.PosCond = 0; + g.NextWindowData.PosCond = 0; } - if (g.NextWindow.SizeCond) + if (g.NextWindowData.SizeCond) { - window_size_x_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindow.SizeCond) != 0 && (g.NextWindow.SizeVal.x > 0.0f); - window_size_y_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindow.SizeCond) != 0 && (g.NextWindow.SizeVal.y > 0.0f); - SetWindowSize(window, g.NextWindow.SizeVal, g.NextWindow.SizeCond); - g.NextWindow.SizeCond = 0; + window_size_x_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindowData.SizeCond) != 0 && (g.NextWindowData.SizeVal.x > 0.0f); + window_size_y_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindowData.SizeCond) != 0 && (g.NextWindowData.SizeVal.y > 0.0f); + SetWindowSize(window, g.NextWindowData.SizeVal, g.NextWindowData.SizeCond); + g.NextWindowData.SizeCond = 0; } - if (g.NextWindow.ContentSizeCond) + if (g.NextWindowData.ContentSizeCond) { // Adjust passed "client size" to become a "window size" - window->SizeContentsExplicit = g.NextWindow.ContentSizeVal; + window->SizeContentsExplicit = g.NextWindowData.ContentSizeVal; window->SizeContentsExplicit.y += window->TitleBarHeight() + window->MenuBarHeight(); - g.NextWindow.ContentSizeCond = 0; + g.NextWindowData.ContentSizeCond = 0; } else if (first_begin_of_the_frame) { window->SizeContentsExplicit = ImVec2(0.0f, 0.0f); } - if (g.NextWindow.CollapsedCond) + if (g.NextWindowData.CollapsedCond) { - SetWindowCollapsed(window, g.NextWindow.CollapsedVal, g.NextWindow.CollapsedCond); - g.NextWindow.CollapsedCond = 0; + SetWindowCollapsed(window, g.NextWindowData.CollapsedVal, g.NextWindowData.CollapsedCond); + g.NextWindowData.CollapsedCond = 0; } - if (g.NextWindow.FocusCond) + if (g.NextWindowData.FocusCond) { SetWindowFocus(); - g.NextWindow.FocusCond = 0; + g.NextWindowData.FocusCond = 0; } if (window->Appearing) SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, false); @@ -4939,7 +4929,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->WriteAccessed = false; window->BeginCount++; - g.NextWindow.SizeConstraintCond = 0; + g.NextWindowData.SizeConstraintCond = 0; // Child window can be out of sight and have "negative" clip windows. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar). @@ -5701,45 +5691,45 @@ void ImGui::SetWindowFocus(const char* name) void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiCond cond, const ImVec2& pivot) { ImGuiContext& g = *GImGui; - g.NextWindow.PosVal = pos; - g.NextWindow.PosPivotVal = pivot; - g.NextWindow.PosCond = cond ? cond : ImGuiCond_Always; + g.NextWindowData.PosVal = pos; + g.NextWindowData.PosPivotVal = pivot; + g.NextWindowData.PosCond = cond ? cond : ImGuiCond_Always; } void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond) { ImGuiContext& g = *GImGui; - g.NextWindow.SizeVal = size; - g.NextWindow.SizeCond = cond ? cond : ImGuiCond_Always; + g.NextWindowData.SizeVal = size; + g.NextWindowData.SizeCond = cond ? cond : ImGuiCond_Always; } void ImGui::SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback, void* custom_callback_user_data) { ImGuiContext& g = *GImGui; - g.NextWindow.SizeConstraintCond = ImGuiCond_Always; - g.NextWindow.SizeConstraintRect = ImRect(size_min, size_max); - g.NextWindow.SizeConstraintCallback = custom_callback; - g.NextWindow.SizeConstraintCallbackUserData = custom_callback_user_data; + g.NextWindowData.SizeConstraintCond = ImGuiCond_Always; + g.NextWindowData.SizeConstraintRect = ImRect(size_min, size_max); + g.NextWindowData.SizeConstraintCallback = custom_callback; + g.NextWindowData.SizeConstraintCallbackUserData = custom_callback_user_data; } void ImGui::SetNextWindowContentSize(const ImVec2& size) { ImGuiContext& g = *GImGui; - g.NextWindow.ContentSizeVal = size; // In Begin() we will add the size of window decorations (title bar, menu etc.) to that to form a SizeContents value. - g.NextWindow.ContentSizeCond = ImGuiCond_Always; + g.NextWindowData.ContentSizeVal = size; // In Begin() we will add the size of window decorations (title bar, menu etc.) to that to form a SizeContents value. + g.NextWindowData.ContentSizeCond = ImGuiCond_Always; } void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiCond cond) { ImGuiContext& g = *GImGui; - g.NextWindow.CollapsedVal = collapsed; - g.NextWindow.CollapsedCond = cond ? cond : ImGuiCond_Always; + g.NextWindowData.CollapsedVal = collapsed; + g.NextWindowData.CollapsedCond = cond ? cond : ImGuiCond_Always; } void ImGui::SetNextWindowFocus() { ImGuiContext& g = *GImGui; - g.NextWindow.FocusCond = ImGuiCond_Always; + g.NextWindowData.FocusCond = ImGuiCond_Always; } // In window space (not screen space!) @@ -9162,8 +9152,8 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF { // Always consume the SetNextWindowSizeConstraint() call in our early return paths ImGuiContext& g = *GImGui; - ImGuiCond backup_next_window_size_constraint = g.NextWindow.SizeConstraintCond; - g.NextWindow.SizeConstraintCond = 0; + ImGuiCond backup_next_window_size_constraint = g.NextWindowData.SizeConstraintCond; + g.NextWindowData.SizeConstraintCond = 0; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -9205,8 +9195,8 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF if (backup_next_window_size_constraint) { - g.NextWindow.SizeConstraintCond = backup_next_window_size_constraint; - g.NextWindow.SizeConstraintRect.Min.x = ImMax(g.NextWindow.SizeConstraintRect.Min.x, w); + g.NextWindowData.SizeConstraintCond = backup_next_window_size_constraint; + g.NextWindowData.SizeConstraintRect.Min.x = ImMax(g.NextWindowData.SizeConstraintRect.Min.x, w); } else { @@ -9268,7 +9258,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi items_getter(data, *current_item, &preview_text); // The old Combo() API exposed "popup_max_height_in_items", however the new more general BeginCombo() API doesn't, so we emulate it here. - if (popup_max_height_in_items != -1 && !g.NextWindow.SizeConstraintCond) + if (popup_max_height_in_items != -1 && !g.NextWindowData.SizeConstraintCond) { float popup_max_height = CalcMaxPopupHeightFromItemCount(popup_max_height_in_items); SetNextWindowSizeConstraints(ImVec2(0,0), ImVec2(FLT_MAX, popup_max_height)); diff --git a/imgui_internal.h b/imgui_internal.h index f66e99eb2..9faade5cc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -487,6 +487,11 @@ struct ImGuiNextWindowData SizeConstraintCallback = NULL; SizeConstraintCallbackUserData = NULL; } + + void Clear() + { + PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = 0; + } }; // Main state for ImGui @@ -532,7 +537,7 @@ struct ImGuiContext ImVector FontStack; // Stack for PushFont()/PopFont() ImVector OpenPopupStack; // Which popups are open (persistent) ImVector CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame) - ImGuiNextWindowData NextWindow; // Storage for SetNextWindow** functions + ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions bool NextTreeNodeOpenVal; // Storage for SetNextTreeNode** functions ImGuiCond NextTreeNodeOpenCond; From 3c6fbe08491418f367cb8d9a7c6215a3bb3c2f93 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 12:31:56 +0100 Subject: [PATCH 5/5] Renamed ImGuiSizeConstraintCallback to ImGuiSizeCallback, ImGuiSizeConstraintCallbackData to ImGuiSizeCallbackData. --- imgui.cpp | 15 ++++++++------- imgui.h | 8 ++++---- imgui_demo.cpp | 4 ++-- imgui_internal.h | 8 ++++---- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index ae85abf06..b616af838 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -213,6 +213,7 @@ Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code. Also read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2018/01/03 (1.54) - renamed ImGuiSizeConstraintCallback to ImGuiSizeCallback, ImGuiSizeConstraintCallbackData to ImGuiSizeCallbackData. - 2017/12/29 (1.54) - removed CalcItemRectClosestPoint() which was weird and not really used by anyone except demo code. If you need it it's easy to replicate on your side. - 2017/12/24 (1.53) - renamed the emblematic ShowTestWindow() function to ShowDemoWindow(). Kept redirection function (will obsolete). - 2017/12/21 (1.53) - ImDrawList: renamed style.AntiAliasedShapes to style.AntiAliasedFill for consistency and as a way to explicitly break code that manipulate those flag at runtime. You can now manipulate ImDrawList::Flags @@ -4188,14 +4189,14 @@ static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size) ImRect cr = g.NextWindowData.SizeConstraintRect; new_size.x = (cr.Min.x >= 0 && cr.Max.x >= 0) ? ImClamp(new_size.x, cr.Min.x, cr.Max.x) : window->SizeFull.x; new_size.y = (cr.Min.y >= 0 && cr.Max.y >= 0) ? ImClamp(new_size.y, cr.Min.y, cr.Max.y) : window->SizeFull.y; - if (g.NextWindowData.SizeConstraintCallback) + if (g.NextWindowData.SizeCallback) { - ImGuiSizeConstraintCallbackData data; - data.UserData = g.NextWindowData.SizeConstraintCallbackUserData; + ImGuiSizeCallbackData data; + data.UserData = g.NextWindowData.SizeCallbackUserData; data.Pos = window->Pos; data.CurrentSize = window->SizeFull; data.DesiredSize = new_size; - g.NextWindowData.SizeConstraintCallback(&data); + g.NextWindowData.SizeCallback(&data); new_size = data.DesiredSize; } } @@ -5703,13 +5704,13 @@ void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond) g.NextWindowData.SizeCond = cond ? cond : ImGuiCond_Always; } -void ImGui::SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback, void* custom_callback_user_data) +void ImGui::SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeCallback custom_callback, void* custom_callback_user_data) { ImGuiContext& g = *GImGui; g.NextWindowData.SizeConstraintCond = ImGuiCond_Always; g.NextWindowData.SizeConstraintRect = ImRect(size_min, size_max); - g.NextWindowData.SizeConstraintCallback = custom_callback; - g.NextWindowData.SizeConstraintCallbackUserData = custom_callback_user_data; + g.NextWindowData.SizeCallback = custom_callback; + g.NextWindowData.SizeCallbackUserData = custom_callback_user_data; } void ImGui::SetNextWindowContentSize(const ImVec2& size) diff --git a/imgui.h b/imgui.h index a8dd3435b..4e9b2e797 100644 --- a/imgui.h +++ b/imgui.h @@ -64,7 +64,7 @@ struct ImGuiStyle; // Runtime data for styling/colors struct ImGuiTextFilter; // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" struct ImGuiTextBuffer; // Text buffer for logging/accumulating text struct ImGuiTextEditCallbackData; // Shared state of ImGui::InputText() when using custom ImGuiTextEditCallback (rare/advanced use) -struct ImGuiSizeConstraintCallbackData;// Structure used to constraint window size in custom ways when using custom ImGuiSizeConstraintCallback (rare/advanced use) +struct ImGuiSizeCallbackData; // Structure used to constraint window size in custom ways when using custom ImGuiSizeCallback (rare/advanced use) struct ImGuiListClipper; // Helper to manually clip large list of items struct ImGuiPayload; // User data payload for drag and drop operations struct ImGuiContext; // ImGui context (opaque) @@ -92,7 +92,7 @@ typedef int ImGuiSelectableFlags; // flags: for Selectable() typedef int ImGuiTreeNodeFlags; // flags: for TreeNode*(),CollapsingHeader()// enum ImGuiTreeNodeFlags_ typedef int ImGuiWindowFlags; // flags: for Begin*() // enum ImGuiWindowFlags_ typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data); -typedef void (*ImGuiSizeConstraintCallback)(ImGuiSizeConstraintCallbackData* data); +typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data); #if defined(_MSC_VER) && !defined(__clang__) typedef unsigned __int64 ImU64; // 64-bit unsigned integer #else @@ -167,7 +167,7 @@ namespace ImGui IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiCond cond = 0, const ImVec2& pivot = ImVec2(0,0)); // set next window position. call before Begin(). use pivot=(0.5f,0.5f) to center on given point, etc. IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiCond cond = 0); // set next window size. set axis to 0.0f to force an auto-fit on this axis. call before Begin() - IMGUI_API void SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeConstraintCallback custom_callback = NULL, void* custom_callback_data = NULL); // set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Use callback to apply non-trivial programmatic constraints. + IMGUI_API void SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeCallback custom_callback = NULL, void* custom_callback_data = NULL); // set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Use callback to apply non-trivial programmatic constraints. IMGUI_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (~ enforce the range of scrollbars). not including window decorations (title bar, menu bar, etc.). set an axis to 0.0f to leave it automatic. call before Begin() IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin() IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most. call before Begin() @@ -1218,7 +1218,7 @@ struct ImGuiTextEditCallbackData // Resizing callback data to apply custom constraint. As enabled by SetNextWindowSizeConstraints(). Callback is called during the next Begin(). // NB: For basic min/max size constraint on each axis you don't need to use the callback! The SetNextWindowSizeConstraints() parameters are enough. -struct ImGuiSizeConstraintCallbackData +struct ImGuiSizeCallbackData { void* UserData; // Read-only. What user passed to SetNextWindowSizeConstraints() ImVec2 Pos; // Read-only. Window position, for reference. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c9d47d4df..4a5c32dec 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2303,8 +2303,8 @@ static void ShowExampleAppConstrainedResize(bool* p_open) { struct CustomConstraints // Helper functions to demonstrate programmatic constraints { - static void Square(ImGuiSizeConstraintCallbackData* data) { data->DesiredSize = ImVec2(IM_MAX(data->DesiredSize.x, data->DesiredSize.y), IM_MAX(data->DesiredSize.x, data->DesiredSize.y)); } - static void Step(ImGuiSizeConstraintCallbackData* data) { float step = (float)(int)(intptr_t)data->UserData; data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); } + static void Square(ImGuiSizeCallbackData* data) { data->DesiredSize = ImVec2(IM_MAX(data->DesiredSize.x, data->DesiredSize.y), IM_MAX(data->DesiredSize.x, data->DesiredSize.y)); } + static void Step(ImGuiSizeCallbackData* data) { float step = (float)(int)(intptr_t)data->UserData; data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); } }; static bool auto_resize = false; diff --git a/imgui_internal.h b/imgui_internal.h index 9faade5cc..8481f3ac0 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -474,8 +474,8 @@ struct ImGuiNextWindowData ImVec2 ContentSizeVal; bool CollapsedVal; ImRect SizeConstraintRect; // Valid if 'SetNextWindowSizeConstraint' is true - ImGuiSizeConstraintCallback SizeConstraintCallback; - void* SizeConstraintCallbackUserData; + ImGuiSizeCallback SizeCallback; + void* SizeCallbackUserData; ImGuiNextWindowData() { @@ -484,8 +484,8 @@ struct ImGuiNextWindowData ContentSizeVal = ImVec2(0.0f, 0.0f); CollapsedVal = false; SizeConstraintRect = ImRect(); - SizeConstraintCallback = NULL; - SizeConstraintCallbackUserData = NULL; + SizeCallback = NULL; + SizeCallbackUserData = NULL; } void Clear()