forked from erkal/kite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PageLayout.elm
148 lines (125 loc) · 2.83 KB
/
PageLayout.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
port module PageLayout exposing (..)
import Window
import Task exposing (Task)
-- MODEL
type alias Model =
{ browserWindow :
{ top : Int
, left : Int
, width : Int
, height : Int
}
, leftBar :
{ top : Int
, left : Int
, width : Int
, height : Int
}
, rightBar :
{ top : Int
, left : Int
, width : Int
, height : Int
}
, tabsBar :
{ top : Int
, left : Int
, width : Int
, height : Int
}
, bottomBar :
{ top : Int
, left : Int
, width : Int
, height : Int
}
, graphSvg :
{ top : Int
, left : Int
, width : Int
, height : Int
}
, welcomeWindow :
{ top : Int
, left : Int
, width : Int
, height : Int
}
}
dimensions : { e | height : a, left : b, top : c, width : d } -> List ( String, String )
dimensions el =
[ ( "position", "absolute" )
, ( "top", toString el.top ++ "px" )
, ( "left", toString el.left ++ "px" )
, ( "width", toString el.width ++ "px" )
, ( "height", toString el.height ++ "px" )
]
calculate : { windowWidth : Int, windowHeight : Int } -> Model
calculate { windowWidth, windowHeight } =
{ browserWindow =
{ top = 0
, left = 0
, width = windowWidth
, height = windowHeight
}
, leftBar =
{ top = 0
, left = 0
, width = 250
, height = windowHeight
}
, rightBar =
{ top = 0
, left = windowWidth - 250
, width = 250
, height = windowHeight
}
, tabsBar =
{ top = 0
, left = 250
, width = windowWidth - 500
, height = 65
}
, bottomBar =
{ top = windowHeight - 40
, left = 0
, width = windowWidth
, height = 40
}
, graphSvg =
{ top = 0
, left = 0
, width = windowWidth
, height = windowHeight
}
, welcomeWindow =
let
( w, h ) =
( min (windowWidth - 60) 600
, min (windowHeight - 60) 500
)
in
{ top = windowHeight // 2 - h // 2
, left = windowWidth // 2 - w // 2
, width = w
, height = h
}
}
initialCmd : Cmd Msg
initialCmd =
Task.perform UpdateSize Window.size
--UPDATE
type Msg
= UpdateSize Window.Size
update : Msg -> Model -> Model
update msg model =
case msg of
UpdateSize { width, height } ->
calculate
{ windowWidth = width
, windowHeight = height
}
--SUBSCRIPTIONS
subscriptions : Sub Msg
subscriptions =
Window.resizes UpdateSize