Class: Shoes::Swt::ListBox

Inherits:
Object
  • Object
show all
Includes:
Common::UpdatePosition, Common::Focus, Common::Remove, Common::Visibility
Defined in:
shoes-swt/lib/shoes/swt/list_box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common::Visibility

#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?

Methods included from Common::Remove

#remove

Methods included from Common::Focus

#focus, #focused?

Constructor Details

#initialize(dsl, app) ⇒ ListBox

Returns a new instance of ListBox.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'shoes-swt/lib/shoes/swt/list_box.rb', line 14

def initialize(dsl, app)
  @dsl = dsl
  @app = app
  @real = ::Swt::Widgets::Combo.new(
    @app.real,
    ::Swt::SWT::DROP_DOWN | ::Swt::SWT::READ_ONLY
  )
  @real.set_size dsl.element_width, dsl.element_height
  @real.add_selection_listener do |_event|
    @dsl.call_change_listeners
  end
  update_items

  # Set initial selection without triggering callbacks!
  choice = @dsl.style[:choose]
  @real.text = choice if choice
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



12
13
14
# File 'shoes-swt/lib/shoes/swt/list_box.rb', line 12

def app
  @app
end

#dslObject (readonly)

Returns the value of attribute dsl.



12
13
14
# File 'shoes-swt/lib/shoes/swt/list_box.rb', line 12

def dsl
  @dsl
end

Instance Method Details

#choose(item) ⇒ Object



45
46
47
48
# File 'shoes-swt/lib/shoes/swt/list_box.rb', line 45

def choose(item)
  @real.text = item
  @dsl.call_change_listeners
end

#enabled(value) ⇒ Object



50
51
52
# File 'shoes-swt/lib/shoes/swt/list_box.rb', line 50

def enabled(value)
  @real.enable_widget value
end

#textObject



40
41
42
43
# File 'shoes-swt/lib/shoes/swt/list_box.rb', line 40

def text
  text = @real.text
  text == '' ? nil : text
end

#update_itemsObject



32
33
34
35
36
37
38
# File 'shoes-swt/lib/shoes/swt/list_box.rb', line 32

def update_items
  # Keep original selection to restore after resetting the list
  text = @real.text

  @real.set_items(*@dsl.items.to_a.map(&:to_s))
  @real.text = text
end