Method: Fidgit::RadioButton#initialize

Defined in:
lib/fidgit/elements/radio_button.rb

#initialize(text, value, options = {}, &block) ⇒ RadioButton

Returns a new instance of RadioButton.

Parameters:

  • value (Object)
  • text (String)

    The string to display in the label.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :checked (Boolean)
  • :shortcut (Symbol) — default: nil

    Adds a shortcut key for this element, that activates it. :auto takes the first letter of the text.

  • :icon (Gosu::Image, nil) — default: nil
  • :justify (:left, :right, :center) — default: :left

    Text justification.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fidgit/elements/radio_button.rb', line 16

def initialize(text, value, options = {}, &block)
  options = {
    checked: false,
    checked_border_color: default(:checked, :border_color),
  }.merge! options

  @checked = options[:checked]
  @value = value

  super(text, options)

  @checked_border_color = options[:checked_border_color].dup
  @unchecked_border_color = border_color
  add_to_group

  @border_color = (checked? ? @checked_border_color : @unchecked_border_color).dup
end