Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events on windows? #230

Open
valyagolev opened this issue Oct 14, 2018 · 7 comments
Open

Events on windows? #230

valyagolev opened this issue Oct 14, 2018 · 7 comments

Comments

@valyagolev
Copy link

It seems that there's no way to add an event to Window, nor to pretend that Window is an Element.

It'd be nice to be able to use some Window events such as 'keydown' or 'resize'.

@bradrn
Copy link
Contributor

bradrn commented Oct 14, 2018

I think this would also go some way towards solving #228, which seems to require handling the onload event (see #228 (comment)).

@valyagolev
Copy link
Author

valyagolev commented Oct 14, 2018

just in case someone needs something now, my temporary, very hacky solution is along the lines of

let keyPressHandler code = ...

let handler e = runUI window $ keyPressHandler e

window   <- askWindow
exported <- ffiExport handler
runFunction (ffi "window.addEventListener('keydown', ({code}) =>{ %1(code); }, false);" exported)

I think maybe adding a class like EventTarget would be a good solution. or maybe, for simplicity, a way to pretend that Window is an Element... I'll see if I could hack a PR together

@bradrn
Copy link
Contributor

bradrn commented Oct 14, 2018

@va1en0k What's keyPressHandler? I can't see it anywhere in threepenny-gui.

@valyagolev
Copy link
Author

it's your event handler, a function a -> UI ()

@bradrn
Copy link
Contributor

bradrn commented Oct 14, 2018

That makes sense. But did you mean a -> IO ()? That's what GHC is giving me for the type.

@valyagolev
Copy link
Author

sorry, yes. in this case it's going to be String -> IO () because I pick the code from the event, but you'll have to tweak it to your needs

@HeinrichApfelmus
Copy link
Owner

Uhm, the "keydown" and "resize" events should go on the document body, which can be obtained with getBody? So attaching a keydown to getBody already works.

That said, the "resize" event currently does not have special support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants