-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.elm
123 lines (92 loc) · 2.21 KB
/
Main.elm
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module Main exposing (main)
import Html exposing (Html, beginnerProgram, br, div, text)
import Html.Attributes exposing (style)
import Select
type alias Model =
{ day : Day
, direction : Direction
, shape : Shape
}
type Direction
= North
| South
| East
| West
type Day
= Sunday
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
type Shape
= Rectangle Length Width
| Circle Radius
| Prism Length Width Height
type alias Length =
Float
type alias Width =
Float
type alias Height =
Float
type alias Radius =
Float
type Msg
= NewDay Day
| NewDirection Direction
| NewShape Shape
emptyModel : Model
emptyModel =
{ day = Friday
, direction = North
, shape = Circle 0.0
}
update : Msg -> Model -> Model
update msg model =
(case msg of
NewDay day_ ->
{ model | day = day_ }
NewDirection direction_ ->
{ model | direction = direction_ }
NewShape shape_ ->
{ model | shape = shape_ }
)
|> Debug.log "update.result"
view : Model -> Html Msg
view model =
let
directions =
[ North, South, East, West ]
days =
[ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday ]
shapes =
[ Rectangle 2.0 4.0
, Rectangle 3.0 3.0
, Rectangle 4.0 2.0
, Circle 1.0
, Circle 2.0
, Prism 1.0 2.0 3.0
, Prism 2.0 3.0 1.0
]
in
div [ style [ ( "padding", "5rem" ) ] ]
[ text <| "Selected direction is: " ++ toString model.direction
, br [] []
, Select.from directions NewDirection
, br [] []
, text <| "Selected day of the week is: " ++ toString model.day
, br [] []
, Select.from days NewDay
, br [] []
, text <| "Selected shape is: " ++ toString model.shape
, br [] []
, Select.from shapes NewShape
]
main : Program Never Model Msg
main =
beginnerProgram
{ model = emptyModel
, update = update
, view = view
}