question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

c# example for ImGuiTextFilter

See original GitHub issue

I was trying to use ImGuiTextFilter but couldn’t find a c# example of it. I looked at the ImGui demo code example and tried to replicate that on ImGui.NET but failed. Here’s the code I was using, let me know how to use this feature.

ImGuiTextFilter testing = new ImGuiTextFilter();
testing.draw()

I did find the ImGuiTextFilterPtr struct/class but not sure how to use it.

reference c++ eample

static ImGuiTextFilter filter;
filter.draw();
        const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
        for (int i = 0; i < IM_ARRAYSIZE(lines); i++)
            if (filter.PassFilter(lines[i]))
                ImGui::BulletText("%s", lines[i]);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
prime31commented, Feb 25, 2019

For the sake of completeness and future visitors, here is an ImGuiTextFilter example as well:

unsafe public class CleanTest
{
    string[] _lines = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
    ImGuiTextFilterPtr _filter;

    public CleanTest()
    {
        var filterPtr = ImGuiNative.ImGuiTextFilter_ImGuiTextFilter(null);
        _filter = new ImGuiTextFilterPtr(filterPtr);
    }

    public void Draw()
    {
        ImGui.Begin("Here We Go");

        _filter.Draw("This is a text filter");

        foreach(var line in _lines)
        {
            if (_filter.PassFilter(line))
                ImGui.BulletText(line);
        }

        ImGui.End();
    }

    public void Destroy()
    {
        ImGuiNative.ImGuiTextFilter_destroy(_filter.NativePtr);
    }
}
3reactions
mellinoecommented, Feb 25, 2019

I pushed two changes to master that fix the raw PInvokes for constructor and destructor functions:

https://github.com/mellinoe/ImGui.NET/commit/8e3caa1b49bd6b8df5bb277c52c5bb9c32115813 https://github.com/mellinoe/ImGui.NET/commit/4588142ef950d3e474de5635a99f890b55095570

Ideally, there would be static functions that invoke the native constructor, with default parameters being generated as with other overloads. Right now, you can invoke the functions added in the first commit and get back a raw pointer, which needs to be deleted later with a matching thing_destroy call.

Another note: you could already create these structures on the C# side and pass a pointer to them to the native side. Where it gets tricky is:

  • ImVector – The native side will likely try to reallocate the buffer at some point, and things will probably not work. If you preallocate a large enough vector, it might work. This matters for ImGuiTextFilter because it contains a vector.
  • Default values – Allocating the struct in C# will zero-init everything, which means it won’t have the default values it would have in C++: for example.
  • Lifetime – if you’re passing a pointer to the C# object, you need to make sure it remains valid (e.g. not on the stack if it’s long-lived).
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# example for ImGuiTextFilter · Issue #107
I was trying to use ImGuiTextFilter but couldn't find a c# example of it. I looked at the ImGui demo code example and...
Read more >
C++ (Cpp) ImGuiTextFilter::PassFilter Examples
C++ (Cpp) ImGuiTextFilter::PassFilter - 2 examples found. These are the top rated real world C++ (Cpp) examples of ImGuiTextFilter::PassFilter extracted ...
Read more >
C++ ImGui Filter using vector<string>
Here is an example for the Filter in ImGui: static ImGuiTextFilter filter; filter. ... How can I filter a vector of strings in...
Read more >
imgui_demo.cpp
Message to beginner C/C++ programmers about the meaning of the 'static' keyword: ... [SECTION] Example App: Custom Rendering using ImDrawList API ...
Read more >
[Source] Simple filtered list for ImGui
Simple filtered list for ImGui - C and C++ Hacks and Cheats Forum.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found