From 20fb286e4febbc04bd97718ed55f752d6b5c948c Mon Sep 17 00:00:00 2001 From: Chaojimengnan Date: Tue, 23 May 2023 13:04:32 +0800 Subject: [PATCH] add `DrawWithHint` to `ImGuiTextFilter` --- imgui.cpp | 10 ++++++++++ imgui.h | 1 + 2 files changed, 11 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index c74abe6a6..8859aea36 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2472,6 +2472,16 @@ bool ImGuiTextFilter::Draw(const char* label, float width) return value_changed; } +bool ImGuiTextFilter::DrawWithHint(const char* label, const char* hint, float width) +{ + if (width != 0.0f) + ImGui::SetNextItemWidth(width); + bool value_changed = ImGui::InputTextWithHint(label, hint, InputBuf, IM_ARRAYSIZE(InputBuf)); + if (value_changed) + Build(); + return value_changed; +} + void ImGuiTextFilter::ImGuiTextRange::split(char separator, ImVector* out) const { out->resize(0); diff --git a/imgui.h b/imgui.h index 157b301c3..78b647c6a 100644 --- a/imgui.h +++ b/imgui.h @@ -2213,6 +2213,7 @@ 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 DrawWithHint(const char* label, const char* hint = "Filter (inc,-exc)", float width = 0.0f); IMGUI_API bool PassFilter(const char* text, const char* text_end = NULL) const; IMGUI_API void Build(); void Clear() { InputBuf[0] = 0; Build(); }