Skip to content

Commit 3818b7c

Browse files
committed
docs cleanup. Add caret and ratio_button
1 parent af427d7 commit 3818b7c

File tree

9 files changed

+88
-16
lines changed

9 files changed

+88
-16
lines changed

lib/scenic/component/button.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ defmodule Scenic.Component.Button do
9191
@default_alignment :center
9292

9393
# --------------------------------------------------------
94+
@doc false
9495
def info(data) do
9596
"""
9697
#{IO.ANSI.red()}Button data must be a bitstring: initial_text
@@ -100,10 +101,12 @@ defmodule Scenic.Component.Button do
100101
end
101102

102103
# --------------------------------------------------------
104+
@doc false
103105
def verify(text) when is_bitstring(text), do: {:ok, text}
104106
def verify(_), do: :invalid_data
105107

106108
# --------------------------------------------------------
109+
@doc false
107110
def init(text, opts) when is_bitstring(text) and is_list(opts) do
108111
id = opts[:id]
109112
styles = opts[:styles]
@@ -185,6 +188,7 @@ defmodule Scenic.Component.Button do
185188
end
186189

187190
# --------------------------------------------------------
191+
@doc false
188192
def handle_input(
189193
{:cursor_enter, _uid},
190194
_context,

lib/scenic/component/input/caret.ex

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,28 @@
44
#
55

66
defmodule Scenic.Component.Input.Caret do
7-
@moduledoc false
7+
@moduledoc """
8+
Add a blinking text-input caret to a graph.
89
10+
11+
## Data
12+
13+
`{height, color}`
14+
15+
* `height` - integer greater than zero
16+
* `color` - any [valid color](Scenic.Primitive.Style.Paint.Color.html).
17+
18+
## Usage
19+
20+
The caret component is used by the TextField component and usually isn't accessed directly,
21+
although you are free to do so if it fits your needs. There is no short-cut helper
22+
function so you will need to add it to the graph manually.
23+
24+
The following example adds a caret to a graph.
25+
26+
graph
27+
|> Caret.add_to_graph({height, theme.text}, id: :caret)
28+
"""
929
use Scenic.Component, has_children: false
1030

1131
import Scenic.Primitives,
@@ -28,6 +48,7 @@ defmodule Scenic.Component.Input.Caret do
2848
# setup
2949

3050
# --------------------------------------------------------
51+
@doc false
3152
def info(data) do
3253
"""
3354
#{IO.ANSI.red()}Caret data must be: {height, color}
@@ -37,6 +58,7 @@ defmodule Scenic.Component.Input.Caret do
3758
end
3859

3960
# --------------------------------------------------------
61+
@doc false
4062
@spec verify(any()) :: :invalid_data | {:ok, {number(), any()}}
4163
def verify({height, color} = data)
4264
when is_number(height) and height > 0 do
@@ -49,6 +71,7 @@ defmodule Scenic.Component.Input.Caret do
4971
def verify(_), do: :invalid_data
5072

5173
# --------------------------------------------------------
74+
@doc false
5275
def init({height, color}, _opts) do
5376
# build the graph, initially not showing
5477
graph =
@@ -72,6 +95,7 @@ defmodule Scenic.Component.Input.Caret do
7295
end
7396

7497
# --------------------------------------------------------
98+
@doc false
7599
def handle_cast(:start_caret, %{graph: graph, timer: nil} = state) do
76100
# turn on the caret
77101
graph =
@@ -127,6 +151,7 @@ defmodule Scenic.Component.Input.Caret do
127151
def handle_cast(_, state), do: {:noreply, state}
128152

129153
# --------------------------------------------------------
154+
@doc false
130155
def handle_info(:blink, %{graph: graph, hidden: hidden} = state) do
131156
# invert the hidden flag
132157
hidden = !hidden

lib/scenic/component/input/checkbox.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ defmodule Scenic.Component.Input.Checkbox do
6666
# @default_height 16
6767
# @default_radius 3
6868

69-
# #--------------------------------------------------------
69+
# --------------------------------------------------------
70+
@doc false
7071
def info(data) do
7172
"""
7273
#{IO.ANSI.red()}Checkbox data must be: {text, checked?}
@@ -76,13 +77,15 @@ defmodule Scenic.Component.Input.Checkbox do
7677
end
7778

7879
# --------------------------------------------------------
80+
@doc false
7981
def verify({text, checked} = data) when is_bitstring(text) and is_boolean(checked) do
8082
{:ok, data}
8183
end
8284

8385
def verify(_), do: :invalid_data
8486

8587
# --------------------------------------------------------
88+
@doc false
8689
def init({text, checked?}, opts) do
8790
id = opts[:id]
8891
styles = opts[:styles]
@@ -149,6 +152,7 @@ defmodule Scenic.Component.Input.Checkbox do
149152
end
150153

151154
# --------------------------------------------------------
155+
@doc false
152156
def handle_input({:cursor_enter, _uid}, _, %{pressed: true} = state) do
153157
state = Map.put(state, :contained, true)
154158
graph = update_graph(state)

lib/scenic/component/input/dropdown.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ defmodule Scenic.Component.Input.Dropdown do
109109
@rotate_up :math.pi()
110110

111111
# --------------------------------------------------------
112+
@doc false
112113
def info(data) do
113114
"""
114115
#{IO.ANSI.red()}Dropdown data must be: {items, initial}
@@ -118,6 +119,7 @@ defmodule Scenic.Component.Input.Dropdown do
118119
end
119120

120121
# --------------------------------------------------------
122+
@doc false
121123
def verify({items, initial} = data) when is_list(items) do
122124
(Enum.all?(items, &verify_item(&1)) &&
123125
Enum.find_value(items, false, fn {_, id} -> id == initial end))
@@ -134,6 +136,7 @@ defmodule Scenic.Component.Input.Dropdown do
134136
defp verify_item(_), do: false
135137

136138
# --------------------------------------------------------
139+
@doc false
137140
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
138141
def init({items, initial_id}, opts) do
139142
id = opts[:id]
@@ -263,6 +266,7 @@ defmodule Scenic.Component.Input.Dropdown do
263266
# tracking when the dropdown is UP
264267

265268
# --------------------------------------------------------
269+
@doc false
266270
def handle_input({:cursor_enter, _uid}, %{id: id}, %{down: false} = state) do
267271
{:noreply, %{state | hover_id: id}}
268272
end

lib/scenic/component/input/radio_button.ex

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
defmodule Scenic.Component.Input.RadioButton do
2-
@moduledoc false
2+
@moduledoc """
3+
Add a single radio button to a graph.
4+
5+
## Data
6+
7+
`{text, id}`
8+
`{text, id, selected?}`
9+
10+
* `text` - a bitstring of the text to display
11+
* `id` - any term. Identifies the radio button.
12+
* `selected?` - boolean. `true` if selected. `false if not`. Default is `false` if
13+
this term is not provided.
14+
15+
## Usage
16+
17+
The RadioButton component is used by the RadioGroup component and usually isn't accessed
18+
directly, although you are free to do so if it fits your needs. There is no short-cut
19+
helper function so you will need to add it to the graph manually.
20+
21+
The following example adds a caret to a graph.
22+
23+
graph
24+
|> RadioButton.add_to_graph({"A button", :an_id, true})
25+
26+
"""
327

428
use Scenic.Component, has_children: false
529

@@ -11,7 +35,8 @@ defmodule Scenic.Component.Input.RadioButton do
1135

1236
# import IEx
1337

14-
# #--------------------------------------------------------
38+
#--------------------------------------------------------
39+
@doc false
1540
def info(data) do
1641
"""
1742
#{IO.ANSI.red()}RadioButton data must be: {text, id} or {text, id, checked?}
@@ -21,6 +46,7 @@ defmodule Scenic.Component.Input.RadioButton do
2146
end
2247

2348
# --------------------------------------------------------
49+
@doc false
2450
def verify({text, _} = data) when is_bitstring(text) do
2551
{:ok, data}
2652
end
@@ -32,6 +58,7 @@ defmodule Scenic.Component.Input.RadioButton do
3258
def verify(_), do: :invalid_data
3359

3460
# --------------------------------------------------------
61+
@doc false
3562
def init({text, id}, opts) when is_bitstring(text), do: init({text, id, false}, opts)
3663

3764
def init({text, id, checked?}, opts) do
@@ -69,14 +96,8 @@ defmodule Scenic.Component.Input.RadioButton do
6996
{:ok, state}
7097
end
7198

72-
# # --------------------------------------------------------
73-
# def handle_cast({:set_value, new_value}, state) do
74-
# state = Map.put(state, :checked, new_value)
75-
# graph = update_graph(state)
76-
# {:noreply, %{state | graph: graph}}
77-
# end
78-
7999
# --------------------------------------------------------
100+
@doc false
80101
def handle_cast({:set_to_msg, set_id}, %{id: id} = state) do
81102
state = Map.put(state, :checked, set_id == id)
82103
graph = update_graph(state)
@@ -98,6 +119,7 @@ defmodule Scenic.Component.Input.RadioButton do
98119
end
99120

100121
# --------------------------------------------------------
122+
@doc false
101123
def handle_input({:cursor_button, {:left, :press, _, _}}, context, state) do
102124
state =
103125
state

lib/scenic/component/input/radio_group.ex

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

8585
@line_height 22
8686

87-
# #--------------------------------------------------------
87+
#--------------------------------------------------------
88+
@doc false
8889
def info(data) do
8990
"""
9091
#{IO.ANSI.red()}RadioGroup data must be a list of items
@@ -103,6 +104,7 @@ defmodule Scenic.Component.Input.RadioGroup do
103104
end
104105

105106
# --------------------------------------------------------
107+
@doc false
106108
def verify(items) when is_list(items) do
107109
items
108110
|> Enum.all?(fn item ->
@@ -120,9 +122,7 @@ defmodule Scenic.Component.Input.RadioGroup do
120122
def verify(_), do: :invalid_data
121123

122124
# --------------------------------------------------------
123-
# def valid?( _items ), do: true
124-
125-
# --------------------------------------------------------
125+
@doc false
126126
def init(items, opts) when is_list(items) do
127127
id = opts[:id]
128128
styles = opts[:styles]
@@ -171,6 +171,7 @@ defmodule Scenic.Component.Input.RadioGroup do
171171

172172
# ============================================================================
173173

174+
@doc false
174175
def filter_event({:click, btn_id}, _from, %{id: id} = state) do
175176
Scene.cast_to_refs(nil, {:set_to_msg, btn_id})
176177

lib/scenic/component/input/slider.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ defmodule Scenic.Component.Input.Slider do
8787
# setup
8888

8989
# --------------------------------------------------------
90+
@doc false
9091
def info(data) do
9192
"""
9293
#{IO.ANSI.red()}Slider data must be: {extents, initial_value}
@@ -103,6 +104,7 @@ defmodule Scenic.Component.Input.Slider do
103104
end
104105

105106
# --------------------------------------------------------
107+
@doc false
106108
def verify({ext, initial} = data) do
107109
verify_initial(ext, initial)
108110
|> case do
@@ -127,6 +129,7 @@ defmodule Scenic.Component.Input.Slider do
127129
defp verify_initial(_, _), do: false
128130

129131
# --------------------------------------------------------
132+
@doc false
130133
def init({extents, value}, opts) do
131134
id = opts[:id]
132135
styles = opts[:styles]
@@ -163,6 +166,7 @@ defmodule Scenic.Component.Input.Slider do
163166
# ============================================================================
164167

165168
# --------------------------------------------------------
169+
@doc false
166170
def handle_input({:cursor_button, {:left, :press, _, {x, _}}}, context, state) do
167171
state =
168172
state

lib/scenic/component/input/text_field.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ defmodule Scenic.Component.Input.TextField do
112112
@hint_color :grey
113113

114114
# --------------------------------------------------------
115+
@doc false
115116
def info(data) do
116117
"""
117118
#{IO.ANSI.red()}TextField data must be a bitstring: initial_text
@@ -121,13 +122,15 @@ defmodule Scenic.Component.Input.TextField do
121122
end
122123

123124
# --------------------------------------------------------
125+
@doc false
124126
def verify(initial_text) when is_bitstring(initial_text) do
125127
{:ok, initial_text}
126128
end
127129

128130
def verify(_), do: :invalid_data
129131

130132
# --------------------------------------------------------
133+
@doc false
131134
def init(value, opts) do
132135
id = opts[:id]
133136
styles = opts[:styles]
@@ -333,6 +336,7 @@ defmodule Scenic.Component.Input.TextField do
333336
# User input handling - get the focus
334337

335338
# --------------------------------------------------------
339+
@doc false
336340
# unfocused click in the text field
337341
def handle_input(
338342
{:cursor_button, {:left, :press, _, _}},

lib/scenic/component/input/toggle.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ defmodule Scenic.Component.Input.Toggle do
9595
}
9696
end
9797

98-
# #--------------------------------------------------------
98+
#--------------------------------------------------------
99+
@doc false
99100
def info(data) do
100101
"""
101102
#{IO.ANSI.red()}Toggle data must be: on?
@@ -105,6 +106,7 @@ defmodule Scenic.Component.Input.Toggle do
105106
end
106107

107108
# --------------------------------------------------------
109+
@doc false
108110
@spec verify(any) :: {:ok, boolean} | :invalid_data
109111
def verify(on? = data) when is_boolean(on?) do
110112
{:ok, data}
@@ -113,6 +115,7 @@ defmodule Scenic.Component.Input.Toggle do
113115
def verify(_), do: :invalid_data
114116

115117
# --------------------------------------------------------
118+
@doc false
116119
@spec init(any, Keyword.t() | map | nil) :: {:ok, State.t()}
117120
def init(on?, opts) do
118121
id = opts[:id]
@@ -195,6 +198,7 @@ defmodule Scenic.Component.Input.Toggle do
195198
end
196199

197200
# --------------------------------------------------------
201+
@doc false
198202
def handle_input({:cursor_enter, _uid}, _, %{pressed?: true} = state) do
199203
state = Map.put(state, :contained?, true)
200204
graph = update_graph(state)

0 commit comments

Comments
 (0)