From 162602752b58b4f58a30d61cf668e1a17bc3d95e Mon Sep 17 00:00:00 2001 From: Nicolas Phister Date: Thu, 29 Sep 2022 16:24:33 +0200 Subject: [PATCH] Text Filter: Expose new customization options to users --- imgui.cpp | 26 ++++++++++++++++++++++++++ imgui.h | 1 + 2 files changed, 27 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 8195b6c84791..f4684ffec738 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2047,6 +2047,7 @@ ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) : MatchMode(ImGuiTextFilterMode_Or) , WordSplitter(',') , MinWordSize(0) + , ShowSettings(false) { if (default_filter) { @@ -2061,11 +2062,36 @@ ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) bool ImGuiTextFilter::Draw(const char* label, float width) { + ImGui::PushID(this); + const ImGuiDir ArrowDirection = ShowSettings ? ImGuiDir_Down : ImGuiDir_Right; + if (ImGui::ArrowButton("Settings", ArrowDirection)) + ShowSettings = !ShowSettings; + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Filter settings"); + ImGui::PopID(); + + ImGui::SameLine(); + if (width != 0.0f) ImGui::SetNextItemWidth(width); bool value_changed = ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf)); if (value_changed) Build(); + + if (ShowSettings) + { + ImGui::TreePush(this); + const char *modes[] = {"Or", "And"}; + ImGui::Combo("Match mode", &MatchMode, modes, 2); + + char buff[2] = {WordSplitter, 0}; + ImGui::InputText("Word splitter", buff, sizeof(buff)); + WordSplitter = buff[0]; + + ImGui::InputScalar("Min word size", ImGuiDataType_S8, &MinWordSize); + ImGui::TreePop(); + } + return value_changed; } diff --git a/imgui.h b/imgui.h index 220458a5cfb5..ab2d1c08f174 100644 --- a/imgui.h +++ b/imgui.h @@ -1713,6 +1713,7 @@ struct ImGuiTextFilter char InputBuf[256]; ImVector Filters; int NegativeFilterCount; + bool ShowSettings; // [Configuration] ImGuiTextFilterMode MatchMode; // if true then all words must match, otherwise any matching word will be a pass