Class: Glimmer::LibUI::ControlProxy::TableProxy
- Inherits:
-
Glimmer::LibUI::ControlProxy
- Object
- Glimmer::LibUI::ControlProxy
- Glimmer::LibUI::ControlProxy::TableProxy
- Includes:
- FiddleConsumer
- Defined in:
- lib/glimmer/libui/control_proxy/table_proxy.rb
Overview
Proxy for LibUI table objects
Follows the Proxy Design Pattern
Constant Summary collapse
- LISTENERS =
['on_changed', 'on_edited']
Constants inherited from Glimmer::LibUI::ControlProxy
BOOLEAN_PROPERTIES, KEYWORD_ALIASES, STRING_PROPERTIES, TransformProxy
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#model_handler ⇒ Object
readonly
Returns the value of attribute model_handler.
-
#table_params ⇒ Object
readonly
Returns the value of attribute table_params.
Attributes inherited from Glimmer::LibUI::ControlProxy
#args, #block, #keyword, #libui, #parent_proxy
Instance Method Summary collapse
- #cell_rows(rows = nil) ⇒ Object (also: #cell_rows=, #set_cell_rows)
- #destroy ⇒ Object
- #editable(value = nil) ⇒ Object (also: #editable=, #set_editable, #editable?)
- #expand(cell_rows) ⇒ Object
- #expanded_cell_rows ⇒ Object
-
#initialize(keyword, parent, args, &block) ⇒ TableProxy
constructor
A new instance of TableProxy.
- #post_add_content ⇒ Object
- #post_initialize_child(child) ⇒ Object
Methods included from FiddleConsumer
Methods inherited from Glimmer::LibUI::ControlProxy
#append_properties, #append_property, #can_handle_listener?, constant_symbol, #content, control_proxies, create, #custom_listener_aliases, #custom_listeners, #data_bind, #default_destroy, descendant_keyword_constant_map, #destroy_child, #enabled, exists?, #handle_custom_listener, #handle_listener, #has_custom_listener?, image_proxies, keyword, #libui_api_keyword, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, widget_proxy_class, #window_proxy
Constructor Details
#initialize(keyword, parent, args, &block) ⇒ TableProxy
Returns a new instance of TableProxy.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 43 def initialize(keyword, parent, args, &block) @keyword = keyword @parent_proxy = parent @args = args @block = block @enabled = true @columns = [] @cell_rows = [] window_proxy.on_destroy do # the following unless condition is an exceptional condition stumbled upon that fails freeing the table model ::LibUI.free_table_model(@model) unless @destroyed && parent_proxy.is_a?(Box) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Glimmer::LibUI::ControlProxy
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
41 42 43 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 41 def columns @columns end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
41 42 43 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 41 def model @model end |
#model_handler ⇒ Object (readonly)
Returns the value of attribute model_handler.
41 42 43 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 41 def model_handler @model_handler end |
#table_params ⇒ Object (readonly)
Returns the value of attribute table_params.
41 42 43 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 41 def table_params @table_params end |
Instance Method Details
#cell_rows(rows = nil) ⇒ Object Also known as: cell_rows=, set_cell_rows
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 81 def cell_rows(rows = nil) if rows.nil? @cell_rows else @cell_rows = rows @cell_rows.tap do @last_cell_rows = array_deep_clone(@cell_rows) Glimmer::DataBinding::Observer.proc do |new_cell_rows| if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows) @last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row| ::LibUI.table_model_row_deleted(model, row) on_changed.each {|listener| listener.call(row, :deleted, @last_cell_rows[row])} end elsif @cell_rows.size > @last_cell_rows.size && @cell_rows.include_all?(*@last_cell_rows) @cell_rows.array_diff_indexes(@last_cell_rows).each do |row| ::LibUI.table_model_row_inserted(model, row) on_changed.each {|listener| listener.call(row, :inserted, @cell_rows[row])} end else @cell_rows.each_with_index do |new_row_data, row| if new_row_data != @last_cell_rows[row] ::LibUI.table_model_row_changed(model, row) on_changed.each {|listener| listener.call(row, :changed, @cell_rows[row])} end end end @last_last_cell_rows = array_deep_clone(@last_cell_rows) @last_cell_rows = array_deep_clone(@cell_rows) end.observe(self, :cell_rows, recursive: true) end end end |
#destroy ⇒ Object
76 77 78 79 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 76 def destroy super @destroyed = true end |
#editable(value = nil) ⇒ Object Also known as: editable=, set_editable, editable?
126 127 128 129 130 131 132 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 126 def editable(value = nil) if value.nil? @editable else @editable = !!value end end |
#expand(cell_rows) ⇒ Object
120 121 122 123 124 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 120 def (cell_rows) cell_rows.to_a.map do |row| row.flatten(1) end end |
#expanded_cell_rows ⇒ Object
116 117 118 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 116 def (cell_rows) end |
#post_add_content ⇒ Object
57 58 59 60 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 57 def post_add_content build_control unless @content_added super end |
#post_initialize_child(child) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 62 def post_initialize_child(child) @columns << child # add extra complementary columns (:text, :color) if it is a dual/triple column (i.e. ImageTextColumnProxy or CheckboxTextColumnProxy case child when Column::ImageTextColumnProxy, Column::CheckboxTextColumnProxy @columns << :text when Column::TextColorColumnProxy @columns << :color when Column::CheckboxTextColorColumnProxy, Column::ImageTextColorColumnProxy @columns << :text @columns << :color end end |