tkwrapper 1.0.2 → 1.1.2
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/lib/util/hash_recursive.rb +3 -6
- data/lib/widgets/base/configuration.rb +13 -17
- data/lib/widgets/base/widget.rb +5 -0
- data/lib/widgets/grid.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42d786c8eda480c18150ef9b6c3e67fc04c14d2c9ec70a037907dee5a9273264
|
4
|
+
data.tar.gz: b669a2881c794270a80da8332a55393c90a7bb3115273b5c28fc5681fb43faf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c583155569bc2adf08a5177c35e123e45a69c997ecb3aa70d78841ab4418406a7daa83277c7efe7654585c77932b58094a4bace040d5c9555de30e4e493c9b0
|
7
|
+
data.tar.gz: 63cb56447bc90a44a86251cfc5ef4507a5482063abb2f24a906610d6d23c3ba8cb341bf64a34ae027577ffbf6bb47ab4935e88a7ab56198e39b44e7f2d0cb890
|
data/lib/util/hash_recursive.rb
CHANGED
@@ -19,12 +19,9 @@ module Util
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.
|
23
|
-
hash.
|
24
|
-
value
|
25
|
-
next recursive_transform_key_value!(value, &block) if value.is_a?(Hash)
|
26
|
-
|
27
|
-
block.call(key, value)
|
22
|
+
def self.clone_recursive(hash)
|
23
|
+
hash.transform_values do |value|
|
24
|
+
value.is_a?(Hash) ? clone_recursive(value) : value
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
@@ -5,7 +5,7 @@ require "#{LIB_DIR}/util/hash_recursive.rb"
|
|
5
5
|
require_relative 'base'
|
6
6
|
|
7
7
|
class TkWrapper::Widgets::Base::Configuration
|
8
|
-
|
8
|
+
attr_reader :config
|
9
9
|
|
10
10
|
GRID_SPECIAL_VALUES = {
|
11
11
|
onecell: {
|
@@ -23,29 +23,19 @@ class TkWrapper::Widgets::Base::Configuration
|
|
23
23
|
NON_TK_OPTIONS = %i[id tk_class tearoff weights menu].freeze
|
24
24
|
|
25
25
|
def initialize(config)
|
26
|
-
@config =
|
26
|
+
@config = parse_and_clone(config)
|
27
27
|
end
|
28
28
|
|
29
|
-
def merge
|
29
|
+
def merge(*configurations)
|
30
30
|
configurations = configurations.map do |configuration|
|
31
|
-
|
31
|
+
configuration = configuration.config if configuration.is_a?(self.class)
|
32
32
|
|
33
|
-
|
33
|
+
parse_and_clone(configuration)
|
34
34
|
end
|
35
35
|
|
36
36
|
Util.merge_recursive!(@config, *configurations)
|
37
37
|
end
|
38
38
|
|
39
|
-
def parse!(config)
|
40
|
-
Util.each_recursive(config) do |hash, key, value|
|
41
|
-
next if value.is_a?(Hash)
|
42
|
-
|
43
|
-
hash[key] = parse_value(key, value)
|
44
|
-
end
|
45
|
-
|
46
|
-
config
|
47
|
-
end
|
48
|
-
|
49
39
|
def [](key)
|
50
40
|
key = key.to_sym
|
51
41
|
return self.class.new(@config[key]) if @config[key].is_a?(Hash)
|
@@ -55,7 +45,13 @@ class TkWrapper::Widgets::Base::Configuration
|
|
55
45
|
|
56
46
|
def []=(key, value)
|
57
47
|
key = key.to_sym
|
58
|
-
@config[key] =
|
48
|
+
@config[key] = parse_and_clone(value, key)
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_and_clone(value, key = nil)
|
52
|
+
return parse_value(key, value) unless value.is_a?(Hash)
|
53
|
+
|
54
|
+
value.each_with_object({}) { |(k, v), h| h[k] = parse_and_clone(v, k) }
|
59
55
|
end
|
60
56
|
|
61
57
|
def parse_value(key, value)
|
@@ -114,6 +110,6 @@ class TkWrapper::Widgets::Base::Configuration
|
|
114
110
|
end
|
115
111
|
|
116
112
|
def merge_global_configurations(manager, widget)
|
117
|
-
merge
|
113
|
+
merge(*manager.configurations(widget))
|
118
114
|
end
|
119
115
|
end
|
data/lib/widgets/base/widget.rb
CHANGED
@@ -60,6 +60,11 @@ class TkWrapper::Widgets::Base::Widget
|
|
60
60
|
@childs.each { |child| child.build(self) }
|
61
61
|
end
|
62
62
|
|
63
|
+
def push(child)
|
64
|
+
@childs.push(child)
|
65
|
+
child.build(self)
|
66
|
+
end
|
67
|
+
|
63
68
|
def configure
|
64
69
|
@config.merge_global_configurations(manager, self)
|
65
70
|
@config.configure_tk_widget(tk_widget)
|
data/lib/widgets/grid.rb
CHANGED
@@ -22,7 +22,7 @@ class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
|
22
22
|
row.each_with_index do |cell, col_i|
|
23
23
|
next unless cell.is_a?(Widget)
|
24
24
|
|
25
|
-
|
25
|
+
cell.config.merge({ grid: { row: row_i, column: col_i } })
|
26
26
|
|
27
27
|
configure_colspan(cell, row_i, col_i)
|
28
28
|
configure_rowspan(cell, row_i, col_i)
|
@@ -35,7 +35,7 @@ class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
|
35
35
|
colspan = cols_after_cell.reduce(1) do |span, content|
|
36
36
|
content == :right ? span + 1 : (break span)
|
37
37
|
end
|
38
|
-
|
38
|
+
cell.config.merge({ grid: { columnspan: colspan } })
|
39
39
|
end
|
40
40
|
|
41
41
|
def configure_rowspan(cell, row_i, col_i)
|
@@ -43,6 +43,6 @@ class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
|
43
43
|
rowspan = rows_after_cell.reduce(1) do |span, row|
|
44
44
|
row[col_i] == :bottom ? span + 1 : (break span)
|
45
45
|
end
|
46
|
-
|
46
|
+
cell.config.merge({ grid: { rowspan: rowspan } })
|
47
47
|
end
|
48
48
|
end
|