Shutdown: Unlock font atlas before destroying context, so we can destroy a context between NewFrame and EndFrame if we wait (facilitate main loop structures). Internals: GetWindowScrollMaxX(), GetWindowScrollMaxY()

This commit is contained in:
omar 2018-10-11 17:11:27 +02:00
parent cf0afb48ac
commit ed4dcd9072
2 changed files with 12 additions and 7 deletions

View File

@ -3290,7 +3290,10 @@ void ImGui::Shutdown(ImGuiContext* context)
// The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame) // The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame)
ImGuiContext& g = *context; ImGuiContext& g = *context;
if (g.IO.Fonts && g.FontAtlasOwnedByContext) if (g.IO.Fonts && g.FontAtlasOwnedByContext)
{
g.IO.Fonts->Locked = false;
IM_DELETE(g.IO.Fonts); IM_DELETE(g.IO.Fonts);
}
g.IO.Fonts = NULL; g.IO.Fonts = NULL;
// Cleanup of other data are conditional on actually having initialized ImGui. // Cleanup of other data are conditional on actually having initialized ImGui.
@ -4309,12 +4312,12 @@ ImVec2 ImGui::CalcWindowExpectedSize(ImGuiWindow* window)
return CalcSizeAfterConstraint(window, CalcSizeAutoFit(window, size_contents)); return CalcSizeAfterConstraint(window, CalcSizeAutoFit(window, size_contents));
} }
static float GetScrollMaxX(ImGuiWindow* window) float ImGui::GetWindowScrollMaxX(ImGuiWindow* window)
{ {
return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x)); return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x));
} }
static float GetScrollMaxY(ImGuiWindow* window) float ImGui::GetWindowScrollMaxY(ImGuiWindow* window)
{ {
return ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y)); return ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y));
} }
@ -4342,8 +4345,8 @@ static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window, bool s
scroll = ImMax(scroll, ImVec2(0.0f, 0.0f)); scroll = ImMax(scroll, ImVec2(0.0f, 0.0f));
if (!window->Collapsed && !window->SkipItems) if (!window->Collapsed && !window->SkipItems)
{ {
scroll.x = ImMin(scroll.x, GetScrollMaxX(window)); scroll.x = ImMin(scroll.x, ImGui::GetWindowScrollMaxX(window));
scroll.y = ImMin(scroll.y, GetScrollMaxY(window)); scroll.y = ImMin(scroll.y, ImGui::GetWindowScrollMaxY(window));
} }
return scroll; return scroll;
} }
@ -6009,12 +6012,12 @@ float ImGui::GetScrollY()
float ImGui::GetScrollMaxX() float ImGui::GetScrollMaxX()
{ {
return GetScrollMaxX(GImGui->CurrentWindow); return GetWindowScrollMaxX(GImGui->CurrentWindow);
} }
float ImGui::GetScrollMaxY() float ImGui::GetScrollMaxY()
{ {
return GetScrollMaxY(GImGui->CurrentWindow); return GetWindowScrollMaxY(GImGui->CurrentWindow);
} }
void ImGui::SetScrollX(float scroll_x) void ImGui::SetScrollX(float scroll_x)
@ -8918,7 +8921,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
(flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "", (flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "",
(flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "", (flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "",
(flags & ImGuiWindowFlags_NoInputs) ? "NoInputs":"", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : ""); (flags & ImGuiWindowFlags_NoInputs) ? "NoInputs":"", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : "");
ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetScrollMaxX(window), window->Scroll.y, GetScrollMaxY(window)); ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetWindowScrollMaxX(window), window->Scroll.y, GetWindowScrollMaxY(window));
ImGui::BulletText("Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d", window->Active, window->WasActive, window->WriteAccessed, (window->Active || window->WasActive) ? window->BeginOrderWithinContext : -1); ImGui::BulletText("Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d", window->Active, window->WasActive, window->WriteAccessed, (window->Active || window->WasActive) ? window->BeginOrderWithinContext : -1);
ImGui::BulletText("Appearing: %d, Hidden: %d (Reg %d Resize %d), SkipItems: %d", window->Appearing, window->Hidden, window->HiddenFramesRegular, window->HiddenFramesForResize, window->SkipItems); ImGui::BulletText("Appearing: %d, Hidden: %d (Reg %d Resize %d), SkipItems: %d", window->Appearing, window->Hidden, window->HiddenFramesRegular, window->HiddenFramesForResize, window->SkipItems);
ImGui::BulletText("NavLastIds: 0x%08X,0x%08X, NavLayerActiveMask: %X", window->NavLastIds[0], window->NavLastIds[1], window->DC.NavLayerActiveMask); ImGui::BulletText("NavLastIds: 0x%08X,0x%08X, NavLayerActiveMask: %X", window->NavLastIds[0], window->NavLastIds[1], window->DC.NavLayerActiveMask);

View File

@ -1125,6 +1125,8 @@ namespace ImGui
IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window); IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window);
IMGUI_API void SetWindowScrollX(ImGuiWindow* window, float new_scroll_x); IMGUI_API void SetWindowScrollX(ImGuiWindow* window, float new_scroll_x);
IMGUI_API void SetWindowScrollY(ImGuiWindow* window, float new_scroll_y); IMGUI_API void SetWindowScrollY(ImGuiWindow* window, float new_scroll_y);
IMGUI_API float GetWindowScrollMaxX(ImGuiWindow* window);
IMGUI_API float GetWindowScrollMaxY(ImGuiWindow* window);
IMGUI_API ImRect GetWindowAllowedExtentRect(ImGuiWindow* window); IMGUI_API ImRect GetWindowAllowedExtentRect(ImGuiWindow* window);
IMGUI_API void SetCurrentFont(ImFont* font); IMGUI_API void SetCurrentFont(ImFont* font);
inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; } inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; }