Sha256: 60cb17a9fd836857c5d00bb6801e57f85458dd3e539ee1fce2916609fadb2e6e

Contents?: true

Size: 829 Bytes

Versions: 1

Compression:

Stored size: 829 Bytes

Contents

require_relative 'observable'
require_relative 'observer'

module Glimmer
  module SWT
    class WidgetBinding
      include Glimmer
      include Observable
      include Observer

      attr_reader :widget, :property
      def initialize(model, property, translator = nil)
        @widget = model
        @property = property
        @translator = translator || proc {|value| value}

        @widget.on_widget_disposed do |dispose_event|
          unregister_all_observables
        end
      end
      def call(value)
        converted_value = translated_value = @translator.call(value)
        @widget.set_attribute(@property, converted_value) unless evaluate_property == converted_value
      end
      def evaluate_property
        @widget.get_attribute(@property)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glimmer-0.4.9 lib/glimmer/swt/widget_binding.rb