@@ -151,6 +151,30 @@ defmodule Scenic.Themes do
151
151
end
152
152
end
153
153
154
+ def validate ( theme_name ) when is_atom ( theme_name ) do
155
+ lib = module ( ) . library ( )
156
+ { themes , schema } = Map . get ( lib , :scenic )
157
+ case Map . get ( themes , theme_name ) do
158
+ nil ->
159
+ {
160
+ :error ,
161
+ """
162
+ #{ IO.ANSI . red ( ) } Invalid theme specification
163
+ Received: #{ inspect ( theme_name ) }
164
+ #{ IO.ANSI . yellow ( ) }
165
+ The theme could not be found in library #{ inspect ( :scenic ) } .
166
+ Ensure you got the name correct.
167
+ #{ IO.ANSI . default_color ( ) }
168
+ """
169
+ }
170
+ theme ->
171
+ case validate ( theme , schema ) do
172
+ { :ok , _ } -> { :ok , theme_name }
173
+ error -> error
174
+ end
175
+ end
176
+ end
177
+
154
178
def validate (
155
179
% {
156
180
text: _ ,
@@ -201,9 +225,12 @@ defmodule Scenic.Themes do
201
225
#{ IO.ANSI . red ( ) } Invalid theme specification
202
226
Received: #{ inspect ( data ) }
203
227
#{ IO.ANSI . yellow ( ) }
204
- Themes can be a tuple represent a theme for example:
228
+ Themes can be a tuple representing a theme for example:
205
229
{:scenic, :light}, {:scenic, :dark}
206
230
231
+ Or an atom representing one of scenics default themes:
232
+ :primary, :secondary
233
+
207
234
Or it may also be a map defining colors for the values of
208
235
:text, :background, :border, :active, :thumb, :focus
209
236
@@ -249,7 +276,7 @@ defmodule Scenic.Themes do
249
276
module ( ) . _get_palette ( )
250
277
end
251
278
252
- @ spec normalize ( { atom , atom } | map ) :: map | nil
279
+ @ spec normalize ( { atom , atom } | map | atom ) :: map | nil
253
280
@ doc """
254
281
Converts a theme from it's tuple form to it's map form.
255
282
"""
@@ -261,9 +288,17 @@ defmodule Scenic.Themes do
261
288
end
262
289
end
263
290
291
+ def normalize ( theme_name ) when is_atom ( theme_name ) do
292
+ themes = module ( ) . library ( )
293
+ case Map . get ( themes , :scenic ) do
294
+ { themes , _schema } -> Map . get ( themes , theme_name )
295
+ nil -> nil
296
+ end
297
+ end
298
+
264
299
def normalize ( theme ) when is_map ( theme ) , do: theme
265
300
266
- @ spec preset ( { atom , atom } | map ) :: map | nil
301
+ @ spec preset ( { atom , atom } | map | atom ) :: map | nil
267
302
@ doc """
268
303
Get a theme.
269
304
"""
@@ -275,6 +310,14 @@ defmodule Scenic.Themes do
275
310
end
276
311
end
277
312
313
+ def preset ( theme_name ) when is_atom ( theme_name ) do
314
+ themes = module ( ) . library ( )
315
+ case Map . get ( themes , :scenic ) do
316
+ { themes , _schema } -> Map . get ( themes , theme_name )
317
+ nil -> nil
318
+ end
319
+ end
320
+
278
321
def preset ( theme ) when is_map ( theme ) , do: theme
279
322
280
323
@ theme_light % {
0 commit comments