Class: Shoes::ListBox
- Defined in:
- lacci/lib/shoes/drawables/list_box.rb
Constant Summary
Constants inherited from Drawable
Constants included from Log
Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG
Instance Attribute Summary
Attributes inherited from Drawable
#debug_id, #destroyed, #parent
Attributes inherited from Linkable
Instance Method Summary collapse
-
#change { ... } ⇒ Shoes::ListBox
Register a block to be called when the selection changes.
-
#choose(item) ⇒ void
Select an item.
-
#initialize(**kwargs, &block) ⇒ ListBox
constructor
A new instance of ListBox.
-
#text ⇒ String|NilClass
The currently chosen text item or nil.
Methods inherited from Drawable
allocate_drawable_id, #app, #banner, #caption, convert_to_float, convert_to_integer, #destroy, #download, drawable_by_id, drawable_class_by_name, dsl_name, #event, expects_parent?, feature_for_shoes_style, get_shoes_events, #hide, #hover, init_args, #inscription, #inspect, is_widget_class?, #leave, #method_missing, #motion, opt_init_args, optional_init_args, register_drawable_id, registered_shoes_events?, required_init_args, #respond_to_missing?, #set_parent, shoes_events, shoes_style, shoes_style_hashes, shoes_style_name?, shoes_style_names, #shoes_style_values, shoes_styles, #show, #style, #subtitle, #tagline, #title, #toggle, unregister_drawable_id, use_current_app, validate_as, with_current_app
Methods included from MarginHelper
Methods included from Colors
Methods included from Log
configure_logger, #log_init, logger
Methods inherited from Linkable
#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_all_shoes_events, #unsub_shoes_event
Constructor Details
#initialize(**kwargs, &block) ⇒ ListBox
Returns a new instance of ListBox.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lacci/lib/shoes/drawables/list_box.rb', line 15 def initialize(**kwargs, &block) # These aren't being set as styles -- remove them from kwargs before calling super # TODO: set [] as default value for items? @items = kwargs.delete(:items) || [] @chosen = kwargs.delete(:choose) || @items&.first super(**kwargs, &block) bind_self_event("change") do |new_item| self.chosen = new_item @callback&.call(self) end create_display_drawable end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Shoes::Drawable
Instance Method Details
#change { ... } ⇒ Shoes::ListBox
Register a block to be called when the selection changes.
54 55 56 57 |
# File 'lacci/lib/shoes/drawables/list_box.rb', line 54 def change(&block) @callback = block self # Allow chaining calls end |
#choose(item) ⇒ void
This method returns an undefined value.
Select an item. item
should be a text entry from items
.
35 36 37 38 39 40 41 |
# File 'lacci/lib/shoes/drawables/list_box.rb', line 35 def choose(item) unless self.items.include?(item) raise Shoes::Errors::NoSuchListItemError, "List items (#{self.items.inspect}) do not contain item #{item.inspect}!" end @chosen = item end |
#text ⇒ String|NilClass
The currently chosen text item or nil.
46 47 48 |
# File 'lacci/lib/shoes/drawables/list_box.rb', line 46 def text @chosen end |