Sha256: fb33a1b4370a13a7960de7a0ed96c35c75480bf4e81482500bd3d98ebd89296f

Contents?: true

Size: 1006 Bytes

Versions: 4

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true
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.pre12 lib/shoes/swt/color_factory.rb
shoes-swt-4.0.0.pre11 lib/shoes/swt/color_factory.rb
shoes-swt-4.0.0.pre10 lib/shoes/swt/color_factory.rb
shoes-swt-4.0.0.pre9 lib/shoes/swt/color_factory.rb