From 2f1489aebbe4047f89cce72d3359218ae0d7eca4 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Wed, 1 Mar 2023 00:07:42 -0800 Subject: [PATCH] Monomer hello world --- app/Main.hs | 56 ++++++++++++++++++++++++++++++++++++++++++++- haskell-clock.cabal | 9 ++++++++ package.yaml | 3 +++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index 1de115b..88622bc 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,11 +1,65 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} + module Main (main) where +import Control.Lens + +import Monomer +import TextShow + import Lib +newtype AppModel = AppModel { + _clickCount :: Int +} deriving (Eq, Show) + +data AppEvent = AppInit | AppIncrease deriving (Show, Eq) + +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)] + + main :: IO () main = do putStrLn "haskell-clock" t <- curTimeString putStrLn t + guiMain - +guiMain :: IO () +guiMain = do + startApp model handleEvent buildUI config + where + config = [ + appWindowTitle "Haskell Clock", + --appWindowIcon "./assets/images/icon.png", + appTheme darkTheme, + appFontDef "Regular" "/usr/share/fonts/TTF/FiraCode-Regular.ttf", + appInitEvent AppInit + ] + model = AppModel 0 diff --git a/haskell-clock.cabal b/haskell-clock.cabal index 168f353..9788b77 100644 --- a/haskell-clock.cabal +++ b/haskell-clock.cabal @@ -33,6 +33,9 @@ library ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: base >=4.7 && <5 + , lens + , monomer + , text-show , time default-language: Haskell2010 @@ -46,6 +49,9 @@ executable haskell-clock-exe build-depends: base >=4.7 && <5 , haskell-clock + , lens + , monomer + , text-show , time default-language: Haskell2010 @@ -60,5 +66,8 @@ test-suite haskell-clock-test build-depends: base >=4.7 && <5 , haskell-clock + , lens + , monomer + , text-show , time default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 7b5c2b8..2f28223 100644 --- a/package.yaml +++ b/package.yaml @@ -22,6 +22,9 @@ description: Please see the README on GitHub at = 4.7 && < 5 - time +- monomer +- lens +- text-show ghc-options: - -Wall