glimmer 0.5.4 → 0.5.5

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: e13a3990377287df2bf023f72f4c6ab4b1cb8a58b4dad96321f4ac59e9efde11
4
- data.tar.gz: 829597311c7719af97c326fd6f456038c1df94a76d8f140dd8acc430a8a951d4
3
+ metadata.gz: f7348e7c25e89b1300de7540833ad43ac060ecf94b8b97b897d8e946390851a5
4
+ data.tar.gz: a4e964bacc785ed789fe25c97c3811b39952d315428ec38e43082d5ba2bd1967
5
5
  SHA512:
6
- metadata.gz: 344b90942d68a6bd994b09eb0e0848f996d57da0526cf54a6fc11f9718aae850b3e53419ba8bb418470f303fda278283ae99420d6a04bbd2cbab5b22e9ad250e
7
- data.tar.gz: 486bbbf6de699a7d3985eea76a5588a83fe32c8a1484648d68b026237390427c2e14b8083b59874f0e0a87454c8d0a05449ca12016ba950c2271d7ac0da7e960
6
+ metadata.gz: 5348edf829a109f758e8a098d19b33dbdb6ddd27add80a5ab37afed35e426d1805742ce065ffb09f9451202ea3974312222bdd16390a47014a97dfc3cf92d399
7
+ data.tar.gz: dc24d11c4522f9c96d8d2fae5178a7053d9599fe5e3e0054db34e047dc519fdb1cbbb928eb8a5b16527db1ac2973224dc802802c9654096fd609e20533eba94d
@@ -1,4 +1,4 @@
1
- # Glimmer 0.5.4 Beta (JRuby Desktop UI DSL + Data-Binding)
1
+ # Glimmer 0.5.5 Beta (JRuby Desktop UI DSL + Data-Binding)
2
2
  [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer?branch=master)
3
3
 
4
4
  Glimmer is a native-UI cross-platform desktop development library written in Ruby. Glimmer's main innovation is a JRuby DSL that enables productive and efficient authoring of desktop application user-interfaces while relying on the robust platform-native Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support to greatly facilitate synchronizing the UI with domain models. As a result, that achieves true decoupling of object oriented components, enabling developers to solve business problems without worrying about UI concerns, or alternatively drive development UI-first, and then write clean business components test-first afterwards.
@@ -111,14 +111,14 @@ Please follow these instructions to make the `glimmer` command available on your
111
111
 
112
112
  Run this command to install directly:
113
113
  ```
114
- jgem install glimmer -v 0.5.4
114
+ jgem install glimmer -v 0.5.5
115
115
  ```
116
116
 
117
117
  ### Option 2: Bundler
118
118
 
119
119
  Add the following to `Gemfile`:
120
120
  ```
121
- gem 'glimmer', '~> 0.5.4'
121
+ gem 'glimmer', '~> 0.5.5'
122
122
  ```
123
123
 
124
124
  And, then run:
@@ -303,6 +303,83 @@ shell {
303
303
  }.open
304
304
  ```
305
305
 
306
+ #### Menus
307
+
308
+ Glimmer DSL provides support for SWT Menu and MenuItem widgets.
309
+
310
+ There are 2 main types of menus in SWT:
311
+ - Menu Bar (shows up on top)
312
+ - Pop Up Menu (shows up when right-clicking a widget)
313
+
314
+ Underneath both types, there can be a 3rd menu type called Drop Down.
315
+
316
+ Glimmer provides special support for Drop Down menus as it automatically instantiates associated Cascade menu items and wires together with proper parenting, swt styles, and calling setMenu.
317
+
318
+ Example [Menu Bar] (you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
319
+
320
+ ```ruby
321
+ shell {
322
+ menu_bar {
323
+ menu {
324
+ text "&File"
325
+ menu_item {
326
+ text "E&xit"
327
+ }
328
+ menu_item(0) {
329
+ text "&New"
330
+ }
331
+ menu(1) {
332
+ text "&Options"
333
+ menu_item(:radio) {
334
+ text "Option 1"
335
+ }
336
+ menu_item(:separator)
337
+ menu_item(:check) {
338
+ text "Option 3"
339
+ }
340
+ }
341
+ }
342
+ menu {
343
+ text "&History"
344
+ menu {
345
+ text "&Recent"
346
+ menu_item {
347
+ text "File 1"
348
+ }
349
+ menu_item {
350
+ text "File 2"
351
+ }
352
+ }
353
+ }
354
+ }
355
+ }.open
356
+ ```
357
+
358
+ Example [Pop Up Menu] (you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
359
+
360
+ ```ruby
361
+ shell {
362
+ label {
363
+ text 'Right-Click Me'
364
+ menu {
365
+ menu {
366
+ text '&History'
367
+ menu {
368
+ text "&Recent"
369
+ menu_item {
370
+ text "File 1"
371
+ }
372
+ menu_item {
373
+ text "File 2"
374
+ }
375
+ }
376
+ }
377
+ }
378
+ }
379
+ }.open
380
+ ```
381
+
382
+
306
383
  #### SWT Proxies
307
384
 
308
385
  Glimmer follows Proxy Design Pattern by having Ruby proxy wrappers for all SWT objects:
@@ -450,6 +527,23 @@ shell(:no_resize) {
450
527
  }
451
528
  ```
452
529
 
530
+ #### Shell extra attributes
531
+
532
+ Shell widget can receive a hash of extra attributes as the last argument (or alone):
533
+ - app_name: name to show for app (especially on the Mac)
534
+ - app_version: version to have OS recognize app by
535
+
536
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
537
+
538
+ ```ruby
539
+ shell(:no_resize, app_name: 'Glimmer Demo', app_version: '1.0') {
540
+ text "Glimmer"
541
+ label {
542
+ text "Hello, World!"
543
+ }
544
+ }.open
545
+ ```
546
+
453
547
  ### Widget Properties
454
548
 
455
549
  Widget properties such as text value, enablement, visibility, 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:
@@ -2,8 +2,7 @@ require 'glimmer/dsl/expression'
2
2
  require 'glimmer/swt/color_proxy'
3
3
  require 'glimmer/swt/display_proxy'
4
4
 
5
- # TODO consider turning static keywords like rgba/rgb into methods
6
- # Support color keyword
5
+ # TODO consider turning in static expressions rgb/rgba/color
7
6
 
8
7
  module Glimmer
9
8
  module DSL
@@ -16,11 +15,6 @@ module Glimmer
16
15
  end
17
16
 
18
17
  def interpret(parent, keyword, *args, &block)
19
- if args.first.is_a?(Display) or args.first.nil?
20
- display = args.delete_at(0)
21
- else
22
- display = SWT::DisplayProxy.instance.swt_display
23
- end
24
18
  SWT::ColorProxy.new(*args)
25
19
  end
26
20
  end
@@ -0,0 +1,31 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/static_expression'
3
+ require 'glimmer/dsl/parent_expression'
4
+ require 'glimmer/swt/menu_proxy'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ class MenuBarExpression < StaticExpression
9
+ include ParentExpression
10
+
11
+ include_package 'org.eclipse.swt.widgets'
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ initial_condition = (keyword == 'menu_bar')
15
+ if initial_condition
16
+ if parent.swt_widget.is_a?(Shell)
17
+ return true
18
+ else
19
+ raise Glimmer::Error, "menu_bar may only be nested under a shell!"
20
+ end
21
+ end
22
+ false
23
+ end
24
+
25
+ def interpret(parent, keyword, *args, &block)
26
+ args = args.unshift(:bar)
27
+ SWT::MenuProxy.new(parent, args)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/static_expression'
3
+ require 'glimmer/dsl/parent_expression'
4
+ require 'glimmer/swt/menu_proxy'
5
+
6
+ module Glimmer
7
+ module DSL
8
+ class MenuExpression < StaticExpression
9
+ include ParentExpression
10
+
11
+ include_package 'org.eclipse.swt.widgets'
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ initial_condition = (keyword == 'menu')
15
+ if initial_condition
16
+ if widget?(parent)
17
+ return true
18
+ else
19
+ raise Glimmer::Error, "menu may only be nested under a widget (like shell or another menu)!"
20
+ end
21
+ end
22
+ false
23
+ end
24
+
25
+ def interpret(parent, keyword, *args, &block)
26
+ SWT::MenuProxy.new(parent, args)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -8,6 +8,7 @@ module Glimmer
8
8
  include ParentExpression
9
9
 
10
10
  def interpret(parent, keyword, *args, &block)
11
+ args = [parent] + args unless parent.nil?
11
12
  SWT::ShellProxy.send(:new, *args)
12
13
  end
13
14
  end
@@ -11,8 +11,6 @@ module Glimmer
11
11
  class ColorProxy
12
12
  include_package 'org.eclipse.swt.graphics'
13
13
 
14
- attr_reader :swt_color
15
-
16
14
  # Initializes a proxy for an SWT Color object
17
15
  #
18
16
  # Takes a standard color single argument, rgba 3 args, or rgba 4 args
@@ -29,19 +27,26 @@ module Glimmer
29
27
  # rgba is 4 arguments representing Red, Green, Blue, and Alpha numeric values
30
28
  #
31
29
  def initialize(*args)
32
- case args.size
33
- when 1
34
- if args.first.is_a?(String) || args.first.is_a?(Symbol)
35
- standard_color = args.first
36
- standard_color = "color_#{standard_color}".to_sym unless standard_color.to_s.downcase.include?('color_')
37
- @swt_color = DisplayProxy.instance.swt_display.getSystemColor(SWTProxy[standard_color])
38
- else
39
- @swt_color = args.first
30
+ @args = args
31
+ end
32
+
33
+ def swt_color
34
+ unless @swt_color
35
+ case @args.size
36
+ when 1
37
+ if @args.first.is_a?(String) || @args.first.is_a?(Symbol)
38
+ standard_color = @args.first
39
+ standard_color = "color_#{standard_color}".to_sym unless standard_color.to_s.downcase.include?('color_')
40
+ @swt_color = DisplayProxy.instance.swt_display.getSystemColor(SWTProxy[standard_color])
41
+ else
42
+ @swt_color = @args.first
43
+ end
44
+ when 3..4
45
+ red, green, blue, alpha = @args
46
+ @swt_color = Color.new(DisplayProxy.instance.swt_display, *[red, green, blue, alpha].compact)
40
47
  end
41
- when 3..4
42
- red, green, blue, alpha = args
43
- @swt_color = Color.new(DisplayProxy.instance.swt_display, *[red, green, blue, alpha].compact)
44
48
  end
49
+ @swt_color
45
50
  end
46
51
  end
47
52
  end
@@ -0,0 +1,84 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+
3
+ module Glimmer
4
+ module SWT
5
+ # Proxy for org.eclipse.swt.widgets.Menu
6
+ #
7
+ # Functions differently from other widget proxies.
8
+ #
9
+ # Glimmer automatically detects if this is a drop down menu
10
+ # or pop up menu from its parent if no SWT style is passed in.
11
+ #
12
+ # There are 3 possibilities:
13
+ # - SWT :bar style is passed in: Menu Bar
14
+ # - Parent is ShellProxy: Pop Up Menu (having style :pop_up)
15
+ # - Parent is another Menu: Drop Down Menu (having style :drop_down)
16
+ #
17
+ # In order to get the SWT Menu object, one must call `#swt_widget`.
18
+ #
19
+ # In the case of a Drop Down menu, this automatically creates an
20
+ # SWT MenuItem object with style :cascade
21
+ #
22
+ # In order to retrieve the menu item widget proxy, one must call `#menu_item_proxy`
23
+ #
24
+ # Follows the Proxy Design Pattern
25
+ class MenuProxy < WidgetProxy
26
+ include_package 'org.eclipse.swt.widgets'
27
+
28
+ attr_reader :menu_item_proxy, :swt_menu_item, :menu_parent
29
+
30
+ def initialize(parent, args)
31
+ index = args.delete(args.last) if args.last.is_a?(Numeric)
32
+ styles = args.map(&:to_sym)
33
+ if !styles.include?(:bar) && !parent.swt_widget.is_a?(Menu)
34
+ styles = styles.unshift(:pop_up)
35
+ end
36
+
37
+ swt_widget_class = self.class.swt_widget_class_for('menu')
38
+ if parent.swt_widget.is_a?(Menu)
39
+ @menu_item_proxy = SWT::WidgetProxy.new('menu_item', parent, [:cascade] + [index].compact)
40
+ @swt_menu_item = @menu_item_proxy.swt_widget
41
+ @swt_widget = swt_widget_class.new(@menu_item_proxy.swt_widget)
42
+ @swt_menu_item.setMenu(swt_widget)
43
+ elsif parent.swt_widget.is_a?(Shell)
44
+ @swt_widget = swt_widget_class.new(parent.swt_widget, style('menu', styles))
45
+ else
46
+ @swt_widget = swt_widget_class.new(parent.swt_widget)
47
+ end
48
+ DEFAULT_INITIALIZERS['menu']&.call(swt_widget)
49
+
50
+ if styles.include?(:bar)
51
+ parent.swt_widget.setMenuBar(swt_widget)
52
+ elsif styles.include?(:pop_up)
53
+ parent.swt_widget.setMenu(swt_widget)
54
+ end
55
+ end
56
+
57
+ def has_attribute?(attribute_name, *args)
58
+ if attribute_name.to_s == "text"
59
+ true
60
+ else
61
+ super(attribute_name, *args)
62
+ end
63
+ end
64
+
65
+ def set_attribute(attribute_name, *args)
66
+ attribute_name
67
+ if attribute_name.to_s == "text"
68
+ text_value = args[0]
69
+ @swt_menu_item.setText text_value
70
+ else
71
+ super(attribute_name, *args)
72
+ end
73
+ end
74
+
75
+ def get_attribute(attribute_name)
76
+ if attribute_name.to_s == "text"
77
+ @swt_menu_item.getText
78
+ else
79
+ super(attribute_name)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -14,13 +14,22 @@ module Glimmer
14
14
 
15
15
  WIDTH_MIN = 130
16
16
  HEIGHT_MIN = 0
17
+ CUSTOM_ATTRIBUTES = %w[app_name app_version]
17
18
 
18
19
  attr_reader :opened_before
19
20
  alias opened_before? opened_before
20
21
 
21
22
  # Instantiates ShellProxy with same arguments expected by SWT Shell
22
23
  def initialize(*args)
23
- if args.first.nil? || !args.first.is_a?(Display) && !args.first.is_a?(Shell)
24
+ if args.last.is_a?(Hash)
25
+ app_attributes = args.delete(args.last)
26
+ Display.setAppName(app_attributes[:app_name])
27
+ Display.setAppVersion(app_attributes[:app_version])
28
+ end
29
+ if args.first.is_a?(ShellProxy)
30
+ args[0] = args[0].swt_widget
31
+ end
32
+ if args.first.nil? || (!args.first.is_a?(Display) && !args.first.is_a?(Shell))
24
33
  @display = DisplayProxy.instance.swt_display
25
34
  args = [@display] + args
26
35
  end
@@ -11,7 +11,7 @@ module Glimmer
11
11
  #
12
12
  # In order to get the SWT TabItem object, one must call `#swt_tab_item`.
13
13
  #
14
- # Behinds the scenes, this creates a tab item widget proxy separately from a composite that
14
+ # Behind the scenes, this creates a tab item widget proxy separately from a composite that
15
15
  # is set as the control of the tab item and `#swt_widget`.
16
16
  #
17
17
  # In order to retrieve the tab item widget proxy, one must call `#widget_proxy`
@@ -22,11 +22,12 @@ module Glimmer
22
22
  include DataBinding::ObservableWidget
23
23
 
24
24
  DEFAULT_STYLES = {
25
- "text" => [:border],
26
- "table" => [:border],
27
- "spinner" => [:border],
28
- "list" => [:border, :v_scroll],
29
- "button" => [:push],
25
+ "text" => [:border],
26
+ "table" => [:border],
27
+ "spinner" => [:border],
28
+ "list" => [:border, :v_scroll],
29
+ "button" => [:push],
30
+ "menu_item" => [:push],
30
31
  }
31
32
 
32
33
  DEFAULT_INITIALIZERS = {
@@ -50,12 +51,29 @@ module Glimmer
50
51
  # Initializes a new SWT Widget
51
52
  #
52
53
  # Styles is a comma separate list of symbols representing SWT styles in lower case
53
- def initialize(underscored_widget_name, parent, styles, &contents)
54
+ def initialize(underscored_widget_name, parent, args)
55
+ styles, extra_options = extract_args(underscored_widget_name, args)
54
56
  swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
55
- @swt_widget = swt_widget_class.new(parent.swt_widget, style(underscored_widget_name, styles))
57
+ @swt_widget = swt_widget_class.new(parent.swt_widget, style(underscored_widget_name, styles), *extra_options)
56
58
  DEFAULT_INITIALIZERS[underscored_widget_name]&.call(@swt_widget)
57
59
  end
58
60
 
61
+ def extract_args(underscored_widget_name, args)
62
+ @arg_extractor_mapping ||= {
63
+ 'menu_item' => lambda do |args|
64
+ index = args.delete(args.last) if args.last.is_a?(Numeric)
65
+ extra_options = [index].compact
66
+ styles = args
67
+ [styles, extra_options]
68
+ end,
69
+ }
70
+ if @arg_extractor_mapping[underscored_widget_name]
71
+ @arg_extractor_mapping[underscored_widget_name].call(args)
72
+ else
73
+ [args, []]
74
+ end
75
+ end
76
+
59
77
  def has_attribute?(attribute_name, *args)
60
78
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
61
79
  if widget_custom_attribute
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.5.4
4
+ version: 0.5.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-04-16 00:00:00.000000000 Z
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -237,6 +237,8 @@ files:
237
237
  - lib/glimmer/dsl/layout_data_expression.rb
238
238
  - lib/glimmer/dsl/layout_expression.rb
239
239
  - lib/glimmer/dsl/list_selection_data_binding_expression.rb
240
+ - lib/glimmer/dsl/menu_bar_expression.rb
241
+ - lib/glimmer/dsl/menu_expression.rb
240
242
  - lib/glimmer/dsl/observe_expression.rb
241
243
  - lib/glimmer/dsl/parent_expression.rb
242
244
  - lib/glimmer/dsl/property_expression.rb
@@ -259,6 +261,7 @@ files:
259
261
  - lib/glimmer/swt/font_proxy.rb
260
262
  - lib/glimmer/swt/layout_data_proxy.rb
261
263
  - lib/glimmer/swt/layout_proxy.rb
264
+ - lib/glimmer/swt/menu_proxy.rb
262
265
  - lib/glimmer/swt/packages.rb
263
266
  - lib/glimmer/swt/shell_proxy.rb
264
267
  - lib/glimmer/swt/swt_proxy.rb