Skip to content
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

Closed
phraktle opened this issue Mar 1, 2023 · 5 comments
Closed

expose ImGuiTextFilter buffer #160

phraktle opened this issue Mar 1, 2023 · 5 comments
Labels
missing binding Some of the original library API is missing

Comments

@phraktle
Copy link

phraktle commented Mar 1, 2023

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.

@phraktle phraktle added the missing binding Some of the original library API is missing label Mar 1, 2023
@SpaiR
Copy link
Owner

SpaiR commented Mar 2, 2023

I think it's possible to add, but usage of ImGuiTextFilter in the context of the binding is, in my opinion, very redundant.

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 ImGuiUtil class. You can add method like:

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);
    }
}

@phraktle
Copy link
Author

phraktle commented Mar 2, 2023

Sure, one could reimplement the functionality – but it does a bit more than contains (parses OR and NOT expressions as well).

@SpaiR
Copy link
Owner

SpaiR commented Mar 2, 2023

Agreed, that sounds like a point. 🤔

@SpaiR SpaiR closed this as completed in 4a5c587 Mar 2, 2023
@SpaiR
Copy link
Owner

SpaiR commented Mar 2, 2023

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);
    }
}

@phraktle
Copy link
Author

phraktle commented Mar 4, 2023

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing binding Some of the original library API is missing
Projects
None yet
Development

No branches or pull requests

2 participants