Sha256: a1880271059749ae3907e71b6dcd3e8330ee33e86350c6d1524131d4ac53dfd9

Contents?: true

Size: 537 Bytes

Versions: 2

Compression:

Stored size: 537 Bytes

Contents

# frozen_string_literal: true

class Scarpe
  class ListBox < Scarpe::Widget
    display_properties :selected_item, :items, :height, :width

    def initialize(args = {}, &block)
      @items = args[:items] || []
      @selected_item = args[:selected_item]
      super()

      bind_self_event("change") do |new_item|
        self.selected_item = new_item
        @callback&.call(new_item)
      end

      create_display_widget
    end

    def change(&block)
      @callback = block
      self # Allow chaining calls
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scarpe-0.2.1 lib/scarpe/list_box.rb
scarpe-0.2.0 lib/scarpe/list_box.rb