mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-24 00:26:36 +00:00
Demo: Added Auto-Scroll option in Log/Console. Comments. Removed some ImColor() uses.
This commit is contained in:
parent
8522a4bbea
commit
2206df9e7a
@ -76,6 +76,7 @@ Other Changes:
|
||||
- ImFontAtlas: FreeType: Added support for imgui allocators + custom FreeType only SetAllocatorFunctions. (#2285) [@Vuhdo]
|
||||
- ImFontAtlas: FreeType: Fixed using imgui_freetype.cpp in unity builds. (#2302)
|
||||
- Demo: Fixed "Log" demo not initializing properly, leading to the first line not showing before a Clear. (#2318) [@bluescan]
|
||||
- Demo: Added "Auto-scroll" option in Log/Console demos. (#2300) [@nicolasnoble, @ocornut]
|
||||
- Examples: Metal, OpenGL2, OpenGL3: Fixed offsetting of clipping rectangle with ImDrawData::DisplayPos != (0,0) when
|
||||
the display frame-buffer scale scale is not (1,1). While this doesn't make a difference when using master branch,
|
||||
this is effectively fixing support for multi-viewport with Mac Retina Displays on those examples. (#2306) [@rasky, @ocornut]
|
||||
|
@ -9301,7 +9301,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
if (draw_list == ImGui::GetWindowDrawList())
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(ImColor(255,100,100), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered)
|
||||
ImGui::TextColored(ImVec4(1.0f,0.4f,0.4f,1.0f), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered)
|
||||
if (node_open) ImGui::TreePop();
|
||||
return;
|
||||
}
|
||||
|
@ -1005,7 +1005,7 @@ static void ShowDemoWindowWidgets()
|
||||
|
||||
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_half_preview = false;
|
||||
@ -3095,10 +3095,12 @@ struct ExampleAppConsole
|
||||
{
|
||||
char InputBuf[256];
|
||||
ImVector<char*> Items;
|
||||
bool ScrollToBottom;
|
||||
ImVector<const char*> Commands;
|
||||
ImVector<char*> History;
|
||||
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
|
||||
ImVector<const char*> Commands;
|
||||
ImGuiTextFilter Filter;
|
||||
bool AutoScroll;
|
||||
bool ScrollToBottom;
|
||||
|
||||
ExampleAppConsole()
|
||||
{
|
||||
@ -3109,6 +3111,8 @@ struct ExampleAppConsole
|
||||
Commands.push_back("HISTORY");
|
||||
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.
|
||||
AutoScroll = true;
|
||||
ScrollToBottom = true;
|
||||
AddLog("Welcome to Dear ImGui!");
|
||||
}
|
||||
~ExampleAppConsole()
|
||||
@ -3142,7 +3146,8 @@ struct ExampleAppConsole
|
||||
buf[IM_ARRAYSIZE(buf)-1] = 0;
|
||||
va_end(args);
|
||||
Items.push_back(Strdup(buf));
|
||||
ScrollToBottom = true;
|
||||
if (AutoScroll)
|
||||
ScrollToBottom = true;
|
||||
}
|
||||
|
||||
void Draw(const char* title, bool* p_open)
|
||||
@ -3168,7 +3173,7 @@ struct ExampleAppConsole
|
||||
|
||||
// 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("Clear")) { ClearLog(); } ImGui::SameLine();
|
||||
bool copy_to_clipboard = ImGui::SmallButton("Copy"); ImGui::SameLine();
|
||||
@ -3177,10 +3182,20 @@ struct ExampleAppConsole
|
||||
|
||||
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();
|
||||
|
||||
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); // 1 separator, 1 input text
|
||||
@ -3205,18 +3220,19 @@ struct ExampleAppConsole
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
|
||||
if (copy_to_clipboard)
|
||||
ImGui::LogToClipboard();
|
||||
ImVec4 col_default_text = ImGui::GetStyleColorVec4(ImGuiCol_Text);
|
||||
for (int i = 0; i < Items.Size; i++)
|
||||
{
|
||||
const char* item = Items[i];
|
||||
if (!filter.PassFilter(item))
|
||||
if (!Filter.PassFilter(item))
|
||||
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::PopStyleColor();
|
||||
if (pop_color)
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
if (copy_to_clipboard)
|
||||
ImGui::LogFinish();
|
||||
@ -3283,6 +3299,9 @@ struct ExampleAppConsole
|
||||
{
|
||||
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
|
||||
@ -3411,10 +3430,12 @@ struct ExampleAppLog
|
||||
ImGuiTextBuffer Buf;
|
||||
ImGuiTextFilter Filter;
|
||||
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;
|
||||
|
||||
ExampleAppLog()
|
||||
{
|
||||
AutoScroll = true;
|
||||
ScrollToBottom = false;
|
||||
Clear();
|
||||
}
|
||||
@ -3436,7 +3457,8 @@ struct ExampleAppLog
|
||||
for (int new_size = Buf.size(); old_size < new_size; old_size++)
|
||||
if (Buf[old_size] == '\n')
|
||||
LineOffsets.push_back(old_size + 1);
|
||||
ScrollToBottom = true;
|
||||
if (AutoScroll)
|
||||
ScrollToBottom = true;
|
||||
}
|
||||
|
||||
void Draw(const char* title, bool* p_open = NULL)
|
||||
@ -3446,13 +3468,31 @@ struct ExampleAppLog
|
||||
ImGui::End();
|
||||
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();
|
||||
bool copy = ImGui::Button("Copy");
|
||||
ImGui::SameLine();
|
||||
Filter.Draw("Filter", -100.0f);
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::BeginChild("scrolling", ImVec2(0,0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
|
||||
if (clear)
|
||||
Clear();
|
||||
if (copy)
|
||||
ImGui::LogToClipboard();
|
||||
|
||||
@ -3461,6 +3501,10 @@ struct ExampleAppLog
|
||||
const char* buf_end = Buf.end();
|
||||
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++)
|
||||
{
|
||||
const char* line_start = buf + LineOffsets[line_no];
|
||||
@ -3508,11 +3552,12 @@ static void ShowExampleAppLog(bool* p_open)
|
||||
{
|
||||
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.
|
||||
// Most of the contents of the window will be added by the log.Draw() call.
|
||||
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Example: Log", p_open);
|
||||
if (ImGui::SmallButton("Add 5 entries"))
|
||||
if (ImGui::SmallButton("[Debug] Add 5 entries"))
|
||||
{
|
||||
static int counter = 0;
|
||||
for (int n = 0; n < 5; n++)
|
||||
|
Loading…
Reference in New Issue
Block a user