Sha256: eb57f1e916787494457af9719f2b38eb1febcaf49759addeffc2ac70f386057a

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

module CyberarmEngine
  class Element
    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

        return :handled
      end

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

      def recalculate
        super

        _width = dimensional_size(@style.width, :width)
        _height= dimensional_size(@style.height,:height)
        @width  = _width  ? _width  : @text.textobject.text_width(@options[:checkmark])
        @height = _height ? _height : @text.height
        update_background
      end

      def value
        @toggled
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cyberarm_engine-0.13.1 lib/cyberarm_engine/ui/elements/toggle_button.rb
cyberarm_engine-0.12.1 lib/cyberarm_engine/ui/elements/toggle_button.rb
cyberarm_engine-0.12.0 lib/cyberarm_engine/ui/elements/toggle_button.rb
cyberarm_engine-0.11.1 lib/cyberarm_engine/ui/elements/toggle_button.rb
cyberarm_engine-0.11.0 lib/cyberarm_engine/ui/elements/toggle_button.rb