glimmer 0.4.2 → 0.4.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: 701abba7777511f578fbf87500a857650e1b5a50fff35ef92ea34be36548d3c4
4
- data.tar.gz: 2d6d523bfef6b75de1b820321d64c0f3c3208afe0ad21c274e66f9a74d59bd93
3
+ metadata.gz: 01b2e0936795d4ac088a3ea7c7045c22fbe064fd7d88283af396c3239f77bb59
4
+ data.tar.gz: c202f93d54b4b20a96cbd5c6f493ebc3d7919d92b7b02db69e6ac8feacd9c6e7
5
5
  SHA512:
6
- metadata.gz: f1d4cda6b63ee73a5ff2b068979fd79b4f2fb3a30581b7b13bb9686383a485fbe2f1e5afb6c1d486f37e8302badbfae1c14390d1f8a2f4f62031bce21e3fafb7
7
- data.tar.gz: 8f1fa157a4326a6b0499584473678d45f7141b992274a64705cccd0b64ec326337c67c6165f252eb4a98872692b56ec76004e4e5372910cdb37bf08cffe23a1b
6
+ metadata.gz: 40669eb87ebceef14f5c397ea2d4c51d55fa7daacfab7ef3a9fc110ea0dc739e2cb7b169824bf4d0cb01c32665c794a440763d9b68be56a891bca2a93c950a02
7
+ data.tar.gz: ca479f2226c69678976cc51f71c8496fd24b96a4538b913bc5f976c2b0653c5538d5bc85f372b06adc593615e045d2718581585fc42cef457df480f7cb7255f0
data/README.markdown CHANGED
@@ -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.4.2
105
+ jgem install glimmer -v 0.4.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.4.2'
112
+ gem 'glimmer', '~> 0.4.3'
113
113
  ```
114
114
 
115
115
  And, then run:
@@ -206,6 +206,17 @@ When building a widget-related SWT object manually (e.g. `GridData.new(...)`), y
206
206
 
207
207
  Glimmer facilitates that with `GSWT` class by allowing you to pass multiple styles as an argument array of symbols instead of dealing with BIT-OR. For example: `GSWT[:border, :v_scroll]`
208
208
 
209
+ **Non-resizable Window**
210
+
211
+ SWT Shell widget by default is resizable. To make it non-resizable, one must pass a complicated style bit concoction like `GSWT[:shell_trim] & (~GSWT[:resize]) & (~GSWT[:max])`.
212
+
213
+ Glimmer makes this easier by alternatively offering `:no_resize` extra SWT style, added for convenience. This makes declaring an non-resizable window as easy as:
214
+ ```ruby
215
+ shell(:no_resize) {
216
+ # ...
217
+ }
218
+ ```
219
+
209
220
  ### Widget Properties
210
221
 
211
222
  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:
@@ -415,16 +426,20 @@ label {
415
426
  }
416
427
  ```
417
428
 
418
- SWT also supports all standard colors available as constants under the `SWT` namespace (e.g. `SWT::COLOR_BLUE`)
429
+ SWT also supports standard colors available as constants under the `SWT` namespace with the `COLOR_` prefix (e.g. `SWT::COLOR_BLUE`, `SWT::COLOR_WHITE`, `SWT::COLOR_RED`)
419
430
 
420
- Glimmer accepts these constants as Ruby symbols prefixed by `color_`.
431
+ Glimmer accepts these constants as lowercase Ruby symbols with or without `color_` prefix.
421
432
 
422
433
  Example:
423
434
 
424
435
  ```ruby
436
+ label {
437
+ background :black
438
+ foreground :yellow
439
+ }
425
440
  label {
426
441
  background :color_white
427
- foreground :color_black
442
+ foreground :color_red
428
443
  }
429
444
  ```
430
445
 
@@ -465,21 +480,24 @@ Data-binding examples:
465
480
  - `text bind(contact, :first_name)`
466
481
  - `text bind(contact, 'address.street')`
467
482
  - `text bind(contact, 'addresses[1].street')`
483
+ - `text bind(contact, :age, computed_by: :date_of_birth)`
468
484
  - `text bind(contact, :name, computed_by: [:first_name, :last_name])`
469
485
  - `text bind(contact, 'profiles[0].name', computed_by: ['profiles[0].first_name', 'profiles[0].last_name'])`
470
486
 
471
- The first example binds the text property of a widget like `label` to the first name of a contact model.
487
+ The 1st example binds the text property of a widget like `label` to the first name of a contact model.
472
488
 
473
- The second example binds the text property of a widget like `label` to the nested street of
489
+ The 2nd example binds the text property of a widget like `label` to the nested street of
474
490
  the address of a contact. This is called nested property data binding.
475
491
 
476
- The third example binds the text property of a widget like `label` to the nested indexed address street of a contact. This is called nested indexed property data binding.
492
+ The 3rd example binds the text property of a widget like `label` to the nested indexed address street of a contact. This is called nested indexed property data binding.
477
493
 
478
- The fourth example demonstrates computed value data binding whereby the value of `name` depends on changes to both `first_name` and `last_name`.
494
+ The 4th example demonstrates computed value data binding whereby the value of `age` depends on changes to `date_of_birth`.
479
495
 
480
- The fifth example demonstrates nested indexed computed value data binding whereby the value of `profiles[0].name` depends on changes to both nested `profiles[0].first_name` and `profiles[0].last_name`.
496
+ The 5th example demonstrates computed value data binding whereby the value of `name` depends on changes to both `first_name` and `last_name`.
481
497
 
482
- 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.
498
+ The 6th example demonstrates nested indexed computed value data binding whereby the value of `profiles[0].name` depends on changes to both nested `profiles[0].first_name` and `profiles[0].last_name`.
499
+
500
+ 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](https://github.com/AndyObtiva/glimmer/tree/master/samples) directory.
483
501
 
484
502
  ### Observer
485
503
 
@@ -553,15 +571,21 @@ end
553
571
 
554
572
  ## Samples
555
573
 
556
- Check the "[samples](https://github.com/AndyObtiva/glimmer/tree/master/samples)" folder for examples on how to write Glimmer applications. To run a sample, make sure to install the `glimmer` gem first and then use the `glimmer` command to run it (alternatively, you may clone the repo, follow contributing instructions, and run `rake install` to install the gem before running `glimmer` command).
574
+ Check the [samples](https://github.com/AndyObtiva/glimmer/tree/master/samples) directory for examples on how to write Glimmer applications. To run a sample, make sure to install the `glimmer` gem first and then use the `glimmer` command to run it (alternatively, you may clone the repo, follow [CONTRIBUTING.md](https://github.com/AndyObtiva/glimmer/blob/master/CONTRIBUTING.md) instructions, and run samples locally with development glimmer command: `bin/glimmer --dev`).
557
575
 
558
- Example:
576
+ Examples:
559
577
 
560
578
  ```
561
- glimmer samples/hello_world.rb
579
+ glimmer samples/hello_tab.rb
580
+ glimmer samples/hello_combo.rb
581
+ glimmer samples/hello_list_single_selection.rb
582
+ glimmer samples/hello_list_multi_selection.rb
583
+ glimmer samples/contactmanager/contact_manager.rb
562
584
  ```
563
585
 
564
- Here is also a more elaborate project (educational game) built with Glimmer:
586
+ The last example (`contact_manager.rb`) is a good sample about how to build tables with Glimmer including data-binding, filtering, and sorting. It even comes with specs in `spec/samples/contactmanager/contact_manager_presenter_spec.rb` to demonstrate how Glimmer facilitates TDD (test-driven development) with the Model View Presenter pattern (a variation on MVC) by separating testable presentation logic from the view layer with data-binding.
587
+
588
+ For a more elaborate project built with Glimmer, check out this educational game:
565
589
 
566
590
  [Math Bowling](https://github.com/AndyObtiva/MathBowling)
567
591
 
@@ -2,6 +2,8 @@ require_relative 'g_swt'
2
2
 
3
3
  module Glimmer
4
4
  class GFont
5
+ ERROR_INVALID_FONT_STYLE = " is an invalid font style! Valid values are :normal, :bold, and :italic"
6
+ FONT_STYLES = [:normal, :bold, :italic]
5
7
  include_package 'org.eclipse.swt.graphics'
6
8
 
7
9
  extend Glimmer
@@ -51,6 +53,7 @@ module Glimmer
51
53
  end
52
54
 
53
55
  def font(font_properties)
56
+ detect_invalid_font_property(font_properties)
54
57
  font_properties[:style] = GSWT[*font_properties[:style]]
55
58
  font_data_args = [:name, :height, :style].map do |font_property_name|
56
59
  font_properties[font_property_name] || send(font_property_name)
@@ -58,5 +61,13 @@ module Glimmer
58
61
  font_datum = FontData.new(*font_data_args)
59
62
  Font.new(@display, font_datum)
60
63
  end
64
+
65
+ def detect_invalid_font_property(font_properties)
66
+ [font_properties[:style]].flatten.select do |style|
67
+ style.is_a?(Symbol) || style.is_a?(String)
68
+ end.each do |style|
69
+ raise style.to_s + ERROR_INVALID_FONT_STYLE if !FONT_STYLES.include?(style.to_sym)
70
+ end
71
+ end
61
72
  end
62
73
  end
@@ -11,7 +11,7 @@ module Glimmer
11
11
 
12
12
  attr_reader :display
13
13
 
14
- # Instantiates shell with same arguments expected by SWT Shell
14
+ # Instantiates shell with same arguments expected by SWT Shell
15
15
  def initialize(*args)
16
16
  if !args.first.is_a?(Display) && !args.first.is_a?(Shell)
17
17
  @display = GDisplay.instance.display
@@ -1,14 +1,27 @@
1
1
  module Glimmer
2
2
  class GSWT
3
3
  class << self
4
+ ERROR_INVALID_STYLE = " is an invalid SWT style! Please choose a style from org.eclipse.swt.SWT class constants."
4
5
  java_import 'org.eclipse.swt.SWT'
5
6
 
6
7
  # Gets SWT constants as if calling SWT::CONSTANT where constant is
7
8
  # passed in as a lower case symbol
8
9
  def [](*symbols)
9
- symbols.compact.reduce(0) { |output, symbol| output | constant(symbol) }
10
+ symbols.compact.reduce(0) do |output, symbol|
11
+ constant_value = constant(symbol)
12
+ if constant_value.is_a?(Integer)
13
+ output | constant(symbol)
14
+ else
15
+ raise symbol.to_s + ERROR_INVALID_STYLE
16
+ end
17
+ end
10
18
  end
11
19
 
20
+ # Returns SWT style integer value for passed in symbol or allows
21
+ # passed in object to pass through (e.g. Integer). This makes is convenient
22
+ # to use symbols or actual SWT style integers in Glimmer
23
+ # Does not raise error for invalid values. Just lets them pass as is.
24
+ # (look into [] operator if you want an error raised on invalid values)
12
25
  def constant(symbol)
13
26
  return symbol unless symbol.is_a?(Symbol) || symbol.is_a?(String)
14
27
  symbol_string = symbol.to_s
@@ -16,7 +29,7 @@ module Glimmer
16
29
  SWT.const_get(swt_constant_symbol)
17
30
  rescue
18
31
  begin
19
- alternative_swt_constant_symbol = SWT.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s}
32
+ alternative_swt_constant_symbol = SWT.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s.upcase}
20
33
  SWT.const_get(alternative_swt_constant_symbol)
21
34
  rescue
22
35
  EXTRA_STYLES[swt_constant_symbol] || symbol
@@ -31,9 +44,20 @@ module Glimmer
31
44
  def constantify_args(args)
32
45
  args.map {|arg| constant(arg)}
33
46
  end
47
+
48
+ # Deconstructs a style integer into symbols
49
+ # Useful for debugging
50
+ def deconstruct(integer)
51
+ SWT.constants.reduce([]) do |found, c|
52
+ constant_value = SWT.const_get(c) rescue -1
53
+ is_found = constant_value.is_a?(Integer) && (constant_value & style) == constant_value
54
+ is_found ? found += [c] : found
55
+ end
56
+ end
34
57
  end
58
+
35
59
  EXTRA_STYLES = {
36
- NO_RESIZE: GSWT[:shell_trim] & (~GSWT[:resize])
60
+ NO_RESIZE: GSWT[:shell_trim] & (~GSWT[:resize]) & (~GSWT[:max])
37
61
  }
38
62
  end
39
63
  end
@@ -55,10 +55,20 @@ module Glimmer
55
55
  end
56
56
 
57
57
  def property_type_converters
58
+ color_converter = Proc.new do |value|
59
+ if (value.is_a?(Symbol) || value.is_a?(String))
60
+ color_string = value.to_s.downcase
61
+ color_string.start_with?('color_') ? value : "color_#{color_string}"
62
+ else
63
+ value
64
+ end
65
+ end
58
66
  @property_type_converters ||= {
59
67
  :text => Proc.new { |value| value.to_s },
60
68
  :items => Proc.new { |value| value.to_java :string},
61
69
  :visible => Proc.new { |value| !!value},
70
+ :background => color_converter,
71
+ :foreground => color_converter,
62
72
  :font => Proc.new do |value|
63
73
  if value.is_a?(Hash)
64
74
  font_properties = value
@@ -74,10 +74,10 @@ module Glimmer
74
74
  @property_name_expression
75
75
  end
76
76
  def computed?
77
- !!computed_by
77
+ !computed_by.empty?
78
78
  end
79
79
  def computed_by
80
- @binding_options[:computed_by]
80
+ [@binding_options[:computed_by]].flatten.compact
81
81
  end
82
82
  def computed_binding_options
83
83
  @binding_options.reject {|k,v| k == :computed_by}
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.4.2
4
+ version: 0.4.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-19 00:00:00.000000000 Z
11
+ date: 2020-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement