mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
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.
This commit is contained in:
parent
c4ff1b3578
commit
cb538fadfe
25
imgui.cpp
25
imgui.cpp
@ -4827,10 +4827,10 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
|
||||
// Retrieve settings from .ini file
|
||||
window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings);
|
||||
SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false);
|
||||
window->Pos = ImFloor(settings->Pos);
|
||||
window->Pos = ImVec2(settings->Pos.x, settings->Pos.y);
|
||||
window->Collapsed = settings->Collapsed;
|
||||
if (ImLengthSqr(settings->Size) > 0.00001f)
|
||||
size = ImFloor(settings->Size);
|
||||
if (settings->Size.x > 0 && settings->Size.y > 0)
|
||||
size = ImVec2(settings->Size.x, settings->Size.y);
|
||||
}
|
||||
window->Size = window->SizeFull = ImFloor(size);
|
||||
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*
|
||||
return (void*)settings;
|
||||
}
|
||||
|
||||
static void SettingsHandlerWindow_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler*, void* entry, const char* line)
|
||||
static void SettingsHandlerWindow_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line)
|
||||
{
|
||||
ImGuiContext& g = *ctx;
|
||||
ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry;
|
||||
float x, y;
|
||||
int x, y;
|
||||
int i;
|
||||
if (sscanf(line, "Pos=%f,%f", &x, &y) == 2) settings->Pos = ImVec2(x, y);
|
||||
else if (sscanf(line, "Size=%f,%f", &x, &y) == 2) settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize);
|
||||
if (sscanf(line, "Pos=%i,%i", &x, &y) == 2) settings->Pos = ImVec2ih((short)x, (short)y);
|
||||
else if (sscanf(line, "Size=%i,%i", &x, &y) == 2) settings->Size = ImVec2ih((short)x, (short)y);
|
||||
else if (sscanf(line, "Collapsed=%d", &i) == 1) settings->Collapsed = (i != 0);
|
||||
}
|
||||
|
||||
@ -9476,8 +9475,8 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
|
||||
window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings);
|
||||
}
|
||||
IM_ASSERT(settings->ID == window->ID);
|
||||
settings->Pos = window->Pos;
|
||||
settings->Size = window->SizeFull;
|
||||
settings->Pos = ImVec2ih((short)window->Pos.x, (short)window->Pos.y);
|
||||
settings->Size = ImVec2ih((short)window->SizeFull.x, (short)window->SizeFull.y);
|
||||
settings->Collapsed = window->Collapsed;
|
||||
}
|
||||
|
||||
@ -9486,11 +9485,9 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
|
||||
for (int i = 0; i != g.SettingsWindows.Size; i++)
|
||||
{
|
||||
const ImGuiWindowSettings* settings = &g.SettingsWindows[i];
|
||||
if (settings->Pos.x == FLT_MAX)
|
||||
continue;
|
||||
buf->appendf("[%s][%s]\n", handler->TypeName, settings->Name);
|
||||
buf->appendf("Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
|
||||
buf->appendf("Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
|
||||
buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y);
|
||||
buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y);
|
||||
buf->appendf("Collapsed=%d\n", settings->Collapsed);
|
||||
buf->appendf("\n");
|
||||
}
|
||||
|
@ -2961,7 +2961,10 @@ void ImGui::ShowAboutWindow(bool* p_open)
|
||||
bool copy_to_clipboard = ImGui::Button("Copy to clipboard");
|
||||
ImGui::BeginChildFrame(ImGui::GetID("cfginfos"), ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 18), ImGuiWindowFlags_NoMove);
|
||||
if (copy_to_clipboard)
|
||||
{
|
||||
ImGui::LogToClipboard();
|
||||
ImGui::LogText("```\n"); // Back quotes will make the text appears without formatting when pasting to GitHub
|
||||
}
|
||||
|
||||
ImGui::Text("Dear ImGui %s (%d)", IMGUI_VERSION, IMGUI_VERSION_NUM);
|
||||
ImGui::Separator();
|
||||
@ -3052,7 +3055,10 @@ void ImGui::ShowAboutWindow(bool* p_open)
|
||||
ImGui::Text("style.ItemInnerSpacing: %.2f,%.2f", style.ItemInnerSpacing.x, style.ItemInnerSpacing.y);
|
||||
|
||||
if (copy_to_clipboard)
|
||||
{
|
||||
ImGui::LogText("\n```\n");
|
||||
ImGui::LogFinish();
|
||||
}
|
||||
ImGui::EndChildFrame();
|
||||
}
|
||||
ImGui::End();
|
||||
|
@ -528,6 +528,14 @@ struct ImVec1
|
||||
ImVec1(float _x) { x = _x; }
|
||||
};
|
||||
|
||||
// 2D vector (half-size integer)
|
||||
struct ImVec2ih
|
||||
{
|
||||
short x, y;
|
||||
ImVec2ih() { x = y = 0; }
|
||||
ImVec2ih(short _x, short _y) { x = _x; y = _y; }
|
||||
};
|
||||
|
||||
// 2D axis aligned bounding-box
|
||||
// NB: we can't rely on ImVec2 math operators being available here
|
||||
struct IMGUI_API ImRect
|
||||
@ -655,11 +663,11 @@ struct ImGuiWindowSettings
|
||||
{
|
||||
char* Name;
|
||||
ImGuiID ID;
|
||||
ImVec2 Pos;
|
||||
ImVec2 Size;
|
||||
ImVec2ih Pos;
|
||||
ImVec2ih Size;
|
||||
bool Collapsed;
|
||||
|
||||
ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2(0,0); Collapsed = false; }
|
||||
ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = false; }
|
||||
};
|
||||
|
||||
struct ImGuiSettingsHandler
|
||||
|
Loading…
Reference in New Issue
Block a user