monomer/examples/tutorial/Tutorial01_Basics.hs
Francisco Vallarino 51ce06f613
Add Monomer logo and badges to README.md (#186)
* Add new Monomer logo and badges to README.md

* Fix sub-title styling

* Add support for loading any image format to use as application icon

* Update Monomer icon image

* Update examples and tutorials to use new icon image

* Adjust logo background color
2022-06-27 16:25:03 -03:00

71 lines
1.6 KiB
Haskell

{-|
Module : Tutorial01_Basics
Copyright : (c) 2018 Francisco Vallarino
License : BSD-3-Clause (see the LICENSE file)
Maintainer : fjvallarino@gmail.com
Stability : experimental
Portability : non-portable
Main module for the '01 - Basics' tutorial.
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Tutorial01_Basics where
import Control.Lens
import Data.Text (Text)
import Monomer
import TextShow
import qualified Monomer.Lens as L
newtype AppModel = AppModel {
_clickCount :: Int
} deriving (Eq, Show)
data AppEvent
= AppInit
| AppIncrease
deriving (Eq, Show)
makeLenses 'AppModel
buildUI
:: WidgetEnv AppModel AppEvent
-> AppModel
-> WidgetNode AppModel AppEvent
buildUI wenv model = widgetTree where
widgetTree = vstack [
label "Hello world",
spacer,
hstack [
label $ "Click count: " <> showt (model ^. clickCount),
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 & clickCount +~ 1)]
main01 :: IO ()
main01 = do
startApp model handleEvent buildUI config
where
config = [
appWindowTitle "Tutorial 01 - Basics",
appWindowIcon "./assets/images/icon.png",
appTheme darkTheme,
appFontDef "Regular" "./assets/fonts/Roboto-Regular.ttf",
appInitEvent AppInit
]
model = AppModel 0