Class: Rubygoo::CheckBox
Direct Known Subclasses
Constant Summary
Constants inherited from Widget
Instance Attribute Summary collapse
-
#checked ⇒ Object
Returns the value of attribute checked.
Attributes inherited from Widget
#app, #container, #enabled, #focus_priority, #focussed, #h, #parent, #relative, #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
#contains?, #enabled?, #focus, #focussed?, #get_color, #key_released, #modal?, #mouse_down, #mouse_dragging, #mouse_motion, #on_focus, #on_unfocus, #removed, #tab_to?, #theme_property, #unfocus, #update, #update_rect
Constructor Details
#initialize(opts = {}) ⇒ CheckBox
Returns a new instance of CheckBox.
5 6 7 |
# File 'lib/rubygoo/check_box.rb', line 5 def initialize(opts={}) super opts end |
Instance Attribute Details
#checked ⇒ Object
Returns the value of attribute checked.
3 4 5 |
# File 'lib/rubygoo/check_box.rb', line 3 def checked @checked end |
Instance Method Details
#added ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rubygoo/check_box.rb', line 9 def added() @checked = false @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 @rect = Rect.new [@x-@x_pad,@y-@y_pad,@w+2*@x_pad,@h+2*@y_pad] end |
#check ⇒ Object
32 33 34 35 |
# File 'lib/rubygoo/check_box.rb', line 32 def check() @checked = true fire :checked, self end |
#checked? ⇒ Boolean
20 21 22 |
# File 'lib/rubygoo/check_box.rb', line 20 def checked?() @checked end |
#draw(adapter) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubygoo/check_box.rb', line 60 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 @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
53 54 55 56 57 58 |
# File 'lib/rubygoo/check_box.rb', line 53 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
48 49 50 |
# File 'lib/rubygoo/check_box.rb', line 48 def mouse_drag(event) toggle end |
#mouse_up(event) ⇒ Object
called when there is a mouse click
43 44 45 |
# File 'lib/rubygoo/check_box.rb', line 43 def mouse_up(event) toggle end |
#toggle ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rubygoo/check_box.rb', line 24 def toggle() if checked? uncheck else check end end |
#uncheck ⇒ Object
37 38 39 40 |
# File 'lib/rubygoo/check_box.rb', line 37 def uncheck() @checked = false fire :checked, self end |