Class: Shoes::ListBox

Inherits:
Drawable show all
Defined in:
lacci/lib/shoes/drawables/list_box.rb

Constant Summary

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

#linkable_id

Instance Method Summary collapse

Methods inherited from Drawable

allocate_drawable_id, #app, #banner, #caption, #destroy, #download, drawable_by_id, drawable_class_by_name, dsl_name, #event, get_shoes_events, #hide, #inscription, #inspect, is_widget_class?, #method_missing, register_drawable_id, #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, validate_as

Methods included from Colors

#gray, #rgb, #to_rgb

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(**args, &block) ⇒ ListBox

Returns a new instance of ListBox.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lacci/lib/shoes/drawables/list_box.rb', line 14

def initialize(**args, &block)
  super

  @items = args[:items] || []
  @chosen = args[:choose] || args[:items]&.first

  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.

Yields:

  • the block to be called when selection changes

Returns:



51
52
53
54
# File 'lacci/lib/shoes/drawables/list_box.rb', line 51

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.

Parameters:

  • item (String)

    the item to choose



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

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

#textString|NilClass

The currently chosen text item or nil.

Returns:

  • (String|NilClass)

    the current text item or nil.



43
44
45
# File 'lacci/lib/shoes/drawables/list_box.rb', line 43

def text
  @chosen
end