CountGrep/Filters.Size always returns 1 #3906

Closed
opened 2021-03-13 04:48:01 +00:00 by flamendless · 3 comments
flamendless commented 2021-03-13 04:48:01 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: 1.81 WIP
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl2.cpp + imgui_impl_glfw.cpp
Compiler: Clang
Operating System: Manjaro Linux x86_64

My Issue/Question:

I'm using the ImGuiTextFilter API (followed the one in the imgui_demo.cpp) for my CommandPalette UI.
The rendering code is as follow:

ImGuiTextFilter CommandPalette::filter;
//Commands::v_cmd is a std::vector with 8 items

//draw
		CommandPalette::filter.Draw(ICON_FA_SEARCH);
		ImGui::SetKeyboardFocusHere(-1);

		for (int i = 0; i < Commands::v_cmd.size(); i++)
		{
			const Command* cmd = Commands::v_cmd[i];

			if (CommandPalette::filter.PassFilter(cmd->m_title.c_str()))
			{
				if (CommandPalette::filter.CountGrep != 0)
				{
					ImGui::TextColored(color, "%s %s", cmd->m_icon, cmd->m_title.c_str());
					ImGui::SameLine();
					ImGui::TextColored(color, "(%s)", cmd->m_desc.c_str());
				}
			}
		}

The filtering works, when I type p, i get the 3 results.

I've tried printing the value of filter.CountGrep after the filter.Draw() and after the filter.PassFilter() but the value is always 1 regardless of the number of items filtered (value is 0 of course when there is no text input in the filter box).

I've tried also printing filter.Filters.Size but same behavior as CountGrep.

I believe CountGrep is incremented many times as I've seen in the source code imgui.cpp

**Version/Branch of Dear ImGui:** Version: 1.81 WIP Branch: master **Back-end/Renderer/Compiler/OS** Back-ends: imgui_impl_opengl2.cpp + imgui_impl_glfw.cpp Compiler: Clang Operating System: Manjaro Linux x86_64 **My Issue/Question:** I'm using the ImGuiTextFilter API (followed the one in the imgui_demo.cpp) for my CommandPalette UI. The rendering code is as follow: ```cpp ImGuiTextFilter CommandPalette::filter; //Commands::v_cmd is a std::vector with 8 items //draw CommandPalette::filter.Draw(ICON_FA_SEARCH); ImGui::SetKeyboardFocusHere(-1); for (int i = 0; i < Commands::v_cmd.size(); i++) { const Command* cmd = Commands::v_cmd[i]; if (CommandPalette::filter.PassFilter(cmd->m_title.c_str())) { if (CommandPalette::filter.CountGrep != 0) { ImGui::TextColored(color, "%s %s", cmd->m_icon, cmd->m_title.c_str()); ImGui::SameLine(); ImGui::TextColored(color, "(%s)", cmd->m_desc.c_str()); } } } ``` The filtering works, when I type `p`, i get the 3 results. I've tried printing the value of `filter.CountGrep` after the `filter.Draw()` and after the `filter.PassFilter()` but the value is always `1` regardless of the number of items filtered (value is 0 of course when there is no text input in the filter box). I've tried also printing `filter.Filters.Size` but same behavior as `CountGrep`. I believe `CountGrep` is incremented many times as I've seen in the source code `imgui.cpp`
ocornut commented 2021-03-15 10:40:39 +00:00 (Migrated from github.com)

What problem are you trying to solve?
CountGrep is an internal flag, you are not meant to read that flag. If you check all examples use of this helper all you are supposed to do is to call PassFilter().

What problem are you trying to solve? `CountGrep` is an internal flag, you are not meant to read that flag. If you check all examples use of this helper all you are supposed to do is to call `PassFilter()`.
flamendless commented 2021-03-15 14:59:36 +00:00 (Migrated from github.com)

Oh that's for internal use. Pardon for that.

I'm trying to get all the count of the items resulted by the text filter.

Oh that's for internal use. Pardon for that. I'm trying to get all the count of the items resulted by the text filter.
ocornut commented 2021-03-15 15:08:58 +00:00 (Migrated from github.com)

if (CommandPalette::filter.PassFilter(cmd->m_title.c_str()))

You are calling the filter and it returns true when an item passes. So you can infer that count if you need it.

> if (CommandPalette::filter.PassFilter(cmd->m_title.c_str())) You are calling the filter and it returns true when an item passes. So you can infer that count if you need it.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#3906
No description provided.