class CyberarmEngine::Element::Progress

Public Class Methods

new(options = {}, block = nil) click to toggle source
Calls superclass method CyberarmEngine::Element::new
# File lib/cyberarm_engine/ui/elements/progress.rb, line 4
def initialize(options = {}, block = nil)
  super(options, block)

  @fraction_background = Background.new(background: @style.fraction_background)
  self.value = options[:fraction] || 0.0
end

Public Instance Methods

recalculate() click to toggle source
# 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() click to toggle source
# File lib/cyberarm_engine/ui/elements/progress.rb, line 11
def render
  @fraction_background.draw
end
update_background() click to toggle source
# 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() click to toggle source
# File lib/cyberarm_engine/ui/elements/progress.rb, line 36
def value
  @fraction
end
value=(decimal) click to toggle source
# 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