Dominaezzz / kotlin-imgui

Kotlin bindings for Dear ImGui
MIT License
83 stars 4 forks source link

Nullable (`None`) flag value cannot be easily `or`ed with other values #15

Closed nlbuescher closed 4 years ago

nlbuescher commented 4 years ago

None is a perfectly valid option to pass as a flag for ImGui, but the code generator doesn't translate it into an enum value

cf ImGuiDockNodeFlags_None vs no equivalent in enum class ImGuiDockNodeFlags

nlbuescher commented 4 years ago

I'm realizing now that a nullable is likely intended to replace the None value. Then I noticed that oring a Nullable with any other value isn't possible.

Dominaezzz commented 4 years ago

None is indeed supposed to be null in Kotlin. Is there a use case for oring with None? It's a no-op anyway.

nlbuescher commented 4 years ago

oring with None is how you add new flags to a variable that was declared as empty. anding with None is a no-op

nlbuescher commented 4 years ago

usecase:

var windowFlags: ImGuiWindowFlags? = null

// possibly add other conditional flags

if (isFullScreen) {
    windowFlags = windowFlags or ImGuiWindowFlags.NoTitleBar or ImGuiWindowFlags.NoCollapse or
        ImGuiWindowFlags.NoResize or ImGuiWindowFlags.NoMove or
        ImGuiWindowFlags.NoBringToFrontOnFocus or ImGuiWindowFlags.NoNavFocus
}
Dominaezzz commented 4 years ago

val value: Flag<ImGuiWindowFlags>? = null or ImGuiWindowFlags.NoTitleBar is possible.

Your example is already possible, with the wrapper class.

EDIT:

Like so

var windowFlags: Flag<ImGuiWindowFlags>? = null

// possibly add other conditional flags

if (isFullScreen) {
    windowFlags = windowFlags or ImGuiWindowFlags.NoTitleBar or ImGuiWindowFlags.NoCollapse or
        ImGuiWindowFlags.NoResize or ImGuiWindowFlags.NoMove or
        ImGuiWindowFlags.NoBringToFrontOnFocus or ImGuiWindowFlags.NoNavFocus
}
nlbuescher commented 4 years ago

I see. Thanks for that. Closing cause derp.