Class: CyberarmEngine::Element::Label

Inherits:
CyberarmEngine::Element show all
Defined in:
lib/cyberarm_engine/ui/elements/label.rb

Direct Known Subclasses

Button

Constant Summary

Constants included from Theme

Theme::THEME

Instance Attribute Summary

Attributes inherited from CyberarmEngine::Element

#background_canvas, #border_canvas, #enabled, #event_handler, #options, #parent, #style, #x, #y, #z

Instance Method Summary collapse

Methods inherited from CyberarmEngine::Element

#background=, #button_down, #button_up, #content_height, #content_width, #default_events, #draw, #enabled?, #height, #hide, #hit?, #inner_height, #inner_width, #is_root?, #noncontent_height, #noncontent_width, #outer_height, #outer_width, #reposition, #root, #set_background, #set_border_color, #set_border_thickness, #set_margin, #set_padding, #show, #stylize, #toggle, #update, #update_background, #visible?, #width

Methods included from Common

#current_state, #darken, #draw_rect, #fill, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #show_cursor, #show_cursor=, #window

Methods included from CyberarmEngine::Event

#event, #publish, #subscribe, #unsubscribe

Methods included from Theme

#deep_merge, #default, #theme_defaults

Constructor Details

#initialize(text, options = {}, block = nil) ⇒ Label

Returns a new instance of Label.



4
5
6
7
8
# File 'lib/cyberarm_engine/ui/elements/label.rb', line 4

def initialize(text, options = {}, block = nil)
  super(options, block)

  @text = Text.new(text, font: @options[:font], z: @z, color: @options[:color], size: @options[:text_size], shadow: @options[:text_shadow])
end

Instance Method Details

#clicked_left_mouse_button(sender, x, y) ⇒ Object



14
15
16
17
18
# File 'lib/cyberarm_engine/ui/elements/label.rb', line 14

def clicked_left_mouse_button(sender, x, y)
  @block.call(self) if @block

  return :handled
end

#recalculateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cyberarm_engine/ui/elements/label.rb', line 20

def recalculate
  @width, @height = 0, 0

  _width = dimensional_size(@style.width, :width)
  _height= dimensional_size(@style.height,:height)

  @width = _width  ? _width  : @text.width.round
  @height= _height ? _height : @text.height.round

  @text.x = @style.border_thickness_left + @style.padding_left + @x
  @text.y = @style.border_thickness_top + @style.padding_top  + @y
  @text.z = @z + 3

  update_background
end

#renderObject



10
11
12
# File 'lib/cyberarm_engine/ui/elements/label.rb', line 10

def render
  @text.draw
end

#valueObject



36
37
38
# File 'lib/cyberarm_engine/ui/elements/label.rb', line 36

def value
  @text.text
end

#value=(value) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/cyberarm_engine/ui/elements/label.rb', line 40

def value=(value)
  @text.text = value

  old_width, old_height = width, height
  recalculate

  root.gui_state.request_recalculate if old_width != width || old_height != height
end