Skip to content

ImGuiReturnMask Usage

Torin edited this page Nov 11, 2023 · 3 revisions

To work with the limitations of not being able to retrieve variable pointers from GameMaker, ImGui_GM encodes both the return value and the modified pointer value into a single return to GameMaker. By default, all wrapper functions should mask with ImGuiReturnMask.Return which masks out only the return value from the library function (so for example, ImGui.Begin will only return the collapsed/clipped bool as returned from ImGui::Begin)

To retrieve other returns, you can either provide a different enum as the mask argument or use ImGuiReturnMask.Both to get both the return as the 0th bit and the pointer boolean as the 1st bit. It's worth mentioning that return values in higher bits are not shifted down, but GameMaker's truthy evaluation shouldn't necessitate doing so.

Below is an example using ImGuiReturnMask.Both to implement window closing behaviour:

// Create Event
open = true;

// Step Event
if (open) {
    // Retrieve both returns and assign to local
    var ret = ImGui.Begin("Test", open, ImGuiWindowFlags.None, ImGuiReturnMask.Both);

    // binary AND to get pointer bit, assign to open variable
    open = ret & ImGuiReturnMask.Pointer;

    // binary AND to get return value, if true (>=0.5) then window is visible!
    if (ret & ImGuiReturnMask.Return) {
        ImGui.TextColored("hewwo", c_aqua);
    }
    ImGui.End();
}
Clone this wiki locally