kotlin-graphics / imgui

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

Text inputs handling #14

Closed Catvert closed 6 years ago

Catvert commented 6 years ago

This post will be used to solve inputs handling problems.

Catvert commented 6 years ago

I have a question, are the inputTexts supposed to work already now? Because in my projects, nothing happens when I press a key in an inputText even with active callbacks.

elect86 commented 6 years ago

Yes, what are you using? Could you paste here a snippet of code?

Catvert commented 6 years ago

Hi ! I am still using libGDX so the Lwjgl3 wrapper. I initialize Lwjgl3 with :

LwjglGL3.init(GlfwWindow((Gdx.graphics as Lwjgl3Graphics).window.windowHandle), true)

I'm going to try to list all the problems I find using keyboard widgets. I use the test window (ImGui. showTestWindow) for the different tests I have performed (in widgets -> basic).

When i install callback, I can correctly enter a number on the keyboard on dragInt/dragFloat. But when I just click on an inputInt/inputFloat the program crash. With this error : Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextFloat(Scanner.java:2345) at imgui.Static_funcsKt.dataTypeApplyOpFromText(static funcs.kt:599) at imgui.imgui.imgui_internal$DefaultImpls.inputScalarEx(internal.kt:2140) at imgui.ImGui.inputScalarEx(imgui.kt:27) at imgui.imgui.imgui_internal$DefaultImpls.inputScalarEx(internal.kt:2114) at imgui.ImGui.inputScalarEx(imgui.kt:27) at imgui.imgui.imgui_widgetsInputKeyboard$DefaultImpls.inputFloat(widgets inputKeyboard.kt:53) at imgui.ImGui.inputFloat(imgui.kt:27) at imgui.imgui.imgui_internal$DefaultImpls.inputFloatN(internal.kt:2075) at imgui.ImGui.inputFloatN(imgui.kt:27) at imgui.imgui.imgui_widgetsInputKeyboard$DefaultImpls.inputFloat3(widgets inputKeyboard.kt:69) at imgui.ImGui.inputFloat3(imgui.kt:27) at imgui.imgui.imgui_widgetsInputKeyboard$DefaultImpls.inputFloat3$default(widgets inputKeyboard.kt:68) at imgui.imgui.demo.widgets.invoke(widgets.kt:298) at imgui.imgui.demo.ExampleApp.invoke(ExampleApp.kt:238) at imgui.imgui.imgui_demoDebugInformations$DefaultImpls.showTestWindow(demo debug informations.kt:85) at imgui.ImGui.showTestWindow(imgui.kt:27) at imgui.imgui.imgui_demoDebugInformations$DefaultImpls.showTestWindow(demo debug informations.kt:81) at imgui.ImGui.showTestWindow(imgui.kt:27) ...

The next thing is the inputText. I can click on it and have a cursor displayed but nothing happens when I press a keyboard touch.

The last problem I encountered is I think it's related to the fact that I use libGDX with this library. Indeed, when I install callbacks in the init function of Lwjgl3, it is impossible for me to use libGDX inputs. I cannot use functions such as Gdx.input.isKeyPressed or the Scene2D. I think the problem is that the install callbacks function replaces all callbacks that libGDX already uses on the window. If necessary, I can try to create my own wrapper for libGDX using an InputMultiplexer for example.

I hope to have been quite clear despite my low level of English. Thanks to you, Catvert.

Catvert commented 6 years ago

Any feedback? :)

elect86 commented 6 years ago

Yes,

sorry for the delay but I'm trying to finish the fbx support for assimp asap

Anyway, the InputMismatchException happened because of a locale mismatch, now the Scanner (used to parse the input) will use the locale set in style.locale, which on start will be the java default locale

inputText is working for me.. can you test the demo under Widgets -> Text -> JVM UTF-16 -> try to type there

At the moment if you pass true in LwjglGL3.init() imgui will install its callbacks (overwriting what is there).. and the thing is, you can only have a single callback per type per time.

we are discussing here, to create support out-of-the-box for multiple callbacks of the same type. In the meanwhile, pass false and call each imgui callback manually from your application callbacks

Catvert commented 6 years ago

Hi ! First of all, thank you again for your work. That's excellent! I don't have any more problems with the InputMismatchException !

I've created the callback adapter for inputs for libGDX, I'll post my results in the wiki (if you can take a look at it when I add it).

I have one last little problem, which has nothing to do with the previous problems. I noticed that you are using a CharArray (CharArray (size)) for the inputText buffer in UTF-16. How can I later translate this buffer to convert it into string? Thanks to you, Catvert.

elect86 commented 6 years ago

Yup, you are welcome :)

I'll try to remember to take a look, maybe you can "up" here to notify

String(CharArray), they offer a constructor accepting char array to build a string

Catvert commented 6 years ago

Oh yes it's working, it was another error in my code. I just finished writing it!

elect86 commented 6 years ago

It looks perfect, thanks

Catvert commented 6 years ago

Thanks to you too! :)

Catvert commented 6 years ago

Hi ! I found an another issue. When I want to put a negative number in an inputInt, if there is no number in the field and I add a minus sign, the program crashes with an InputMismatchException from the Scanner.

Sylvyrfysh commented 6 years ago

stacktrace? code?

Catvert commented 6 years ago

Hi ! This is the stacktrace, when I put a minus sign on an empty inputInt in the demo window : Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at imgui.Static_funcsKt.dataTypeApplyOpFromText(static funcs.kt:577) at imgui.imgui.imgui_internal$DefaultImpls.inputScalarEx(internal.kt:2135) at imgui.ImGui.inputScalarEx(imgui.kt:27) at imgui.imgui.imgui_widgetsInputKeyboard$DefaultImpls.inputInt(widgets inputKeyboard.kt:92) at imgui.ImGui.inputInt(imgui.kt:27) at imgui.imgui.imgui_widgetsInputKeyboard$DefaultImpls.inputInt$default(widgets inputKeyboard.kt:88) at imgui.imgui.demo.widgets.invoke(widgets.kt:312) at imgui.imgui.demo.ExampleApp.invoke(ExampleApp.kt:234) at imgui.imgui.imgui_demoDebugInformations$DefaultImpls.showDemoWindow(demo debug informations.kt:86) at imgui.ImGui.showDemoWindow(imgui.kt:27) at imgui.imgui.imgui_demoDebugInformations$DefaultImpls.showDemoWindow(demo debug informations.kt:82) at imgui.ImGui.showDemoWindow(imgui.kt:27)

Sylvyrfysh commented 6 years ago

23 fixes

Catvert commented 6 years ago

Nice work thanks !