Bonito.jl icon indicating copy to clipboard operation
Bonito.jl copied to clipboard

Keyboard input doesn't work

Open EdsterG opened this issue 2 years ago • 8 comments

I'm not sure whether this is an issue with JSServe or WGLMakie, but the Textbox widget from WGLMakie doesn't work with JSServe.

EdsterG avatar Feb 10 '23 02:02 EdsterG

i can't get Makie.Textbox to work either (ditto for Menu). i think the intention is you have to refactor your code to use Bonito.TextField (Dropdown) instead. like this:

julia> using Bonito

julia> app = App() do
           TextField("default text")
       end

it would be unfortunate if a refactoring is needed, as then the same code can't be used to create a desktop app with GLMakie and a webapp with WGLMakie.

bjarthur avatar Jan 08 '24 15:01 bjarthur

Yeah this is a bug that will get fixed hopefully :) Bonito.TextField should be a good workaround for now!

SimonDanisch avatar Jan 08 '24 16:01 SimonDanisch

i might have some time to help. would this be a good issue for someone new to makie's internals to tackle? if so, point me in the right direction.

bjarthur avatar Jan 08 '24 16:01 bjarthur

Cool! :) I'm not sure what the bug is ... So first it would be nice to nail down where things go wrong: Maybe here?: https://github.com/MakieOrg/Makie.jl/blob/v0.19.5/src/makielayout/blocks/textbox.jl#L187-L193

Events are collected on JS here: https://github.com/MakieOrg/Makie.jl/blob/v0.19.5/WGLMakie/src/wglmakie.js#L169-L174 If you dev WGLMakie you can just add e.g. console.log(event.code) in there and then look into the browsers js console to see what happens. You may need to close the display tab and run rm(Bonito.bundle_path(WGLMakie.WGL)) for Bonito to pick up the changed JS code...

You could also start by looking into what happens here: https://github.com/MakieOrg/Makie.jl/blob/v0.19.5/WGLMakie/src/events.jl#L15-L49

It does look a bit like events.unicode_input isn't even triggered there? Maybe the fix is to just push the keybord button there...

SimonDanisch avatar Jan 08 '24 16:01 SimonDanisch

the problem is not that one can't input text to the box, but that the box is just rendered as text (with an html p tag). specifically, with this julia code:

using Bonito
using WGLMakie
import WGLMakie as W

App() do
    fig = W.Figure(size=(640,480))
    W.Textbox(fig[1,1], placeholder="default text")
end

i get this:

Screenshot 2024-01-08 at 1 20 17 PM

where as using a bonito textfield i get this:

Screenshot 2024-01-08 at 1 48 43 PM

bjarthur avatar Jan 08 '24 18:01 bjarthur

Ah, really? That's not actually supposed to work 😅 You need to do:

App() do
    fig = W.Figure(size=(640,480))
    textbox = W.Textbox(fig[1,1], placeholder="default text")
    return DOM.div(fig)
end

SimonDanisch avatar Jan 08 '24 21:01 SimonDanisch

so i put some print statements in those three spots. keydown and code_to_keyboard both seem to be working properly, but on(topscene, events(scene).unicode_input; priority=60) do char seems never to be called. how does one push the button there?

bjarthur avatar Jan 09 '24 21:01 bjarthur

the on(topscene, events(scene).keyboardbutton; priority=60) do event method here:

https://github.com/MakieOrg/Makie.jl/blob/v0.19.5/src/makielayout/blocks/textbox.jl#L215

doesn't seem to be called either despite the keyboardbutton observable being updated here:

https://github.com/MakieOrg/Makie.jl/blob/v0.19.5/WGLMakie/src/events.jl#L92

i put print statements in both places. the latter assignment is executed, while the former function is not.

bjarthur avatar Jan 11 '24 20:01 bjarthur