ImGuiTextFilter: minor tweaks, made ImGuiTextRange fields match upcoming ImStrv. Removed exposed ImGuiTextRange helpers.

Rename CountGrep to CountInclude (#3906)
Toward #2435
This commit is contained in:
ocornut 2026-09-18 16:51:18 +02:00
parent f09485d7be
commit c8fc1829d0
2 changed files with 31 additions and 31 deletions

View file

@ -3093,7 +3093,7 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) //-V1077
{
InputBuf[0] = 0;
CountGrep = 0;
CountInclude = 0;
if (default_filter)
{
ImStrncpy(InputBuf, default_filter, IM_COUNTOF(InputBuf));
@ -3111,7 +3111,7 @@ bool ImGuiTextFilter::Draw(const char* label, float width)
return value_changed;
}
void ImGuiTextFilter::ImGuiTextRange::split(char separator, ImVector<ImGuiTextRange>* out) const
static void ImStrSplit(const char* b, const char* e, char separator, ImVector<ImGuiTextFilter::ImGuiTextRange>* out)
{
out->resize(0);
const char* wb = b;
@ -3120,32 +3120,32 @@ void ImGuiTextFilter::ImGuiTextRange::split(char separator, ImVector<ImGuiTextRa
{
if (*we == separator)
{
out->push_back(ImGuiTextRange(wb, we));
out->push_back(ImGuiTextFilter::ImGuiTextRange(wb, we));
wb = we + 1;
}
we++;
}
if (wb != we)
out->push_back(ImGuiTextRange(wb, we));
out->push_back(ImGuiTextFilter::ImGuiTextRange(wb, we));
}
void ImGuiTextFilter::Build()
{
Filters.resize(0);
ImGuiTextRange input_range(InputBuf, InputBuf + ImStrlen(InputBuf));
input_range.split(',', &Filters);
ImStrSplit(InputBuf, InputBuf + ImStrlen(InputBuf), ',', &Filters);
CountGrep = 0;
CountInclude = 0;
for (ImGuiTextRange& f : Filters)
{
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())
while (f.Begin < f.End && ImCharIsBlankA(f.Begin[0]))
f.Begin++;
while (f.End > f.Begin && ImCharIsBlankA(f.End[-1]))
f.End--;
if (f.Begin == f.End)
continue;
if (f.b[0] != '-')
CountGrep += 1;
if (f.Begin[0] != '-')
CountInclude += 1;
}
}
@ -3159,24 +3159,24 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
for (const ImGuiTextRange& f : Filters)
{
if (f.b == f.e)
if (f.Begin == f.End)
continue;
if (f.b[0] == '-')
if (f.Begin[0] == '-')
{
// Subtract
if (ImStristr(text, text_end, f.b + 1, f.e) != NULL)
if (ImStristr(text, text_end, f.Begin + 1, f.End) != NULL)
return false;
}
else
{
// Grep
if (ImStristr(text, text_end, f.b, f.e) != NULL)
if (ImStristr(text, text_end, f.Begin, f.End) != NULL)
return true;
}
}
// Implicit * grep
if (CountGrep == 0)
if (CountInclude == 0)
return true;
return false;

26
imgui.h
View file

@ -2789,26 +2789,26 @@ struct ImGuiOnceUponAFrame
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(); }
IMGUI_API void Build(); // Update internal data when filter changes
inline void Clear() { InputBuf[0] = 0; Build(); } // Clear filter
inline bool IsActive() const { return Filters.Size != 0; } // Useful if you need e.g. an alternative code-path when there are no filters
// [Internal]
// Helper to call InputText() + Build() when buffer is changed.
IMGUI_API bool Draw(const char* label = "Filter (inc,-exc)", float width = 0.0f);
// [Internal] Don't use! Will be replaced with ImStrv.
struct ImGuiTextRange
{
const char* b;
const char* e;
ImGuiTextRange() { b = e = NULL; }
ImGuiTextRange(const char* _b, const char* _e) { b = _b; e = _e; }
bool empty() const { return b == e; }
IMGUI_API void split(char separator, ImVector<ImGuiTextRange>* out) const;
const char* Begin;
const char* End;
ImGuiTextRange(const char* b, const char* e) { Begin = b; End = e; }
};
// [Internal] Members
char InputBuf[256];
ImVector<ImGuiTextRange>Filters;
int CountGrep;
int CountInclude;
};
// Helper: Growable text buffer for logging/accumulating text