From 963259d128c9d8b1f0b9dcdbc07d32cb64c0a1f5 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Nov 2017 19:20:50 +0100 Subject: [PATCH 01/14] Settings: Internals: Renamed ImGuiSettingsWindow to ImGuiWindowSettings. --- imgui.cpp | 22 +++++++++++----------- imgui_internal.h | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 91de2d97..f77a5b2e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -643,8 +643,8 @@ static void AddDrawListToRenderList(ImVector& out_rende static void AddWindowToRenderList(ImVector& out_render_list, ImGuiWindow* window); static void AddWindowToSortedBuffer(ImVector& out_sorted_windows, ImGuiWindow* window); -static ImGuiSettingsWindow* FindWindowSettings(const char* name); -static ImGuiSettingsWindow* AddWindowSettings(const char* name); +static ImGuiWindowSettings* FindWindowSettings(const char* name); +static ImGuiWindowSettings* AddWindowSettings(const char* name); static void LoadIniSettingsFromDisk(const char* ini_filename); static void LoadIniSettingsFromMemory(const char* buf); @@ -2473,7 +2473,7 @@ void ImGui::NewFrame() static void* SettingsHandlerWindow_ReadOpenEntry(ImGuiContext&, const char* name) { - ImGuiSettingsWindow* settings = FindWindowSettings(name); + ImGuiWindowSettings* settings = FindWindowSettings(name); if (!settings) settings = AddWindowSettings(name); return (void*)settings; @@ -2481,7 +2481,7 @@ static void* SettingsHandlerWindow_ReadOpenEntry(ImGuiContext&, const char* name static void SettingsHandlerWindow_ReadLine(ImGuiContext&, void* entry, const char* line) { - ImGuiSettingsWindow* settings = (ImGuiSettingsWindow*)entry; + ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry; float x, y; int i; if (sscanf(line, "Pos=%f,%f", &x, &y) == 2) settings->Pos = ImVec2(x, y); @@ -2497,7 +2497,7 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext& g, ImGuiTextBuffer* buf ImGuiWindow* window = g.Windows[i]; if (window->Flags & ImGuiWindowFlags_NoSavedSettings) continue; - ImGuiSettingsWindow* settings = FindWindowSettings(window->Name); + ImGuiWindowSettings* settings = FindWindowSettings(window->Name); if (!settings) // This will only return NULL in the rare instance where the window was first created with ImGuiWindowFlags_NoSavedSettings then had the flag disabled later on. We don't bind settings in this case (bug #1000). continue; settings->Pos = window->Pos; @@ -2510,7 +2510,7 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext& g, ImGuiTextBuffer* buf buf->reserve(buf->size() + g.SettingsWindows.Size * 96); // ballpark reserve for (int i = 0; i != g.SettingsWindows.Size; i++) { - const ImGuiSettingsWindow* settings = &g.SettingsWindows[i]; + const ImGuiWindowSettings* settings = &g.SettingsWindows[i]; if (settings->Pos.x == FLT_MAX) continue; const char* name = settings->Name; @@ -2609,24 +2609,24 @@ void ImGui::Shutdown() g.Initialized = false; } -static ImGuiSettingsWindow* FindWindowSettings(const char* name) +static ImGuiWindowSettings* FindWindowSettings(const char* name) { ImGuiContext& g = *GImGui; ImGuiID id = ImHash(name, 0); for (int i = 0; i != g.SettingsWindows.Size; i++) { - ImGuiSettingsWindow* ini = &g.SettingsWindows[i]; + ImGuiWindowSettings* ini = &g.SettingsWindows[i]; if (ini->Id == id) return ini; } return NULL; } -static ImGuiSettingsWindow* AddWindowSettings(const char* name) +static ImGuiWindowSettings* AddWindowSettings(const char* name) { ImGuiContext& g = *GImGui; g.SettingsWindows.resize(g.SettingsWindows.Size + 1); - ImGuiSettingsWindow* settings = &g.SettingsWindows.back(); + ImGuiWindowSettings* settings = &g.SettingsWindows.back(); settings->Name = ImStrdup(name); settings->Id = ImHash(name, 0); settings->Collapsed = false; @@ -4078,7 +4078,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl window->PosFloat = ImVec2(60, 60); window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - ImGuiSettingsWindow* settings = FindWindowSettings(name); + ImGuiWindowSettings* settings = FindWindowSettings(name); if (!settings) settings = AddWindowSettings(name); else diff --git a/imgui_internal.h b/imgui_internal.h index 249dff85..84ad3e00 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -38,10 +38,10 @@ struct ImGuiGroupData; struct ImGuiSimpleColumns; struct ImGuiDrawContext; struct ImGuiTextEditState; -struct ImGuiSettingsWindow; struct ImGuiMouseCursorData; struct ImGuiPopupRef; struct ImGuiWindow; +struct ImGuiWindowSettings; typedef int ImGuiLayoutType; // enum: horizontal or vertical // enum ImGuiLayoutType_ typedef int ImGuiButtonFlags; // flags: for ButtonEx(), ButtonBehavior() // enum ImGuiButtonFlags_ @@ -371,7 +371,7 @@ struct IMGUI_API ImGuiTextEditState }; // Data saved in imgui.ini file -struct ImGuiSettingsWindow +struct ImGuiWindowSettings { char* Name; ImGuiID Id; @@ -379,7 +379,7 @@ struct ImGuiSettingsWindow ImVec2 Size; bool Collapsed; - ImGuiSettingsWindow() { Name = NULL; Id = 0; Pos = Size = ImVec2(0,0); Collapsed = false; } + ImGuiWindowSettings() { Name = NULL; Id = 0; Pos = Size = ImVec2(0,0); Collapsed = false; } }; struct ImGuiSettingsHandler @@ -500,7 +500,7 @@ struct ImGuiContext // Settings float SettingsDirtyTimer; // Save .ini Settings on disk when time reaches zero - ImVector SettingsWindows; // .ini settings for ImGuiWindow + ImVector SettingsWindows; // .ini settings for ImGuiWindow ImVector SettingsHandlers; // List of .ini settings handlers // Logging From 35eb5c5c998d1f55f2f3c23365f9228fd188d82a Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Nov 2017 19:25:16 +0100 Subject: [PATCH 02/14] Settings: Internals: Exposed FindWindowSettings(). Simplified some code. --- imgui.cpp | 21 +++++++-------------- imgui_internal.h | 3 ++- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index f77a5b2e..a7773291 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -643,7 +643,6 @@ static void AddDrawListToRenderList(ImVector& out_rende static void AddWindowToRenderList(ImVector& out_render_list, ImGuiWindow* window); static void AddWindowToSortedBuffer(ImVector& out_sorted_windows, ImGuiWindow* window); -static ImGuiWindowSettings* FindWindowSettings(const char* name); static ImGuiWindowSettings* AddWindowSettings(const char* name); static void LoadIniSettingsFromDisk(const char* ini_filename); @@ -2473,7 +2472,7 @@ void ImGui::NewFrame() static void* SettingsHandlerWindow_ReadOpenEntry(ImGuiContext&, const char* name) { - ImGuiWindowSettings* settings = FindWindowSettings(name); + ImGuiWindowSettings* settings = ImGui::FindWindowSettings(ImHash(name, 0)); if (!settings) settings = AddWindowSettings(name); return (void*)settings; @@ -2497,7 +2496,7 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext& g, ImGuiTextBuffer* buf ImGuiWindow* window = g.Windows[i]; if (window->Flags & ImGuiWindowFlags_NoSavedSettings) continue; - ImGuiWindowSettings* settings = FindWindowSettings(window->Name); + ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); if (!settings) // This will only return NULL in the rare instance where the window was first created with ImGuiWindowFlags_NoSavedSettings then had the flag disabled later on. We don't bind settings in this case (bug #1000). continue; settings->Pos = window->Pos; @@ -2609,29 +2608,23 @@ void ImGui::Shutdown() g.Initialized = false; } -static ImGuiWindowSettings* FindWindowSettings(const char* name) +ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id) { ImGuiContext& g = *GImGui; - ImGuiID id = ImHash(name, 0); for (int i = 0; i != g.SettingsWindows.Size; i++) - { - ImGuiWindowSettings* ini = &g.SettingsWindows[i]; - if (ini->Id == id) - return ini; - } + if (g.SettingsWindows[i].Id == id) + return &g.SettingsWindows[i]; return NULL; } static ImGuiWindowSettings* AddWindowSettings(const char* name) { ImGuiContext& g = *GImGui; - g.SettingsWindows.resize(g.SettingsWindows.Size + 1); + g.SettingsWindows.push_back(ImGuiWindowSettings()); ImGuiWindowSettings* settings = &g.SettingsWindows.back(); settings->Name = ImStrdup(name); settings->Id = ImHash(name, 0); - settings->Collapsed = false; settings->Pos = ImVec2(FLT_MAX,FLT_MAX); - settings->Size = ImVec2(0,0); return settings; } @@ -4078,7 +4071,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl window->PosFloat = ImVec2(60, 60); window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - ImGuiWindowSettings* settings = FindWindowSettings(name); + ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); if (!settings) settings = AddWindowSettings(name); else diff --git a/imgui_internal.h b/imgui_internal.h index 84ad3e00..23e99f16 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -803,7 +803,8 @@ namespace ImGui IMGUI_API void Initialize(); - IMGUI_API void MarkIniSettingsDirty(); + IMGUI_API void MarkIniSettingsDirty(); + IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); IMGUI_API void ClearActiveID(); From 7ae71e4984bf5aed6ca17f933ff1a1e0c8428d35 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Nov 2017 20:03:10 +0100 Subject: [PATCH 03/14] Settings: Internals: Added FindSettingsHandler() --- imgui.cpp | 14 ++++++++++---- imgui_internal.h | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a7773291..97048752 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2639,6 +2639,15 @@ static void LoadIniSettingsFromDisk(const char* ini_filename) ImGui::MemFree(file_data); } +ImGuiSettingsHandler* ImGui::FindSettingsHandler(ImGuiID type_hash) +{ + ImGuiContext& g = *GImGui; + for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++) + if (g.SettingsHandlers[handler_n].TypeHash == type_hash) + return &g.SettingsHandlers[handler_n]; + return NULL; +} + // Zero-tolerance, no error reporting, cheap .ini parsing static void LoadIniSettingsFromMemory(const char* buf_readonly) { @@ -2680,10 +2689,7 @@ static void LoadIniSettingsFromMemory(const char* buf_readonly) name_start++; // Skip second '[' } const ImGuiID type_hash = ImHash(type_start, 0, 0); - entry_handler = NULL; - for (int handler_n = 0; handler_n < g.SettingsHandlers.Size && entry_handler == NULL; handler_n++) - if (g.SettingsHandlers[handler_n].TypeHash == type_hash) - entry_handler = &g.SettingsHandlers[handler_n]; + entry_handler = ImGui::FindSettingsHandler(type_hash); entry_data = entry_handler ? entry_handler->ReadOpenEntryFn(g, name_start) : NULL; } else if (entry_handler != NULL && entry_data != NULL) diff --git a/imgui_internal.h b/imgui_internal.h index 23e99f16..1528bdd9 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -803,8 +803,9 @@ namespace ImGui IMGUI_API void Initialize(); - IMGUI_API void MarkIniSettingsDirty(); - IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); + IMGUI_API void MarkIniSettingsDirty(); + IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(ImGuiID type_id); + IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); IMGUI_API void ClearActiveID(); From 2e1013a0c62f949a16082cfc9a2a2750fc38d506 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Nov 2017 21:04:13 +0100 Subject: [PATCH 04/14] Settings: Internals: Simplifying code a bit. Creating Settings structure during first save. Windows where ImGuiWindowFlags_NoSavedSettings was late toggled will save settings correctly. (#1000) --- imgui.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 97048752..1f237646 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2497,8 +2497,8 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext& g, ImGuiTextBuffer* buf if (window->Flags & ImGuiWindowFlags_NoSavedSettings) continue; ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); - if (!settings) // This will only return NULL in the rare instance where the window was first created with ImGuiWindowFlags_NoSavedSettings then had the flag disabled later on. We don't bind settings in this case (bug #1000). - continue; + if (!settings) + settings = AddWindowSettings(window->Name); settings->Pos = window->Pos; settings->Size = window->SizeFull; settings->Collapsed = window->Collapsed; @@ -2624,7 +2624,6 @@ static ImGuiWindowSettings* AddWindowSettings(const char* name) ImGuiWindowSettings* settings = &g.SettingsWindows.back(); settings->Name = ImStrdup(name); settings->Id = ImHash(name, 0); - settings->Pos = ImVec2(FLT_MAX,FLT_MAX); return settings; } @@ -4077,21 +4076,15 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl window->PosFloat = ImVec2(60, 60); window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); - if (!settings) - settings = AddWindowSettings(name); - else - SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); - - if (settings->Pos.x != FLT_MAX) + if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID)) { + SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); window->PosFloat = settings->Pos; window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); window->Collapsed = settings->Collapsed; + if (ImLengthSqr(settings->Size) > 0.00001f) + size = settings->Size; } - - if (ImLengthSqr(settings->Size) > 0.00001f) - size = settings->Size; window->Size = window->SizeFull = size; } From 52e475230f7abcfb79a2a90f4954da1976223615 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Nov 2017 22:51:07 +0100 Subject: [PATCH 05/14] Settings: Internals: Renaming. --- imgui.cpp | 6 +++--- imgui_internal.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1f237646..e8668779 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2470,7 +2470,7 @@ void ImGui::NewFrame() ImGui::Begin("Debug##Default"); } -static void* SettingsHandlerWindow_ReadOpenEntry(ImGuiContext&, const char* name) +static void* SettingsHandlerWindow_ReadOpen(ImGuiContext&, const char* name) { ImGuiWindowSettings* settings = ImGui::FindWindowSettings(ImHash(name, 0)); if (!settings) @@ -2533,7 +2533,7 @@ void ImGui::Initialize() ImGuiSettingsHandler ini_handler; ini_handler.TypeName = "Window"; ini_handler.TypeHash = ImHash("Window", 0, 0); - ini_handler.ReadOpenEntryFn = SettingsHandlerWindow_ReadOpenEntry; + ini_handler.ReadOpenFn = SettingsHandlerWindow_ReadOpen; ini_handler.ReadLineFn = SettingsHandlerWindow_ReadLine; ini_handler.WriteAllFn = SettingsHandlerWindow_WriteAll; g.SettingsHandlers.push_front(ini_handler); @@ -2689,7 +2689,7 @@ static void LoadIniSettingsFromMemory(const char* buf_readonly) } const ImGuiID type_hash = ImHash(type_start, 0, 0); entry_handler = ImGui::FindSettingsHandler(type_hash); - entry_data = entry_handler ? entry_handler->ReadOpenEntryFn(g, name_start) : NULL; + entry_data = entry_handler ? entry_handler->ReadOpenFn(g, name_start) : NULL; } else if (entry_handler != NULL && entry_data != NULL) { diff --git a/imgui_internal.h b/imgui_internal.h index 1528bdd9..80d18ac5 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -386,7 +386,7 @@ struct ImGuiSettingsHandler { const char* TypeName; // Short description stored in .ini file. Disallowed characters: '[' ']' ImGuiID TypeHash; // == ImHash(TypeName, 0, 0) - void* (*ReadOpenEntryFn)(ImGuiContext& ctx, const char* name); + void* (*ReadOpenFn)(ImGuiContext& ctx, const char* name); void (*ReadLineFn)(ImGuiContext& ctx, void* entry, const char* line); void (*WriteAllFn)(ImGuiContext& ctx, ImGuiTextBuffer* out_buf); }; From 25c159fac8c36411395871b7c41c2cd4cdd562fa Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 29 Nov 2017 21:10:59 +0100 Subject: [PATCH 06/14] Internals: Removed unnecessary duplicate scrolling code + added extra infos to Metrics window. --- imgui.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e8668779..84bde0c4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4162,6 +4162,16 @@ static ImVec2 CalcSizeAutoFit(ImGuiWindow* window) return size_auto_fit; } +static float GetScrollMaxX(ImGuiWindow* window) +{ + return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x)); +} + +static float GetScrollMaxY(ImGuiWindow* window) +{ + return ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y)); +} + static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window) { ImVec2 scroll = window->Scroll; @@ -4174,8 +4184,8 @@ static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window) scroll = ImMax(scroll, ImVec2(0.0f, 0.0f)); if (!window->Collapsed && !window->SkipItems) { - scroll.x = ImMin(scroll.x, ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x))); // == GetScrollMaxX for that window - scroll.y = ImMin(scroll.y, ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y))); // == GetScrollMaxY for that window + scroll.x = ImMin(scroll.x, GetScrollMaxX(window)); + scroll.y = ImMin(scroll.y, GetScrollMaxY(window)); } return scroll; } @@ -5671,14 +5681,12 @@ float ImGui::GetScrollY() float ImGui::GetScrollMaxX() { - ImGuiWindow* window = GetCurrentWindowRead(); - return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x)); + return GetScrollMaxX(GImGui->CurrentWindow); } float ImGui::GetScrollMaxY() { - ImGuiWindow* window = GetCurrentWindowRead(); - return ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y)); + return GetScrollMaxY(GImGui->CurrentWindow); } void ImGui::SetScrollX(float scroll_x) @@ -11039,7 +11047,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), SizeContents (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->SizeContents.x, window->SizeContents.y); if (ImGui::IsItemHovered()) GImGui->OverlayDrawList.AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255,255,0,255)); - ImGui::BulletText("Scroll: (%.2f,%.2f)", window->Scroll.x, window->Scroll.y); + ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetScrollMaxX(window), window->Scroll.y, GetScrollMaxY(window)); ImGui::BulletText("Active: %d, WriteAccessed: %d", window->Active, window->WriteAccessed); if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow"); if (window->DC.ChildWindows.Size > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows"); From a20fe279c5b022a2df2510081b1f32605d9f4dce Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 29 Nov 2017 23:33:31 +0100 Subject: [PATCH 07/14] Demo: Layout: Removed unnecessary BeginChild/EndChild calls --- imgui_demo.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 30a4ce46..a2522621 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2807,11 +2807,9 @@ static void ShowExampleAppLayout(bool* p_open) ImGui::Separator(); ImGui::TextWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); ImGui::EndChild(); - ImGui::BeginChild("buttons"); if (ImGui::Button("Revert")) {} ImGui::SameLine(); if (ImGui::Button("Save")) {} - ImGui::EndChild(); ImGui::EndGroup(); } ImGui::End(); From c36e586cce1279b419ab4b443ca6ce63b03ce7cc Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 29 Nov 2017 23:39:23 +0100 Subject: [PATCH 08/14] Style, Scrolling: Fixed padding and scrolling asymetry where lower/right sides of a window wouldn't use WindowPadding properly + causing minor scrolling glitches. --- imgui.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 84bde0c4..08f4ec25 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1983,7 +1983,7 @@ void ImGui::ItemSize(const ImVec2& size, float text_offset_y) window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y); window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y)); window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); - window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); + window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y); //if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG] window->DC.PrevLineHeight = line_height; @@ -4146,18 +4146,17 @@ static ImVec2 CalcSizeAutoFit(ImGuiWindow* window) if ((flags & ImGuiWindowFlags_Tooltip) != 0) { // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose. - size_auto_fit = window->SizeContents + window->WindowPadding - ImVec2(0.0f, style.ItemSpacing.y); + size_auto_fit = window->SizeContents; } else { // Handling case of auto fit window not fitting on the screen (on either axis): we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than DisplaySize-WindowPadding. - size_auto_fit = ImClamp(window->SizeContents + window->WindowPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - g.Style.DisplaySafeAreaPadding)); + size_auto_fit = ImClamp(window->SizeContents, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - g.Style.DisplaySafeAreaPadding)); ImVec2 size_auto_fit_after_constraint = CalcSizeFullWithConstraint(window, size_auto_fit); if (size_auto_fit_after_constraint.x < window->SizeContents.x && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar)) size_auto_fit.y += style.ScrollbarSize; if (size_auto_fit_after_constraint.y < window->SizeContents.y && !(flags & ImGuiWindowFlags_NoScrollbar)) size_auto_fit.x += style.ScrollbarSize; - size_auto_fit.y = ImMax(size_auto_fit.y - style.ItemSpacing.y, 0.0f); } return size_auto_fit; } @@ -4364,6 +4363,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Update contents size from last frame for auto-fitting (unless explicitly specified) window->SizeContents.x = (float)(int)((window->SizeContentsExplicit.x != 0.0f) ? window->SizeContentsExplicit.x : ((window_is_new ? 0.0f : window->DC.CursorMaxPos.x - window->Pos.x) + window->Scroll.x)); window->SizeContents.y = (float)(int)((window->SizeContentsExplicit.y != 0.0f) ? window->SizeContentsExplicit.y : ((window_is_new ? 0.0f : window->DC.CursorMaxPos.y - window->Pos.y) + window->Scroll.y)); + window->SizeContents += window->WindowPadding; // Hide popup/tooltip window when first appearing while we measure size (because we recycle them) if (window->HiddenFrames > 0) @@ -4430,10 +4430,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Update scrollbar status (based on the Size that was effective during last frame or the auto-resized Size). We need to do this before manual resize (below) is effective. if (!window->Collapsed) { - window->ScrollbarY = (flags & ImGuiWindowFlags_AlwaysVerticalScrollbar) || ((window->SizeContents.y > window->SizeFull.y + style.ItemSpacing.y) && !(flags & ImGuiWindowFlags_NoScrollbar)); + window->ScrollbarY = (flags & ImGuiWindowFlags_AlwaysVerticalScrollbar) || ((window->SizeContents.y > window->SizeFull.y) && !(flags & ImGuiWindowFlags_NoScrollbar)); window->ScrollbarX = (flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar) || ((window->SizeContents.x > window->SizeFull.x - (window->ScrollbarY ? style.ScrollbarSize : 0.0f) - window->WindowPadding.x) && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar)); if (window->ScrollbarX && !window->ScrollbarY) - window->ScrollbarY = (window->SizeContents.y > window->SizeFull.y + style.ItemSpacing.y - style.ScrollbarSize) && !(flags & ImGuiWindowFlags_NoScrollbar); + window->ScrollbarY = (window->SizeContents.y > window->SizeFull.y + style.ScrollbarSize) && !(flags & ImGuiWindowFlags_NoScrollbar); window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f); } @@ -10409,7 +10409,6 @@ void ImGui::EndGroup() ImGuiGroupData& group_data = window->DC.GroupStack.back(); ImRect group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos); - group_bb.Max.y -= g.Style.ItemSpacing.y; // Cancel out last vertical spacing because we are adding one ourselves. group_bb.Max = ImMax(group_bb.Min, group_bb.Max); window->DC.CursorPos = group_data.BackupCursorPos; From b513fdce481a950cc27b90b8284eb5765922ee7b Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 29 Nov 2017 23:47:15 +0100 Subject: [PATCH 09/14] Scrolling: SetScrollFromPosY() tweak to match change in a0d53fee81084a547bf21f46e736ea89f79fffb5 with similar desirable jump/discontinuity at each limit to skip the (ItemSpacing>WindowPadding) difference (followup to 0e5b64ecd2e291eac3475e10ab8aa1fa773a3a03, #150) --- imgui.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 08f4ec25..20b0b2e8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5709,9 +5709,13 @@ void ImGui::SetScrollFromPosY(float pos_y, float center_y_ratio) ImGuiWindow* window = GetCurrentWindow(); IM_ASSERT(center_y_ratio >= 0.0f && center_y_ratio <= 1.0f); window->ScrollTarget.y = (float)(int)(pos_y + window->Scroll.y); - if (center_y_ratio <= 0.0f && window->ScrollTarget.y <= window->WindowPadding.y) // Minor hack to make "scroll to top" take account of WindowPadding, else it would scroll to (WindowPadding.y - ItemSpacing.y) - window->ScrollTarget.y = 0.0f; window->ScrollTargetCenterRatio.y = center_y_ratio; + + // Minor hack to to make scrolling to top/bottom of window take account of WindowPadding, it looks more right to the user this way + if (center_y_ratio <= 0.0f && window->ScrollTarget.y <= window->WindowPadding.y) + window->ScrollTarget.y = 0.0f; + else if (center_y_ratio >= 1.0f && window->ScrollTarget.y >= window->SizeContents.y - window->WindowPadding.y + GImGui->Style.ItemSpacing.y) + window->ScrollTarget.y = window->SizeContents.y; } // center_y_ratio: 0.0f top of last item, 0.5f vertical center of last item, 1.0f bottom of last item. From 0d53c8d4809bdfcacb0ad52d695fa257007ad4ad Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 29 Nov 2017 23:47:59 +0100 Subject: [PATCH 10/14] Demo: Console: Fixed incorrect positioning which was hidden by a minor scroll issue (this would affect people who copied the console code as is) --- imgui_demo.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index a2522621..6b0fed76 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2480,7 +2480,7 @@ struct ExampleAppConsole ImGui::PopStyleVar(); ImGui::Separator(); - ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetItemsLineHeightWithSpacing()), false, ImGuiWindowFlags_HorizontalScrollbar); + ImGui::BeginChild("ScrollingRegion", ImVec2(0, -ImGui::GetStyle().ItemSpacing.y - ImGui::GetItemsLineHeightWithSpacing()), false, ImGuiWindowFlags_HorizontalScrollbar); // Leave room for 1 separator + 1 InputText if (ImGui::BeginPopupContextWindow()) { if (ImGui::Selectable("Clear")) ClearLog(); @@ -2807,9 +2807,9 @@ static void ShowExampleAppLayout(bool* p_open) ImGui::Separator(); ImGui::TextWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); ImGui::EndChild(); - if (ImGui::Button("Revert")) {} - ImGui::SameLine(); - if (ImGui::Button("Save")) {} + if (ImGui::Button("Revert")) {} + ImGui::SameLine(); + if (ImGui::Button("Save")) {} ImGui::EndGroup(); } ImGui::End(); From aea3fe41b9a3dea659b92f50215be2b6b104bb68 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 30 Nov 2017 23:07:48 +0100 Subject: [PATCH 11/14] Style: Tweaks Dark and Light styles. (#707) --- imgui_draw.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 48101444..2c937e59 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -203,8 +203,8 @@ void ImGui::StyleColorsDark(ImGuiStyle* dst) colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); colors[ImGuiCol_Separator] = colors[ImGuiCol_Border];//ImVec4(0.61f, 0.61f, 0.61f, 1.00f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f); colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.25f); colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); @@ -230,7 +230,7 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst) //colors[ImGuiCol_TextActive] = ImVec4(1.00f, 1.00f, 0.00f, 1.00f); colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 1.00f); colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f); + colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.98f); colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.30f); colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); @@ -254,8 +254,8 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst) colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.14f, 0.44f, 0.80f, 0.78f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.14f, 0.44f, 0.80f, 1.00f); colors[ImGuiCol_ResizeGrip] = ImVec4(0.80f, 0.80f, 0.80f, 0.56f); colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); From c860a0a85cc6f5264dc1774568ea965df0ff027e Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 1 Dec 2017 17:38:25 +0100 Subject: [PATCH 12/14] Internals: ImRect: Added IsFinite() helper. --- imgui_internal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/imgui_internal.h b/imgui_internal.h index 80d18ac5..b3371f5c 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -281,6 +281,7 @@ struct IMGUI_API ImRect void Translate(const ImVec2& v) { Min.x += v.x; Min.y += v.y; Max.x += v.x; Max.y += v.y; } void ClipWith(const ImRect& clip) { if (Min.x < clip.Min.x) Min.x = clip.Min.x; if (Min.y < clip.Min.y) Min.y = clip.Min.y; if (Max.x > clip.Max.x) Max.x = clip.Max.x; if (Max.y > clip.Max.y) Max.y = clip.Max.y; } void Floor() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; } + bool IsFinite() const { return Min.x != FLT_MAX; } ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const { if (!on_edge && Contains(p)) From be6384eb2a85aaaba0b152a464b6d2d949eddee3 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 30 Nov 2017 19:06:09 +0100 Subject: [PATCH 13/14] Style: Tweaked default WindowRounding value from 9 to 7 (#707) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 20b0b2e8..f31b99d8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -707,7 +707,7 @@ ImGuiStyle::ImGuiStyle() { Alpha = 1.0f; // Global alpha applies to everything in ImGui WindowPadding = ImVec2(8,8); // Padding within a window - WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + WindowRounding = 7.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows WindowBorderSize = 0.0f; // Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested. WindowMinSize = ImVec2(32,32); // Minimum window size WindowTitleAlign = ImVec2(0.0f,0.5f);// Alignment for title bar text From 5f7cd7fb1c0793e5581e9914a39c53f327262a64 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 30 Nov 2017 18:02:42 +0100 Subject: [PATCH 14/14] Internals: Splitter Behavior doesn't show a border. (#319) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index f31b99d8..de781c5f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10343,7 +10343,7 @@ bool ImGui::SplitterBehavior(ImGuiID id, const ImRect& bb, ImGuiAxis axis, float // Render const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator); - RenderFrame(bb_render.Min, bb_render.Max, col, true, g.Style.FrameRounding); + window->DrawList->AddRectFilled(bb_render.Min, bb_render.Max, col, g.Style.FrameRounding); return held; }