-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.hs
66 lines (59 loc) · 1.58 KB
/
Demo.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
-- |
-- Module : Tutorial01_Basics
-- Copyright : (c) 2018 Francisco Vallarino
-- License : BSD-3-Clause (see the LICENSE file)
-- Maintainer : [email protected]
-- Stability : experimental
-- Portability : non-portable
--
-- Main module for the '01 - Basics' tutorial.
module Main where
import Data.Text (Text, pack)
import Monomer
import System.Environment (getEnv)
import TextShow
newtype AppModel = AppModel
{ counter :: Int
}
deriving (Eq, Show)
data AppEvent
= AppInit
| AppIncrease
deriving (Eq, Show)
buildUI :: WidgetEnv AppModel AppEvent -> AppModel -> WidgetNode AppModel AppEvent
buildUI wenv model =
vstack
[ label "Hello world",
spacer,
hstack
[ label $ "Click count: " <> showt (model.counter),
spacer,
button "Increase count" AppIncrease
]
]
`styleBasic` [padding 10]
handleEvent ::
WidgetEnv AppModel AppEvent ->
WidgetNode AppModel AppEvent ->
AppModel ->
AppEvent ->
[AppEventResponse AppModel AppEvent]
handleEvent wenv node model evt = case evt of
AppInit -> []
AppIncrease -> [Model (model {counter = model.counter + 1})]
main :: IO ()
main = do
robotFont <- pack <$> getEnv "ROBOTO_TTF"
startApp model handleEvent buildUI (config robotFont)
where
config f =
[ appWindowTitle "Tutorial 01 - Basics",
appTheme darkTheme,
appFontDef "Regular" f,
appInitEvent AppInit
]
model = AppModel 0