Skip to content

Commit

Permalink
Fixed ImGuiTextFilter triming of leading/trailing blanks. Documented …
Browse files Browse the repository at this point in the history
…"Filtering" section of demo better.
  • Loading branch information
ocornut committed Aug 25, 2014
1 parent 710b9b6 commit d17a586
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ static void RegisterAliveId(const ImGuiID& id)

//-----------------------------------------------------------------------------

// Helper: Key->value storage
void ImGuiStorage::Clear()
{
Data.clear();
Expand Down Expand Up @@ -797,6 +798,7 @@ void ImGuiStorage::SetAllInt(int v)

//-----------------------------------------------------------------------------

// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
ImGuiTextFilter::ImGuiTextFilter()
{
InputBuf[0] = 0;
Expand Down Expand Up @@ -888,6 +890,7 @@ bool ImGuiTextFilter::PassFilter(const char* val) const

//-----------------------------------------------------------------------------

// Helper: Text buffer for logging/accumulating text
void ImGuiTextBuffer::append(const char* fmt, ...)
{
va_list args;
Expand Down Expand Up @@ -5854,7 +5857,12 @@ void ShowTestWindow(bool* open)
if (ImGui::CollapsingHeader("Filtering"))
{
static ImGuiTextFilter filter;
filter.Draw();
ImGui::Text("Filter usage:\n"
" \"\" display all lines\n"
" \"xxx\" display lines containing \"xxx\"\n"
" \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
" \"-xxx\" hide lines containing \"xxx\"");
filter.Draw();
const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
if (filter.PassFilter(lines[i]))
Expand Down
6 changes: 3 additions & 3 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ImVector

// Helpers at bottom of the file:
// - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only
// - struct ImGuiTextFilter // Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]"
// - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
// - struct ImDrawList // Draw command list
Expand Down Expand Up @@ -449,7 +449,7 @@ struct ImGuiOncePerFrame
bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; }
};

// Helper: Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]"
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
struct ImGuiTextFilter
{
struct TextRange
Expand All @@ -463,7 +463,7 @@ struct ImGuiTextFilter
const char* end() const { return e; }
bool empty() const { return b == e; }
char front() const { return *b; }
static bool isblank(char c) { return c == ' ' && c == '\t'; }
static bool isblank(char c) { return c == ' ' || c == '\t'; }
void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; }
void split(char separator, ImVector<TextRange>& out);
};
Expand Down

0 comments on commit d17a586

Please sign in to comment.