Class: Rubygoo::RadioGroup

Inherits:
Container show all
Defined in:
lib/rubygoo/radio_group.rb

Overview

contains radio buttons, allowing only one to be checked at a time

Constant Summary

Constants inherited from Widget

Widget::DEFAULT_PARAMS

Instance Attribute Summary

Attributes inherited from Container

#bg_color, #queued_widgets, #rect, #widgets

Attributes inherited from Widget

#app, #container, #enabled, #focus_priority, #focussed, #goo_id, #h, #mouse_over, #opts, #padding_left, #padding_top, #parent, #relative, #visible, #w, #x, #y

Instance Method Summary collapse

Methods inherited from Container

#_draw, #_key_pressed, #_key_released, #_mouse_down, #_mouse_drag, #_mouse_dragging, #_mouse_motion, #_mouse_up, #_update, #added, #clear, #get, #remove, #resize, #tab_to?

Methods inherited from Widget

#_draw, #_focus, #_key_pressed, #_key_released, #_mouse_down, #_mouse_drag, #_mouse_dragging, #_mouse_motion, #_mouse_up, #_unfocus, #_update, #added, #contains?, #disable, #draw, #enable, #enabled?, #focus, #focussed?, #get, #get_color, goo_prop, #hide, inherited, #key_pressed, #key_released, #modal?, #mouse_down, #mouse_drag, #mouse_dragging, #mouse_enter, #mouse_exit, #mouse_motion, #mouse_over?, #mouse_up, #removed, #show, #tab_to?, #theme_property, #unfocus, #update, #update_rect, #visible?

Methods included from Inflector

#camelize, #classify, #constantize, #dasherize, #demodulize, #foreign_key, #humanize, #inflections, #ordinalize, #pluralize, #singularize, #tableize, #titleize, #underscore

Constructor Details

#initialize(opts = {}) ⇒ RadioGroup

Returns a new instance of RadioGroup.



6
7
8
# File 'lib/rubygoo/radio_group.rb', line 6

def initialize(opts={})
  super opts
end

Instance Method Details

#add(*widgets) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rubygoo/radio_group.rb', line 10

def add(*widgets)
  widgets.uniq.each do |w|
    if w.respond_to? :checked?
      w.when :checked do |*opts|
        widget = opts.first
        if widget.checked?
          update_group_selection widget
        end
      end
    end
  end

  super *widgets 
end

#update_group_selection(selected_widget) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rubygoo/radio_group.rb', line 25

def update_group_selection(selected_widget)
  @widgets.select{|w| w.respond_to? :checked? and w.checked?}.each do |w|
    unless selected_widget == w
      w.uncheck
    end
  end
end