class Fidgit::RadioButton

Attributes

group[R]
value[R]

Public Class Methods

new(text, value, options = {}, &block) click to toggle source

@param (see Button#initialize) @param [Object] value

@option (see Button#initialize) @option options [Boolean] :checked

Calls superclass method Fidgit::Button::new
# 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

Public Instance Methods

check() click to toggle source

Check the button and update its group. This may uncheck another button in the group if one is selected.

# File lib/fidgit/elements/radio_button.rb, line 41
def check
  return if checked?

  @checked = true
  @group.value = value
  @border_color = @checked_border_color.dup
  publish :changed, @checked

  nil
end
checked?() click to toggle source
# File lib/fidgit/elements/radio_button.rb, line 9
def checked?; @checked; end
clicked_left_mouse_button(sender, x, y) click to toggle source
# File lib/fidgit/elements/radio_button.rb, line 34
def clicked_left_mouse_button(sender, x, y)
  super
  check
  nil
end
uncheck() click to toggle source

Uncheck the button and update its group.

# File lib/fidgit/elements/radio_button.rb, line 53
def uncheck
  return unless checked?

  @checked = false
  @group.value = value
  @border_color = @unchecked_border_color.dup
  publish :changed, @checked

  nil
end

Protected Instance Methods

add_to_group() click to toggle source
# File lib/fidgit/elements/radio_button.rb, line 73
def add_to_group
  container = parent
  while container and not container.is_a? Group
    container = container.parent
  end

  raise "#{self.class.name} must be placed inside a group element" unless container

  @group = container
  @group.add_button self
  nil
end
parent=(parent) click to toggle source
Calls superclass method Fidgit::Button#parent=
# File lib/fidgit/elements/radio_button.rb, line 65
def parent=(parent)
  @group.remove_button self if @parent
  super(parent)
  add_to_group if parent
  parent
end