Class: Nuklear::UI::SelectList

Inherits:
Base
  • Object
show all
Includes:
Container
Defined in:
lib/nuklear/ui/select_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Container

#<<, #commands, #find, #layout_row_dynamic, #method_missing, #run_command, #run_commands, #traverse, #ui_checkbox, #ui_color_picker, #ui_combo, #ui_edit_focus, #ui_edit_string, #ui_layout_row_begin, #ui_layout_row_dynamic, #ui_layout_row_push, #ui_layout_row_static, #ui_layout_row_template_begin, #ui_layout_row_template_dynamic, #ui_layout_row_template_end, #ui_layout_row_template_static, #ui_layout_row_template_variable, #ui_layout_space_begin, #ui_layout_space_end, #ui_layout_space_push, #ui_layout_widget_bounds, #ui_menu_item, #ui_option, #ui_selectable, #ui_window_close

Methods inherited from Base

descendants, #dsl, inherited

Methods included from Enableable

#disable, #disabled=, #disabled?, #enable, #enabled=, #enabled?

Methods included from Events

#event_listeners_for, #on, #trigger

Constructor Details

#initialize(choices, selection: choices[0], item_height:, width:, height:, **options) ⇒ SelectList

Returns a new instance of SelectList.



8
9
10
11
12
13
14
15
16
# File 'lib/nuklear/ui/select_list.rb', line 8

def initialize(choices, selection: choices[0], item_height:, width:, height:, **options)
  super(**options)
  self.choices = choices
  self.selection = selection
  self.item_height = item_height
  self.width = width
  self.height = height
  on(:selection_changed) { yield self.selection } if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Nuklear::UI::Container

Instance Attribute Details

#choicesObject

Returns the value of attribute choices.



6
7
8
# File 'lib/nuklear/ui/select_list.rb', line 6

def choices
  @choices
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/nuklear/ui/select_list.rb', line 6

def height
  @height
end

#item_heightObject

Returns the value of attribute item_height.



6
7
8
# File 'lib/nuklear/ui/select_list.rb', line 6

def item_height
  @item_height
end

#selectionObject

Returns the value of attribute selection.



6
7
8
# File 'lib/nuklear/ui/select_list.rb', line 6

def selection
  @selection
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/nuklear/ui/select_list.rb', line 6

def width
  @width
end

Instance Method Details

#result(choice_index, context) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/nuklear/ui/select_list.rb', line 22

def result(choice_index, context)
  if @selection != choices[choice_index]
    @selection = choices[choice_index]
    trigger(:selection_changed)
    @last_event = nil
  end
end

#to_commandObject



18
19
20
# File 'lib/nuklear/ui/select_list.rb', line 18

def to_command
  [ :ui_combo, choices.index(selection) || 0, choices, item_height, width, height ]
end