-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.elm
60 lines (51 loc) · 1.46 KB
/
View.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
module View exposing (render)
import Html exposing (Html, div, text)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import Dict
import Helpers exposing ((=>), px, exclusiveRange)
import Shared exposing (Position, Board, Model, Msg(..))
itemStyle: Html.Attribute Msg
itemStyle =
style [
"display" => "inline-block",
"border" => "1px solid black",
"width" => px 30,
"height" => px 30,
"line-height" => px 30,
"text-align" => "center",
"cursor" => "pointer",
"margin" => px 1,
"background" => "yellow",
"color" => "green"
]
extractValue: Position -> Board -> String
extractValue position board =
case Dict.get position board of
Just s -> s
Nothing -> ""
renderItem: Position -> Board -> Html Msg
renderItem position board =
let gem = extractValue position board
in div [
itemStyle,
onClick Roll
] [ text gem ]
renderLine: Int -> Int -> Board -> Html Msg
renderLine i width board =
let list = exclusiveRange 0 width
elements = List.map (\j -> renderItem (i, j) board) list
in div [ style [
"margin" => "0 auto",
"width" => px (width * 34)
] ] elements
renderBoard: Model -> Html Msg
renderBoard { width, height, board } =
let list = exclusiveRange 0 height
elements = List.map (\i -> renderLine i width board) list
in div [ style [
"-moz-user-select" => "none",
"user-select" => "none"
] ] elements
render: Model -> Html Msg
render model = renderBoard model