Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "examples" flag to optionally build examples and tutorials #218

Merged
merged 4 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ghcid
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--command "stack repl --main-is monomer:exe:tutorial"
--command "stack repl --main-is monomer:exe:dev-test-app"
--test ":main"
--restart=package.yaml
61 changes: 61 additions & 0 deletions dev-test-app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Control.Lens
import Data.Maybe
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)]

main :: IO ()
main = do
startApp model handleEvent buildUI config
where
config = [
appWindowTitle "Dev test app",
appWindowIcon "./assets/images/icon.png",
appTheme darkTheme,
appFontDef "Regular" "./assets/fonts/Roboto-Regular.ttf",
appInitEvent AppInit
]
model = AppModel 0
2 changes: 1 addition & 1 deletion docs/tutorials/00-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ git clone https://github.com/fjvallarino/monomer.git
Then, inside the cloned directory, build the project with:

```bash
stack build
stack build --flag monomer:examples
```

In case you have not followed the instructions for the starter project, you
Expand Down
66 changes: 66 additions & 0 deletions monomer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ source-repository head
type: git
location: https://github.com/fjvallarino/monomer

flag examples
manual: True
default: False

library
exposed-modules:
Monomer
Expand Down Expand Up @@ -228,6 +232,48 @@ executable books
, transformers >=0.5 && <0.7
, vector >=0.12 && <0.14
, wreq >=0.5.2 && <0.6
if flag(examples)
buildable: True
else
buildable: False
default-language: Haskell2010

executable dev-test-app
main-is: Main.hs
other-modules:
Paths_monomer
hs-source-dirs:
dev-test-app
default-extensions:
OverloadedStrings
ghc-options: -threaded
build-depends:
JuicyPixels >=3.2.9 && <3.5
, OpenGLRaw ==3.3.*
, async >=2.1 && <2.3
, attoparsec >=0.12 && <0.15
, base >=4.11 && <5
, bytestring >=0.10 && <0.12
, bytestring-to-vector ==0.3.*
, containers >=0.5.11 && <0.7
, data-default >=0.5 && <0.8
, exceptions ==0.10.*
, extra >=1.6 && <1.9
, formatting >=6.0 && <8.0
, http-client >=0.6 && <0.9
, lens >=4.16 && <6
, monomer
, mtl >=2.1 && <2.3
, nanovg >=0.8.1 && <1.0
, process ==1.6.*
, sdl2 >=2.5.0 && <2.6
, stm ==2.5.*
, text >=1.2 && <2.1
, text-show >=3.7 && <3.10
, time >=1.8 && <1.16
, transformers >=0.5 && <0.7
, vector >=0.12 && <0.14
, wreq >=0.5.2 && <0.6
default-language: Haskell2010

executable generative
Expand Down Expand Up @@ -270,6 +316,10 @@ executable generative
, transformers >=0.5 && <0.7
, vector >=0.12 && <0.14
, wreq >=0.5.2 && <0.6
if flag(examples)
buildable: True
else
buildable: False
default-language: Haskell2010

executable opengl
Expand Down Expand Up @@ -310,6 +360,10 @@ executable opengl
, transformers >=0.5 && <0.7
, vector >=0.12 && <0.14
, wreq >=0.5.2 && <0.6
if flag(examples)
buildable: True
else
buildable: False
default-language: Haskell2010

executable ticker
Expand Down Expand Up @@ -353,6 +407,10 @@ executable ticker
, websockets ==0.12.*
, wreq >=0.5.2 && <0.6
, wuss >=1.1 && <2.3
if flag(examples)
buildable: True
else
buildable: False
default-language: Haskell2010

executable todo
Expand Down Expand Up @@ -392,6 +450,10 @@ executable todo
, transformers >=0.5 && <0.7
, vector >=0.12 && <0.14
, wreq >=0.5.2 && <0.6
if flag(examples)
buildable: True
else
buildable: False
default-language: Haskell2010

executable tutorial
Expand Down Expand Up @@ -439,6 +501,10 @@ executable tutorial
, transformers >=0.5 && <0.7
, vector >=0.12 && <0.14
, wreq >=0.5.2 && <0.6
if flag(examples)
buildable: True
else
buildable: False
default-language: Haskell2010

test-suite monomer-test
Expand Down
73 changes: 61 additions & 12 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ dependencies:
- vector >= 0.12 && < 0.14
- wreq >= 0.5.2 && < 0.6

flags:
examples:
default: False
manual: True

library:
source-dirs: src
include-dirs: cbits
Expand All @@ -74,61 +79,105 @@ library:
extra-libraries: GLEW

executables:
todo:
dev-test-app:
main: Main.hs
source-dirs: examples/todo
source-dirs: dev-test-app
dependencies:
- monomer
ghc-options:
- -threaded

todo:
main: Main.hs
source-dirs: examples/todo
when:
- condition: flag(examples)
then:
buildable: True
else:
buildable: False
dependencies:
- monomer
ghc-options:
- -threaded

books:
main: Main.hs
source-dirs: examples/books
ghc-options:
- -threaded
when:
- condition: flag(examples)
then:
buildable: True
else:
buildable: False
dependencies:
- aeson >= 1.4 && < 2.3
- monomer
- wreq >= 0.5.2 && < 0.6
ghc-options:
- -threaded

ticker:
main: Main.hs
source-dirs: examples/ticker
ghc-options:
- -threaded
when:
- condition: flag(examples)
then:
buildable: True
else:
buildable: False
dependencies:
- aeson >= 1.4 && < 2.3
- monomer
- websockets >= 0.12 && < 0.13
- wuss >= 1.1 && < 2.3
ghc-options:
- -threaded

generative:
main: Main.hs
source-dirs: examples/generative
ghc-options:
- -threaded
when:
- condition: flag(examples)
then:
buildable: True
else:
buildable: False
dependencies:
- monomer
- random >= 1.1 && < 1.3
ghc-options:
- -threaded

opengl:
main: Main.hs
source-dirs: examples/opengl
ghc-options:
- -threaded
when:
- condition: flag(examples)
then:
buildable: True
else:
buildable: False
dependencies:
- monomer
- random >= 1.1 && < 1.3
ghc-options:
- -threaded

tutorial:
main: Main.hs
source-dirs: examples/tutorial
ghc-options:
- -threaded
when:
- condition: flag(examples)
then:
buildable: True
else:
buildable: False
dependencies:
- monomer
- random >= 1.1 && < 1.3
ghc-options:
- -threaded

tests:
monomer-test:
Expand Down