Sha256: a7adc5c6cc4b66d17bf62ec4b17fe7f3242b57d9015601183fbd32c6a780b17f

Contents?: true

Size: 965 Bytes

Versions: 2

Compression:

Stored size: 965 Bytes

Contents

module CyberarmEngine
  class ToggleButton < Button
    attr_reader :toggled

    def initialize(options, block = nil)
      super(options[:checkmark], options, block)
      @toggled = options[:toggled] || false
      if @toggled
        @text.text = @options[:checkmark]
      else
        @text.text = ""
      end

      return self
    end

    def toggled=(boolean)
      @toggled = !boolean
      toggle
    end

    def clicked_left_mouse_button(sender, x, y)
      toggle

      @block.call(self) if @block
    end

    def toggle
      if @toggled
        @toggled = false
        @text.text = ""
      else
        @toggled = true
        @text.text = @options[:checkmark]
      end
    end

    def recalculate
      super

      unless @visible
        @width = 0
        @height= 0
        return
      end

      @width = @text.textobject.text_width(@options[:checkmark])
      update_background
    end

    def value
      @toggled
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cyberarm_engine-0.7.1 lib/cyberarm_engine/ui/toggle_button.rb
cyberarm_engine-0.7.0 lib/cyberarm_engine/ui/toggle_button.rb