Class: Rubygoo::Button
Constant Summary
Constants inherited from Widget
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
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
- #added ⇒ Object
- #draw(adapter) ⇒ Object
-
#initialize(new_text, opts = {}) ⇒ Button
constructor
A new instance of Button.
-
#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.
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, #get_color, goo_prop, #hide, inherited, #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?
Methods included from Inflector
#camelize, #classify, #constantize, #dasherize, #demodulize, #foreign_key, #humanize, #inflections, #ordinalize, #pluralize, #singularize, #tableize, #titleize, #underscore
Constructor Details
#initialize(new_text, opts = {}) ⇒ Button
Returns a new instance of Button.
8 9 10 11 12 13 14 15 |
# File 'lib/rubygoo/button.rb', line 8 def initialize(new_text, opts={}) @icon_image = opts[:icon] @image = opts[:image] @hover_image = opts[:hover_image] @text = new_text super opts end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/rubygoo/button.rb', line 5 def text @text end |
Instance Method Details
#added ⇒ Object
17 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 44 |
# File 'lib/rubygoo/button.rb', line 17 def added() font = theme_property :font @font_size = @opts[:font_size] @font_size ||= theme_property :font_size @color = theme_property :color @bg_color = theme_property :bg_color @border_color = theme_property :border_color @focus_color = theme_property :focus_color @hover_color = theme_property :hover_color @disabled_color = theme_property :disabled_color @font_file = File.join(@app.theme_dir,font) @rendered_text ||= @app.renderer.render_text @text, @font_file, @font_size, @color if @text and !@text.empty? if @image @w = @image.width+2*@padding_left @h = @image.height+2*@padding_top @x = @x - @padding_left @y = @y - @padding_top else @w = @rendered_text.width+2*@padding_left @h = @rendered_text.height+2*@padding_top @x = @x - @padding_left @y = @y - @padding_top end update_rect end |
#draw(adapter) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rubygoo/button.rb', line 64 def draw(adapter) x1 = @rect[0] y1 = @rect[1] x2 = @rect[2] + x1 y2 = @rect[3] + y1 img = @image.nil? ? @rendered_text : @image if @image adapter.draw_image @image, @x+@padding_left, @y+@padding_top, @color else if @focussed adapter.fill x1, y1, x2, y2, @focus_color elsif @bg_color adapter.fill x1, y1, x2, y2, @bg_color end if @border_color adapter.draw_box x1, y1, x2, y2, @border_color end if @disabled_color and !enabled? adapter.fill x1, y1, x2, y2, @disabled_color end if @icon_image # TODO center icon ix = x1#+((x2-x1)[email protected]) iy = y1#+((y2-y1)[email protected]) adapter.draw_image @icon_image, ix+@padding_left,iy+@padding_top end adapter.draw_image @rendered_text, @x+@padding_left, @y+@padding_top, @color end if mouse_over? and (@hover_image or @hover_color) if @hover_image adapter.draw_image @hover_image, @x+@padding_left, @y+@padding_top, @color else adapter.fill x1, y1, x2, y2, @hover_color end end end |
#key_pressed(event) ⇒ Object
called when a key press is sent to us
57 58 59 60 61 62 |
# File 'lib/rubygoo/button.rb', line 57 def key_pressed(event) case event.data[:key] when K_SPACE fire :pressed, event end end |
#mouse_drag(event) ⇒ Object
called when there is a mouse click at the end of a drag
52 53 54 |
# File 'lib/rubygoo/button.rb', line 52 def mouse_drag(event) fire :pressed, event end |
#mouse_up(event) ⇒ Object
called when there is a mouse click
47 48 49 |
# File 'lib/rubygoo/button.rb', line 47 def mouse_up(event) fire :pressed, event end |