ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.87k stars 304 forks source link

How do I use ImGuiListClipper for drawing a flow container of tiles #393

Closed Shadowblitz16 closed 1 year ago

Shadowblitz16 commented 1 year ago

I am trying to simulate a scroll area and only draw the visible tiles...

                    var size  = ImGui.GetContentRegionAvail();
                    var index = 0;
                    var count = Tiles.Length;

                    var clipper = new ImGuiListClipperPtr();
                    clipper.Begin((int)(size.X * size.Y), TileSizeY);

                    for (var i=0; i<Tiles.Length; i++)
                    {
                        if (ImGui.GetItemRectMax().X < size.X) ImGui.SameLine();

                        var image = Image(Tiles[index].GetTexture(), new(1,0), new(0,1));
                        Raylib.BeginTextureMode(image);
                        Raylib.DrawRectangleLines(0,0, TileSizeX, TileSizeY, Color.WHITE);
                        Raylib.EndTextureMode();
                        index++;
                    }
                    clipper.End();
Shadowblitz16 commented 1 year ago

ListClipperPtr crashes the program and there is no ImGuiList class to pass to it's constructor

sonoro1234 commented 1 year ago

https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp#L5658

Shadowblitz16 commented 1 year ago

yes it crashes. Also please provide C# code when people ask for examples. ListClipper doesn't have a Begin, Step or End method only ListClipperPtr does so the c++ api is not a good reference

TheLostTree commented 1 year ago

Confirming that ListClipperPtr crashes for me as well :(

TheLostTree commented 1 year ago

Nevermind! I figured out that using this works without crashing

ImGuiListClipperPtr listClipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper());
ocornut commented 1 year ago

I have also pushed a workaround on dear imgui side: https://github.com/ocornut/imgui/commit/e95d66faa8e6c0255572632f34fad97a32f680cd