Class: CyberarmEngine::Element::Progress
- Inherits:
-
CyberarmEngine::Element
- Object
- CyberarmEngine::Element
- CyberarmEngine::Element::Progress
- Defined in:
- lib/cyberarm_engine/ui/elements/progress.rb
Constant Summary
Constants included from Theme
Instance Attribute Summary
Attributes inherited from CyberarmEngine::Element
#background_canvas, #border_canvas, #enabled, #event_handler, #options, #parent, #style, #tip, #x, #y, #z
Instance Method Summary collapse
-
#initialize(options = {}, block = nil) ⇒ Progress
constructor
A new instance of Progress.
- #recalculate ⇒ Object
- #render ⇒ Object
- #update_background ⇒ Object
- #value ⇒ Object
- #value=(decimal) ⇒ Object
Methods inherited from CyberarmEngine::Element
#background=, #button_down, #button_up, #content_height, #content_width, #default_events, #dimensional_size, #draggable?, #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, #set_static_position, #show, #stylize, #to_s, #toggle, #update, #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(options = {}, block = nil) ⇒ Progress
Returns a new instance of Progress.
4 5 6 7 8 9 |
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 4 def initialize( = {}, block = nil) super(, block) @fraction_background = Background.new(background: @style.fraction_background) self.value = [:fraction] || 0.0 end |
Instance Method Details
#recalculate ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 15 def recalculate _width = dimensional_size(@style.width, :width) _height = dimensional_size(@style.height, :height) @width = _width @height = _height update_background end |
#render ⇒ Object
11 12 13 |
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 11 def render @fraction_background.draw end |
#update_background ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 24 def update_background super @fraction_background.x = @style.border_thickness_left + @style.padding_left + @x @fraction_background.y = @style.border_thickness_top + @style.padding_top + @y @fraction_background.z = @z @fraction_background.width = @width * @fraction @fraction_background.height = @height @fraction_background.background = @style.fraction_background end |
#value ⇒ Object
36 37 38 |
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 36 def value @fraction end |
#value=(decimal) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/cyberarm_engine/ui/elements/progress.rb', line 40 def value=(decimal) raise "value must be number" unless decimal.is_a?(Numeric) @fraction = decimal.clamp(0.0, 1.0) update_background publish(:changed, @fraction) @fraction end |