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
- CUSTOM_LISTENER_NAMES =
['on_changed', 'on_edited']
Constants inherited from Glimmer::LibUI::ControlProxy
BOOLEAN_PROPERTIES, KEYWORD_ALIASES, STRING_PROPERTIES, TransformProxy
Instance Attribute Summary collapse
-
#column_attributes ⇒ Object
readonly
Returns the value of attribute column_attributes.
-
#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, #content_added, #keyword, #libui, #parent_proxy
Instance Method Summary collapse
- #array_deep_clone(array_or_object) ⇒ Object
- #cell_rows(rows = nil) ⇒ Object (also: #cell_rows=, #set_cell_rows)
- #data_bind_read(property, model_binding) ⇒ Object
- #data_bind_write(property, model_binding) ⇒ Object
- #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_name_aliases, #custom_listener_names, #default_destroy, #deregister_all_custom_listeners, #deregister_custom_listeners, descendant_keyword_constant_map, #destroy_child, #enabled, exists?, #handle_custom_listener, #handle_listener, #has_custom_listener?, image_proxies, keyword, #libui_api_keyword, #listeners, #listeners_for, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #notify_custom_listeners, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, widget_proxy_class, #window_proxy
Methods included from DataBindable
#data_bind, #data_binding_model_attribute_observer_registrations
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 56 57 |
# 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 = [] @last_cell_rows = [] register_cell_rows_observer 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
#column_attributes ⇒ Object (readonly)
Returns the value of attribute column_attributes.
41 42 43 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 41 def column_attributes @column_attributes end |
#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
#array_deep_clone(array_or_object) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 151 def array_deep_clone(array_or_object) if array_or_object.is_a?(Array) array_or_object.map do |element| array_deep_clone(element) end else array_or_object.clone end end |
#cell_rows(rows = nil) ⇒ Object Also known as: cell_rows=, set_cell_rows
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 85 def cell_rows(rows = nil) if rows.nil? @cell_rows else if rows != @cell_rows @cell_rows = rows @cell_rows = @cell_rows.to_a if @cell_rows.is_a?(Enumerator) end @cell_rows end end |
#data_bind_read(property, model_binding) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 121 def data_bind_read(property, model_binding) if model_binding.[:column_attributes].is_a?(Array) @column_attributes = model_binding.[:column_attributes] else column_attribute_mapping = model_binding.[:column_attributes].is_a?(Hash) ? model_binding.[:column_attributes] : {} @column_attributes = columns.select {|column| column.is_a?(Column)}.map(&:name).map {|column_name| column_attribute_mapping[column_name] || column_name.underscore} end model_attribute_observer = model_attribute_observer_registration = nil model_attribute_observer = Glimmer::DataBinding::Observer.proc do new_value = model_binding.evaluate_property new_value = new_value.to_a if new_value.is_a?(Enumerator) if model_binding.[:column_attributes] || (!new_value.empty? && !new_value.first.is_a?(Array)) @model_attribute_array_observer_registration&.deregister @model_attribute_array_observer_registration = model_attribute_observer.observe(new_value, @column_attributes, ignore_frozen: true, attribute_writer_type: [:attribute=, :set_attribute]) model_attribute_observer.add_dependent(model_attribute_observer_registration => @model_attribute_array_observer_registration) end # TODO look if multiple notifications are happening as a result of observing array and observing model binding send("#{property}=", new_value) unless @last_cell_rows == new_value end model_attribute_observer_registration = model_attribute_observer.observe(model_binding, attribute_writer_type: [:attribute=, :set_attribute]) model_attribute_observer.call # initial update data_binding_model_attribute_observer_registrations << model_attribute_observer_registration model_attribute_observer end |
#data_bind_write(property, model_binding) ⇒ Object
146 147 148 149 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 146 def data_bind_write(property, model_binding) # TODO ensure writing is happening to models if rows are not arrays handle_listener('on_edited') { model_binding.call(cell_rows) } if property == 'cell_rows' end |
#destroy ⇒ Object
78 79 80 81 82 83 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 78 def destroy super # TODO consider replacing unobserve with observer_registration.deregister @cell_rows_observer&.unobserve(self, :cell_rows, recursive: true, ignore_frozen: true, attribute_writer_type: [:attribute=, :set_attribute]) @destroyed = true end |
#editable(value = nil) ⇒ Object Also known as: editable=, set_editable, editable?
110 111 112 113 114 115 116 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 110 def editable(value = nil) if value.nil? @editable else @editable = !!value end end |
#expand(cell_rows) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 103 def (cell_rows) cell_rows.to_a.map do |row| row = @column_attributes.map {|attribute| row.send(attribute) } if @column_attributes&.any? && !row.is_a?(Array) row.flatten(1) end end |
#expanded_cell_rows ⇒ Object
99 100 101 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 99 def (cell_rows) end |
#post_add_content ⇒ Object
59 60 61 62 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 59 def post_add_content build_control unless @content_added super end |
#post_initialize_child(child) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/glimmer/libui/control_proxy/table_proxy.rb', line 64 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 |