Skip to content

Commit cb538fa

Browse files
committed
Internals: Storing settings using ImVec2ih to match what we are doing with dock node. + removed ImMax from reading Size value (done in Begin) + removed seemingly unnecessary FLT_MAX compare in SettingsHandlerWindow_WriteAll.
About: Added backquote to text copied into clipboard so it doesn't mess up with github formatting when pasted.
1 parent c4ff1b3 commit cb538fa

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

imgui.cpp

+11-14
Original file line numberDiff line numberDiff line change
@@ -4827,10 +4827,10 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
48274827
// Retrieve settings from .ini file
48284828
window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings);
48294829
SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false);
4830-
window->Pos = ImFloor(settings->Pos);
4830+
window->Pos = ImVec2(settings->Pos.x, settings->Pos.y);
48314831
window->Collapsed = settings->Collapsed;
4832-
if (ImLengthSqr(settings->Size) > 0.00001f)
4833-
size = ImFloor(settings->Size);
4832+
if (settings->Size.x > 0 && settings->Size.y > 0)
4833+
size = ImVec2(settings->Size.x, settings->Size.y);
48344834
}
48354835
window->Size = window->SizeFull = ImFloor(size);
48364836
window->DC.CursorStartPos = window->DC.CursorMaxPos = window->Pos; // So first call to CalcContentSize() doesn't return crazy values
@@ -9447,14 +9447,13 @@ static void* SettingsHandlerWindow_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*
94479447
return (void*)settings;
94489448
}
94499449

9450-
static void SettingsHandlerWindow_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler*, void* entry, const char* line)
9450+
static void SettingsHandlerWindow_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line)
94519451
{
9452-
ImGuiContext& g = *ctx;
94539452
ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry;
9454-
float x, y;
9453+
int x, y;
94559454
int i;
9456-
if (sscanf(line, "Pos=%f,%f", &x, &y) == 2) settings->Pos = ImVec2(x, y);
9457-
else if (sscanf(line, "Size=%f,%f", &x, &y) == 2) settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize);
9455+
if (sscanf(line, "Pos=%i,%i", &x, &y) == 2) settings->Pos = ImVec2ih((short)x, (short)y);
9456+
else if (sscanf(line, "Size=%i,%i", &x, &y) == 2) settings->Size = ImVec2ih((short)x, (short)y);
94589457
else if (sscanf(line, "Collapsed=%d", &i) == 1) settings->Collapsed = (i != 0);
94599458
}
94609459

@@ -9476,8 +9475,8 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
94769475
window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings);
94779476
}
94789477
IM_ASSERT(settings->ID == window->ID);
9479-
settings->Pos = window->Pos;
9480-
settings->Size = window->SizeFull;
9478+
settings->Pos = ImVec2ih((short)window->Pos.x, (short)window->Pos.y);
9479+
settings->Size = ImVec2ih((short)window->SizeFull.x, (short)window->SizeFull.y);
94819480
settings->Collapsed = window->Collapsed;
94829481
}
94839482

@@ -9486,11 +9485,9 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
94869485
for (int i = 0; i != g.SettingsWindows.Size; i++)
94879486
{
94889487
const ImGuiWindowSettings* settings = &g.SettingsWindows[i];
9489-
if (settings->Pos.x == FLT_MAX)
9490-
continue;
94919488
buf->appendf("[%s][%s]\n", handler->TypeName, settings->Name);
9492-
buf->appendf("Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
9493-
buf->appendf("Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
9489+
buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y);
9490+
buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y);
94949491
buf->appendf("Collapsed=%d\n", settings->Collapsed);
94959492
buf->appendf("\n");
94969493
}

imgui_demo.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,10 @@ void ImGui::ShowAboutWindow(bool* p_open)
29612961
bool copy_to_clipboard = ImGui::Button("Copy to clipboard");
29622962
ImGui::BeginChildFrame(ImGui::GetID("cfginfos"), ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 18), ImGuiWindowFlags_NoMove);
29632963
if (copy_to_clipboard)
2964+
{
29642965
ImGui::LogToClipboard();
2966+
ImGui::LogText("```\n"); // Back quotes will make the text appears without formatting when pasting to GitHub
2967+
}
29652968

29662969
ImGui::Text("Dear ImGui %s (%d)", IMGUI_VERSION, IMGUI_VERSION_NUM);
29672970
ImGui::Separator();
@@ -3052,7 +3055,10 @@ void ImGui::ShowAboutWindow(bool* p_open)
30523055
ImGui::Text("style.ItemInnerSpacing: %.2f,%.2f", style.ItemInnerSpacing.x, style.ItemInnerSpacing.y);
30533056

30543057
if (copy_to_clipboard)
3058+
{
3059+
ImGui::LogText("\n```\n");
30553060
ImGui::LogFinish();
3061+
}
30563062
ImGui::EndChildFrame();
30573063
}
30583064
ImGui::End();

imgui_internal.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,14 @@ struct ImVec1
528528
ImVec1(float _x) { x = _x; }
529529
};
530530

531+
// 2D vector (half-size integer)
532+
struct ImVec2ih
533+
{
534+
short x, y;
535+
ImVec2ih() { x = y = 0; }
536+
ImVec2ih(short _x, short _y) { x = _x; y = _y; }
537+
};
538+
531539
// 2D axis aligned bounding-box
532540
// NB: we can't rely on ImVec2 math operators being available here
533541
struct IMGUI_API ImRect
@@ -655,11 +663,11 @@ struct ImGuiWindowSettings
655663
{
656664
char* Name;
657665
ImGuiID ID;
658-
ImVec2 Pos;
659-
ImVec2 Size;
666+
ImVec2ih Pos;
667+
ImVec2ih Size;
660668
bool Collapsed;
661669

662-
ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2(0,0); Collapsed = false; }
670+
ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = false; }
663671
};
664672

665673
struct ImGuiSettingsHandler

0 commit comments

Comments
 (0)