Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for library themes #252

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
14 changes: 7 additions & 7 deletions lib/scenic/component/button.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule Scenic.Component.Button do

alias Scenic.Graph
alias Scenic.Scene
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes
alias Scenic.Assets.Static

import Scenic.Primitives, only: [{:rrect, 3}, {:text, 3}, {:update_opts, 2}]
Expand Down Expand Up @@ -164,12 +164,12 @@ defmodule Scenic.Component.Button do
# theme is passed in as an inherited style
theme =
case opts[:theme] do
nil -> Theme.preset(:primary)
:dark -> Theme.preset(:primary)
:light -> Theme.preset(:primary)
nil -> Themes.preset({:scenic, :primary})
{:scenic, :dark} -> Themes.preset({:scenic, :primary})
{:scenic, :light} -> Themes.preset({:scenic, :primary})
theme -> theme
end
|> Theme.normalize()
|> Themes.normalize()

# font related info
font = Keyword.get(styles, :font, @default_font)
Expand Down Expand Up @@ -278,11 +278,11 @@ defmodule Scenic.Component.Button do
)
end

defp do_special_theme_outline(graph, :dark, border) do
defp do_special_theme_outline(graph, {:scenic, :dark}, border) do
Graph.modify(graph, :btn, &update_opts(&1, stroke: {1, border}))
end

Copy link
Contributor Author

@vacarsu vacarsu Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about these, It doesn't seem like they will ever match. I left them as is since I was already making such a sweeping change.

defp do_special_theme_outline(graph, :light, border) do
defp do_special_theme_outline(graph, {:scenic, :light}, border) do
Graph.modify(graph, :btn, &update_opts(&1, stroke: {1, border}))
end

Expand Down
4 changes: 2 additions & 2 deletions lib/scenic/component/input/caret.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Scenic.Component.Input.Caret do
]

alias Scenic.Graph
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes

@width 2
@inset_v 4
Expand Down Expand Up @@ -86,7 +86,7 @@ defmodule Scenic.Component.Input.Caret do
case opts[:color] do
nil ->
opts[:theme]
|> Theme.normalize()
|> Themes.normalize()
|> Map.get(:highlight)

c ->
Expand Down
6 changes: 3 additions & 3 deletions lib/scenic/component/input/checkbox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Scenic.Component.Input.Checkbox do
alias Scenic.Graph
alias Scenic.Scene
alias Scenic.Primitive
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes
alias Scenic.Script
alias Scenic.Assets.Static

Expand Down Expand Up @@ -95,8 +95,8 @@ defmodule Scenic.Component.Input.Checkbox do

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

# font related info
{:ok, {Static.Font, fm}} = Static.meta(@default_font)
Expand Down
6 changes: 3 additions & 3 deletions lib/scenic/component/input/dropdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Scenic.Component.Input.Dropdown do

alias Scenic.Graph
alias Scenic.Scene
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes
import Scenic.Primitives
alias Scenic.Assets.Static

Expand Down Expand Up @@ -188,8 +188,8 @@ defmodule Scenic.Component.Input.Dropdown do

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

# font related info
{:ok, {Static.Font, fm}} = Static.meta(@default_font)
Expand Down
6 changes: 3 additions & 3 deletions lib/scenic/component/input/radio_button.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Scenic.Component.Input.RadioButton do
alias Scenic.Scene
alias Scenic.Graph
alias Scenic.Primitive
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes
alias Scenic.Assets.Static

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

# font related info
{:ok, {Static.Font, fm}} = Static.meta(@default_font)
Expand Down
6 changes: 3 additions & 3 deletions lib/scenic/component/input/slider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule Scenic.Component.Input.Slider do
use Scenic.Component, has_children: false

alias Scenic.Graph
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes
import Scenic.Primitives, only: [{:rect, 3}, {:line, 3}, {:rrect, 3}, {:update_opts, 2}]

require Logger
Expand Down Expand Up @@ -192,8 +192,8 @@ defmodule Scenic.Component.Input.Slider do

# theme is passed in as an inherited style
theme =
(opts[:theme] || Theme.preset(:primary))
|> Theme.normalize()
(opts[:theme] || Themes.preset({:scenic, :dark}))
|> Themes.normalize()

# get button specific styles
width = opts[:width] || @default_width
Expand Down
6 changes: 3 additions & 3 deletions lib/scenic/component/input/text_field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defmodule Scenic.Component.Input.TextField do

alias Scenic.Graph
alias Scenic.Component.Input.Caret
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes
# alias Scenic.Assets.Static

require Logger
Expand Down Expand Up @@ -138,8 +138,8 @@ defmodule Scenic.Component.Input.TextField do

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

# get the text_field specific opts
hint = opts[:hint] || @default_hint
Expand Down
4 changes: 2 additions & 2 deletions lib/scenic/component/input/toggle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule Scenic.Component.Input.Toggle do
alias Scenic.Graph
alias Scenic.Primitive
alias Scenic.Primitive.Group
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes
alias Scenic.ViewPort

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

# get toggle specific opts
thumb_radius = Keyword.get(opts, :thumb_radius, @default_thumb_radius)
Expand Down
4 changes: 2 additions & 2 deletions lib/scenic/graph/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Scenic.Graph.Compiler do
alias Scenic.Primitive
alias Scenic.Graph
alias Scenic.Color
alias Scenic.Primitive.Style.Theme
alias Scenic.Themes
alias Scenic.Graph.Compiler

# import IEx
Expand Down Expand Up @@ -271,7 +271,7 @@ defmodule Scenic.Graph.Compiler do
defp do_text_color(ops, %{reqs: %{theme: theme}} = state) do
color =
theme
|> Theme.normalize()
|> Themes.normalize()
|> Map.get(:text)
|> Color.to_rgba()

Expand Down
5 changes: 3 additions & 2 deletions lib/scenic/primitive/style/style.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ defmodule Scenic.Primitive.Style do
"""

alias Scenic.Primitive.Style
alias Scenic.Themes

# import IEx

Expand Down Expand Up @@ -85,7 +86,7 @@ defmodule Scenic.Primitive.Style do
:stroke => Style.Stroke,
:text_align => Style.TextAlign,
:text_base => Style.TextBase,
:theme => Style.Theme
:theme => Themes
}

@valid_styles @opts_map
Expand All @@ -106,7 +107,7 @@ defmodule Scenic.Primitive.Style do
stroke: [type: {:custom, Style.Stroke, :validate, []}],
text_align: [type: {:custom, Style.TextAlign, :validate, []}],
text_base: [type: {:custom, Style.TextBase, :validate, []}],
theme: [type: {:custom, Style.Theme, :validate, []}]
theme: [type: {:custom, Themes, :validate, []}]
]

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