glimmer 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +38 -5
- data/lib/command_handlers/models/model_binding.rb +1 -1
- data/lib/command_handlers/models/r_color.rb +3 -2
- data/lib/command_handlers/models/r_font.rb +60 -0
- data/lib/command_handlers/models/r_shell.rb +6 -6
- data/lib/command_handlers/models/r_swt.rb +18 -0
- data/lib/command_handlers/models/r_widget.rb +29 -24
- data/lib/command_handlers/models/table_items_binding.rb +1 -1
- data/lib/command_handlers/models/tree_items_binding.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 425d16ab524a7ca569aad23a16f90be2d191e30f9718ccc29829eadc4d479b73
|
4
|
+
data.tar.gz: 5b23ea4769c1921379f6a3314a9e5496e1b339dd3ea43b12bfef58678cf17be2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5415bc5431a2ea2b4368c58bb97212cf6aea9f2711df08bd7757a5ee9c6eb84931616c082b023039d59dcea8140408e870973bf0043d07607667fa9e12381de6
|
7
|
+
data.tar.gz: 71678e659abb1776861c6f054520be42631b72e8013f0d5c3bbf399dedf09b9a2e0681155dda4ef327a73d7298a7c4628dd98076cb286ee0a8b2054dcf055c9d
|
data/README.markdown
CHANGED
@@ -42,7 +42,7 @@ shell {
|
|
42
42
|
(1..3).each { |row|
|
43
43
|
(1..3).each { |column|
|
44
44
|
button {
|
45
|
-
layout_data GridData.new(:fill
|
45
|
+
layout_data GridData.new(RSwt[:fill], RSwt[:fill], true, true)
|
46
46
|
text bind(@tic_tac_toe_board.box(row, column), :sign)
|
47
47
|
enabled bind(@tic_tac_toe_board.box(row, column), :empty)
|
48
48
|
on_widget_selected {
|
@@ -102,14 +102,14 @@ Please follow these instructions to make the `glimmer` command available on your
|
|
102
102
|
|
103
103
|
Run this command to install directly:
|
104
104
|
```
|
105
|
-
jgem install glimmer -v 0.3.
|
105
|
+
jgem install glimmer -v 0.3.5
|
106
106
|
```
|
107
107
|
|
108
108
|
### Option 2: Bundler
|
109
109
|
|
110
110
|
Add the following to `Gemfile`:
|
111
111
|
```
|
112
|
-
gem 'glimmer', '~> 0.3.
|
112
|
+
gem 'glimmer', '~> 0.3.5'
|
113
113
|
```
|
114
114
|
|
115
115
|
And, then run:
|
@@ -200,6 +200,12 @@ You may check out all available `SWT` styles here:
|
|
200
200
|
|
201
201
|
https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
|
202
202
|
|
203
|
+
**Final Note** (advanced case outside of standard Glimmer DSL):
|
204
|
+
|
205
|
+
When building a widget-related SWT object manually (e.g. `GridData.new(...)`), you are expected to use `SWT::CONSTANT` directly or BIT-OR a few SWT constants together like `SWT::BORDER | SWT::V_SCROLL`.
|
206
|
+
|
207
|
+
Glimmer facilitates that with `RSwt` class by allowing you to pass multiple styles as an argument array of symbols instead of dealing with BIT-OR. For example: `RSwt[:border, :v_scroll]`
|
208
|
+
|
203
209
|
### Widget Properties
|
204
210
|
|
205
211
|
Widget properties such as value, enablement, and layout details are set within the widget block using methods matching SWT widget property names in lower snakecase. You may refer to SWT widget guide for details on available widget properties:
|
@@ -225,9 +231,9 @@ button {
|
|
225
231
|
|
226
232
|
In the above example, the `text` widget `enabled` property was data-bound to `#empty` method on `@tic_tac_toe_board.box(row, column)` (learn more about data-binding below)
|
227
233
|
|
228
|
-
###
|
234
|
+
### Colors
|
229
235
|
|
230
|
-
|
236
|
+
Colors make up a subset of widget properties. SWT accepts color objects created with RGB (Red Green Blue) or RGBA (Red Green Blue Alpha). Glimmer supports constructing color objects using the `rgb` and `rgba` DSL methods.
|
231
237
|
|
232
238
|
Example:
|
233
239
|
|
@@ -255,6 +261,31 @@ You may check out all available standard colors in `SWT` over here:
|
|
255
261
|
|
256
262
|
https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
|
257
263
|
|
264
|
+
### Fonts
|
265
|
+
|
266
|
+
Fonts are represented in Glimmer as a hash of name, height, and style keys.
|
267
|
+
|
268
|
+
The style can be one (or more) of 3 values: `:normal`, `:bold`, and `:italic`
|
269
|
+
|
270
|
+
Example:
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
label {
|
274
|
+
font name: 'Arial', height: 36, style: :normal
|
275
|
+
}
|
276
|
+
```
|
277
|
+
|
278
|
+
Keys are optional, so some of them may be left off.
|
279
|
+
When passing multiple styles, they are included in an array.
|
280
|
+
|
281
|
+
Example:
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
label {
|
285
|
+
font style: [:bold, :italic]
|
286
|
+
}
|
287
|
+
```
|
288
|
+
|
258
289
|
### Data-Binding
|
259
290
|
|
260
291
|
Data-binding is done with `bind` command following widget property to bind and taking model and bindable attribute as arguments.
|
@@ -428,6 +459,8 @@ a new component and extend the DSL with it
|
|
428
459
|
- Provide a display builder method to use independently of shell
|
429
460
|
- Supported a single computed data binding as a string (not array)
|
430
461
|
- Disallow use of SWT::CONSTANTs with ORing since it's not intuitive at all
|
462
|
+
- Support data binding translator option via a block
|
463
|
+
- Center windows upon launching
|
431
464
|
|
432
465
|
## Contributors
|
433
466
|
|
@@ -121,7 +121,7 @@ class ModelBinding
|
|
121
121
|
@computed_model_bindings.each do |computed_model_binding|
|
122
122
|
computed_observer_for(observer).unobserve(computed_model_binding)
|
123
123
|
end
|
124
|
-
@computed_observer_collection
|
124
|
+
@computed_observer_collection.delete(observer)
|
125
125
|
elsif nested_property?
|
126
126
|
nested_property_observers_for(observer).clear
|
127
127
|
else
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'r_swt'
|
2
|
+
|
1
3
|
class RColor
|
2
4
|
attr_reader :display, :red, :green, :blue, :alpha
|
3
5
|
|
@@ -7,8 +9,7 @@ class RColor
|
|
7
9
|
include_package 'org.eclipse.swt'
|
8
10
|
|
9
11
|
def for(display, standard_color)
|
10
|
-
|
11
|
-
display.getSystemColor(standard_color_swt_constant)
|
12
|
+
display.getSystemColor(RSwt[standard_color])
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative 'r_swt'
|
2
|
+
|
3
|
+
class RFont
|
4
|
+
include_package 'org.eclipse.swt.graphics'
|
5
|
+
|
6
|
+
extend Glimmer
|
7
|
+
|
8
|
+
attr_reader :r_widget
|
9
|
+
attr_accessor :display
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def for(r_widget)
|
13
|
+
@instances ||= {}
|
14
|
+
unless @instances[r_widget]
|
15
|
+
@instances[r_widget] = new(r_widget)
|
16
|
+
add_contents(r_widget) {
|
17
|
+
on_widget_disposed { |dispose_event|
|
18
|
+
@instances.delete(r_widget)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
@instances[r_widget]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(r_widget, display = nil)
|
27
|
+
@r_widget = r_widget
|
28
|
+
@display = display || @r_widget.widget.display
|
29
|
+
end
|
30
|
+
|
31
|
+
def r_widget=(a_widget)
|
32
|
+
@r_widget = a_widget
|
33
|
+
@font_datum = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def font_datum
|
37
|
+
@font_datum ||= @r_widget.widget.getFont.getFontData[0]
|
38
|
+
end
|
39
|
+
|
40
|
+
def name
|
41
|
+
font_datum.getName
|
42
|
+
end
|
43
|
+
|
44
|
+
def height
|
45
|
+
font_datum.getHeight
|
46
|
+
end
|
47
|
+
|
48
|
+
def style
|
49
|
+
font_datum.getStyle
|
50
|
+
end
|
51
|
+
|
52
|
+
def font(font_properties)
|
53
|
+
font_properties[:style] = RSwt[*font_properties[:style]]
|
54
|
+
font_data_args = [:name, :height, :style].map do |font_property_name|
|
55
|
+
font_properties[font_property_name] || send(font_property_name)
|
56
|
+
end
|
57
|
+
font_datum = FontData.new(*font_data_args)
|
58
|
+
Font.new(@display, font_datum)
|
59
|
+
end
|
60
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
|
1
|
+
require_relative 'r_widget'
|
2
2
|
|
3
3
|
class RShell < RWidget
|
4
4
|
include_package 'org.eclipse.swt.layout'
|
5
5
|
include_package 'org.eclipse.swt.widgets'
|
6
|
-
|
6
|
+
|
7
7
|
attr_reader :display
|
8
|
-
|
8
|
+
|
9
9
|
def initialize(display = Display.new)
|
10
10
|
@display = display
|
11
11
|
@widget = Shell.new(@display)
|
12
12
|
@widget.setLayout(FillLayout.new)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def open
|
16
16
|
@widget.pack
|
17
17
|
@widget.open
|
@@ -20,5 +20,5 @@ class RShell < RWidget
|
|
20
20
|
end
|
21
21
|
@display.dispose
|
22
22
|
end
|
23
|
-
|
24
|
-
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class RSwt
|
2
|
+
class << self
|
3
|
+
# Gets SWT constants as if calling SWT::CONSTANT where constant is
|
4
|
+
# passed in as a lower case symbol
|
5
|
+
def [](*symbols)
|
6
|
+
symbols.compact.reduce(0) { |output, symbol| output | constant(symbol) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def constant(symbol)
|
10
|
+
return symbol if symbol.is_a?(Integer)
|
11
|
+
swt_constant_symbol = symbol.to_s.upcase.to_sym
|
12
|
+
org.eclipse.swt.SWT.const_get(swt_constant_symbol)
|
13
|
+
rescue
|
14
|
+
swt_constant_symbol = org.eclipse.swt.SWT.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s}
|
15
|
+
org.eclipse.swt.SWT.const_get(swt_constant_symbol)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,22 +1,25 @@
|
|
1
1
|
require_relative "r_widget_listener"
|
2
2
|
require_relative "r_runnable"
|
3
3
|
require_relative "r_color"
|
4
|
+
require_relative "r_font"
|
5
|
+
require_relative "r_swt"
|
4
6
|
|
5
7
|
class RWidget
|
6
8
|
include_package 'org.eclipse.swt'
|
7
9
|
include_package 'org.eclipse.swt.widgets'
|
8
10
|
include_package 'org.eclipse.swt.layout'
|
11
|
+
include_package 'org.eclipse.swt.graphics'
|
9
12
|
include Parent
|
10
13
|
|
11
14
|
attr_reader :widget
|
12
15
|
|
13
16
|
#TODO externalize
|
14
17
|
@@default_styles = {
|
15
|
-
"text" =>
|
16
|
-
"table" =>
|
17
|
-
"spinner" =>
|
18
|
-
"list" =>
|
19
|
-
"button" =>
|
18
|
+
"text" => RSwt[:border],
|
19
|
+
"table" => RSwt[:border],
|
20
|
+
"spinner" => RSwt[:border],
|
21
|
+
"list" => RSwt[:border, :v_scroll],
|
22
|
+
"button" => RSwt[:push],
|
20
23
|
}
|
21
24
|
|
22
25
|
#TODO externalize
|
@@ -30,12 +33,6 @@ class RWidget
|
|
30
33
|
"group" => Proc.new {|group| group.setLayout(GridLayout.new) },
|
31
34
|
}
|
32
35
|
|
33
|
-
@@property_type_converters = {
|
34
|
-
:text => Proc.new { |value| value.to_s },
|
35
|
-
:items => Proc.new { |value| value.to_java :string},
|
36
|
-
:visible => Proc.new { |value| !!value},
|
37
|
-
}
|
38
|
-
|
39
36
|
#styles is a comma separate list of symbols representing SWT styles in lower case
|
40
37
|
def initialize(underscored_widget_name, parent, styles, &contents)
|
41
38
|
@widget = underscored_widget_name.swt_widget.new(parent, style(underscored_widget_name, styles))
|
@@ -47,14 +44,30 @@ class RWidget
|
|
47
44
|
end
|
48
45
|
|
49
46
|
def set_attribute(attribute_name, *args)
|
50
|
-
apply_property_type_converters(attribute_name, args)
|
47
|
+
apply_property_type_converters(attribute_name, args)
|
51
48
|
@widget.send(attribute_setter(attribute_name), *args)
|
52
49
|
end
|
53
50
|
|
51
|
+
def property_type_converters
|
52
|
+
@property_type_converters ||= {
|
53
|
+
:text => Proc.new { |value| value.to_s },
|
54
|
+
:items => Proc.new { |value| value.to_java :string},
|
55
|
+
:visible => Proc.new { |value| !!value},
|
56
|
+
:font => Proc.new do |value|
|
57
|
+
if value.is_a?(Hash)
|
58
|
+
font_properties = value
|
59
|
+
RFont.for(self).font(font_properties)
|
60
|
+
else
|
61
|
+
value
|
62
|
+
end
|
63
|
+
end,
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
54
67
|
def apply_property_type_converters(attribute_name, args)
|
55
68
|
if args.count == 1
|
56
69
|
value = args.first
|
57
|
-
converter =
|
70
|
+
converter = property_type_converters[attribute_name.to_sym]
|
58
71
|
args[0] = converter.call(value) if converter
|
59
72
|
end
|
60
73
|
if args.count == 1 && args.first.is_a?(Symbol) && args.first.to_s.start_with?('color_')
|
@@ -148,29 +161,21 @@ class RWidget
|
|
148
161
|
end
|
149
162
|
|
150
163
|
def has_style?(style)
|
151
|
-
(widget.style & style
|
164
|
+
(widget.style & RSwt[style]) == RSwt[style]
|
152
165
|
end
|
153
166
|
|
154
167
|
private
|
155
168
|
|
156
169
|
def style(underscored_widget_name, styles)
|
157
|
-
styles.empty? ? default_style(underscored_widget_name) :
|
170
|
+
styles.empty? ? default_style(underscored_widget_name) : RSwt[*styles]
|
158
171
|
end
|
159
172
|
|
160
173
|
def default_style(underscored_widget_name)
|
161
174
|
style = @@default_styles[underscored_widget_name] if @@default_styles[underscored_widget_name]
|
162
|
-
style =
|
175
|
+
style = RSwt[:none] unless style
|
163
176
|
style
|
164
177
|
end
|
165
178
|
|
166
|
-
def swt_style(styles)
|
167
|
-
swt_styles(styles).inject(0) { |combined_style, style| combined_style | style }
|
168
|
-
end
|
169
|
-
|
170
|
-
def swt_styles(styles)
|
171
|
-
styles.map(&:swt_constant)
|
172
|
-
end
|
173
|
-
|
174
179
|
def attribute_setter(attribute_name)
|
175
180
|
"set#{attribute_name.to_s.camelcase(:upper)}"
|
176
181
|
end
|
@@ -33,7 +33,7 @@ class TableItemsBinding
|
|
33
33
|
def populate_table(model_collection, parent, column_properties)
|
34
34
|
parent.widget.removeAll
|
35
35
|
model_collection.each do |model|
|
36
|
-
table_item = TableItem.new(parent.widget,
|
36
|
+
table_item = TableItem.new(parent.widget, RSwt[:none])
|
37
37
|
for index in 0..(column_properties.size-1)
|
38
38
|
table_item.setText(index, model.send(column_properties[index]).to_s)
|
39
39
|
end
|
@@ -36,7 +36,7 @@ class TreeItemsBinding
|
|
36
36
|
populate_tree_node(model_tree_root_node, parent.widget, tree_properties)
|
37
37
|
end
|
38
38
|
def populate_tree_node(model_tree_node, parent, tree_properties)
|
39
|
-
table_item = TreeItem.new(parent,
|
39
|
+
table_item = TreeItem.new(parent, RSwt[:none])
|
40
40
|
table_item.setText((model_tree_node && model_tree_node.send(tree_properties[:text])).to_s)
|
41
41
|
[model_tree_node && model_tree_node.send(tree_properties[:children])].flatten.to_a.compact.each do |child|
|
42
42
|
observe(child, @tree_properties[:text])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,8 +168,10 @@ files:
|
|
168
168
|
- lib/command_handlers/models/observable_model.rb
|
169
169
|
- lib/command_handlers/models/observer.rb
|
170
170
|
- lib/command_handlers/models/r_color.rb
|
171
|
+
- lib/command_handlers/models/r_font.rb
|
171
172
|
- lib/command_handlers/models/r_runnable.rb
|
172
173
|
- lib/command_handlers/models/r_shell.rb
|
174
|
+
- lib/command_handlers/models/r_swt.rb
|
173
175
|
- lib/command_handlers/models/r_tab_item_composite.rb
|
174
176
|
- lib/command_handlers/models/r_widget.rb
|
175
177
|
- lib/command_handlers/models/r_widget_listener.rb
|