Class: Umbra::RadioButton
- Inherits:
-
ToggleButton
- Object
- Widget
- Button
- ToggleButton
- Umbra::RadioButton
- Defined in:
- lib/umbra/radiobutton.rb
Overview
A selectable button that has a text value. It is linked to a ButtonGroup
that is shared by other radio buttons. Only one is selected at a time, unlike Checkbox
. text
is the value to display, which can include an ampersand for a hotkey. value
is the value returned if selected, which usually is similar to text (or a short word). width
is helpful if placing the brackets to right of text, used to align round brackets
By default, radio buttons place the button on the left of the text.
Typically, the ButtonGroup
‘s `command` is passed a block to execute whenever any of the radiobuttons of this group is fired.
Instance Attribute Summary collapse
-
#button_group ⇒ Object
group that this button belongs to.
Attributes inherited from ToggleButton
Attributes inherited from Button
Attributes inherited from Widget
#col, #col_offset, #curpos, #focusable, #graphic, #handler, #key_label, #modified, #name, #repaint_required, #row, #row_offset, #state
Instance Method Summary collapse
-
#checked(tf) ⇒ Object
If user has pressed on this then set the group to this button.
-
#getvalue ⇒ Object
all radio buttons will return the value of the selected value, not the offered value.
- #getvalue_for_paint ⇒ Object
-
#initialize(config = {}, &block) ⇒ RadioButton
constructor
A new instance of RadioButton.
- #toggle ⇒ Object
Methods inherited from ToggleButton
#checked?, #fire, #handle_key, #value
Methods inherited from Button
#action, button_layout, #fire, #handle_key, #map_keys, #repaint, #selected?
Methods inherited from Widget
#_form=, #color_pair, #command, #handle_key, #height, #highlight_attr, #init_vars, #modified?, #on_enter, #on_leave, #repaint, #repaint_all, #rowcol, #set_form_col, #set_form_row, #text, #touch, #variable_set, #visible, #width
Methods included from KeyMappingHandler
#_process_key, #bind_key, #bind_keys, #process_key, #unbind_key
Methods included from EventHandler
#bind_event, #event?, #fire_handler, #fire_property_change, #register_events
Constructor Details
#initialize(config = {}, &block) ⇒ RadioButton
Returns a new instance of RadioButton.
34 35 36 37 38 39 |
# File 'lib/umbra/radiobutton.rb', line 34 def initialize config={}, &block @surround_chars = ['(', ')'] if @surround_chars.nil? super $log.warn "XXX: FIXMe Please set 'value' for radiobutton. If not sure, try setting it to the same value as 'text'" unless @value @value ||= @text end |
Instance Attribute Details
#button_group ⇒ Object
group that this button belongs to.
32 33 34 |
# File 'lib/umbra/radiobutton.rb', line 32 def @button_group end |
Instance Method Details
#checked(tf) ⇒ Object
If user has pressed on this then set the group to this button.
68 69 70 71 72 73 74 75 |
# File 'lib/umbra/radiobutton.rb', line 68 def checked tf if @button_group.value == value @button_group.value = "" else @button_group.value = value end end |
#getvalue ⇒ Object
all radio buttons will return the value of the selected value, not the offered value
42 43 44 |
# File 'lib/umbra/radiobutton.rb', line 42 def getvalue @button_group.value end |
#getvalue_for_paint ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/umbra/radiobutton.rb', line 46 def getvalue_for_paint = getvalue() == @value ? "o" : " " $log.debug "called get_value_for paint for buttong #{@value} :#{} " dtext = @width.nil? ? text : "%-*s" % [@width, text] if @align_right @text_offset = 0 @col_offset = dtext.length + @surround_chars[0].length + 1 return "#{dtext} " + @surround_chars[0] + + @surround_chars[1] else pretext = @surround_chars[0] + + @surround_chars[1] @text_offset = pretext.length + 1 @col_offset = @surround_chars[0].length return pretext + " #{dtext}" end end |
#toggle ⇒ Object
62 63 64 |
# File 'lib/umbra/radiobutton.rb', line 62 def toggle fire end |