class Umbra::RadioButton
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. @example
radio1 = RadioButton.new text: "Red", value: "Red", row: 10, col: 20 radio2 = RadioButton.new text: "Blue", value: "Blue", row: 11, col: 20 group = ButtonGroup.new "Color" group.add(radio1).add(radio2) form.add_widget radio1, radio2
Attributes
Public Class Methods
new(config={})
click to toggle source
Calls superclass method
# 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
Public Instance Methods
checked(tf)
click to toggle source
If user has pressed on this then set the group to this button.
# 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()
click to toggle source
all radio buttons will return the value of the selected value, not the offered value
# File lib/umbra/radiobutton.rb, line 42 def getvalue @button_group.value end
getvalue_for_paint()
click to toggle source
# File lib/umbra/radiobutton.rb, line 46 def getvalue_for_paint buttontext = getvalue() == @value ? "o" : " " $log.debug "called get_value_for paint for buttong #{@value} :#{buttontext} " 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] + buttontext + @surround_chars[1] else pretext = @surround_chars[0] + buttontext + @surround_chars[1] @text_offset = pretext.length + 1 @col_offset = @surround_chars[0].length return pretext + " #{dtext}" end end
toggle()
click to toggle source
# File lib/umbra/radiobutton.rb, line 62 def toggle fire end