ImGuiTextFilter: moved ImGuiTextFilterItem to internals. (#2435)

This commit is contained in:
ocornut 2026-09-21 15:12:59 +02:00
parent d5c68c301a
commit e19fea020f
3 changed files with 16 additions and 14 deletions

View file

@ -3156,7 +3156,7 @@ void ImGuiTextFilter::Build()
// FIXME-OPT: as items are derived from user input buffer and we expect the insert() to behave sanely.
if (is_excl)
{
_Items.insert(_Items.Data + _CountExclude, ImGuiTextFilter::ImGuiTextFilterItem(word_b, word_e));
_Items.insert(_Items.Data + _CountExclude, ImGuiTextFilterItem(word_b, word_e));
_CountExclude++;
if (seq_incl_start_idx != -1)
seq_incl_start_idx++;
@ -3165,7 +3165,7 @@ void ImGuiTextFilter::Build()
{
if (seq_incl_start_idx == -1)
seq_incl_start_idx = _Items.Size;
_Items.insert(_Items.Data + _Items.Size, ImGuiTextFilter::ImGuiTextFilterItem(word_b, word_e));
_Items.insert(_Items.Data + _Items.Size, ImGuiTextFilterItem(word_b, word_e));
_Items.Data[seq_incl_start_idx].CountInclude++;
}
}

16
imgui.h
View file

@ -2786,6 +2786,7 @@ struct ImGuiOnceUponAFrame
};
// Helper: Parse and apply text filters e.g. 'aaa bbb' (all), 'aaa,bbb' (any), '-aaa' (exclude), '"Hello, world"' (exact sequence)
struct ImGuiTextFilterItem;
struct ImGuiTextFilter
{
IMGUI_API ImGuiTextFilter(const char* default_filter = "");
@ -2801,19 +2802,10 @@ struct ImGuiTextFilter
inline bool Draw(const char* label, float width) { if (width != 0.0f) ImGui::SetNextItemWidth(width); return Draw(label); }
#endif
// [Internal] Types
struct ImGuiTextFilterItem
{
const char* Begin;
int Len;
int CountInclude; // >0 when beginning of an AND chain.
ImGuiTextFilterItem(const char* b, const char* e) { IM_ASSERT(e > b); Begin = b; Len = (int)(e - b); CountInclude = 0; }
};
// [Internal] Members
// Members
char InputBuf[256]; // User input buffer
int _CountExclude; // >= 0 count of leading exclude
ImVector<ImGuiTextFilterItem> _Items; // Pre-parsed, trimmed, reordered items
int _CountExclude; // [Internal] >= 0 count of leading exclude
ImVector<ImGuiTextFilterItem> _Items; // [Internal] Pre-parsed, trimmed, reordered items
};
// Helper: Growable text buffer for logging/accumulating text

View file

@ -368,6 +368,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer
// - Helper: ImPool<>
// - Helper: ImChunkStream<>
// - Helper: ImGuiTextIndex
// - Helper: ImGuiTextFilterItem
// - Helper: ImGuiStorage
//-----------------------------------------------------------------------------
@ -836,6 +837,15 @@ struct ImGuiTextIndex
void append(const char* base, int old_size, int new_size);
};
// [Internal] Types
struct ImGuiTextFilterItem
{
const char* Begin;
int Len;
int CountInclude; // >0 when beginning of an AND chain.
ImGuiTextFilterItem(const char* b, const char* e) { IM_ASSERT(e > b); Begin = b; Len = (int)(e - b); CountInclude = 0; }
};
// Helper: ImGuiPackedDate (sizeof() == 2)
// Store a date in a way that is efficient to read/write in text form. If we stored e.g. number of days since Epoch we'd need costlier back and forth.
// This is specifically designed to be able to prune old .ini data.