-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.elm
129 lines (96 loc) · 2.85 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
124
125
126
127
128
129
module Main exposing (..)
import Html exposing (Html, div)
import Html.App as App
import Html.Attributes
import Svg exposing (..)
import Svg.Attributes exposing (..)
import Svg.Events
import Button.Model exposing (Button, initialButtons)
import Button.View
import Button.Msg
import Button.Update
import Debug
import Time exposing (Time)
import AnimationFrame
import Json.Decode as Json exposing (..)
import Window exposing (Size)
import Task
-- MODEL
type alias Model =
{ buttons : List Button
, menuShowed : Bool
, size : Size
}
size : Float
size =
500
init : Model
init =
{ buttons = (initialButtons size)
, menuShowed = False
, size = Size 0 0
}
-- UPDATE
type Msg
= DoNothing
| ButtonMsg Button.Msg.Msg
| ToggleMenu Float Float
| SizeChange Size
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ButtonMsg buttonMsg ->
let
( updatedButtons, buttonCmd ) =
Button.Update.update buttonMsg model.buttons
in
( { model | buttons = updatedButtons }, Cmd.map ButtonMsg buttonCmd )
ToggleMenu x y ->
if Debug.log "SHOWED" model.menuShowed then
let
( updatedButtons, buttonCmd ) =
Button.Update.update (Button.Msg.HideAll) model.buttons
in
( { model | buttons = updatedButtons, menuShowed = False }, Cmd.map ButtonMsg buttonCmd )
else
let
( updatedButtons, buttonCmd ) =
Button.Update.update (Button.Msg.ShowAll x y) model.buttons
in
( { model | buttons = updatedButtons, menuShowed = True }, Cmd.map ButtonMsg buttonCmd )
SizeChange size ->
( { model | size = size }, Cmd.none )
_ ->
( model, Cmd.none )
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ Sub.map ButtonMsg (Button.Update.subscriptions model.buttons)
, Window.resizes SizeChange
]
-- VIEW
view : Model -> Html Msg
view model =
svg
[ viewBox <| "0 0 " ++ (toString model.size.width) ++ " " ++ (toString model.size.height)
, width <| toString model.size.width
, height <| toString model.size.height
, class "radialnav"
, Svg.Events.on "click" eventPos
]
[ App.map ButtonMsg (Button.View.view model.buttons) ]
eventPos : Json.Decoder Msg
eventPos =
Json.object2
ToggleMenu
("clientX" := Json.float)
("clientY" := Json.float)
main : Program Never
main =
App.program
{ init = ( init, Task.perform (\_ -> DoNothing) SizeChange Window.size )
, view = view
, update = update
, subscriptions = subscriptions
}