11module Layouts.PlayLayout exposing
22 ( Alignment (..)
3+ , ColorScheme (..)
34 , Model
45 , Msg
56 , Props
@@ -52,13 +53,32 @@ type Alignment
5253 | AlignBottom
5354
5455
56+ type ColorScheme
57+ = Light
58+ | Dark
59+ | Sepia
60+
61+
62+ {- | Solarized colors <https://ethanschoonover.com/solarized/>
63+ -}
64+ sepiaColors : { fg : Css .Color , bg : Css .Color }
65+ sepiaColors =
66+ { fg = Css . rgb 7 54 66
67+ , bg = Css . rgb 253 246 227
68+ }
69+
70+
5571type alias Model =
56- { alignment : Alignment }
72+ { alignment : Alignment
73+ , colorScheme : ColorScheme
74+ }
5775
5876
5977init : () -> ( Model , Effect Msg )
6078init _ =
61- ( { alignment = AlignTop }
79+ ( { alignment = AlignTop
80+ , colorScheme = Light
81+ }
6282 , Effect . none
6383 )
6484
@@ -69,6 +89,7 @@ init _ =
6989
7090type Msg
7191 = SetAlignment Alignment
92+ | SetColorScheme ColorScheme
7293
7394
7495update : Msg -> Model -> ( Model , Effect Msg )
@@ -79,6 +100,11 @@ update msg model =
79100 , Effect . none
80101 )
81102
103+ SetColorScheme colorScheme ->
104+ ( { model | colorScheme = colorScheme }
105+ , Effect . none
106+ )
107+
82108
83109subscriptions : Model -> Sub Msg
84110subscriptions _ =
@@ -89,8 +115,8 @@ subscriptions _ =
89115-- VIEW
90116
91117
92- viewImage : ReadDirection -> Alignment -> String -> File -> Html msg
93- viewImage readDirection alignment readonlyId file =
118+ viewImage : ReadDirection -> Model -> String -> File -> Html msg
119+ viewImage readDirection model readOnlyId file =
94120 div
95121 [ css <|
96122 case readDirection of
@@ -104,7 +130,7 @@ viewImage readDirection alignment readonlyId file =
104130 [ src
105131 ( host
106132 ++ " /readonly/"
107- ++ readonlyId
133+ ++ readOnlyId
108134 ++ " /tables/files/columns/content/files/rowid/"
109135 ++ String . fromInt file. rowid
110136 )
@@ -113,6 +139,18 @@ viewImage readDirection alignment readonlyId file =
113139 , border_solid
114140 , border_color orange_500
115141 , p_2
142+ , case model. colorScheme of
143+ Light ->
144+ Css . property " " " "
145+
146+ Dark ->
147+ Css . batch
148+ [ Css . property " filter" " invert(1)"
149+ , Css . opacity ( Css . num 0.85 )
150+ ]
151+
152+ Sepia ->
153+ Css . property " mix-blend-mode" " multiply"
116154 ]
117155 ++ ( case readDirection of
118156 ReadHorizontal ->
@@ -122,7 +160,7 @@ viewImage readDirection alignment readonlyId file =
122160 , align_top
123161 , border_r_2
124162 , object_contain
125- , case alignment of
163+ , case model . alignment of
126164 AlignTop ->
127165 object_top
128166
@@ -155,19 +193,26 @@ filesAreType filetype files =
155193 )
156194
157195
158- getSidebar : Alignment -> Html Msg
159- getSidebar alignment =
196+ getSidebar : Model -> Html Msg
197+ getSidebar model =
160198 let
199+ alignment =
200+ model. alignment
201+
202+ colorScheme =
203+ model. colorScheme
204+
161205 btnCss =
162206 Css . batch
163207 [ cursor_pointer
164208 , py_1
165209 , bg_color gray_100
166210 , Css . hover [ bg_color gray_50 ]
167211 , Css . active [ bg_color gray_200 ]
212+ , text_center
168213 ]
169214
170- markSelectedFor : Alignment -> Alignment -> Css . Style
215+ markSelectedFor : a -> a -> Css . Style
171216 markSelectedFor reference actual =
172217 if reference == actual then
173218 Css . batch
@@ -183,6 +228,85 @@ getSidebar alignment =
183228 , border_solid
184229 , border_color transparent
185230 ]
231+
232+ alignmentButtons =
233+ [ button
234+ [ css [ btnCss, markSelectedFor AlignTop alignment ]
235+ , title " Align pages at the top"
236+ , onClick ( SetAlignment AlignTop )
237+ ]
238+ [ text " ⬆️" ]
239+ , button
240+ [ css [ btnCss, markSelectedFor AlignCenter alignment ]
241+ , title " Center pages"
242+ , onClick ( SetAlignment AlignCenter )
243+ ]
244+ [ text " ⏺" ]
245+ , button
246+ [ css [ btnCss, markSelectedFor AlignBottom alignment ]
247+ , title " Align pages at the bottom"
248+ , onClick ( SetAlignment AlignBottom )
249+ ]
250+ [ text " ⬇️" ]
251+ ]
252+
253+ iconStyle =
254+ Css . batch
255+ [ inline_block
256+ , w_5
257+ , h_5
258+ , rounded_full
259+ , border
260+ , border_solid
261+ , border_color gray_400
262+ , bg_color gray_100
263+ , text_center
264+ ]
265+
266+ iconContent =
267+ [ span
268+ [ css [ relative, top_0_dot_5 ] ]
269+ [ text " ♫" ]
270+ ]
271+
272+ colorSchemeButtons =
273+ [ button
274+ [ css [ btnCss, markSelectedFor Light colorScheme ]
275+ , title " Light color scheme"
276+ , onClick ( SetColorScheme Light )
277+ ]
278+ [ span
279+ [ css [ iconStyle, bg_color white, text_color black ] ]
280+ iconContent
281+ ]
282+ , button
283+ [ css [ btnCss, markSelectedFor Dark colorScheme ]
284+ , title " Dark color scheme"
285+ , onClick ( SetColorScheme Dark )
286+ ]
287+ [ span
288+ [ css [ iconStyle, bg_color black, text_color white ]
289+ ]
290+ iconContent
291+ ]
292+ , button
293+ [ css [ btnCss, markSelectedFor Sepia colorScheme ]
294+ , title " Sepia color scheme"
295+ , onClick ( SetColorScheme Sepia )
296+ ]
297+ [ span
298+ [ css
299+ [ iconStyle
300+ , Css . backgroundColor sepiaColors. bg
301+ , Css . color sepiaColors. fg
302+ ]
303+ ]
304+ iconContent
305+ ]
306+ ]
307+
308+ placeholder =
309+ [ div [ css [ h_3 ] ] [] ]
186310 in
187311 div
188312 [ css
@@ -196,29 +320,14 @@ getSidebar alignment =
196320 , gap_y_0_dot_5
197321 ]
198322 ]
199- [ button
200- [ css [ btnCss, markSelectedFor AlignTop alignment ]
201- , title " Align pages at the top"
202- , onClick ( SetAlignment AlignTop )
203- ]
204- [ text " ⬆️" ]
205- , button
206- [ css [ btnCss, markSelectedFor AlignCenter alignment ]
207- , title " Center pages"
208- , onClick ( SetAlignment AlignCenter )
209- ]
210- [ text " ⏺" ]
211- , button
212- [ css [ btnCss, markSelectedFor AlignBottom alignment ]
213- , title " Align pages at the bottom"
214- , onClick ( SetAlignment AlignBottom )
215- ]
216- [ text " ⬇️" ]
217- ]
323+ ( alignmentButtons
324+ ++ placeholder
325+ ++ colorSchemeButtons
326+ )
218327
219328
220- viewSong : ReadDirection -> Alignment -> String -> Song -> Html Msg
221- viewSong readDirection alignment sharedModel song =
329+ viewSong : ReadDirection -> Model -> String -> Song -> Html Msg
330+ viewSong readDirection model readOnlyId song =
222331 let
223332 divImages : List ( Html Msg ) -> Html Msg
224333 divImages content =
@@ -243,7 +352,7 @@ viewSong readDirection alignment sharedModel song =
243352 [ src
244353 ( host
245354 ++ " /readonly/"
246- ++ sharedModel
355+ ++ readOnlyId
247356 ++ " /tables/files/columns/content/files/rowid/"
248357 ++ String . fromInt file. rowid
249358 )
@@ -261,7 +370,7 @@ viewSong readDirection alignment sharedModel song =
261370 else
262371 divImages <|
263372 ( if readDirection == ReadHorizontal then
264- [ getSidebar alignment ]
373+ [ getSidebar model ]
265374
266375 else
267376 []
@@ -270,17 +379,30 @@ viewSong readDirection alignment sharedModel song =
270379 |> List . map
271380 ( viewImage
272381 readDirection
273- alignment
274- sharedModel
382+ model
383+ readOnlyId
275384 )
276385 )
277386
278387
279388viewPages : Props -> Shared .Model -> Model -> Song -> Html Msg
280389viewPages settings sharedModel model song =
390+ let
391+ readOnlyId =
392+ sharedModel. readonlyId
393+ |> Maybe . withDefault " "
394+ in
281395 div
282396 [ css
283- [ bg_color white
397+ [ case model. colorScheme of
398+ Light ->
399+ bg_color white
400+
401+ Dark ->
402+ bg_color black
403+
404+ Sepia ->
405+ Css . backgroundColor sepiaColors. bg
284406
285407 -- Make bg color cover the whole page:
286408 , overflow_scroll
@@ -296,15 +418,7 @@ viewPages settings sharedModel model song =
296418 w_full
297419 ]
298420 ]
299- [ viewSong
300- settings. readDirection
301- model. alignment
302- ( Maybe . withDefault
303- " "
304- sharedModel. readonlyId
305- )
306- song
307- ]
421+ [ viewSong settings. readDirection model readOnlyId song ]
308422
309423
310424view :
0 commit comments