kotlin-graphics / imgui

Bloat-free Immediate Mode Graphical User interface for JVM with minimal dependencies (rewrite of dear imgui)
MIT License
594 stars 37 forks source link

popen at begin not updating. or am i doing something wrong? #147

Closed gurachan closed 3 years ago

gurachan commented 3 years ago

in java

boolean[] popen_yikes = new boolean[] { true }; 
UI.begin("Sample", popen_yikes, 0, WindowFlag.AlwaysAutoResize.i)

if I hit the X button should popen_yikes became false? I don't understand how to handle the close xD because it's not updating the popen_yikes

I mean on the checkbox

boolean[] test = new boolean[] { false }; 
UI.checkbox(" say hi?", test);

why the test gets updated?

and not the popen_yikes one.

zeroeightysix commented 3 years ago

Hmm, what does UI#begin look like? This is just a guess, but are you not calling ImGui.end() to finish drawing the window?

gurachan commented 3 years ago

its a

boolean[] isopen = {
    false
};

@Override
public void render(...........) {

    gui.ImGuiIO = UI.getIo();
    gui.implGl3.newFrame();
    gui.implGlfw.newFrame();
    UI.newFrame();

    if (UI.begin("sample1", isopen, WindowFlag.AlwaysAutoResize.i + WindowFlag.MenuBar.i)) {

        UI.end();
    }

    //test if its updating really since the above wont close
    System.err.println(isopen[0]);
    UI.render();
    gui.implGl3.renderDrawData(Objects.requireNonNull(UI.getDrawData()));
}

in checkbox it works tho ... since imgui kotlin did that to counter KMutableProperty0 thingy I feel the logic is the same but it's just not updating unlike checkboxes..

gurachan commented 3 years ago

yeah its totaly broken i just used the MutableProperty0 as

MutableProperty0<Boolean> hi = new MutableProperty0<Boolean>(true);

this one updates it..

boolean imgui.ImGui.begin(@NotNull String name, @Nullable KMutableProperty0<Boolean> pOpen, int flags_) vs boolean imgui.ImGui.begin(@NotNull String name, @NotNull boolean[] pOpen, int flags)

in java, the one with @NotNull boolean[] pOpen is broken only on the begin one.. because on checkboxes it works

the behavior of updating the open only works with MutableProperty0.. but not @NotNull boolean[] pOpen..

im using java 8 btw

elect86 commented 3 years ago

@Dj-jom2x If you want, I can add you, so you can easily create a new branch and test there an hotfix for that and push it back if fine

exuvo commented 3 years ago

ImGUI only changes the passed array value to false when close is clicked, it does nothing else at all with the value. So to stop it from drawing the window you need to use the variable in an if check for begin. Ex:

boolean[] isOpen = {true}; 

public void draw() {
  if (isOpen[0] && ImGui.INSTANCE.begin("test", isOpen, 0)) { // if close is clicked isOpen[0] becomes false
    ImGui.INSTANCE.text("test " + isOpen[0]); // will be seen as false for 1 frame
    ImGui.INSTANCE.end();
  }
}

Just tested this and it works as expected. Also remember that if the boolean[] is a local variable it is only false 1 frame so keep it permanent.

gurachan commented 3 years ago

ooow only 1 frame. thanks for explaining :) I already change all my booleans to MutableProperty0 xD before I read this.. because MutableProperty0 is more readable. I guess i can close this now :)