Class: Rubygoo::Label

Inherits:
Widget
  • Object
show all
Defined in:
lib/rubygoo/label.rb

Constant Summary

Constants inherited from Widget

Widget::DEFAULT_PARAMS

Instance Attribute Summary

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

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_pressed, #key_released, #modal?, #mouse_down, #mouse_drag, #mouse_dragging, #mouse_enter, #mouse_exit, #mouse_motion, #mouse_over?, #mouse_up, #removed, #show, #theme_property, #unfocus, #update, #update_rect, #visible?

Constructor Details

#initialize(text, opts = {}) ⇒ Label

Returns a new instance of Label.



4
5
6
7
8
# File 'lib/rubygoo/label.rb', line 4

def initialize(text, opts={})
  @font_size = opts[:font_size]
  super opts
  @text = text
end

Instance Method Details

#addedObject



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

def added()
  font = theme_property :font
  @font_size ||= theme_property :font_size
  @color = theme_property :color
  @bg_color = theme_property :bg_color
  @focus_color = theme_property :focus_color
  @border_color = theme_property :border_color
  @font_file ||= File.join(@app.theme_dir,font)

  set_text @text
end

#draw(adapter) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rubygoo/label.rb', line 30

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 @border_color
    adapter.draw_box x1, y1, x2, y2, @border_color
  end

  adapter.draw_image @rendered_text, @x, @y, @color
end

#set_text(text) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rubygoo/label.rb', line 22

def set_text(text)
  @text = text
  @rendered_text = @app.renderer.render_text @text, @font_file, @font_size, @color
  @w = @rendered_text.width
  @h = @rendered_text.height
  update_rect
end

#tab_to?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rubygoo/label.rb', line 48

def tab_to?()
  false
end