mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
ImGuiTextFilter::PassFilter() supports string range. Added [] helper to ImGuiTextBuffer.
This commit is contained in:
parent
72d3fca52f
commit
42567a9516
15
imgui.cpp
15
imgui.cpp
@ -777,13 +777,13 @@ const ImWchar* ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin)
|
||||
return buf_mid_line;
|
||||
}
|
||||
|
||||
const char* ImStristr(const char* haystack, const char* needle, const char* needle_end)
|
||||
const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end)
|
||||
{
|
||||
if (!needle_end)
|
||||
needle_end = needle + strlen(needle);
|
||||
|
||||
const char un0 = (char)toupper(*needle);
|
||||
while (*haystack)
|
||||
while ((!haystack_end && *haystack) || (haystack_end && haystack < haystack_end))
|
||||
{
|
||||
if (toupper(*haystack) == un0)
|
||||
{
|
||||
@ -1326,13 +1326,13 @@ void ImGuiTextFilter::Build()
|
||||
}
|
||||
}
|
||||
|
||||
bool ImGuiTextFilter::PassFilter(const char* val) const
|
||||
bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
|
||||
{
|
||||
if (Filters.empty())
|
||||
return true;
|
||||
|
||||
if (val == NULL)
|
||||
val = "";
|
||||
if (text == NULL)
|
||||
text = "";
|
||||
|
||||
for (int i = 0; i != Filters.Size; i++)
|
||||
{
|
||||
@ -1342,13 +1342,13 @@ bool ImGuiTextFilter::PassFilter(const char* val) const
|
||||
if (f.front() == '-')
|
||||
{
|
||||
// Subtract
|
||||
if (ImStristr(val, f.begin()+1, f.end()) != NULL)
|
||||
if (ImStristr(text, text_end, f.begin()+1, f.end()) != NULL)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grep
|
||||
if (ImStristr(val, f.begin(), f.end()) != NULL)
|
||||
if (ImStristr(text, text_end, f.begin(), f.end()) != NULL)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -2635,6 +2635,7 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex
|
||||
|
||||
// Helper to calculate coarse clipping of large list of evenly sized items.
|
||||
// NB: Prefer using the ImGuiListClipper higher-level helper if you can!
|
||||
// NB: 'items_count' is only used to clamp the result, if you don't know your count you can use INT_MAX
|
||||
// If you are displaying thousands of items and you have a random access to the list, you can perform clipping yourself to save on CPU.
|
||||
// {
|
||||
// float item_height = ImGui::GetTextLineHeightWithSpacing();
|
||||
|
4
imgui.h
4
imgui.h
@ -851,7 +851,7 @@ struct ImGuiTextFilter
|
||||
ImGuiTextFilter(const char* default_filter = "");
|
||||
void Clear() { InputBuf[0] = 0; Build(); }
|
||||
void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f); // Helper calling InputText+Build
|
||||
bool PassFilter(const char* val) const;
|
||||
bool PassFilter(const char* text, const char* text_end = NULL) const;
|
||||
bool IsActive() const { return !Filters.empty(); }
|
||||
IMGUI_API void Build();
|
||||
};
|
||||
@ -862,6 +862,7 @@ struct ImGuiTextBuffer
|
||||
ImVector<char> Buf;
|
||||
|
||||
ImGuiTextBuffer() { Buf.push_back(0); }
|
||||
inline char operator[](int i) { return Buf.Data[i]; }
|
||||
const char* begin() const { return &Buf.front(); }
|
||||
const char* end() const { return &Buf.back(); } // Buf is zero-terminated, so end() will point on the zero-terminator
|
||||
int size() const { return Buf.Size-1; }
|
||||
@ -962,6 +963,7 @@ struct ImColor
|
||||
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) // display only visible items
|
||||
// ImGui::Text("line number %d", i);
|
||||
// clipper.End();
|
||||
// NB: 'count' is only used to clamp the result, if you don't know your count you can use INT_MAX
|
||||
struct ImGuiListClipper
|
||||
{
|
||||
float ItemsHeight;
|
||||
|
@ -93,7 +93,7 @@ int ImStrnicmp(const char* str1, const char* str2, int count);
|
||||
char* ImStrdup(const char* str);
|
||||
int ImStrlenW(const ImWchar* str);
|
||||
const ImWchar* ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line
|
||||
const char* ImStristr(const char* haystack, const char* needle, const char* needle_end);
|
||||
const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end);
|
||||
int ImFormatString(char* buf, int buf_size, const char* fmt, ...) IM_PRINTFARGS(3);
|
||||
int ImFormatStringV(char* buf, int buf_size, const char* fmt, va_list args);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user