Display a full image with wxHaskell

204 views Asked by At

I am using wxHaskell to display a full image in a window. My code is:

import Graphics.UI.WX
import Graphics.UI.WXCore

main :: IO ()
main = start testimg

testimg :: IO ()
testimg = do
  f <- frame [text := "Test Image"]
  p <- panel f []

  image <- bitmapCreateFromFile "landscape.png"
  imagep <- panel p [ on paint := onPaint image ]

  set f [ layout:= fill $ container p $ widget imagep ]

  where
    onPaint image dc rect = drawBitmap dc image pointZero True []

Anyway when the app runs nothing is displayed (not even the window's borders). How can I make it work?

1

There are 1 answers

0
Schoon On

You missed a fill before widget imagep with the effect that the panel you paint in the picture doesn't get any surface. And I'd recommend setting an outerSize, too. You might also want to have a look at https://github.com/wxHaskell/wxHaskell/blob/master/samples/wx/ImageViewer.hs for inspiration. Good luck!

import Graphics.UI.WX
import Graphics.UI.WXCore

main :: IO ()
main = start testimg

testimg :: IO ()
testimg = do
  f <- frame [text := "Test Image"]
  p <- panel f []

  image <- bitmapCreateFromFile "landscape.png"
  imagep <- panel p [ on paint := onPaint image ]

  set f [ layout:= fill $ container p $ fill $ widget imagep 
        , outerSize := sz 500 500
        ]

  where
    onPaint image dc rect = drawBitmap dc image pointZero True []