Class: CyberarmEngine::Element::Label
- Inherits:
-
CyberarmEngine::Element
- Object
- CyberarmEngine::Element
- CyberarmEngine::Element::Label
- Defined in:
- lib/cyberarm_engine/ui/elements/label.rb
Direct Known Subclasses
Constant Summary
Constants included from 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
- #clicked_left_mouse_button(sender, x, y) ⇒ Object
-
#initialize(text, options = {}, block = nil) ⇒ Label
constructor
A new instance of Label.
- #recalculate ⇒ Object
- #render ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Methods inherited from CyberarmEngine::Element
#background=, #button_down, #button_up, #default_events, #draw, #enabled?, #height, #hide, #hit?, #inner_height, #inner_width, #is_root?, #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, = {}, block = nil) super(, block) @text = Text.new(text, font: [:font], z: @z, color: [:color], size: [:text_size], shadow: [: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 (sender, x, y) @block.call(self) if @block return :handled end |
#recalculate ⇒ Object
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 |
#render ⇒ Object
10 11 12 |
# File 'lib/cyberarm_engine/ui/elements/label.rb', line 10 def render @text.draw end |
#value ⇒ Object
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 |