-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
module Main exposing (..) | ||
|
||
import Element | ||
exposing | ||
( Element | ||
, Attribute | ||
, column | ||
, row | ||
, button | ||
, label | ||
, map | ||
, beginnerProgram | ||
) | ||
import Element.Attributes | ||
exposing | ||
( text | ||
, textColor | ||
, fontSize | ||
, flexGrow | ||
, justifyContent | ||
, alignItems | ||
, marginHorizontal | ||
, marginBottom | ||
) | ||
import Element.Events exposing (onTouchUpInside) | ||
import Color exposing (Color) | ||
|
||
|
||
main : Program Never Model Msg | ||
main = | ||
beginnerProgram | ||
{ model = 0 | ||
, view = view | ||
, update = update | ||
} | ||
|
||
|
||
|
||
-- MODEL | ||
|
||
|
||
type alias Model = | ||
Int | ||
|
||
|
||
|
||
-- UPDATE | ||
|
||
|
||
type Msg | ||
= Increment | ||
| Decrement | ||
|
||
|
||
update : Msg -> Model -> Model | ||
update msg model = | ||
case msg of | ||
Increment -> | ||
model + 1 | ||
|
||
Decrement -> | ||
model - 1 | ||
|
||
|
||
|
||
-- VIEW | ||
|
||
|
||
view : Model -> Element Msg | ||
view model = | ||
column [ flexGrow 1, justifyContent "center", alignItems "center" ] | ||
[ label [ text <| toString model, fontSize 50, marginBottom 25 ] | ||
, row [] | ||
[ viewButton "Decrement" Decrement Color.red | ||
, viewButton "Increment" Increment Color.green | ||
] | ||
] | ||
|
||
|
||
viewButton : String -> msg -> Color -> Element msg | ||
viewButton label msg color = | ||
button | ||
[ text label | ||
, textColor color | ||
, fontSize 25 | ||
, onTouchUpInside msg | ||
, marginHorizontal 20 | ||
] |