mirror of https://github.com/ocornut/imgui
ImGuiTextFilter, TextRange: removed cruft from TextRange since it's not a publicly and generic helper at the moment + marked internal stuff + changed a reference to a pointer. (#1879)
This commit is contained in:
parent
d016ef1825
commit
048add5ef2
22
imgui.cpp
22
imgui.cpp
|
@ -1833,37 +1833,41 @@ bool ImGuiTextFilter::Draw(const char* label, float width)
|
||||||
return value_changed;
|
return value_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>& out)
|
void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>* out) const
|
||||||
{
|
{
|
||||||
out.resize(0);
|
out->resize(0);
|
||||||
const char* wb = b;
|
const char* wb = b;
|
||||||
const char* we = wb;
|
const char* we = wb;
|
||||||
while (we < e)
|
while (we < e)
|
||||||
{
|
{
|
||||||
if (*we == separator)
|
if (*we == separator)
|
||||||
{
|
{
|
||||||
out.push_back(TextRange(wb, we));
|
out->push_back(TextRange(wb, we));
|
||||||
wb = we + 1;
|
wb = we + 1;
|
||||||
}
|
}
|
||||||
we++;
|
we++;
|
||||||
}
|
}
|
||||||
if (wb != we)
|
if (wb != we)
|
||||||
out.push_back(TextRange(wb, we));
|
out->push_back(TextRange(wb, we));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiTextFilter::Build()
|
void ImGuiTextFilter::Build()
|
||||||
{
|
{
|
||||||
Filters.resize(0);
|
Filters.resize(0);
|
||||||
TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
|
TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
|
||||||
input_range.split(',', Filters);
|
input_range.split(',', &Filters);
|
||||||
|
|
||||||
CountGrep = 0;
|
CountGrep = 0;
|
||||||
for (int i = 0; i != Filters.Size; i++)
|
for (int i = 0; i != Filters.Size; i++)
|
||||||
{
|
{
|
||||||
Filters[i].trim_blanks();
|
TextRange& f = Filters[i];
|
||||||
if (Filters[i].empty())
|
while (f.b < f.e && ImCharIsBlankA(f.b[0]))
|
||||||
|
f.b++;
|
||||||
|
while (f.e > f.b && ImCharIsBlankA(f.e[-1]))
|
||||||
|
f.e--;
|
||||||
|
if (f.empty())
|
||||||
continue;
|
continue;
|
||||||
if (Filters[i].front() != '-')
|
if (Filters[i].b[0] != '-')
|
||||||
CountGrep += 1;
|
CountGrep += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1881,7 +1885,7 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
|
||||||
const TextRange& f = Filters[i];
|
const TextRange& f = Filters[i];
|
||||||
if (f.empty())
|
if (f.empty())
|
||||||
continue;
|
continue;
|
||||||
if (f.front() == '-')
|
if (f.b[0] == '-')
|
||||||
{
|
{
|
||||||
// Subtract
|
// Subtract
|
||||||
if (ImStristr(text, text_end, f.begin()+1, f.end()) != NULL)
|
if (ImStristr(text, text_end, f.begin()+1, f.end()) != NULL)
|
||||||
|
|
23
imgui.h
23
imgui.h
|
@ -1309,6 +1309,14 @@ struct ImGuiOnceUponAFrame
|
||||||
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
|
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
|
||||||
struct ImGuiTextFilter
|
struct ImGuiTextFilter
|
||||||
{
|
{
|
||||||
|
IMGUI_API ImGuiTextFilter(const char* default_filter = "");
|
||||||
|
IMGUI_API bool Draw(const char* label = "Filter (inc,-exc)", float width = 0.0f); // Helper calling InputText+Build
|
||||||
|
IMGUI_API bool PassFilter(const char* text, const char* text_end = NULL) const;
|
||||||
|
IMGUI_API void Build();
|
||||||
|
void Clear() { InputBuf[0] = 0; Build(); }
|
||||||
|
bool IsActive() const { return !Filters.empty(); }
|
||||||
|
|
||||||
|
// [Internal]
|
||||||
struct TextRange
|
struct TextRange
|
||||||
{
|
{
|
||||||
const char* b;
|
const char* b;
|
||||||
|
@ -1317,24 +1325,13 @@ struct ImGuiTextFilter
|
||||||
TextRange() { b = e = NULL; }
|
TextRange() { b = e = NULL; }
|
||||||
TextRange(const char* _b, const char* _e) { b = _b; e = _e; }
|
TextRange(const char* _b, const char* _e) { b = _b; e = _e; }
|
||||||
const char* begin() const { return b; }
|
const char* begin() const { return b; }
|
||||||
const char* end() const { return e; }
|
const char* end () const { return e; }
|
||||||
bool empty() const { return b == e; }
|
bool empty() const { return b == e; }
|
||||||
char front() const { return *b; }
|
IMGUI_API void split(char separator, ImVector<TextRange>* out) const;
|
||||||
static bool is_blank(char c) { return c == ' ' || c == '\t'; }
|
|
||||||
void trim_blanks() { while (b < e && is_blank(*b)) b++; while (e > b && is_blank(*(e-1))) e--; }
|
|
||||||
IMGUI_API void split(char separator, ImVector<TextRange>& out);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
char InputBuf[256];
|
char InputBuf[256];
|
||||||
ImVector<TextRange> Filters;
|
ImVector<TextRange> Filters;
|
||||||
int CountGrep;
|
int CountGrep;
|
||||||
|
|
||||||
IMGUI_API ImGuiTextFilter(const char* default_filter = "");
|
|
||||||
IMGUI_API bool Draw(const char* label = "Filter (inc,-exc)", float width = 0.0f); // Helper calling InputText+Build
|
|
||||||
IMGUI_API bool PassFilter(const char* text, const char* text_end = NULL) const;
|
|
||||||
IMGUI_API void Build();
|
|
||||||
void Clear() { InputBuf[0] = 0; Build(); }
|
|
||||||
bool IsActive() const { return !Filters.empty(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper: Text buffer for logging/accumulating text
|
// Helper: Text buffer for logging/accumulating text
|
||||||
|
|
Loading…
Reference in New Issue