Class: Rubygoo::CheckBox
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_PARAMS =
{:align=>:right}
Instance Attribute Summary collapse
-
#checked ⇒ Object
Returns the value of attribute checked.
Attributes inherited from Widget
#app, #container, #enabled, #focus_priority, #focussed, #h, #mouse_over, #opts, #parent, #relative, #visible, #w, #x, #x_pad, #y, #y_pad
Instance Method Summary collapse
- #added ⇒ Object
- #check ⇒ Object
- #checked? ⇒ Boolean
- #draw(adapter) ⇒ Object
-
#initialize(opts = {}) ⇒ CheckBox
constructor
A new instance of CheckBox.
-
#key_pressed(event) ⇒ Object
called when a key press is sent to us.
-
#mouse_drag(event) ⇒ Object
called when there is a mouse click at the end of a drag.
-
#mouse_up(event) ⇒ Object
called when there is a mouse click.
- #toggle ⇒ Object
- #uncheck ⇒ Object
Methods inherited from Widget
#_draw, #_focus, #_key_pressed, #_key_released, #_mouse_down, #_mouse_drag, #_mouse_dragging, #_mouse_motion, #_mouse_up, #_unfocus, #_update, #contains?, #disable, #enable, #enabled?, #focus, #focussed?, #get_color, #hide, #key_released, #modal?, #mouse_down, #mouse_dragging, #mouse_enter, #mouse_exit, #mouse_motion, #mouse_over?, #removed, #show, #tab_to?, #theme_property, #unfocus, #update, #update_rect, #visible?
Constructor Details
#initialize(opts = {}) ⇒ CheckBox
Returns a new instance of CheckBox.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rubygoo/check_box.rb', line 7 def initialize(opts={}) opts = DEFAULT_PARAMS.merge opts super opts @checked = opts[:checked] # only supports label on the right # TODO maybe I should do this in added @label_text = opts[:label] @label_alignment = opts[:align] end |
Instance Attribute Details
#checked ⇒ Object
Returns the value of attribute checked.
4 5 6 |
# File 'lib/rubygoo/check_box.rb', line 4 def checked @checked end |
Instance Method Details
#added ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubygoo/check_box.rb', line 18 def added() @color = theme_property :color @bg_color = theme_property :bg_color @border_color = theme_property :border_color @focus_color = theme_property :focus_color @checked_color = theme_property :checked_color @hover_color = theme_property :hover_color @rect = Rect.new [@x-@x_pad,@y-@y_pad,@w+2*@x_pad,@h+2*@y_pad] unless @label_text.nil? or @label_text.empty? @label = Label.new @label_text, :x=>0,:y=>0, :relative=>@relative, :visible=>false @parent.add @label case @label_alignment when :right lx = @x+2*@x_pad+@w ly = @y when :left ly = @y lx = @x-2*@x_pad-@label.w end @label.x = lx @label.y = ly @label.show end end |
#check ⇒ Object
57 58 59 60 |
# File 'lib/rubygoo/check_box.rb', line 57 def check() @checked = true fire :checked, self end |
#checked? ⇒ Boolean
45 46 47 |
# File 'lib/rubygoo/check_box.rb', line 45 def checked?() @checked end |
#draw(adapter) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rubygoo/check_box.rb', line 85 def draw(adapter) x1 = @rect[0] y1 = @rect[1] x2 = @rect[2] + x1 y2 = @rect[3] + y1 if @focussed adapter.fill x1, y1, x2, y2, @focus_color elsif @bg_color adapter.fill x1, y1, x2, y2, @bg_color end if @checked rect = @rect.inflate(-@x_pad,-@y_pad) cx1 = rect[0] cy1 = rect[1] cx2 = rect[2] + x1 cy2 = rect[3] + y1 adapter.fill cx1, cy1, cx2, cy2, @checked_color end if mouse_over? and @hover_color adapter.fill x1, y1, x2, y2, @hover_color end if @border_color adapter.draw_box x1, y1, x2, y2, @border_color end end |
#key_pressed(event) ⇒ Object
called when a key press is sent to us
78 79 80 81 82 83 |
# File 'lib/rubygoo/check_box.rb', line 78 def key_pressed(event) case event.data[:key] when K_SPACE toggle end end |
#mouse_drag(event) ⇒ Object
called when there is a mouse click at the end of a drag
73 74 75 |
# File 'lib/rubygoo/check_box.rb', line 73 def mouse_drag(event) toggle end |
#mouse_up(event) ⇒ Object
called when there is a mouse click
68 69 70 |
# File 'lib/rubygoo/check_box.rb', line 68 def mouse_up(event) toggle end |
#toggle ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/rubygoo/check_box.rb', line 49 def toggle() if checked? uncheck else check end end |
#uncheck ⇒ Object
62 63 64 65 |
# File 'lib/rubygoo/check_box.rb', line 62 def uncheck() @checked = false fire :checked, self end |