miso-0.10.0.0: examples/svg/Main.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import qualified Data.Map as M
import Miso
import Miso.String (MisoString, pack, ms)
import Miso.Svg hiding (height_, id_, style_, width_)
main :: IO ()
main = startApp App {..}
where
initialAction = Id
model = emptyModel
update = updateModel
view = viewModel
events = defaultEvents
subs = [ mouseSub HandleMouse ]
mountPoint = Nothing
emptyModel :: Model
emptyModel = Model (0,0)
updateModel :: Action -> Model -> Effect Action Model
updateModel (HandleMouse newCoords) model =
noEff model { mouseCoords = newCoords }
updateModel Id model = noEff model
data Action
= HandleMouse (Int, Int)
| Id
newtype Model
= Model
{ mouseCoords :: (Int, Int)
} deriving (Show, Eq)
viewModel :: Model -> View Action
viewModel (Model (x,y)) =
div_ [ ] [
svg_ [ style_ $ M.fromList [ ("border-style", "solid")
, ("height", "700px")
]
, width_ "auto"
] [
g_ [] [
ellipse_ [ cx_ $ pack $ show x
, cy_ $ pack $ show y
, style_ svgStyle
, rx_ "100"
, ry_ "100"
] [ ]
]
, text_ [ x_ $ pack $ show x
, y_ $ pack $ show y
] [ text $ ms $ show (x,y) ]
]
]
svgStyle :: M.Map MisoString MisoString
svgStyle =
M.fromList [
("fill", "yellow")
, ("stroke", "purple")
, ("stroke-width", "2")
]