Skip to content

Commit cfa4ec7

Browse files
authored
Merge pull request #49 from boydm/boyd
Improve specs in components.ex and primitives.ex
2 parents d21fd40 + 08f7a72 commit cfa4ec7

File tree

6 files changed

+156
-24
lines changed

6 files changed

+156
-24
lines changed

changelist.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
space and sometimes it would be global. If you want to capture that sort of input, either
1313
cover the space with a clear rect, or capture the input.
1414
* Add the `:direction` option to the `Dropdown` component so can can go either up or down.
15+
* Add specs to functions in components and primitives
1516

1617
### 0.7.0
1718
* First public release

lib/scenic/component.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ defmodule Scenic.Component do
2424

2525
use Scenic.Scene, unquote(opts)
2626

27+
@spec add_to_graph(graph :: Scenic.Graph.t(), data :: any, opts :: list) :: Scenic.Graph.t()
2728
def add_to_graph(graph, data \\ nil, opts \\ [])
2829

2930
def add_to_graph(%Scenic.Graph{} = graph, data, opts) do
@@ -32,6 +33,7 @@ defmodule Scenic.Component do
3233
end
3334

3435
@doc false
36+
@spec info(data :: any) :: String.t()
3537
def info(data) do
3638
"""
3739
#{inspect(__MODULE__)} invalid add_to_graph data
@@ -40,6 +42,7 @@ defmodule Scenic.Component do
4042
end
4143

4244
@doc false
45+
@spec verify!(data :: any) :: any
4346
def verify!(data) do
4447
case verify(data) do
4548
{:ok, data} -> data

lib/scenic/components.ex

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ defmodule Scenic.Components do
176176
177177
178178
"""
179-
def button(graph, data, options \\ [])
179+
@spec button(
180+
source :: Graph.t() | Primitive.t(),
181+
title :: String.t(),
182+
options :: list
183+
) :: Graph.t() | Primitive.t()
184+
185+
def button(graph, title, options \\ [])
180186

181187
def button(%Graph{} = g, data, options) do
182188
add_to_graph(g, Component.Button, data, options)
@@ -236,6 +242,12 @@ defmodule Scenic.Components do
236242
|> checkbox( {"Example", true}, id: :checkbox_id, translate: {20, 20} )
237243
238244
"""
245+
@spec checkbox(
246+
source :: Graph.t() | Primitive.t(),
247+
data :: {String.t(), boolean},
248+
options :: list
249+
) :: Graph.t() | Primitive.t()
250+
239251
def checkbox(graph, data, options \\ [])
240252

241253
def checkbox(%Graph{} = g, data, options) do
@@ -320,6 +332,12 @@ defmodule Scenic.Components do
320332
], :controls}, id: :dropdown_id, translate: {20, 20} )
321333
322334
"""
335+
@spec dropdown(
336+
source :: Graph.t() | Primitive.t(),
337+
data :: {list({String.t(), any}), any},
338+
options :: list
339+
) :: Graph.t() | Primitive.t()
340+
323341
def dropdown(graph, data, options \\ [])
324342

325343
def dropdown(%Graph{} = g, data, options) do
@@ -399,6 +417,11 @@ defmodule Scenic.Components do
399417
], id: :radio_group_id, translate: {20, 20} )
400418
401419
"""
420+
@spec radio_group(
421+
source :: Graph.t() | Primitive.t(),
422+
data :: list({String.t(), any} | {String.t(), any, boolean}),
423+
options :: list
424+
) :: Graph.t() | Primitive.t()
402425
def radio_group(graph, data, options \\ [])
403426

404427
def radio_group(%Graph{} = g, data, options) do
@@ -456,10 +479,10 @@ defmodule Scenic.Components do
456479
457480
### Examples
458481
459-
The following example creates a numeric sliderand positions it on the screen.
482+
The following example creates a numeric slider and positions it on the screen.
460483
461484
graph
462-
|> Component.Input.Slider.add_to_graph( {{0,100}, 0, :num_slider}, translate: {20,20} )
485+
|> slider( {{0,100}, 0}, id: :num_slider, translate: {20,20} )
463486
464487
The following example creates a list slider and positions it on the screen.
465488
@@ -472,6 +495,12 @@ defmodule Scenic.Components do
472495
], :cornflower_blue}, id: :slider_id, translate: {20,20} )
473496
474497
"""
498+
@spec slider(
499+
source :: Graph.t() | Primitive.t(),
500+
data :: {{number, number}, number} | list,
501+
options :: list
502+
) :: Graph.t() | Primitive.t()
503+
475504
def slider(graph, data, options \\ [])
476505

477506
def slider(%Graph{} = g, data, options) do
@@ -546,6 +575,12 @@ defmodule Scenic.Components do
546575
"", id: :pass_id, type: :password, hint: "Enter password", translate: {20,20}
547576
)
548577
"""
578+
@spec text_field(
579+
source :: Graph.t() | Primitive.t(),
580+
data :: String.t(),
581+
options :: list
582+
) :: Graph.t() | Primitive.t()
583+
549584
def text_field(graph, data, options \\ [])
550585

551586
def text_field(%Graph{} = g, data, options) do

lib/scenic/graph.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ defmodule Scenic.Graph do
508508
end
509509
end
510510

511-
@spec modify(graph :: Graph.t(), id :: any, action :: function) :: Graph.t()
511+
@spec modify(graph :: Graph.t(), id :: any, action :: (... -> Primitive.t())) :: Graph.t()
512512
def modify(graph, id, action)
513513

514514
# pass in an atom based id, and it will transform all mapped uids

0 commit comments

Comments
 (0)