-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose ImGuiTextFilter buffer #160
Comments
I think it's possible to add, but usage of Speaking about your use case, you can simply do: // Class field
private ImString filter = new ImString();
// Method body
ImGui.inputTextWithHint("##filter", "Filter", filter);
String[] lines = {"aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world"};
for (String line : lines) {
if (filter.isEmpty() || line.contains(filter.get())) {
ImGui.bulletText(line);
}
} Will do absolutely what you need. It's very useful to have an public boolean isPassFilter(ImString filter, String str) {
return filter.isEmpty() || line.contains(filter.get());
} to have something like: // Class field
private ImString filter = new ImString();
// Method body
ImGui.inputTextWithHint("##filter", "Filter", filter);
String[] lines = {"aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world"};
for (String line : lines) {
if (ImGuiUtil.isPassFilter(filter, line)) {
ImGui.bulletText(line);
}
} |
Sure, one could reimplement the functionality – but it does a bit more than contains (parses OR and NOT expressions as well). |
Agreed, that sounds like a point. 🤔 |
Added appropriate method. Using example from the previous comment, it will work like: // Class field
private ImString filterStr = new ImString();
private ImGuiTextFilter textFilter = new ImGuiTextFilter();
// Method body
ImGui.inputTextWithHint("##filter", "Filter", filterStr);
textFilter.setInputBuffer(filterStr.get());
textFilter.build();
String[] lines = {"aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world"};
for (String line : lines) {
if (textFilter.passFilter(line)) {
ImGui.bulletText(line);
}
} |
Thanks, that works! Note for the example: it's best to set the filter only on changes. if (ImGui.inputTextWithHint("##filter", "Filter", filterStr)) {
textFilter.setInputBuffer(filterStr.get());
textFilter.build();
} |
Version
1.86.7
What part of the binding has gaps?
Dear ImGui
What is missing?
See ocornut/imgui#6206 - is there a way to pass the buffer from an
ImGuiTextFilter
to an input field? If not, it would be great if it could at least be set explicitly.The text was updated successfully, but these errors were encountered: