|
@@ -62,7 +62,6 @@ Index of this file:
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
#ifdef _MSC_VER
|
|
|
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
|
|
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
|
|
|
-#define vsnprintf _vsnprintf
|
|
|
|
|
#endif
|
|
#endif
|
|
|
#ifdef __clang__
|
|
#ifdef __clang__
|
|
|
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
|
|
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
|
|
@@ -70,6 +69,7 @@ Index of this file:
|
|
|
#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int'
|
|
#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int'
|
|
|
#pragma clang diagnostic ignored "-Wformat-security" // warning : warning: format string is not a string literal
|
|
#pragma clang diagnostic ignored "-Wformat-security" // warning : warning: format string is not a string literal
|
|
|
#pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
|
|
#pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
|
|
|
|
|
+#pragma clang diagnostic ignored "-Wunused-macros" // warning : warning: macro is not used // we define snprintf/vsnprintf on Windows so they are available, but not always used.
|
|
|
#if __has_warning("-Wzero-as-null-pointer-constant")
|
|
#if __has_warning("-Wzero-as-null-pointer-constant")
|
|
|
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning : zero as null pointer constant // some standard header variations use #define NULL 0
|
|
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning : zero as null pointer constant // some standard header variations use #define NULL 0
|
|
|
#endif
|
|
#endif
|
|
@@ -91,9 +91,11 @@ Index of this file:
|
|
|
|
|
|
|
|
// Play it nice with Windows users. Notepad in 2017 still doesn't display text data with Unix-style \n.
|
|
// Play it nice with Windows users. Notepad in 2017 still doesn't display text data with Unix-style \n.
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
-#define IM_NEWLINE "\r\n"
|
|
|
|
|
|
|
+#define IM_NEWLINE "\r\n"
|
|
|
|
|
+#define snprintf _snprintf
|
|
|
|
|
+#define vsnprintf _vsnprintf
|
|
|
#else
|
|
#else
|
|
|
-#define IM_NEWLINE "\n"
|
|
|
|
|
|
|
+#define IM_NEWLINE "\n"
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
|
|
#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
|
|
@@ -893,6 +895,25 @@ static void ShowDemoWindowWidgets()
|
|
|
}
|
|
}
|
|
|
ImGui::TreePop();
|
|
ImGui::TreePop();
|
|
|
}
|
|
}
|
|
|
|
|
+ if (ImGui::TreeNode("Alignment"))
|
|
|
|
|
+ {
|
|
|
|
|
+ ShowHelpMarker("Alignment applies when a selectable is larger than its text content.\nBy default, Selectables uses style.SelectableTextAlign but it can be overriden on a per-item basis using PushStyleVar().");
|
|
|
|
|
+ static bool selected[3*3] = { true, false, true, false, true, false, true, false, true };
|
|
|
|
|
+ for (int y = 0; y < 3; y++)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int x = 0; x < 3; x++)
|
|
|
|
|
+ {
|
|
|
|
|
+ ImVec2 alignment = ImVec2((float)x / 2.0f, (float)y / 2.0f);
|
|
|
|
|
+ char name[32];
|
|
|
|
|
+ sprintf(name, "(%.1f,%.1f)", alignment.x, alignment.y);
|
|
|
|
|
+ if (x > 0) ImGui::SameLine();
|
|
|
|
|
+ ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, alignment);
|
|
|
|
|
+ ImGui::Selectable(name, &selected[3*y+x], ImGuiSelectableFlags_None, ImVec2(80,80));
|
|
|
|
|
+ ImGui::PopStyleVar();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ImGui::TreePop();
|
|
|
|
|
+ }
|
|
|
ImGui::TreePop();
|
|
ImGui::TreePop();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1005,7 +1026,7 @@ static void ShowDemoWindowWidgets()
|
|
|
|
|
|
|
|
if (ImGui::TreeNode("Color/Picker Widgets"))
|
|
if (ImGui::TreeNode("Color/Picker Widgets"))
|
|
|
{
|
|
{
|
|
|
- static ImVec4 color = ImColor(114, 144, 154, 200);
|
|
|
|
|
|
|
+ static ImVec4 color = ImVec4(114.0f/255.0f, 144.0f/255.0f, 154.0f/255.0f, 200.0f/255.0f);
|
|
|
|
|
|
|
|
static bool alpha_preview = true;
|
|
static bool alpha_preview = true;
|
|
|
static bool alpha_half_preview = false;
|
|
static bool alpha_half_preview = false;
|
|
@@ -2825,6 +2846,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
|
|
ImGui::Text("Alignment");
|
|
ImGui::Text("Alignment");
|
|
|
ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f");
|
|
ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f");
|
|
|
ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); ShowHelpMarker("Alignment applies when a button is larger than its text content.");
|
|
ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); ShowHelpMarker("Alignment applies when a button is larger than its text content.");
|
|
|
|
|
+ ImGui::SliderFloat2("SelectableTextAlign", (float*)&style.SelectableTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); ShowHelpMarker("Alignment applies when a selectable is larger than its text content.");
|
|
|
ImGui::Text("Safe Area Padding"); ImGui::SameLine(); ShowHelpMarker("Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured).");
|
|
ImGui::Text("Safe Area Padding"); ImGui::SameLine(); ShowHelpMarker("Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured).");
|
|
|
ImGui::SliderFloat2("DisplaySafeAreaPadding", (float*)&style.DisplaySafeAreaPadding, 0.0f, 30.0f, "%.0f");
|
|
ImGui::SliderFloat2("DisplaySafeAreaPadding", (float*)&style.DisplaySafeAreaPadding, 0.0f, 30.0f, "%.0f");
|
|
|
ImGui::EndTabItem();
|
|
ImGui::EndTabItem();
|
|
@@ -3095,10 +3117,12 @@ struct ExampleAppConsole
|
|
|
{
|
|
{
|
|
|
char InputBuf[256];
|
|
char InputBuf[256];
|
|
|
ImVector<char*> Items;
|
|
ImVector<char*> Items;
|
|
|
- bool ScrollToBottom;
|
|
|
|
|
|
|
+ ImVector<const char*> Commands;
|
|
|
ImVector<char*> History;
|
|
ImVector<char*> History;
|
|
|
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
|
|
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
|
|
|
- ImVector<const char*> Commands;
|
|
|
|
|
|
|
+ ImGuiTextFilter Filter;
|
|
|
|
|
+ bool AutoScroll;
|
|
|
|
|
+ bool ScrollToBottom;
|
|
|
|
|
|
|
|
ExampleAppConsole()
|
|
ExampleAppConsole()
|
|
|
{
|
|
{
|
|
@@ -3109,6 +3133,8 @@ struct ExampleAppConsole
|
|
|
Commands.push_back("HISTORY");
|
|
Commands.push_back("HISTORY");
|
|
|
Commands.push_back("CLEAR");
|
|
Commands.push_back("CLEAR");
|
|
|
Commands.push_back("CLASSIFY"); // "classify" is only here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
|
|
Commands.push_back("CLASSIFY"); // "classify" is only here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
|
|
|
|
|
+ AutoScroll = true;
|
|
|
|
|
+ ScrollToBottom = true;
|
|
|
AddLog("Welcome to Dear ImGui!");
|
|
AddLog("Welcome to Dear ImGui!");
|
|
|
}
|
|
}
|
|
|
~ExampleAppConsole()
|
|
~ExampleAppConsole()
|
|
@@ -3142,7 +3168,8 @@ struct ExampleAppConsole
|
|
|
buf[IM_ARRAYSIZE(buf)-1] = 0;
|
|
buf[IM_ARRAYSIZE(buf)-1] = 0;
|
|
|
va_end(args);
|
|
va_end(args);
|
|
|
Items.push_back(Strdup(buf));
|
|
Items.push_back(Strdup(buf));
|
|
|
- ScrollToBottom = true;
|
|
|
|
|
|
|
+ if (AutoScroll)
|
|
|
|
|
+ ScrollToBottom = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Draw(const char* title, bool* p_open)
|
|
void Draw(const char* title, bool* p_open)
|
|
@@ -3168,7 +3195,7 @@ struct ExampleAppConsole
|
|
|
|
|
|
|
|
// TODO: display items starting from the bottom
|
|
// TODO: display items starting from the bottom
|
|
|
|
|
|
|
|
- if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
|
|
|
|
|
|
|
+ if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
|
|
|
if (ImGui::SmallButton("Add Dummy Error")) { AddLog("[error] something went wrong"); } ImGui::SameLine();
|
|
if (ImGui::SmallButton("Add Dummy Error")) { AddLog("[error] something went wrong"); } ImGui::SameLine();
|
|
|
if (ImGui::SmallButton("Clear")) { ClearLog(); } ImGui::SameLine();
|
|
if (ImGui::SmallButton("Clear")) { ClearLog(); } ImGui::SameLine();
|
|
|
bool copy_to_clipboard = ImGui::SmallButton("Copy"); ImGui::SameLine();
|
|
bool copy_to_clipboard = ImGui::SmallButton("Copy"); ImGui::SameLine();
|
|
@@ -3177,10 +3204,20 @@ struct ExampleAppConsole
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
- ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
|
|
|
|
|
- static ImGuiTextFilter filter;
|
|
|
|
|
- filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
|
|
|
|
|
- ImGui::PopStyleVar();
|
|
|
|
|
|
|
+ // Options menu
|
|
|
|
|
+ if (ImGui::BeginPopup("Options"))
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ImGui::Checkbox("Auto-scroll", &AutoScroll))
|
|
|
|
|
+ if (AutoScroll)
|
|
|
|
|
+ ScrollToBottom = true;
|
|
|
|
|
+ ImGui::EndPopup();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Options, Filter
|
|
|
|
|
+ if (ImGui::Button("Options"))
|
|
|
|
|
+ ImGui::OpenPopup("Options");
|
|
|
|
|
+ ImGui::SameLine();
|
|
|
|
|
+ Filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
|
|
|
ImGui::Separator();
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); // 1 separator, 1 input text
|
|
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); // 1 separator, 1 input text
|
|
@@ -3205,18 +3242,19 @@ struct ExampleAppConsole
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
|
|
|
if (copy_to_clipboard)
|
|
if (copy_to_clipboard)
|
|
|
ImGui::LogToClipboard();
|
|
ImGui::LogToClipboard();
|
|
|
- ImVec4 col_default_text = ImGui::GetStyleColorVec4(ImGuiCol_Text);
|
|
|
|
|
for (int i = 0; i < Items.Size; i++)
|
|
for (int i = 0; i < Items.Size; i++)
|
|
|
{
|
|
{
|
|
|
const char* item = Items[i];
|
|
const char* item = Items[i];
|
|
|
- if (!filter.PassFilter(item))
|
|
|
|
|
|
|
+ if (!Filter.PassFilter(item))
|
|
|
continue;
|
|
continue;
|
|
|
- ImVec4 col = col_default_text;
|
|
|
|
|
- if (strstr(item, "[error]")) col = ImColor(1.0f,0.4f,0.4f,1.0f);
|
|
|
|
|
- else if (strncmp(item, "# ", 2) == 0) col = ImColor(1.0f,0.78f,0.58f,1.0f);
|
|
|
|
|
- ImGui::PushStyleColor(ImGuiCol_Text, col);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Normally you would store more information in your item (e.g. make Items[] an array of structure, store color/type etc.)
|
|
|
|
|
+ bool pop_color = false;
|
|
|
|
|
+ if (strstr(item, "[error]")) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.4f, 0.4f, 1.0f)); pop_color = true; }
|
|
|
|
|
+ else if (strncmp(item, "# ", 2) == 0) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.8f, 0.6f, 1.0f)); pop_color = true; }
|
|
|
ImGui::TextUnformatted(item);
|
|
ImGui::TextUnformatted(item);
|
|
|
- ImGui::PopStyleColor();
|
|
|
|
|
|
|
+ if (pop_color)
|
|
|
|
|
+ ImGui::PopStyleColor();
|
|
|
}
|
|
}
|
|
|
if (copy_to_clipboard)
|
|
if (copy_to_clipboard)
|
|
|
ImGui::LogFinish();
|
|
ImGui::LogFinish();
|
|
@@ -3283,6 +3321,9 @@ struct ExampleAppConsole
|
|
|
{
|
|
{
|
|
|
AddLog("Unknown command: '%s'\n", command_line);
|
|
AddLog("Unknown command: '%s'\n", command_line);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // On commad input, we scroll to bottom even if AutoScroll==false
|
|
|
|
|
+ ScrollToBottom = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data) // In C++11 you are better off using lambdas for this sort of forwarding callbacks
|
|
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data) // In C++11 you are better off using lambdas for this sort of forwarding callbacks
|
|
@@ -3411,10 +3452,12 @@ struct ExampleAppLog
|
|
|
ImGuiTextBuffer Buf;
|
|
ImGuiTextBuffer Buf;
|
|
|
ImGuiTextFilter Filter;
|
|
ImGuiTextFilter Filter;
|
|
|
ImVector<int> LineOffsets; // Index to lines offset. We maintain this with AddLog() calls, allowing us to have a random access on lines
|
|
ImVector<int> LineOffsets; // Index to lines offset. We maintain this with AddLog() calls, allowing us to have a random access on lines
|
|
|
|
|
+ bool AutoScroll;
|
|
|
bool ScrollToBottom;
|
|
bool ScrollToBottom;
|
|
|
|
|
|
|
|
ExampleAppLog()
|
|
ExampleAppLog()
|
|
|
{
|
|
{
|
|
|
|
|
+ AutoScroll = true;
|
|
|
ScrollToBottom = false;
|
|
ScrollToBottom = false;
|
|
|
Clear();
|
|
Clear();
|
|
|
}
|
|
}
|
|
@@ -3436,7 +3479,8 @@ struct ExampleAppLog
|
|
|
for (int new_size = Buf.size(); old_size < new_size; old_size++)
|
|
for (int new_size = Buf.size(); old_size < new_size; old_size++)
|
|
|
if (Buf[old_size] == '\n')
|
|
if (Buf[old_size] == '\n')
|
|
|
LineOffsets.push_back(old_size + 1);
|
|
LineOffsets.push_back(old_size + 1);
|
|
|
- ScrollToBottom = true;
|
|
|
|
|
|
|
+ if (AutoScroll)
|
|
|
|
|
+ ScrollToBottom = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Draw(const char* title, bool* p_open = NULL)
|
|
void Draw(const char* title, bool* p_open = NULL)
|
|
@@ -3446,13 +3490,31 @@ struct ExampleAppLog
|
|
|
ImGui::End();
|
|
ImGui::End();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (ImGui::Button("Clear")) Clear();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Options menu
|
|
|
|
|
+ if (ImGui::BeginPopup("Options"))
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ImGui::Checkbox("Auto-scroll", &AutoScroll))
|
|
|
|
|
+ if (AutoScroll)
|
|
|
|
|
+ ScrollToBottom = true;
|
|
|
|
|
+ ImGui::EndPopup();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Main window
|
|
|
|
|
+ if (ImGui::Button("Options"))
|
|
|
|
|
+ ImGui::OpenPopup("Options");
|
|
|
|
|
+ ImGui::SameLine();
|
|
|
|
|
+ bool clear = ImGui::Button("Clear");
|
|
|
ImGui::SameLine();
|
|
ImGui::SameLine();
|
|
|
bool copy = ImGui::Button("Copy");
|
|
bool copy = ImGui::Button("Copy");
|
|
|
ImGui::SameLine();
|
|
ImGui::SameLine();
|
|
|
Filter.Draw("Filter", -100.0f);
|
|
Filter.Draw("Filter", -100.0f);
|
|
|
|
|
+
|
|
|
ImGui::Separator();
|
|
ImGui::Separator();
|
|
|
ImGui::BeginChild("scrolling", ImVec2(0,0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
|
ImGui::BeginChild("scrolling", ImVec2(0,0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
|
|
|
|
+
|
|
|
|
|
+ if (clear)
|
|
|
|
|
+ Clear();
|
|
|
if (copy)
|
|
if (copy)
|
|
|
ImGui::LogToClipboard();
|
|
ImGui::LogToClipboard();
|
|
|
|
|
|
|
@@ -3461,6 +3523,10 @@ struct ExampleAppLog
|
|
|
const char* buf_end = Buf.end();
|
|
const char* buf_end = Buf.end();
|
|
|
if (Filter.IsActive())
|
|
if (Filter.IsActive())
|
|
|
{
|
|
{
|
|
|
|
|
+ // In this example we don't use the clipper when Filter is enabled.
|
|
|
|
|
+ // This is because we don't have a random access on the result on our filter.
|
|
|
|
|
+ // A real application processing logs with ten of thousands of entries may want to store the result of search/filter.
|
|
|
|
|
+ // especially if the filtering function is not trivial (e.g. reg-exp).
|
|
|
for (int line_no = 0; line_no < LineOffsets.Size; line_no++)
|
|
for (int line_no = 0; line_no < LineOffsets.Size; line_no++)
|
|
|
{
|
|
{
|
|
|
const char* line_start = buf + LineOffsets[line_no];
|
|
const char* line_start = buf + LineOffsets[line_no];
|
|
@@ -3508,11 +3574,12 @@ static void ShowExampleAppLog(bool* p_open)
|
|
|
{
|
|
{
|
|
|
static ExampleAppLog log;
|
|
static ExampleAppLog log;
|
|
|
|
|
|
|
|
- // For the demo: add a debug button before the normal log window contents
|
|
|
|
|
|
|
+ // For the demo: add a debug button _BEFORE_ the normal log window contents
|
|
|
// We take advantage of the fact that multiple calls to Begin()/End() are appending to the same window.
|
|
// We take advantage of the fact that multiple calls to Begin()/End() are appending to the same window.
|
|
|
|
|
+ // Most of the contents of the window will be added by the log.Draw() call.
|
|
|
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
|
|
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
|
|
|
ImGui::Begin("Example: Log", p_open);
|
|
ImGui::Begin("Example: Log", p_open);
|
|
|
- if (ImGui::SmallButton("Add 5 entries"))
|
|
|
|
|
|
|
+ if (ImGui::SmallButton("[Debug] Add 5 entries"))
|
|
|
{
|
|
{
|
|
|
static int counter = 0;
|
|
static int counter = 0;
|
|
|
for (int n = 0; n < 5; n++)
|
|
for (int n = 0; n < 5; n++)
|