class CyberarmEngine::Element::ToggleButton

Attributes

toggled[R]
value[R]

Public Class Methods

new(options, block = nil) click to toggle source
Calls superclass method CyberarmEngine::Element::Button::new
# File lib/cyberarm_engine/ui/elements/toggle_button.rb, line 6
def initialize(options, block = nil)
  if options.dig(:theme, :ToggleButton, :checkmark_image)
    options[:theme][:ToggleButton][:image_width] ||= options[:theme][:Label][:text_size]
    super(get_image(options.dig(:theme, :ToggleButton, :checkmark_image)), options, block)

    @_image = @image
  else
    super(options[:checkmark], options, block)
  end

  @value = options[:checked] || false

  if @value
    @image = @_image if @_image
    @raw_text = @options[:checkmark]
  else
    @image = nil
    @raw_text = ""
  end
end

Public Instance Methods

clicked_left_mouse_button(_sender, _x, _y) click to toggle source
# File lib/cyberarm_engine/ui/elements/toggle_button.rb, line 27
def clicked_left_mouse_button(_sender, _x, _y)
  self.value = !@value

  @block.call(self) if @block

  :handled
end
recalculate() click to toggle source
# File lib/cyberarm_engine/ui/elements/toggle_button.rb, line 35
def recalculate
  super
  return if @image

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

  @width  = _width  || @text.textobject.text_width(@options[:checkmark])
  @height = _height || @text.height

  update_background
end
value=(boolean) click to toggle source
# File lib/cyberarm_engine/ui/elements/toggle_button.rb, line 48
def value=(boolean)
  @value = boolean

  if boolean
    @image = @_image if @_image
    @raw_text = @options[:checkmark]
  else
    @image = nil
    @raw_text = ""
  end

  recalculate

  publish(:changed, @value)
end