kotlin-graphics / imgui

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

how to use textEditCallbackStub? in java? #151

Open gurachan opened 4 years ago

gurachan commented 4 years ago

I don't understand this :(

https://github.com/kotlin-graphics/imgui/blob/78812070f9baaede41a01ba21ffb89d3edd6ea94/imgui-core/src/main/kotlin/imgui/demo/showExampleApp/Console.kt#L219-L223

anyone does have a java version of console.kt .. java decompiler doesn't make any sense :( I want to know how to use that callback thingy in inputText

the decompilation looks like

image

when i read this val textEditCallbackStub: InputTextCallback

i thought its going to be InputTextCallback textEditCallbackStub but theres method stub for InputTextCallback i dont understand xD

elect86 commented 3 years ago

Fire up the demo test, then -> widgets -> Text Input -> Filtered Text Input

The following filter is apply

    val filterImGuiLetters: InputTextCallback = { data: InputTextCallbackData ->
        when {
            data.eventChar.i < 256 && data.eventChar in "imgui" -> false
            else -> true
        }
    }

It basically means that if the typed char is no one of imgui then it gets filtered (blocked)

Eg. you can type uiiiiuuuummg

elect86 commented 3 years ago

Sorry, I misunderstood what you asked

    var filter = new Function1<InputTextCallbackData, Boolean>() {
        @Override
        public Boolean invoke(InputTextCallbackData inputTextCallbackData) {
            if ("ciao".indexOf(inputTextCallbackData.getEventChar()) != -1)
                return Boolean.FALSE;
            else
                return Boolean.TRUE;
        }
    };
    imgui.inputText("label", "buf", 0, filter, null);

Ps: I can add some overload so you don't have to type null at the end