glimmer-dsl-libui 0.7.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +21 -4
- data/VERSION +1 -1
- data/docs/examples/GLIMMER-DSL-LIBUI-BASIC-EXAMPLES.md +8 -2
- data/examples/basic_table_selection.rb +163 -152
- data/examples/basic_table_selection2.rb +314 -0
- data/examples/basic_table_selection3.rb +307 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/control_proxy/column.rb +15 -0
- data/lib/glimmer/libui/control_proxy/table_proxy.rb +85 -8
- data/lib/glimmer/libui/custom_control/refined_table.rb +1 -0
- metadata +4 -2
@@ -37,6 +37,28 @@ module Glimmer
|
|
37
37
|
include Glimmer::FiddleConsumer
|
38
38
|
|
39
39
|
CUSTOM_LISTENER_NAMES = ['on_changed', 'on_edited']
|
40
|
+
DEFAULT_COLUMN_SORT_BLOCK = lambda do |table_cell_row, column, table_proxy|
|
41
|
+
if table_cell_row.is_a?(Array)
|
42
|
+
value = table_cell_row[column]
|
43
|
+
else
|
44
|
+
attribute = table_proxy.column_attributes[column]
|
45
|
+
value = table_cell_row.send(attribute)
|
46
|
+
end
|
47
|
+
if value.is_a?(Array)
|
48
|
+
# This is needed to not crash on sorting an unsortable array
|
49
|
+
value = value.map do |element|
|
50
|
+
case element
|
51
|
+
when true
|
52
|
+
1
|
53
|
+
when false
|
54
|
+
0
|
55
|
+
else
|
56
|
+
element
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
value
|
61
|
+
end
|
40
62
|
|
41
63
|
attr_reader :model_handler, :model, :table_params, :columns
|
42
64
|
|
@@ -66,6 +88,7 @@ module Glimmer
|
|
66
88
|
configure_selection
|
67
89
|
configure_header_visible
|
68
90
|
configure_column_sort_indicators
|
91
|
+
configure_sorting
|
69
92
|
end
|
70
93
|
|
71
94
|
def post_initialize_child(child)
|
@@ -183,6 +206,7 @@ module Glimmer
|
|
183
206
|
result = ::LibUI.table_header_visible(@libui)
|
184
207
|
LibUI.integer_to_boolean(result)
|
185
208
|
end
|
209
|
+
alias header_visible? header_visible
|
186
210
|
|
187
211
|
def header_visible=(value)
|
188
212
|
@header_visible = value
|
@@ -194,6 +218,17 @@ module Glimmer
|
|
194
218
|
end
|
195
219
|
alias set_header_visible header_visible=
|
196
220
|
|
221
|
+
def sortable
|
222
|
+
@sortable = true if @sortable.nil?
|
223
|
+
@sortable
|
224
|
+
end
|
225
|
+
alias sortable? sortable
|
226
|
+
|
227
|
+
def sortable=(value)
|
228
|
+
@sortable = value
|
229
|
+
end
|
230
|
+
alias set_sortable sortable=
|
231
|
+
|
197
232
|
def column_attributes
|
198
233
|
@column_attributes ||= columns.select {|column| column.is_a?(Column)}.map(&:name).map(&:underscore)
|
199
234
|
end
|
@@ -224,7 +259,12 @@ module Glimmer
|
|
224
259
|
end
|
225
260
|
|
226
261
|
def data_bind_write(property, model_binding)
|
227
|
-
|
262
|
+
case property
|
263
|
+
when 'cell_rows'
|
264
|
+
handle_listener('on_edited') { model_binding.call(cell_rows) }
|
265
|
+
when 'selection'
|
266
|
+
handle_listener('on_selection_changed') { model_binding.call(selection) }
|
267
|
+
end
|
228
268
|
end
|
229
269
|
|
230
270
|
def array_deep_dup(array_or_object)
|
@@ -620,16 +660,14 @@ module Glimmer
|
|
620
660
|
def register_column_listeners
|
621
661
|
# register accumulated column listeners after table content is closed
|
622
662
|
return if @columns.nil? || @columns.empty?
|
623
|
-
if @columns.any? {|column| column.is_a?(Column)
|
663
|
+
if @columns.any? {|column| column.is_a?(Column)}
|
624
664
|
::LibUI.table_header_on_clicked(@libui) do |_, column_index|
|
625
665
|
actual_columns = @columns.select {|column| column.is_a?(Column)}
|
626
666
|
column = actual_columns[column_index]
|
627
|
-
if column.is_a?(Column)
|
667
|
+
if column.is_a?(Column) && !column.is_a?(Column::ButtonColumnProxy)
|
628
668
|
column_listeners = column.column_listeners_for('on_clicked')
|
629
|
-
|
630
|
-
|
631
|
-
column_listener.call(column, column_index)
|
632
|
-
end
|
669
|
+
column_listeners.each do |column_listener|
|
670
|
+
column_listener.call(column, column_index)
|
633
671
|
end
|
634
672
|
end
|
635
673
|
end
|
@@ -649,8 +687,47 @@ module Glimmer
|
|
649
687
|
end
|
650
688
|
|
651
689
|
def configure_column_sort_indicators
|
652
|
-
column_proxies.each
|
690
|
+
column_proxies.each(&:configure_sort_indicator)
|
653
691
|
end
|
692
|
+
|
693
|
+
def configure_sorting
|
694
|
+
if sortable?
|
695
|
+
columns.each do |column_object|
|
696
|
+
next unless column_object.is_a?(Column) && !column_object.is_a?(Column::ButtonColumnProxy)
|
697
|
+
column_object.on_clicked do |column_proxy, column|
|
698
|
+
sort_by_column(column_proxy, column)
|
699
|
+
end
|
700
|
+
end
|
701
|
+
end
|
702
|
+
end
|
703
|
+
|
704
|
+
def sort_by_column(column_proxy, column)
|
705
|
+
return unless sortable? && cell_rows.is_a?(Array)
|
706
|
+
old_selection = backup_selection
|
707
|
+
column_proxy.toggle_sort_indicator
|
708
|
+
cell_rows.sort_by! {|table_cell_row| DEFAULT_COLUMN_SORT_BLOCK.call(table_cell_row, column, self) }
|
709
|
+
cell_rows.reverse! if column_proxy.sort_indicator == :descending
|
710
|
+
restore_selection(old_selection)
|
711
|
+
end
|
712
|
+
|
713
|
+
def backup_selection
|
714
|
+
if selection_mode == ::LibUI::TableSelectionModeZeroOrMany
|
715
|
+
selected_rows = selection&.map { |row| cell_rows[row] }
|
716
|
+
else
|
717
|
+
selected_row = selection && cell_rows[selection]
|
718
|
+
end
|
719
|
+
end
|
720
|
+
|
721
|
+
def restore_selection(old_selection)
|
722
|
+
if selection_mode == ::LibUI::TableSelectionModeZeroOrMany
|
723
|
+
selected_rows = old_selection
|
724
|
+
self.selection = selected_rows&.map {|row_data| cell_rows.index(row_data) }
|
725
|
+
else
|
726
|
+
selected_row = old_selection
|
727
|
+
self.selection = cell_rows.index(selected_row)
|
728
|
+
end
|
729
|
+
end
|
730
|
+
|
654
731
|
end
|
655
732
|
end
|
656
733
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-libui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -357,6 +357,8 @@ files:
|
|
357
357
|
- examples/basic_table_image_text3.rb
|
358
358
|
- examples/basic_table_progress_bar.rb
|
359
359
|
- examples/basic_table_selection.rb
|
360
|
+
- examples/basic_table_selection2.rb
|
361
|
+
- examples/basic_table_selection3.rb
|
360
362
|
- examples/basic_transform.rb
|
361
363
|
- examples/basic_transform2.rb
|
362
364
|
- examples/basic_window.rb
|