Skip to content

Commit 5d90cb4

Browse files
authored
Merge pull request #50 from boydm/boyd
Add Component tests
2 parents 0eccac2 + d33431d commit 5d90cb4

File tree

14 files changed

+1258
-110
lines changed

14 files changed

+1258
-110
lines changed

lib/scenic/component/button.ex

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,30 @@ defmodule Scenic.Component.Button do
5757
|> text(text,
5858
fill: theme.text,
5959
translate: {width / 2, height * 0.7},
60-
text_align: :center
60+
text_align: :center,
61+
id: :title
6162
)
6263

6364
:left ->
6465
Graph.build(font: font, font_size: font_size)
6566
|> rrect({width, height, radius}, fill: theme.background, id: :btn)
66-
|> text(text, fill: theme.text, translate: {8, height * 0.7}, text_align: :left)
67+
|> text(
68+
text,
69+
fill: theme.text,
70+
translate: {8, height * 0.7},
71+
text_align: :left,
72+
id: :title
73+
)
6774

6875
:right ->
6976
Graph.build(font: font, font_size: font_size)
7077
|> rrect({width, height, radius}, fill: theme.background, id: :btn)
71-
|> text(text, fill: theme.text, translate: {width - 8, height * 0.7}, text_align: :right)
78+
|> text(text,
79+
fill: theme.text,
80+
translate: {width - 8, height * 0.7},
81+
text_align: :right,
82+
id: :title
83+
)
7284
end
7385

7486
# special case the dark and light themes to show an outline

lib/scenic/component/input/caret.ex

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ defmodule Scenic.Component.Input.Caret do
1818
@width 2
1919
@inset_v 4
2020

21-
# carat blink speed in hertz
22-
@carat_hz 1.5
23-
@carat_ms trunc(@carat_hz * 500)
21+
# caret blink speed in hertz
22+
@caret_hz 1.5
23+
@caret_ms trunc(@caret_hz * 500)
2424

2525
# ============================================================================
2626
# setup
@@ -70,22 +70,22 @@ defmodule Scenic.Component.Input.Caret do
7070
end
7171

7272
# --------------------------------------------------------
73-
def handle_cast(:gain_focus, %{graph: graph, timer: nil} = state) do
74-
# turn on the carat
73+
def handle_cast(:start_caret, %{graph: graph, timer: nil} = state) do
74+
# turn on the caret
7575
graph =
7676
graph
7777
|> Graph.modify(:caret, &update_opts(&1, hidden: false))
7878
|> push_graph()
7979

8080
# start the timer
81-
{:ok, timer} = :timer.send_interval(@carat_ms, :blink)
81+
{:ok, timer} = :timer.send_interval(@caret_ms, :blink)
8282

8383
{:noreply, %{state | graph: graph, hidden: false, timer: timer, focused: true}}
8484
end
8585

8686
# --------------------------------------------------------
87-
def handle_cast(:lose_focus, %{graph: graph, timer: timer} = state) do
88-
# hide the carat
87+
def handle_cast(:stop_caret, %{graph: graph, timer: timer} = state) do
88+
# hide the caret
8989
graph =
9090
graph
9191
|> Graph.modify(:caret, &update_opts(&1, hidden: true))
@@ -102,10 +102,10 @@ defmodule Scenic.Component.Input.Caret do
102102

103103
# --------------------------------------------------------
104104
def handle_cast(
105-
:reset_carat,
105+
:reset_caret,
106106
%{graph: graph, timer: timer, focused: true} = state
107107
) do
108-
# show the carat
108+
# show the caret
109109
graph =
110110
graph
111111
|> Graph.modify(:caret, &update_opts(&1, hidden: false))
@@ -115,7 +115,7 @@ defmodule Scenic.Component.Input.Caret do
115115
if timer, do: :timer.cancel(timer)
116116

117117
# restart the timer
118-
{:ok, timer} = :timer.send_interval(@carat_ms, :blink)
118+
{:ok, timer} = :timer.send_interval(@caret_ms, :blink)
119119

120120
{:noreply, %{state | graph: graph, hidden: false, timer: timer}}
121121
end

lib/scenic/component/input/dropdown.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Scenic.Component.Input.Dropdown do
1111
alias Scenic.Primitive.Style.Theme
1212
import Scenic.Primitives
1313

14-
# import IEx
14+
import IEx
1515

1616
@default_width 160
1717
@default_height 30
@@ -43,12 +43,12 @@ defmodule Scenic.Component.Input.Dropdown do
4343

4444
# --------------------------------------------------------
4545
def verify({items, initial} = data) when is_list(items) do
46-
Enum.all?(items, &verify_item(&1)) &&
47-
Enum.find_value(items, false, fn {_, id} -> id == initial end)
48-
|> case do
49-
true -> {:ok, data}
50-
_ -> :invalid_data
51-
end
46+
(Enum.all?(items, &verify_item(&1)) &&
47+
Enum.find_value(items, false, fn {_, id} -> id == initial end))
48+
|> case do
49+
true -> {:ok, data}
50+
_ -> :invalid_data
51+
end
5252
end
5353

5454
def verify(_), do: :invalid_data
@@ -269,7 +269,7 @@ defmodule Scenic.Component.Input.Dropdown do
269269
# push to the viewport
270270
|> push_graph()
271271

272-
{:continue, %{state | down: false, graph: graph}}
272+
{:noreply, %{state | down: false, graph: graph}}
273273
end
274274

275275
# --------------------------------------------------------

lib/scenic/component/input/radio_button.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ defmodule Scenic.Component.Input.RadioButton do
6767
{:ok, state}
6868
end
6969

70-
# --------------------------------------------------------
71-
def handle_cast({:set_value, new_value}, state) do
72-
state = Map.put(state, :checked, new_value)
73-
graph = update_graph(state)
74-
{:noreply, %{state | graph: graph}}
75-
end
70+
# # --------------------------------------------------------
71+
# def handle_cast({:set_value, new_value}, state) do
72+
# state = Map.put(state, :checked, new_value)
73+
# graph = update_graph(state)
74+
# {:noreply, %{state | graph: graph}}
75+
# end
7676

7777
# --------------------------------------------------------
7878
def handle_cast({:set_to_msg, set_id}, %{id: id} = state) do

lib/scenic/component/input/radio_group.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ defmodule Scenic.Component.Input.RadioGroup do
9090
{:ok, state}
9191
end
9292

93-
# --------------------------------------------------------
94-
def handle_cast({:set_value, new_value}, state) do
95-
{:noreply, %{state | value: new_value}}
96-
end
93+
# # --------------------------------------------------------
94+
# def handle_cast({:set_value, new_value}, state) do
95+
# {:noreply, %{state | value: new_value}}
96+
# end
9797

9898
# ============================================================================
9999

0 commit comments

Comments
 (0)