Sha256: 5833cc43edb836e39c7c79ef7f5eb4a3f5b06b42bd6c3e5265dee3697d5a6a77

Contents?: true

Size: 976 Bytes

Versions: 4

Compression:

Stored size: 976 Bytes

Contents

class Shoes
  module Swt
    # ColorFactory is used for tracking SWT-backed resources related to colors
    # that potentially need to get disposed. It can additionally take gradients
    # and maybe other values, though, so it can't assume values will be
    # disposable.
    #
    # Additionally this factory does caching against the DSL element so we
    # don't needlessly generate things like OS colors over and over again.
    class ColorFactory
      def initialize
        @swt_elements = {}
      end

      def dispose
        @swt_elements.each_value do |swt_element|
          swt_element.dispose if swt_element.respond_to?(:dispose)
        end
        @swt_elements.clear
      end

      def create(element)
        return nil if element.nil?
        return @swt_elements[element] if @swt_elements.include?(element)
        swt_element = ::Shoes.backend_for(element)
        @swt_elements[element] = swt_element
        swt_element
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shoes-swt-4.0.0.pre8 lib/shoes/swt/color_factory.rb
shoes-swt-4.0.0.pre7 lib/shoes/swt/color_factory.rb
shoes-swt-4.0.0.pre6 lib/shoes/swt/color_factory.rb
shoes-swt-4.0.0.pre5 lib/shoes/swt/color_factory.rb