glimmer 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1cfa3ffb6be614db3b3e6509edf06c483067889a384c0ffbe94cfb27eea3c73
4
- data.tar.gz: 4e30d971345d5df61a8ffcd7d736cc71cf2e7992dfe75fba39763ecba1bcbc6d
3
+ metadata.gz: 6b229c575994db66837bce7ab4d21eea4dc48c01f6875269942cc6c1d325cf04
4
+ data.tar.gz: 87759b07eda23d64c7321f55dc3ab4a339b15e0cd59fb3b93eaee079c730caad
5
5
  SHA512:
6
- metadata.gz: be20760fda63f6b5458fd00ddcdd1f008057a3b376ad11dbaaa9ee488c0ec72cf67d9322b9f6673d23ff8c49679dc636ef98b17db0a8092fdabf41010f400074
7
- data.tar.gz: 221280c0420afd17a8f843b2691b445ee2da99240d7b916e4f3af52eec1772458aa846393db9dbc6c44ba8ee1874b53ad517a946ffb05a39653fd669cd771163
6
+ metadata.gz: a968e1d522df3c64bdf9366c5a551fe17f160004a1270697b9583fae58e5c86204773d97f95db92a88f1820b1c3cc3bec1a985c5f1e6a35e48c9b325ac62ca51
7
+ data.tar.gz: 5f70f66d16b9c1b6daef6b737d9612f96bd722622d25c95c3ba022f620905c7ade6edb7a040ab4ea35bbcf9023e8f6ba7dda519c4c0439d6d311f4c9305bafc9
@@ -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.2
105
+ jgem install glimmer -v 0.3.3
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.2'
112
+ gem 'glimmer', '~> 0.3.3'
113
113
  ```
114
114
 
115
115
  And, then run:
@@ -152,13 +152,108 @@ Other widget examples:
152
152
  - `table_column`: wrapper for `org.eclipse.swt.widgets.TableColumn`
153
153
  - `tree`: wrapper for `org.eclipse.swt.widgets.Tree`
154
154
 
155
+ ### Widget Styles
156
+
157
+ SWT widgets receive `SWT` styles in their constructor as per this guide:
158
+
159
+ https://wiki.eclipse.org/SWT_Widget_Style_Bits
160
+
161
+ Glimmer DSL facilitates that by passing symbols representing `SWT` constants as widget method arguments (i.e. inside widget `()` parentheses. See example below) in lower case version (e.g. `SWT::MULTI` becomes `:multi`).
162
+
163
+ These styles customize widget look, feel, and behavior.
164
+
165
+ Example:
166
+ ```ruby
167
+ list(:multi) { # SWT styles go inside ()
168
+ # ...
169
+ }
170
+ ```
171
+
172
+ Passing `:multi` to `list` widget enables list element multi-selection.
173
+
174
+ ```ruby
175
+ composite(:border) { # SWT styles go inside ()
176
+ # ...
177
+ }
178
+ ```
179
+
180
+ Passing `:border` to `composite` widget ensures it has a border.
181
+
182
+ When you need to pass in **multiple SWT styles**, simply separate by commas.
183
+
184
+ Example:
185
+ ```ruby
186
+ text(:center, :border) { # Multiple SWT styles separated by comma
187
+ # ...
188
+ }
189
+ ```
190
+
191
+ Glimmer ships with SWT style **smart defaults** so you wouldn't have to set them yourself most of the time (albeit you can always override them):
192
+
193
+ - `text(:border)`
194
+ - `table(:border)`
195
+ - `spinner(:border)`
196
+ - `list(:border, :v_scroll)`
197
+ - `button(:push)`
198
+
199
+ You may check out all available `SWT` styles here:
200
+
201
+ https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
202
+
155
203
  ### Widget Properties
156
204
 
157
- Widget properties (e.g. `text`) may be set with methods matching their names in lower snakecase.
205
+ 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:
158
206
 
159
- Widget property examples:
160
- - `text` to set text value of a `label`
161
- - `gridData` to set grid data of a `composite`
207
+ https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/guide/swt_widgets_controls.htm?cp=2_0_7_0_0
208
+
209
+
210
+ Code examples:
211
+
212
+ ```ruby
213
+ label {
214
+ text "Hello World!" # SWT properties go inside {} block
215
+ }
216
+ ```
217
+
218
+ In the above example, the `label` widget `text` property was set to "Hello World!".
219
+
220
+ ```ruby
221
+ button {
222
+ enabled bind(@tic_tac_toe_board.box(row, column), :empty)
223
+ }
224
+ ```
225
+
226
+ 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
+
228
+ ### Color
229
+
230
+ Color makes 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
+
232
+ Example:
233
+
234
+ ```ruby
235
+ label {
236
+ background rgb(144, 240, 244)
237
+ foreground rgba(38, 92, 232, 255)
238
+ }
239
+ ```
240
+
241
+ SWT also supports all standard colors available as constants under the `SWT` namespace (e.g. `SWT::COLOR_BLUE`)
242
+
243
+ Glimmer accepts these constants as Ruby symbols prefixed by `color_`.
244
+
245
+ Example:
246
+
247
+ ```ruby
248
+ label {
249
+ background :color_white
250
+ foreground :color_black
251
+ }
252
+ ```
253
+
254
+ You may check out all available standard colors in `SWT` over here:
255
+
256
+ https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
162
257
 
163
258
  ### Data-Binding
164
259
 
@@ -184,9 +279,9 @@ The fifth example demonstrates nested indexed computed value data binding whereb
184
279
 
185
280
  You may learn more about Glimmer's syntax by reading the Eclipse Zone Tutorial mentioned in resources and opening up the samples under the `samples` folder.
186
281
 
187
- ### Observer/Observable
282
+ ### Observer
188
283
 
189
- Glimmer comes with the two classes `Observer`/`Observable`, which are used internally for data-binding, but can also be used externally for custom use of the Observer Pattern.
284
+ Glimmer comes with `Observer` module, which is used internally for data-binding, but can also be used externally for custom use of the Observer Pattern.
190
285
 
191
286
  In summary, the class that needs to observe an object, must include Observer and implement `#update(changed_value)` method. The class to be observed doesn't need to do anything. It will automatically be enhanced by Glimmer for observation.
192
287
 
@@ -239,6 +334,9 @@ Here is a list of SWT widgets:
239
334
 
240
335
  https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/guide/swt_widgets_controls.htm?cp=2_0_7_0_0
241
336
 
337
+ Here is a list of SWT style bits:
338
+
339
+ https://wiki.eclipse.org/SWT_Widget_Style_Bits
242
340
 
243
341
  ## Girb (Glimmer irb)
244
342
 
@@ -299,15 +397,20 @@ jruby -J-XstartOnFirstThread -J-classpath "path_to/swt.jar" -r glimmer -S applic
299
397
 
300
398
  These features have been suggested. You might see them in a future version of Glimmer. You are welcome to contribute more feature suggestions.
301
399
 
302
- - Auto-include SWT packages when including Glimmer
303
400
  - Glimmer Application: provide a standard structure for building a Glimmer app
304
401
  - Glimmer Component: Glimmer already supports components by externalizing to objects, but it would be good if there is a module to include so Glimmer would automatically register
305
402
  a new component and extend the DSL with it
306
- - **Nested indexed property data binding**: a complementary feature to nested property data binding that binds to a collection element by index (e.g. `bind(user, 'addresses[1].street')`)
307
- - **bind_collection**: an iterator that enables spawning widgets based on a variable collection (e.g. `bind_collection('user.addresses') { |address| address_widget {...} }` spawns 3 `AddressWidget`s if `user.addresses` is set with 3 addresses; and replaces with 2 `AddressWidget`s if `user.addresses` is reset with 2 addresses only). Needs further thought on naming and functionality.
403
+ - Glimmer Wizard: provide a standard structure for building a Glimmer wizard (multi-step/multi-screen process)
404
+ - bind_collection: an iterator that enables spawning widgets based on a variable collection (e.g. `bind_collection('user.addresses') { |address| address_widget {...} }` spawns 3 `AddressWidget`s if `user.addresses` is set with 3 addresses; and replaces with 2 `AddressWidget`s if `user.addresses` is reset with 2 addresses only). Needs further thought on naming and functionality.
308
405
  - Automatic relayout of "glimmer components" when disposing one or as an option
309
406
  - Consider using Ruby Refinements for Glimmer
310
-
407
+ - Add 'font' to Glimmer DSL to build font objects easily
408
+ - Add grid layout support to Glimmer DSL to layout grid components easily
409
+ - Add rerendering support to Glimmer to rerender any widget easily
410
+ - Avoid disposing display when disposing a shell to allow recycling
411
+ - Provide a display builder method to use independently of shell
412
+ - Supported a single computed data binding as a string (not array)
413
+ - Disallow use of SWT::CONSTANTs with ORing since it's not intuitive at all
311
414
 
312
415
  ## Contributors
313
416
 
@@ -1,17 +1,18 @@
1
- require File.dirname(__FILE__) + "/command_handler_chain_factory"
2
- require File.dirname(__FILE__) + "/command_handlers/shell_command_handler"
3
- require File.dirname(__FILE__) + "/command_handlers/widget_listener_command_handler"
4
- require File.dirname(__FILE__) + "/command_handlers/bind_command_handler"
5
- require File.dirname(__FILE__) + "/command_handlers/tab_item_command_handler"
6
- require File.dirname(__FILE__) + "/command_handlers/combo_selection_data_binding_command_handler"
7
- require File.dirname(__FILE__) + "/command_handlers/list_selection_data_binding_command_handler"
8
- require File.dirname(__FILE__) + "/command_handlers/tree_items_data_binding_command_handler"
9
- require File.dirname(__FILE__) + "/command_handlers/tree_properties_data_binding_command_handler"
10
- require File.dirname(__FILE__) + "/command_handlers/table_items_data_binding_command_handler"
11
- require File.dirname(__FILE__) + "/command_handlers/table_column_properties_data_binding_command_handler"
12
- require File.dirname(__FILE__) + "/command_handlers/data_binding_command_handler"
13
- require File.dirname(__FILE__) + "/command_handlers/widget_method_command_handler"
14
- require File.dirname(__FILE__) + "/command_handlers/widget_command_handler"
1
+ require_relative "command_handler_chain_factory"
2
+ require_relative "command_handlers/color_command_handler"
3
+ require_relative "command_handlers/shell_command_handler"
4
+ require_relative "command_handlers/widget_listener_command_handler"
5
+ require_relative "command_handlers/bind_command_handler"
6
+ require_relative "command_handlers/tab_item_command_handler"
7
+ require_relative "command_handlers/combo_selection_data_binding_command_handler"
8
+ require_relative "command_handlers/list_selection_data_binding_command_handler"
9
+ require_relative "command_handlers/tree_items_data_binding_command_handler"
10
+ require_relative "command_handlers/tree_properties_data_binding_command_handler"
11
+ require_relative "command_handlers/table_items_data_binding_command_handler"
12
+ require_relative "command_handlers/table_column_properties_data_binding_command_handler"
13
+ require_relative "command_handlers/data_binding_command_handler"
14
+ require_relative "command_handlers/widget_method_command_handler"
15
+ require_relative "command_handlers/widget_command_handler"
15
16
 
16
17
  # edit to add more command handlers and extend Glimmer
17
18
  CommandHandlerChainFactory.def_dsl(:swt,
@@ -26,6 +27,7 @@ CommandHandlerChainFactory.def_dsl(:swt,
26
27
  TableItemsDataBindingCommandHandler.new,
27
28
  TableColumnPropertiesDataBindingCommandHandler.new,
28
29
  DataBindingCommandHandler.new,
30
+ ColorCommandHandler.new,
29
31
  WidgetMethodCommandHandler.new,
30
32
  WidgetCommandHandler.new
31
33
  )
@@ -0,0 +1,16 @@
1
+ require_relative '../command_handler'
2
+ require_relative 'models/r_color'
3
+
4
+ class ColorCommandHandler
5
+ include CommandHandler
6
+
7
+ def can_handle?(parent, command_symbol, *args, &block)
8
+ parent.is_a?(RWidget) and
9
+ ['rgba', 'rgb'].include?(command_symbol.to_s) and
10
+ (3..4).include?(args.count)
11
+ end
12
+
13
+ def do_handle(parent, command_symbol, *args, &block)
14
+ RColor.new(parent.widget.display, *args).color
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ class RColor
2
+ attr_reader :display
3
+ attr_reader :color
4
+
5
+ include_package 'org.eclipse.swt.graphics'
6
+
7
+ class << self
8
+ def for(display, standard_color)
9
+ standard_color_swt_constant = org.eclipse.swt.SWT.const_get(standard_color.to_s.upcase.to_sym)
10
+ display.getSystemColor(standard_color_swt_constant)
11
+ end
12
+ end
13
+
14
+ def initialize(display, red, green, blue, alpha = nil)
15
+ @display = display
16
+ @color = Color.new(@display, *[red, green, blue, alpha].compact)
17
+ end
18
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative "r_widget_listener"
2
2
  require_relative "r_runnable"
3
+ require_relative "r_color"
3
4
 
4
5
  class RWidget
5
6
  include_package 'org.eclipse.swt'
@@ -40,6 +41,10 @@ class RWidget
40
41
  end
41
42
 
42
43
  def set_attribute(attribute_name, *args)
44
+ if args.count == 1 && args.first.is_a?(Symbol) && args.first.to_s.start_with?('color_')
45
+ standard_color = args.first
46
+ args[0] = RColor.for(widget.getDisplay, standard_color)
47
+ end
43
48
  @widget.send(attribute_setter(attribute_name), *args)
44
49
  end
45
50
 
@@ -10,7 +10,7 @@ class WidgetBinding
10
10
  @@property_type_converters = {
11
11
  :text => Proc.new { |value| value.to_s },
12
12
  :items => Proc.new { |value| value.to_java :string},
13
- :visible => Proc.new { |value| !!value}
13
+ :visible => Proc.new { |value| !!value},
14
14
  }
15
15
  def initialize(model, property, translator = nil)
16
16
  @widget = model
@@ -3,13 +3,13 @@ require File.dirname(__FILE__) + "/models/r_shell"
3
3
 
4
4
  class ShellCommandHandler
5
5
  include CommandHandler
6
-
6
+
7
7
  def can_handle?(parent, command_symbol, *args, &block)
8
8
  command_symbol.to_s == "shell"
9
9
  end
10
-
11
- def do_handle(parent, command_symbol, *args, &block)
10
+
11
+ def do_handle(parent, command_symbol, *args, &block)
12
12
  RShell.send(:new, *args)
13
13
  end
14
-
15
- end
14
+
15
+ end
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.2
4
+ version: 0.3.3
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 00:00:00.000000000 Z
11
+ date: 2020-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -156,6 +156,7 @@ files:
156
156
  - lib/command_handler_chain_link.rb
157
157
  - lib/command_handlers.rb
158
158
  - lib/command_handlers/bind_command_handler.rb
159
+ - lib/command_handlers/color_command_handler.rb
159
160
  - lib/command_handlers/combo_selection_data_binding_command_handler.rb
160
161
  - lib/command_handlers/data_binding_command_handler.rb
161
162
  - lib/command_handlers/list_selection_data_binding_command_handler.rb
@@ -166,6 +167,7 @@ files:
166
167
  - lib/command_handlers/models/observable_array.rb
167
168
  - lib/command_handlers/models/observable_model.rb
168
169
  - lib/command_handlers/models/observer.rb
170
+ - lib/command_handlers/models/r_color.rb
169
171
  - lib/command_handlers/models/r_runnable.rb
170
172
  - lib/command_handlers/models/r_shell.rb
171
173
  - lib/command_handlers/models/r_tab_item_composite.rb