-
Notifications
You must be signed in to change notification settings - Fork 310
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
c# example for ImGuiTextFilter #107
Comments
The C# code generator needs to be augmented to allow constructors for native objects to be called. Without that, there's no current way to create an ImGuiTextFilter. It's not a lot of work to add this functionality to the code generator; the information is already there waiting to be used. |
I'm not sure what the generated constructor for |
It turns out this not only affects text filters but also ImFontConfig which needs to be created on the native side. @mellinoe if you can point me in the right direction (brief overview of what needs to be done) I can try to carve out some time to get this going. |
I pushed two changes to master that fix the raw PInvokes for constructor and destructor functions: 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 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:
|
Sorry about double post. Used the wrong GitHub account. Thanks @mellinoe! Works like a champ. For those who find this later here is an // create the object on the native side
var nativeConfig = ImGuiNative.ImFontConfig_ImFontConfig();
// fill with data
(*nativeConfig).OversampleH = 3;
(*nativeConfig).OversampleV = 1;
(*nativeConfig).RasterizerMultiply = 1f;
(*nativeConfig).GlyphExtraSpacing = new Num.Vector2(10, 0);
// use the object
ImGui.GetIO().Fonts.AddFontFromFileTTF("/Library/Fonts/Comic Sans MS.ttf", 16, nativeConfig);
// delete the reference. ImGui copies it
ImGuiNative.ImFontConfig_destroy(nativeConfig); Or, using the Ptr wrapper class: // create the object on the native side and wrap it in a C# class
var nativeConfig = ImGuiNative.ImFontConfig_ImFontConfig();
var config = new ImFontConfigPtr(nativeConfig);
// use the object
config.OversampleH = 2;
config.OversampleV = 1;
config.RasterizerMultiply = 1f;
ImGui.GetIO().Fonts.AddFontFromFileTTF("/Library/Fonts/Comic Sans MS.ttf", 16, nativeConfig);
// delete the reference. ImGui copies it
config.Destroy(); |
For the sake of completeness and future visitors, here is an 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);
}
} |
One last thing for @mellinoe: any chance of a NuGet bump? |
This helped me with other issue i was having creating ImFontConfig. Thanks! |
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.
I did find the ImGuiTextFilterPtr struct/class but not sure how to use it.
reference c++ eample
The text was updated successfully, but these errors were encountered: