Sha256: 8dddad05d64d2a58975d187307931e7e8d3c7568fc2737d83bf68f773b030d73

Contents?: true

Size: 942 Bytes

Versions: 1

Compression:

Stored size: 942 Bytes

Contents

# frozen_string_literal: true

class Shoes
  module Common
    # Changeable elements are elements that receive `change' events.
    # These are ListBox, EditBox and EditLine. To have your code respond
    # to these events, either pass a block in when creating the element,
    # or call #change on the element with a block.
    module Changeable
      # Add an extra change event listener block
      #
      # @yield The block to execute on a change event
      def change(&blk)
        add_change_listener(blk)
      end

      # The GUI backend needs to call this when an actual change happens in
      # the backend.
      def call_change_listeners
        change_listeners.each do |listener|
          listener.call(self)
        end
      end

      private

      def change_listeners
        @change_listeners ||= []
      end

      def add_change_listener(callable)
        change_listeners << callable
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-core-4.0.0.rc1 lib/shoes/common/changeable.rb