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

Can't draw an image onto Canvas #228

Open
zcleghern opened this issue Sep 13, 2018 · 3 comments
Open

Can't draw an image onto Canvas #228

zcleghern opened this issue Sep 13, 2018 · 3 comments

Comments

@zcleghern
Copy link

I'm having an issue with canvases. I have modified the Canvas.hs example program to draw an image onto the canvas with

canvas # drawImg

right after the canvas setup code; here it is for reference:

canvas <- UI.canvas
          # set UI.height canvasSize
          # set UI.width  canvasSize
          # set style [("border", "solid black 1px"), ("background", "#eee")]

where drawImg is

drawImg :: UI.Canvas -> UI ()
drawImg canvas = do
  url <- UI.loadFile "image/png" "resources/img.png"
  img <- UI.img # set UI.src url
  UI.drawImage img (0,0) canvas

which should be the same behavior as the on click function for drawing an image in the original version of the code.

The actual behavior of this code is a blank canvas, just as in the original example. Why is this? Should I instead add this call to the line that sets up the canvas? I'm guessing most likely my problem is that I need to understand do notation better.

@bradrn
Copy link
Contributor

bradrn commented Sep 16, 2018

I think that what's happening here is that you're trying to draw on the canvas before it is fully loaded. I'm not entirely sure how to fix it though, seeing as threepenny-gui doesn't seem to obviously provide any sort of onload event.

@zcleghern
Copy link
Author

I'll play around with this, but thanks!

@zcleghern
Copy link
Author

I can't seem to draw the image unless i have the code in the same place as the example code i.e. drawing an image when the user presses the corresponding button (also it seems to be off-center no matter what x y values I supply)

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

No branches or pull requests

2 participants