1
1
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
+ """
3
27
4
28
use Scenic.Component , has_children: false
5
29
@@ -11,7 +35,8 @@ defmodule Scenic.Component.Input.RadioButton do
11
35
12
36
# import IEx
13
37
14
- # #--------------------------------------------------------
38
+ #--------------------------------------------------------
39
+ @ doc false
15
40
def info ( data ) do
16
41
"""
17
42
#{ IO.ANSI . red ( ) } RadioButton data must be: {text, id} or {text, id, checked?}
@@ -21,6 +46,7 @@ defmodule Scenic.Component.Input.RadioButton do
21
46
end
22
47
23
48
# --------------------------------------------------------
49
+ @ doc false
24
50
def verify ( { text , _ } = data ) when is_bitstring ( text ) do
25
51
{ :ok , data }
26
52
end
@@ -32,6 +58,7 @@ defmodule Scenic.Component.Input.RadioButton do
32
58
def verify ( _ ) , do: :invalid_data
33
59
34
60
# --------------------------------------------------------
61
+ @ doc false
35
62
def init ( { text , id } , opts ) when is_bitstring ( text ) , do: init ( { text , id , false } , opts )
36
63
37
64
def init ( { text , id , checked? } , opts ) do
@@ -69,14 +96,8 @@ defmodule Scenic.Component.Input.RadioButton do
69
96
{ :ok , state }
70
97
end
71
98
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
-
79
99
# --------------------------------------------------------
100
+ @ doc false
80
101
def handle_cast ( { :set_to_msg , set_id } , % { id: id } = state ) do
81
102
state = Map . put ( state , :checked , set_id == id )
82
103
graph = update_graph ( state )
@@ -98,6 +119,7 @@ defmodule Scenic.Component.Input.RadioButton do
98
119
end
99
120
100
121
# --------------------------------------------------------
122
+ @ doc false
101
123
def handle_input ( { :cursor_button , { :left , :press , _ , _ } } , context , state ) do
102
124
state =
103
125
state
0 commit comments