class Fidgit::Group

Attributes

selected[R]

Public Class Methods

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

@example

group do
  horizontal do
    radio_button 1, text: '1', checked: true
    radio_button 2, text: '2'
    subscribe :changed do |sender, value|
      puts value
    end
  end
end

@param (see Packer#initialize)

@option (see Packer#initialize)

Calls superclass method
# File lib/fidgit/elements/group.rb, line 23
def initialize(options = {}, &block)
  super(options)

  @selected = nil
  @buttons = []
end

Public Instance Methods

add_button(button) click to toggle source
# File lib/fidgit/elements/group.rb, line 30
def add_button(button)
  @buttons.push button
  self.value = button.value if button.checked?
  nil
end
remove_button(button) click to toggle source
# File lib/fidgit/elements/group.rb, line 36
def remove_button(button)
  self.value = nil if button == @selected
  @buttons.delete button
  nil
end
value() click to toggle source
# File lib/fidgit/elements/group.rb, line 7
def value; @selected ? @selected.value : nil; end
value=(value) click to toggle source

@example

@my_group = group do
  horizontal do
    radio_button(1, text: '1', checked: true)
    radio_button(2, text: '2')
  end
 end

# later
@my_group.value = 2
# File lib/fidgit/elements/group.rb, line 52
def value=(value)
  if value != self.value
    button = @buttons.find { |b| b.value == value }
    @selected.uncheck if @selected and @selected.checked?
    @selected = button
    @selected.check if @selected and not @selected.checked?
    publish :changed, self.value
  end

  value
end