mirror of
https://github.com/ocornut/imgui.git
synced 2026-09-26 16:05:45 +03:00
ImGuiTextFilter: added undocumented FilterOp support. (#2435)
This commit is contained in:
parent
565564bb5c
commit
249e5a939d
2 changed files with 15 additions and 5 deletions
19
imgui.cpp
19
imgui.cpp
|
|
@ -3094,6 +3094,7 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
|
|||
ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) //-V1077
|
||||
{
|
||||
InputBuf[0] = 0;
|
||||
FilterOp = '|';
|
||||
MinWordSize = 1;
|
||||
_CountExclude = _CountInclude = 0;
|
||||
if (default_filter)
|
||||
|
|
@ -3122,6 +3123,7 @@ void ImGuiTextFilter::Build()
|
|||
{
|
||||
_Items.resize(0);
|
||||
_CountExclude = _CountInclude = 0;
|
||||
IM_ASSERT(FilterOp == '|' || FilterOp == '&');
|
||||
const char* buf_e = InputBuf + ImStrlen(InputBuf);
|
||||
const char* word_e;
|
||||
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 = "";
|
||||
|
||||
// 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];
|
||||
if (ImStristr(text, text_end, item.Begin, item.End) != NULL)
|
||||
return (n < _CountExclude) ? false : true;
|
||||
const bool is_match = ImStristr(text, text_end, _Items.Data[n].Begin, _Items.Data[n].End) != NULL;
|
||||
if (is_match && !is_and_filter) // or incl 1 -> 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
|
||||
if (_CountInclude == 0)
|
||||
return true;
|
||||
return false;
|
||||
return is_and_filter;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
1
imgui.h
1
imgui.h
|
|
@ -2811,6 +2811,7 @@ struct ImGuiTextFilter
|
|||
|
||||
// [Internal] Members
|
||||
char InputBuf[256]; // User input buffer
|
||||
char FilterOp; // == '|' (any) pr '&' (all)
|
||||
ImU8 MinWordSize; // == 1
|
||||
int _CountExclude; // >= 0
|
||||
int _CountInclude; // >= 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue