Class: Interphase::ListView
- Defined in:
- lib/interphase/widgets/list_view.rb
Overview
A list view which can be populated with objects.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Attributes inherited from Widget
Instance Method Summary collapse
-
#initialize(columns, **options, &block) ⇒ ListView
constructor
Create a new list view.
-
#refresh_rows ⇒ Object
Refreshes the contents of the list view according to its rows.
Methods inherited from Widget
#destroy, #method_missing, #on, #respond_to_missing?, #show, #size
Constructor Details
#initialize(columns, **options, &block) ⇒ ListView
Create a new list view.
columns
-
The columns which this list view has, as an
Array
ofString
objects.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/interphase/widgets/list_view.rb', line 14 def initialize(columns, **, &block) @store = Gtk::ListStore.new(*[String] * columns.length) super(Gtk::TreeView.new(@store), , &block) # Init columns columns.each_with_index do |col, index| renderer = Gtk::CellRendererText.new new_col = Gtk::TreeViewColumn.new(col[0], renderer, text: index) gtk_instance.append_column(new_col) end @rows = Interphase::Helpers::Observable.new([]) { refresh_rows } refresh_rows end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Interphase::Widget
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
9 10 11 |
# File 'lib/interphase/widgets/list_view.rb', line 9 def rows @rows end |
Instance Method Details
#refresh_rows ⇒ Object
Refreshes the contents of the list view according to its rows. This is called automatically upon mutating #rows.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/interphase/widgets/list_view.rb', line 33 def refresh_rows @store.clear # Insert the rows @rows.each do |data_row| store_row = @store.append # Basically a memcpy data_row.each_with_index do |item, index| store_row[index] = item end end end |