Class: Shoes::Swt::ListBox
- Inherits:
-
Object
- Object
- Shoes::Swt::ListBox
- Includes:
- Common::UpdatePosition, Common::Focus, Common::Remove, Common::Visibility
- Defined in:
- shoes-swt/lib/shoes/swt/list_box.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#dsl ⇒ Object
readonly
Returns the value of attribute dsl.
Instance Method Summary collapse
- #choose(item) ⇒ Object
- #enabled(value) ⇒ Object
-
#initialize(dsl, app) ⇒ ListBox
constructor
A new instance of ListBox.
- #text ⇒ Object
- #update_items ⇒ Object
Methods included from Common::Visibility
#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?
Methods included from Common::Remove
Methods included from Common::Focus
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
#app ⇒ Object (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 |
#dsl ⇒ Object (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. value end |
#text ⇒ Object
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_items ⇒ Object
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 |