mirror of
https://github.com/ocornut/imgui.git
synced 2026-08-26 17:11:53 +00:00
Merge branch 'master' into docking
# Conflicts: # imgui.cpp # imgui.h # imgui_internal.h
This commit is contained in:
82
imgui.cpp
82
imgui.cpp
@@ -102,6 +102,7 @@ CODE
|
||||
- Easy to hack and improve.
|
||||
- Minimize setup and maintenance.
|
||||
- Minimize state storage on user side.
|
||||
- Minimize state synchronization.
|
||||
- Portable, minimize dependencies, run on target (consoles, phones, etc.).
|
||||
- Efficient runtime and memory consumption.
|
||||
|
||||
@@ -392,6 +393,7 @@ CODE
|
||||
- likewise io.MousePos and GetMousePos() will use OS coordinates.
|
||||
If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos.
|
||||
|
||||
- 2022/04/05 (1.88) - inputs: renamed ImGuiKeyModFlags to ImGuiModFlags. Kept inline redirection enums (will obsolete). This was never used in public API functions but technically present in imgui.h and ImGuiIO.
|
||||
- 2022/01/20 (1.87) - inputs: reworded gamepad IO.
|
||||
- Backend writing to io.NavInputs[] -> backend should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values.
|
||||
- 2022/01/19 (1.87) - sliders, drags: removed support for legacy arithmetic operators (+,+-,*,/) when inputing text. This doesn't break any api/code but a feature that used to be accessible by end-users (which seemingly no one used).
|
||||
@@ -1286,7 +1288,7 @@ void ImGuiIO::ClearInputKeys()
|
||||
KeysData[n].DownDurationPrev = -1.0f;
|
||||
}
|
||||
KeyCtrl = KeyShift = KeyAlt = KeySuper = false;
|
||||
KeyMods = ImGuiKeyModFlags_None;
|
||||
KeyMods = ImGuiModFlags_None;
|
||||
for (int n = 0; n < IM_ARRAYSIZE(NavInputsDownDuration); n++)
|
||||
NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f;
|
||||
}
|
||||
@@ -3769,20 +3771,23 @@ void ImGui::GetAllocatorFunctions(ImGuiMemAllocFunc* p_alloc_func, ImGuiMemFreeF
|
||||
|
||||
ImGuiContext* ImGui::CreateContext(ImFontAtlas* shared_font_atlas)
|
||||
{
|
||||
ImGuiContext* prev_ctx = GetCurrentContext();
|
||||
ImGuiContext* ctx = IM_NEW(ImGuiContext)(shared_font_atlas);
|
||||
if (GImGui == NULL)
|
||||
SetCurrentContext(ctx);
|
||||
Initialize(ctx);
|
||||
SetCurrentContext(ctx);
|
||||
Initialize();
|
||||
if (prev_ctx != NULL)
|
||||
SetCurrentContext(prev_ctx); // Restore previous context if any, else keep new one.
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void ImGui::DestroyContext(ImGuiContext* ctx)
|
||||
{
|
||||
if (ctx == NULL)
|
||||
ctx = GImGui;
|
||||
Shutdown(ctx);
|
||||
if (GImGui == ctx)
|
||||
SetCurrentContext(NULL);
|
||||
ImGuiContext* prev_ctx = GetCurrentContext();
|
||||
if (ctx == NULL) //-V1051
|
||||
ctx = prev_ctx;
|
||||
SetCurrentContext(ctx);
|
||||
Shutdown();
|
||||
SetCurrentContext((prev_ctx != ctx) ? prev_ctx : NULL);
|
||||
IM_DELETE(ctx);
|
||||
}
|
||||
|
||||
@@ -4144,7 +4149,7 @@ static void ImGui::UpdateKeyboardInputs()
|
||||
#endif
|
||||
|
||||
// Synchronize io.KeyMods with individual modifiers io.KeyXXX bools
|
||||
io.KeyMods = GetMergedKeyModFlags();
|
||||
io.KeyMods = GetMergedModFlags();
|
||||
|
||||
// Clear gamepad data if disabled
|
||||
if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0)
|
||||
@@ -4400,15 +4405,16 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
|
||||
io.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false;
|
||||
}
|
||||
|
||||
ImGuiKeyModFlags ImGui::GetMergedKeyModFlags()
|
||||
// [Internal] Do not use directly (can read io.KeyMods instead)
|
||||
ImGuiModFlags ImGui::GetMergedModFlags()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiKeyModFlags key_mod_flags = ImGuiKeyModFlags_None;
|
||||
if (g.IO.KeyCtrl) { key_mod_flags |= ImGuiKeyModFlags_Ctrl; }
|
||||
if (g.IO.KeyShift) { key_mod_flags |= ImGuiKeyModFlags_Shift; }
|
||||
if (g.IO.KeyAlt) { key_mod_flags |= ImGuiKeyModFlags_Alt; }
|
||||
if (g.IO.KeySuper) { key_mod_flags |= ImGuiKeyModFlags_Super; }
|
||||
return key_mod_flags;
|
||||
ImGuiModFlags key_mods = ImGuiModFlags_None;
|
||||
if (g.IO.KeyCtrl) { key_mods |= ImGuiModFlags_Ctrl; }
|
||||
if (g.IO.KeyShift) { key_mods |= ImGuiModFlags_Shift; }
|
||||
if (g.IO.KeyAlt) { key_mods |= ImGuiModFlags_Alt; }
|
||||
if (g.IO.KeySuper) { key_mods |= ImGuiModFlags_Super; }
|
||||
return key_mods;
|
||||
}
|
||||
|
||||
void ImGui::NewFrame()
|
||||
@@ -4633,9 +4639,9 @@ void ImGui::NewFrame()
|
||||
CallContextHooks(&g, ImGuiContextHookType_NewFramePost);
|
||||
}
|
||||
|
||||
void ImGui::Initialize(ImGuiContext* context)
|
||||
void ImGui::Initialize()
|
||||
{
|
||||
ImGuiContext& g = *context;
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(!g.Initialized && !g.SettingsLoaded);
|
||||
|
||||
// Add .ini handle for ImGuiWindow type
|
||||
@@ -4672,10 +4678,10 @@ void ImGui::Initialize(ImGuiContext* context)
|
||||
}
|
||||
|
||||
// This function is merely here to free heap allocations.
|
||||
void ImGui::Shutdown(ImGuiContext* context)
|
||||
void ImGui::Shutdown()
|
||||
{
|
||||
// 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 = *GImGui;
|
||||
if (g.IO.Fonts && g.FontAtlasOwnedByContext)
|
||||
{
|
||||
g.IO.Fonts->Locked = false;
|
||||
@@ -4689,18 +4695,10 @@ void ImGui::Shutdown(ImGuiContext* context)
|
||||
|
||||
// Save settings (unless we haven't attempted to load them: CreateContext/DestroyContext without a call to NewFrame shouldn't save an empty file)
|
||||
if (g.SettingsLoaded && g.IO.IniFilename != NULL)
|
||||
{
|
||||
ImGuiContext* backup_context = GImGui;
|
||||
SetCurrentContext(&g);
|
||||
SaveIniSettingsToDisk(g.IO.IniFilename);
|
||||
SetCurrentContext(backup_context);
|
||||
}
|
||||
|
||||
// Destroy platform windows
|
||||
ImGuiContext* backup_context = ImGui::GetCurrentContext();
|
||||
SetCurrentContext(context);
|
||||
DestroyPlatformWindows();
|
||||
SetCurrentContext(backup_context);
|
||||
|
||||
// Shutdown extensions
|
||||
DockContextShutdown(&g);
|
||||
@@ -8501,7 +8499,7 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
|
||||
if (key == ImGuiKey_ModShift) { io.KeyShift = keydata->Down; }
|
||||
if (key == ImGuiKey_ModAlt) { io.KeyAlt = keydata->Down; }
|
||||
if (key == ImGuiKey_ModSuper) { io.KeySuper = keydata->Down; }
|
||||
io.KeyMods = GetMergedKeyModFlags();
|
||||
io.KeyMods = GetMergedModFlags();
|
||||
}
|
||||
|
||||
// Allow legacy code using io.KeysDown[GetKeyIndex()] with new backends
|
||||
@@ -8566,9 +8564,12 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
|
||||
|
||||
// Helper function to verify ABI compatibility between caller code and compiled version of Dear ImGui.
|
||||
// Verify that the type sizes are matching between the calling file's compilation unit and imgui.cpp's compilation unit
|
||||
// If the user has inconsistent compilation settings, imgui configuration #define, packing pragma, etc. your user code
|
||||
// may see different structures than what imgui.cpp sees, which is problematic.
|
||||
// We usually require settings to be in imconfig.h to make sure that they are accessible to all compilation units involved with Dear ImGui.
|
||||
// If this triggers you have an issue:
|
||||
// - Most commonly: mismatched headers and compiled code version.
|
||||
// - Or: mismatched configuration #define, compilation settings, packing pragma etc.
|
||||
// The configuration settings mentioned in imconfig.h must be set for all compilation units involved with Dear ImGui,
|
||||
// which is way it is required you put them in your imconfig file (and not just before including imgui.h).
|
||||
// Otherwise it is possible that different compilation units would see different structure layout
|
||||
bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx)
|
||||
{
|
||||
bool error = false;
|
||||
@@ -8602,10 +8603,11 @@ static void ImGui::ErrorCheckNewFrameSanityChecks()
|
||||
IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value!");
|
||||
IM_ASSERT(g.IO.Fonts->IsBuilt() && "Font Atlas not built! Make sure you called ImGui_ImplXXXX_NewFrame() function for renderer backend, which should call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8()");
|
||||
IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!");
|
||||
IM_ASSERT(g.Style.CircleTessellationMaxError > 0.0f && "Invalid style setting!");
|
||||
IM_ASSERT(g.Style.CircleTessellationMaxError > 0.0f && "Invalid style setting!");
|
||||
IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting!"); // Allows us to avoid a few clamps in color computations
|
||||
IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting.");
|
||||
IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right);
|
||||
IM_ASSERT(g.Style.ColorButtonPosition == ImGuiDir_Left || g.Style.ColorButtonPosition == ImGuiDir_Right);
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_COUNT; n++)
|
||||
IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < ImGuiKey_LegacyNativeKey_END && "io.KeyMap[] contains an out of bound value (need to be 0..511, or -1 for unmapped key)");
|
||||
@@ -8670,11 +8672,11 @@ static void ImGui::ErrorCheckEndFrameSanityChecks()
|
||||
// send key release events mid-frame. This would normally trigger this assertion and lead to sheared inputs.
|
||||
// We silently accommodate for this case by ignoring/ the case where all io.KeyXXX modifiers were released (aka key_mod_flags == 0),
|
||||
// while still correctly asserting on mid-frame key press events.
|
||||
const ImGuiKeyModFlags key_mod_flags = GetMergedKeyModFlags();
|
||||
IM_ASSERT((key_mod_flags == 0 || g.IO.KeyMods == key_mod_flags) && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods");
|
||||
IM_UNUSED(key_mod_flags);
|
||||
const ImGuiModFlags key_mods = GetMergedModFlags();
|
||||
IM_ASSERT((key_mods == 0 || g.IO.KeyMods == key_mods) && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods");
|
||||
IM_UNUSED(key_mods);
|
||||
|
||||
// Recover from errors
|
||||
// [EXPERIMENTAL] Recover from errors: You may call this yourself before EndFrame().
|
||||
//ErrorCheckEndFrameRecover();
|
||||
|
||||
// Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you
|
||||
@@ -8856,7 +8858,7 @@ void ImGuiStackSizes::CompareWithCurrentState()
|
||||
// - GetWindowContentRegionMin(), GetWindowContentRegionMax()
|
||||
// - BeginGroup()
|
||||
// - EndGroup()
|
||||
// Also see in imgui_widgets: tab bars, columns.
|
||||
// Also see in imgui_widgets: tab bars, and in imgui_tables: tables, columns.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Advance cursor given item size for layout.
|
||||
@@ -12612,7 +12614,7 @@ void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* view
|
||||
g.PlatformIO.Platform_OnChangedViewport(g.CurrentViewport);
|
||||
}
|
||||
|
||||
static void SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
|
||||
void ImGui::SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
|
||||
{
|
||||
// Abandon viewport
|
||||
if (window->ViewportOwned && window->Viewport->Window == window)
|
||||
|
||||
Reference in New Issue
Block a user