Class: Cura::Component::Listbox
- Defined in:
- lib/cura/component/listbox.rb
Overview
A component containing a selectable list of components.
Instance Attribute Summary collapse
-
#selected_index ⇒ nil, Integer
Get the currently selected item’s index.
Attributes inherited from Pack
Attributes included from Attributes::HasOrientation
Attributes included from Attributes::HasAncestry
Attributes included from Attributes::HasOffsets
Attributes included from Attributes::HasEvents
Instance Method Summary collapse
-
#add_child(component, object = nil) ⇒ Component
Add a child to this group.
-
#delete_child_at(index) ⇒ Component
Remove a child from this listbox’s children at the given index.
-
#initialize(attributes = {}) ⇒ Listbox
constructor
A new instance of Listbox.
-
#loopable=(value) ⇒ Boolean
Set whether this listbox is loopable or not.
-
#loopable? ⇒ Boolean
Get whether this listbox is loopable or not.
-
#object_at(index) ⇒ Object
Get the associated object with the child at the given index.
-
#selected_child ⇒ Component
Get the child at the selected index.
-
#selected_object ⇒ Component
Get the object associated with the child at the selected index.
Methods inherited from Pack
#draw, #fill=, #fill?, #height=, #width=
Methods included from Attributes::HasOrientation
Methods included from Attributes::HasAttributes
Methods inherited from Group
#draw, #height, #update, #width
Methods included from Attributes::HasChildren
#add_children, #children, #children?, #delete_child, #delete_children, #each
Methods inherited from Base
#application, #background, #contains_coordinates?, #cursor, #draw, #focus, #focused?, #foreground, #inspect, #pencil, #update
Methods included from Attributes::HasRelativeCoordinates
Methods included from Attributes::HasCoordinates
Methods included from Attributes::HasAncestry
Methods included from Attributes::HasOffsets
#border, #border=, #margin, #margin=, #padding, #padding=
Methods included from Attributes::HasColors
#background, #background=, #foreground, #foreground=
Methods included from Attributes::HasFocusability
Methods included from Attributes::HasEvents
Methods included from Attributes::HasDimensions
#height, #height=, #resize, #width, #width=
Constructor Details
#initialize(attributes = {}) ⇒ Listbox
Returns a new instance of Listbox.
42 43 44 45 46 47 48 49 |
# File 'lib/cura/component/listbox.rb', line 42 def initialize(attributes={}) @focusable = true @loopable = true @selected_index = 0 @objects = [] super end |
Instance Attribute Details
#selected_index ⇒ nil, Integer
Get the currently selected item’s index. Returns ‘nil` is nothing is selected.
55 56 57 |
# File 'lib/cura/component/listbox.rb', line 55 def selected_index @selected_index end |
Instance Method Details
#add_child(component, object = nil) ⇒ Component
Add a child to this group.
91 92 93 94 95 96 97 |
# File 'lib/cura/component/listbox.rb', line 91 def add_child(component, object=nil) child = super(component) @objects << object child end |
#delete_child_at(index) ⇒ Component
Remove a child from this listbox’s children at the given index.
103 104 105 106 107 108 109 110 |
# File 'lib/cura/component/listbox.rb', line 103 def delete_child_at(index) deleted_child = super @objects.delete_at(index) self.selected_index = @children.length - 1 if @selected_index >= @children.length deleted_child end |
#loopable=(value) ⇒ Boolean
Set whether this listbox is loopable or not.
138 139 140 |
# File 'lib/cura/component/listbox.rb', line 138 def loopable=(value) @loopable = !!value end |
#loopable? ⇒ Boolean
Get whether this listbox is loopable or not.
130 131 132 |
# File 'lib/cura/component/listbox.rb', line 130 def loopable? @loopable end |
#object_at(index) ⇒ Object
Get the associated object with the child at the given index.
116 117 118 |
# File 'lib/cura/component/listbox.rb', line 116 def object_at(index) @objects[index] end |
#selected_child ⇒ Component
Get the child at the selected index.
82 83 84 |
# File 'lib/cura/component/listbox.rb', line 82 def selected_child @children[@selected_index] end |
#selected_object ⇒ Component
Get the object associated with the child at the selected index.
123 124 125 |
# File 'lib/cura/component/listbox.rb', line 123 def selected_object @objects[@selected_index] end |