Class: MittensUi::ListBox

Inherits:
Core
  • Object
show all
Defined in:
lib/mittens_ui/listbox.rb

Instance Attribute Summary collapse

Attributes inherited from Core

#core_widget

Instance Method Summary collapse

Methods inherited from Core

#hidden?, #hide, #remove, #show

Methods included from Helpers

#icon_map, #list_system_icons, #set_margin_from_opts_for

Constructor Details

#initialize(options = {}) ⇒ ListBox

Returns a new instance of ListBox.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mittens_ui/listbox.rb', line 7

def initialize(options={})
  @items = options[:items]

  list_store = Gtk::ListStore.new(String)

  @items.each do |i|
    iter = list_store.append
    iter[0] = i
  end

  renderer = Gtk::CellRendererText.new

  @gtk_combobox = Gtk::ComboBox.new(model: list_store)
  @gtk_combobox.pack_start(renderer, true)
  @gtk_combobox.set_attributes(renderer, "text" => 0)
  @gtk_combobox.set_cell_data_func(renderer) do |_layout, _cell_renderer, _model, iter|
    set_selected_value(iter[0])
  end

  @gtk_combobox.set_active(0)

  super(@gtk_combobox)
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



5
6
7
# File 'lib/mittens_ui/listbox.rb', line 5

def items
  @items
end

Instance Method Details

#get_selected_valueObject Also known as: selected_value



36
37
38
# File 'lib/mittens_ui/listbox.rb', line 36

def get_selected_value
  @selected_value
end

#renderObject



41
42
43
44
# File 'lib/mittens_ui/listbox.rb', line 41

def render
  $vertical_box.pack_start(@gtk_combobox)
  return self
end

#set_selected_value(value) ⇒ Object Also known as: set_value



31
32
33
# File 'lib/mittens_ui/listbox.rb', line 31

def set_selected_value(value)
  @selected_value = value
end