ImGuiTextFilter: added undocumented FilterOp support. (#2435)
This commit is contained in:
parent
565564bb5c
commit
249e5a939d
19
imgui.cpp
19
imgui.cpp
@ -3094,6 +3094,7 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
|
|||||||
ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) //-V1077
|
ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) //-V1077
|
||||||
{
|
{
|
||||||
InputBuf[0] = 0;
|
InputBuf[0] = 0;
|
||||||
|
FilterOp = '|';
|
||||||
MinWordSize = 1;
|
MinWordSize = 1;
|
||||||
_CountExclude = _CountInclude = 0;
|
_CountExclude = _CountInclude = 0;
|
||||||
if (default_filter)
|
if (default_filter)
|
||||||
@ -3122,6 +3123,7 @@ void ImGuiTextFilter::Build()
|
|||||||
{
|
{
|
||||||
_Items.resize(0);
|
_Items.resize(0);
|
||||||
_CountExclude = _CountInclude = 0;
|
_CountExclude = _CountInclude = 0;
|
||||||
|
IM_ASSERT(FilterOp == '|' || FilterOp == '&');
|
||||||
const char* buf_e = InputBuf + ImStrlen(InputBuf);
|
const char* buf_e = InputBuf + ImStrlen(InputBuf);
|
||||||
const char* word_e;
|
const char* word_e;
|
||||||
for (const char* word_b = InputBuf; word_b < buf_e; word_b = word_e + 1)
|
for (const char* word_b = InputBuf; word_b < buf_e; word_b = word_e + 1)
|
||||||
@ -3171,17 +3173,24 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
|
|||||||
text = text_end = "";
|
text = text_end = "";
|
||||||
|
|
||||||
// Filters are sorted so that '-' ones are always leading.
|
// Filters are sorted so that '-' ones are always leading.
|
||||||
for (int n = 0; n < _Items.Size; n++)
|
int n;
|
||||||
|
for (n = 0; n < _CountExclude; n++)
|
||||||
|
if (ImStristr(text, text_end, _Items.Data[n].Begin, _Items.Data[n].End) != NULL)
|
||||||
|
return false;
|
||||||
|
const bool is_and_filter = (FilterOp == '&');
|
||||||
|
for (; n < _Items.Size; n++)
|
||||||
{
|
{
|
||||||
const ImGuiTextFilterItem& item = _Items[n];
|
const bool is_match = ImStristr(text, text_end, _Items.Data[n].Begin, _Items.Data[n].End) != NULL;
|
||||||
if (ImStristr(text, text_end, item.Begin, item.End) != NULL)
|
if (is_match && !is_and_filter) // or incl 1 -> true
|
||||||
return (n < _CountExclude) ? false : true;
|
return true; // or incl 0 -> continue
|
||||||
|
if (!is_match && is_and_filter) // and incl 1 -> continue
|
||||||
|
return false; // and incl 0 -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
// When no inclusion are specified (only exclusions) we implicitly pass
|
// When no inclusion are specified (only exclusions) we implicitly pass
|
||||||
if (_CountInclude == 0)
|
if (_CountInclude == 0)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return is_and_filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
1
imgui.h
1
imgui.h
@ -2811,6 +2811,7 @@ struct ImGuiTextFilter
|
|||||||
|
|
||||||
// [Internal] Members
|
// [Internal] Members
|
||||||
char InputBuf[256]; // User input buffer
|
char InputBuf[256]; // User input buffer
|
||||||
|
char FilterOp; // == '|' (any) pr '&' (all)
|
||||||
ImU8 MinWordSize; // == 1
|
ImU8 MinWordSize; // == 1
|
||||||
int _CountExclude; // >= 0
|
int _CountExclude; // >= 0
|
||||||
int _CountInclude; // >= 0
|
int _CountInclude; // >= 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user