Skip to content

Commit 26feb2d

Browse files
committed
add support for theme libraries
1 parent bd8a1e6 commit 26feb2d

File tree

22 files changed

+611
-287
lines changed

22 files changed

+611
-287
lines changed

lib/scenic/component/button.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ defmodule Scenic.Component.Button do
131131

132132
alias Scenic.Graph
133133
alias Scenic.Scene
134-
alias Scenic.Primitive.Style.Theme
134+
alias Scenic.Themes
135135
alias Scenic.Assets.Static
136136

137137
import Scenic.Primitives, only: [{:rrect, 3}, {:text, 3}, {:update_opts, 2}]
@@ -164,12 +164,12 @@ defmodule Scenic.Component.Button do
164164
# theme is passed in as an inherited style
165165
theme =
166166
case opts[:theme] do
167-
nil -> Theme.preset(:primary)
168-
:dark -> Theme.preset(:primary)
169-
:light -> Theme.preset(:primary)
167+
nil -> Themes.preset({:scenic, :primary})
168+
{:scenic, :dark} -> Themes.preset({:scenic, :primary})
169+
{:scenic, :light} -> Themes.preset({:scenic, :primary})
170170
theme -> theme
171171
end
172-
|> Theme.normalize()
172+
|> Themes.normalize()
173173

174174
# font related info
175175
font = Keyword.get(styles, :font, @default_font)
@@ -278,11 +278,11 @@ defmodule Scenic.Component.Button do
278278
)
279279
end
280280

281-
defp do_special_theme_outline(graph, :dark, border) do
281+
defp do_special_theme_outline(graph, {:scenic, :dark}, border) do
282282
Graph.modify(graph, :btn, &update_opts(&1, stroke: {1, border}))
283283
end
284284

285-
defp do_special_theme_outline(graph, :light, border) do
285+
defp do_special_theme_outline(graph, {:scenic, :light}, border) do
286286
Graph.modify(graph, :btn, &update_opts(&1, stroke: {1, border}))
287287
end
288288

lib/scenic/component/input/caret.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule Scenic.Component.Input.Caret do
4747
]
4848

4949
alias Scenic.Graph
50-
alias Scenic.Primitive.Style.Theme
50+
alias Scenic.Themes
5151

5252
@width 2
5353
@inset_v 4
@@ -86,7 +86,7 @@ defmodule Scenic.Component.Input.Caret do
8686
case opts[:color] do
8787
nil ->
8888
opts[:theme]
89-
|> Theme.normalize()
89+
|> Themes.normalize()
9090
|> Map.get(:highlight)
9191

9292
c ->

lib/scenic/component/input/checkbox.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ defmodule Scenic.Component.Input.Checkbox do
5454
alias Scenic.Graph
5555
alias Scenic.Scene
5656
alias Scenic.Primitive
57-
alias Scenic.Primitive.Style.Theme
57+
alias Scenic.Themes
5858
alias Scenic.Script
5959
alias Scenic.Assets.Static
6060

@@ -95,8 +95,8 @@ defmodule Scenic.Component.Input.Checkbox do
9595

9696
# theme is passed in as an inherited style
9797
theme =
98-
(opts[:theme] || Theme.preset(:dark))
99-
|> Theme.normalize()
98+
(opts[:theme] || Themes.preset({:scenic, :dark}))
99+
|> Themes.normalize()
100100

101101
# font related info
102102
{:ok, {Static.Font, fm}} = Static.meta(@default_font)

lib/scenic/component/input/dropdown.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ defmodule Scenic.Component.Input.Dropdown do
8484

8585
alias Scenic.Graph
8686
alias Scenic.Scene
87-
alias Scenic.Primitive.Style.Theme
87+
alias Scenic.Themes
8888
import Scenic.Primitives
8989
alias Scenic.Assets.Static
9090

@@ -188,8 +188,8 @@ defmodule Scenic.Component.Input.Dropdown do
188188

189189
# theme is passed in as an inherited style
190190
theme =
191-
(opts[:theme] || Theme.preset(:dark))
192-
|> Theme.normalize()
191+
(opts[:theme] || Themes.preset(:dark))
192+
|> Themes.normalize()
193193

194194
# font related info
195195
{:ok, {Static.Font, fm}} = Static.meta(@default_font)

lib/scenic/component/input/radio_button.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule Scenic.Component.Input.RadioButton do
3030
alias Scenic.Scene
3131
alias Scenic.Graph
3232
alias Scenic.Primitive
33-
alias Scenic.Primitive.Style.Theme
33+
alias Scenic.Themes
3434
alias Scenic.Assets.Static
3535

3636
require Logger
@@ -70,8 +70,8 @@ defmodule Scenic.Component.Input.RadioButton do
7070
def init(scene, {text, id, checked?}, opts) do
7171
# theme is passed in as an inherited style
7272
theme =
73-
(opts[:theme] || Theme.preset(:dark))
74-
|> Theme.normalize()
73+
(opts[:theme] || Themes.preset(:dark))
74+
|> Themes.normalize()
7575

7676
# font related info
7777
{:ok, {Static.Font, fm}} = Static.meta(@default_font)

lib/scenic/component/input/slider.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ defmodule Scenic.Component.Input.Slider do
6969
use Scenic.Component, has_children: false
7070

7171
alias Scenic.Graph
72-
alias Scenic.Primitive.Style.Theme
72+
alias Scenic.Themes
7373
import Scenic.Primitives, only: [{:rect, 3}, {:line, 3}, {:rrect, 3}, {:update_opts, 2}]
7474

7575
require Logger
@@ -192,8 +192,8 @@ defmodule Scenic.Component.Input.Slider do
192192

193193
# theme is passed in as an inherited style
194194
theme =
195-
(opts[:theme] || Theme.preset(:primary))
196-
|> Theme.normalize()
195+
(opts[:theme] || Themes.preset(:primary))
196+
|> Themes.normalize()
197197

198198
# get button specific styles
199199
width = opts[:width] || @default_width

lib/scenic/component/input/text_field.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ defmodule Scenic.Component.Input.TextField do
8080

8181
alias Scenic.Graph
8282
alias Scenic.Component.Input.Caret
83-
alias Scenic.Primitive.Style.Theme
83+
alias Scenic.Themes
8484
# alias Scenic.Assets.Static
8585

8686
require Logger
@@ -138,8 +138,8 @@ defmodule Scenic.Component.Input.TextField do
138138

139139
# theme is passed in as an inherited style
140140
theme =
141-
(opts[:theme] || Theme.preset(:dark))
142-
|> Theme.normalize()
141+
(opts[:theme] || Themes.preset({:scenic, :dark}))
142+
|> Themes.normalize()
143143

144144
# get the text_field specific opts
145145
hint = opts[:hint] || @default_hint

lib/scenic/component/input/toggle.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ defmodule Scenic.Component.Input.Toggle do
5959
alias Scenic.Graph
6060
alias Scenic.Primitive
6161
alias Scenic.Primitive.Group
62-
alias Scenic.Primitive.Style.Theme
62+
alias Scenic.Themes
6363
alias Scenic.ViewPort
6464

6565
import Scenic.Primitives
@@ -131,7 +131,7 @@ defmodule Scenic.Component.Input.Toggle do
131131
# theme is passed in as an inherited style
132132
theme =
133133
opts[:theme]
134-
|> Theme.normalize()
134+
|> Themes.normalize()
135135

136136
# get toggle specific opts
137137
thumb_radius = Keyword.get(opts, :thumb_radius, @default_thumb_radius)

lib/scenic/graph/compiler.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule Scenic.Graph.Compiler do
1212
alias Scenic.Primitive
1313
alias Scenic.Graph
1414
alias Scenic.Color
15-
alias Scenic.Primitive.Style.Theme
15+
alias Scenic.Themes
1616
alias Scenic.Graph.Compiler
1717

1818
# import IEx
@@ -271,7 +271,7 @@ defmodule Scenic.Graph.Compiler do
271271
defp do_text_color(ops, %{reqs: %{theme: theme}} = state) do
272272
color =
273273
theme
274-
|> Theme.normalize()
274+
|> Themes.normalize()
275275
|> Map.get(:text)
276276
|> Color.to_rgba()
277277

lib/scenic/primitive/style/style.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ defmodule Scenic.Primitive.Style do
4949
"""
5050

5151
alias Scenic.Primitive.Style
52+
alias Scenic.Themes
5253

5354
# import IEx
5455

@@ -85,7 +86,7 @@ defmodule Scenic.Primitive.Style do
8586
:stroke => Style.Stroke,
8687
:text_align => Style.TextAlign,
8788
:text_base => Style.TextBase,
88-
:theme => Style.Theme
89+
:theme => Themes
8990
}
9091

9192
@valid_styles @opts_map
@@ -106,7 +107,7 @@ defmodule Scenic.Primitive.Style do
106107
stroke: [type: {:custom, Style.Stroke, :validate, []}],
107108
text_align: [type: {:custom, Style.TextAlign, :validate, []}],
108109
text_base: [type: {:custom, Style.TextBase, :validate, []}],
109-
theme: [type: {:custom, Style.Theme, :validate, []}]
110+
theme: [type: {:custom, Themes, :validate, []}]
110111
]
111112

112113
@callback validate(data :: any) :: {:ok, data :: any} | {:error, String.t()}

0 commit comments

Comments
 (0)