FlorianMichael / fabric-imgui-example-mod

Example Fabric mod which includes Dear ImGui
Creative Commons Zero v1.0 Universal
18 stars 1 forks source link

Doing multiple imgui.begin() - can't interact with the second window? #6

Closed AwertaDreams closed 1 month ago

AwertaDreams commented 1 month ago

Hello. My first ImGui window stops being responsive after i open a new one via a imgui.checkbox.

public class ImGuiScreen {
    private static boolean drawMainMenu = false;
    private static boolean drawAutoEnchant = false;
    private static int[] intervalHolder = { (int) (CHECK_INTERVAL / 1000) };

    public static void drawHud(DrawContext context, RenderTickCounter tickCounter) {

        if (drawMainMenu) {
            ImGuiImpl.draw(io -> {
                ImGui.begin("EntityFix // 0.0.1 ");
                if (ImGui.beginTabBar("TabBar")) {
                    if (ImGui.beginTabItem("Entity Scan")) {
                        if (ImGui.sliderInt("Interval (in seconds)", intervalHolder, 1, 120)) {
                            CHECK_INTERVAL = intervalHolder[0] * 1000L;
                        };
                        ImGui.endTabItem();
                    }

                    if (ImGui.beginTabItem("Auto Enchanter")) {
                        if (ImGui.checkbox("open overlay", drawAutoEnchant)) {

                        }
                        ImGui.endTabItem();
                    }
                }
                ImGui.endTabBar();

                ImGui.end();

            });
        }

        if (drawAutoEnchant) {
            ImGuiImpl.draw(io -> {
                ImGui.begin("tbox");
                ImGui.text("helol");
                ImGui.end();
            });
        }
    }

    public static void toggleMainMenu() {
        drawMainMenu = !drawMainMenu;
    }

}

This is how i use a Mixin to render the ImGui

@Mixin(InGameHud.class)
public class InGameHudMixin {
    private MinecraftClient client = MinecraftClient.getInstance();

    @Inject(method="renderStatusEffectOverlay", at=@At("RETURN"))
    private void onRenderStatusEffectsOverlay(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
        drawHud(context, tickCounter);

    }

}
FlorianMichael commented 1 month ago

You can only have one ImGuiImpl.draw() invoke at the same time, move both windows into the same call.

AwertaDreams commented 1 month ago

Oh, thank you haha