@@ -151,6 +151,30 @@ defmodule Scenic.Themes do
151151 end
152152 end
153153
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+
154178 def validate (
155179 % {
156180 text: _ ,
@@ -201,9 +225,12 @@ defmodule Scenic.Themes do
201225 #{ IO.ANSI . red ( ) } Invalid theme specification
202226 Received: #{ inspect ( data ) }
203227 #{ 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:
205229 {:scenic, :light}, {:scenic, :dark}
206230
231+ Or an atom representing one of scenics default themes:
232+ :primary, :secondary
233+
207234 Or it may also be a map defining colors for the values of
208235 :text, :background, :border, :active, :thumb, :focus
209236
@@ -249,7 +276,7 @@ defmodule Scenic.Themes do
249276 module ( ) . _get_palette ( )
250277 end
251278
252- @ spec normalize ( { atom , atom } | map ) :: map | nil
279+ @ spec normalize ( { atom , atom } | map | atom ) :: map | nil
253280 @ doc """
254281 Converts a theme from it's tuple form to it's map form.
255282 """
@@ -261,9 +288,17 @@ defmodule Scenic.Themes do
261288 end
262289 end
263290
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+
264299 def normalize ( theme ) when is_map ( theme ) , do: theme
265300
266- @ spec preset ( { atom , atom } | map ) :: map | nil
301+ @ spec preset ( { atom , atom } | map | atom ) :: map | nil
267302 @ doc """
268303 Get a theme.
269304 """
@@ -275,6 +310,14 @@ defmodule Scenic.Themes do
275310 end
276311 end
277312
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+
278321 def preset ( theme ) when is_map ( theme ) , do: theme
279322
280323 @ theme_light % {
0 commit comments