-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathMain.elm
120 lines (93 loc) · 2.65 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
module Main exposing (..)
import NativeUi as Ui exposing (Node)
import NativeUi.Style as Style exposing (defaultTransform)
import NativeUi.Elements as Elements exposing (..)
import NativeUi.Events exposing (..)
import NativeUi.Image as Image exposing (..)
-- MODEL
type alias Model =
Int
model : Model
model =
9000
-- UPDATE
type Msg
= Increment
| Decrement
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Increment ->
( model + 1, Cmd.none )
Decrement ->
( model - 1, Cmd.none )
-- VIEW
view : Model -> Node Msg
view count =
let
imageSource =
{ uri = "https://raw.githubusercontent.com/futurice/spiceprogram/master/assets/img/logo/chilicorn_no_text-128.png"
, cache = Just ForceCache
}
in
Elements.view
[ Ui.style [ Style.alignItems "center" ]
]
[ image
[ Ui.style
[ Style.height 64
, Style.width 64
, Style.marginBottom 30
, Style.marginTop 30
]
, source imageSource
]
[]
, text
[ Ui.style
[ Style.textAlign "center"
, Style.marginBottom 30
]
]
[ Ui.string ("Counter: " ++ toString count)
]
, Elements.view
[ Ui.style
[ Style.width 80
, Style.flexDirection "row"
, Style.justifyContent "space-between"
]
]
[ button Decrement "#d33" "-"
, button Increment "#3d3" "+"
]
]
button : Msg -> String -> String -> Node Msg
button msg color content =
text
[ Ui.style
[ Style.color "white"
, Style.textAlign "center"
, Style.backgroundColor color
, Style.paddingTop 5
, Style.paddingBottom 5
, Style.width 30
, Style.fontWeight "bold"
, Style.shadowColor "#000"
, Style.shadowOpacity 0.25
, Style.shadowOffset 1 1
, Style.shadowRadius 5
, Style.transform { defaultTransform | rotate = Just "10deg" }
]
, onPress msg
]
[ Ui.string content ]
-- PROGRAM
main : Program Never Model Msg
main =
Ui.program
{ init = ( model, Cmd.none )
, view = view
, update = update
, subscriptions = \_ -> Sub.none
}