glimmer-dsl-swt 4.18.4.9 → 4.18.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +73 -0
  3. data/README.md +14 -5
  4. data/VERSION +1 -1
  5. data/bin/glimmer +3 -3
  6. data/docs/reference/GLIMMER_CONFIGURATION.md +7 -3
  7. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +464 -149
  8. data/docs/reference/GLIMMER_SAMPLES.md +91 -4
  9. data/glimmer-dsl-swt.gemspec +24 -13
  10. data/lib/ext/glimmer/config.rb +3 -7
  11. data/lib/glimmer/data_binding/list_selection_binding.rb +13 -7
  12. data/lib/glimmer/data_binding/table_items_binding.rb +22 -17
  13. data/lib/glimmer/data_binding/tree_items_binding.rb +19 -15
  14. data/lib/glimmer/data_binding/widget_binding.rb +13 -15
  15. data/lib/glimmer/dsl/swt/{file_dialog_expression.rb → auto_exec_expression.rb} +6 -18
  16. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
  17. data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
  18. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
  19. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +4 -1
  20. data/lib/glimmer/dsl/swt/data_binding_expression.rb +2 -2
  21. data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
  22. data/lib/glimmer/dsl/swt/dsl.rb +1 -0
  23. data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
  24. data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
  25. data/lib/glimmer/dsl/swt/image_expression.rb +16 -2
  26. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
  27. data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
  28. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +8 -5
  29. data/lib/glimmer/dsl/swt/shape_expression.rb +2 -2
  30. data/lib/glimmer/dsl/swt/shell_expression.rb +5 -2
  31. data/lib/glimmer/dsl/swt/widget_expression.rb +8 -4
  32. data/lib/glimmer/launcher.rb +3 -0
  33. data/lib/glimmer/rake_task/scaffold.rb +3 -0
  34. data/lib/glimmer/swt/color_proxy.rb +1 -1
  35. data/lib/glimmer/swt/custom/code_text.rb +33 -11
  36. data/lib/glimmer/swt/custom/drawable.rb +55 -0
  37. data/lib/glimmer/swt/custom/shape.rb +187 -43
  38. data/lib/glimmer/swt/custom/shape/arc.rb +60 -0
  39. data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/focus.rb} +15 -20
  40. data/lib/glimmer/swt/custom/shape/image.rb +99 -0
  41. data/lib/glimmer/swt/custom/shape/line.rb +65 -0
  42. data/lib/glimmer/swt/custom/shape/oval.rb +61 -0
  43. data/lib/glimmer/swt/custom/shape/point.rb +54 -0
  44. data/lib/glimmer/swt/custom/shape/polygon.rb +73 -0
  45. data/lib/glimmer/swt/custom/shape/polyline.rb +74 -0
  46. data/lib/glimmer/swt/custom/shape/rectangle.rb +101 -0
  47. data/lib/glimmer/swt/custom/shape/text.rb +85 -0
  48. data/lib/glimmer/swt/date_time_proxy.rb +9 -3
  49. data/lib/glimmer/swt/dialog_proxy.rb +92 -0
  50. data/lib/glimmer/swt/display_proxy.rb +62 -2
  51. data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
  52. data/lib/glimmer/swt/font_proxy.rb +13 -7
  53. data/lib/glimmer/swt/image_proxy.rb +15 -4
  54. data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
  55. data/lib/glimmer/swt/layout_proxy.rb +19 -15
  56. data/lib/glimmer/swt/menu_proxy.rb +2 -2
  57. data/lib/glimmer/swt/message_box_proxy.rb +21 -7
  58. data/lib/glimmer/swt/properties.rb +3 -0
  59. data/lib/glimmer/swt/proxy_properties.rb +145 -0
  60. data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -2
  61. data/lib/glimmer/swt/shell_proxy.rb +96 -80
  62. data/lib/glimmer/swt/swt_proxy.rb +17 -0
  63. data/lib/glimmer/swt/tab_item_proxy.rb +5 -3
  64. data/lib/glimmer/swt/table_proxy.rb +32 -11
  65. data/lib/glimmer/swt/transform_proxy.rb +39 -35
  66. data/lib/glimmer/swt/tree_proxy.rb +11 -16
  67. data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
  68. data/lib/glimmer/swt/widget_proxy.rb +192 -141
  69. data/lib/glimmer/ui.rb +5 -0
  70. data/lib/glimmer/ui/custom_shell.rb +13 -7
  71. data/lib/glimmer/ui/custom_widget.rb +4 -5
  72. data/samples/elaborate/contact_manager.rb +7 -7
  73. data/samples/elaborate/login.rb +25 -21
  74. data/samples/elaborate/mandelbrot_fractal.rb +87 -31
  75. data/samples/elaborate/meta_sample.rb +1 -1
  76. data/samples/elaborate/tetris.rb +1 -0
  77. data/samples/elaborate/tic_tac_toe.rb +16 -14
  78. data/samples/elaborate/tic_tac_toe/board.rb +5 -5
  79. data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
  80. data/samples/hello/hello_button.rb +7 -7
  81. data/samples/hello/hello_canvas.rb +143 -41
  82. data/samples/hello/hello_checkbox.rb +16 -14
  83. data/samples/hello/hello_checkbox_group.rb +11 -9
  84. data/samples/hello/hello_color_dialog.rb +66 -0
  85. data/samples/hello/hello_combo.rb +14 -12
  86. data/samples/hello/hello_computed.rb +7 -7
  87. data/samples/hello/hello_cursor.rb +2 -1
  88. data/samples/hello/hello_custom_shell.rb +17 -21
  89. data/samples/hello/hello_custom_widget.rb +4 -6
  90. data/samples/hello/hello_date_time.rb +14 -12
  91. data/samples/hello/hello_directory_dialog.rb +7 -7
  92. data/samples/hello/hello_expand_bar.rb +8 -8
  93. data/samples/hello/hello_file_dialog.rb +7 -7
  94. data/samples/hello/hello_font_dialog.rb +82 -0
  95. data/samples/hello/hello_group.rb +18 -16
  96. data/samples/hello/hello_list_multi_selection.rb +13 -11
  97. data/samples/hello/hello_list_single_selection.rb +13 -11
  98. data/samples/hello/hello_progress_bar.rb +125 -0
  99. data/samples/hello/hello_radio.rb +18 -16
  100. data/samples/hello/hello_radio_group.rb +14 -12
  101. data/samples/hello/hello_spinner.rb +7 -7
  102. data/samples/hello/hello_tab.rb +5 -5
  103. data/samples/hello/hello_table.rb +10 -5
  104. data/samples/hello/hello_tree.rb +485 -0
  105. metadata +22 -22
  106. data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
  107. data/lib/glimmer/swt/file_dialog_proxy.rb +0 -66
@@ -219,7 +219,7 @@ class MetaSampleApplication
219
219
  SampleDirectory.sample_directories.each { |sample_directory|
220
220
  expand_item {
221
221
  layout_data(:fill, :fill, true, true)
222
- text " #{sample_directory.name} Samples"
222
+ text " #{sample_directory.name} Samples (#{sample_directory.samples.count})"
223
223
 
224
224
  radio_group { |radio_group_proxy|
225
225
  row_layout(:vertical) {
@@ -182,6 +182,7 @@ class Tetris
182
182
  time = Time.now
183
183
  sleep @game.delay
184
184
  break if @game.game_over? || body_root.disposed?
185
+ # ensure entire game tetromino down movement happens as one GUI update event with sync_exec (to avoid flicker/stutter)
185
186
  sync_exec {
186
187
  @game.down! unless @game.paused?
187
188
  }
@@ -22,11 +22,21 @@
22
22
  require_relative "tic_tac_toe/board"
23
23
 
24
24
  class TicTacToe
25
- include Glimmer
25
+ include Glimmer::UI::CustomShell
26
26
 
27
- def initialize
27
+ before_body {
28
28
  @tic_tac_toe_board = Board.new
29
- @shell = shell {
29
+ }
30
+
31
+ after_body {
32
+ observe(@tic_tac_toe_board, :game_status) { |game_status|
33
+ display_win_message if game_status == Board::WIN
34
+ display_draw_message if game_status == Board::DRAW
35
+ }
36
+ }
37
+
38
+ body {
39
+ shell {
30
40
  text "Tic-Tac-Toe"
31
41
  minimum_size 176, 200
32
42
  composite {
@@ -46,11 +56,7 @@ class TicTacToe
46
56
  }
47
57
  }
48
58
  }
49
- observe(@tic_tac_toe_board, :game_status) { |game_status|
50
- display_win_message if game_status == Board::WIN
51
- display_draw_message if game_status == Board::DRAW
52
- }
53
- end
59
+ }
54
60
 
55
61
  def display_win_message
56
62
  display_game_over_message("Player #{@tic_tac_toe_board.winning_sign} has won!")
@@ -65,12 +71,8 @@ class TicTacToe
65
71
  text 'Game Over'
66
72
  message message_text
67
73
  }.open
68
- @tic_tac_toe_board.reset
69
- end
70
-
71
- def open
72
- @shell.open
74
+ @tic_tac_toe_board.reset!
73
75
  end
74
76
  end
75
77
 
76
- TicTacToe.new.open
78
+ TicTacToe.launch
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -60,10 +60,10 @@ class TicTacToe
60
60
  win
61
61
  end
62
62
 
63
- def reset
63
+ def reset!
64
64
  (1..3).each do |row|
65
65
  (1..3).each do |column|
66
- self[row, column].reset
66
+ self[row, column].reset!
67
67
  end
68
68
  end
69
69
  @winning_sign = Cell::EMPTY
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -25,14 +25,14 @@ class TicTacToe
25
25
  attr_accessor :sign, :empty
26
26
 
27
27
  def initialize
28
- reset
28
+ reset!
29
29
  end
30
30
 
31
31
  def mark(sign)
32
32
  self.sign = sign
33
33
  end
34
34
 
35
- def reset
35
+ def reset!
36
36
  self.sign = EMPTY
37
37
  end
38
38
 
@@ -20,15 +20,15 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  class HelloButton
23
- include Glimmer
23
+ include Glimmer::UI::CustomShell
24
24
 
25
25
  attr_accessor :count
26
26
 
27
- def initialize
27
+ before_body {
28
28
  @count = 0
29
- end
29
+ }
30
30
 
31
- def launch
31
+ body {
32
32
  shell {
33
33
  text 'Hello, Button!'
34
34
 
@@ -39,8 +39,8 @@ class HelloButton
39
39
  self.count += 1
40
40
  }
41
41
  }
42
- }.open
43
- end
42
+ }
43
+ }
44
44
  end
45
45
 
46
- HelloButton.new.launch
46
+ HelloButton.launch
@@ -19,46 +19,148 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- include Glimmer
23
-
24
- shell {
25
- text 'Hello, Canvas Image Icon!'
26
- minimum_size 320, 400
27
-
28
- canvas {
29
- background :yellow
30
- rectangle(0, 0, 220, 400) {
31
- background :red
32
- }
33
- rectangle(50, 20, 300, 150, 30, 50) {
34
- background :magenta
35
- }
36
- rectangle(150, 200, 100, 70, true) {
37
- background :dark_magenta
38
- foreground :yellow
39
- }
40
- rectangle(50, 200, 30, 70, false) {
41
- background :magenta
42
- foreground :dark_blue
43
- }
44
- rectangle(205, 50, 88, 96) {
45
- foreground :yellow
46
- }
47
- text('Picasso', 60, 80) {
48
- background :yellow
49
- foreground :dark_magenta
50
- font name: 'Courier', height: 30
51
- }
52
- oval(110, 310, 100, 100) {
53
- # patterns provide a differnet way to make gradients
54
- background_pattern 0, 0, 105, 0, :yellow, rgb(128, 138, 248)
55
- }
56
- arc(210, 210, 100, 100, 30, -77) {
57
- background :red
58
- }
59
- polygon(250, 210, 260, 170, 270, 210, 290, 230) {
60
- background :dark_yellow
22
+ class HelloCanvas
23
+ include Glimmer::UI::CustomShell
24
+
25
+ attr_accessor :selected_shape
26
+
27
+ before_body {
28
+ @image_object = image(File.expand_path('../../icons/scaffold_app.png', __dir__), width: 50)
29
+ }
30
+
31
+ body {
32
+ shell {
33
+ text 'Hello, Canvas!'
34
+ minimum_size 320, 400
35
+
36
+ @canvas = canvas {
37
+ background :yellow
38
+ rectangle(0, 0, 220, 400) {
39
+ background :red
40
+ }
41
+ rectangle(50, 20, 300, 150, 30, 50) {
42
+ background :magenta
43
+ }
44
+ rectangle(150, 200, 100, 70, true) {
45
+ background :dark_magenta
46
+ foreground :yellow
47
+ }
48
+ rectangle(50, 200, 30, 70, false) {
49
+ background :magenta
50
+ foreground :dark_blue
51
+ }
52
+ rectangle(205, 50, 88, 96) {
53
+ foreground :yellow
54
+ }
55
+ text('Picasso', 60, 80) {
56
+ background :yellow
57
+ foreground :dark_magenta
58
+ font name: 'Courier', height: 30
59
+ }
60
+ oval(110, 310, 100, 100) {
61
+ # patterns provide a differnet way to make gradients
62
+ background_pattern 0, 0, 105, 0, :yellow, rgb(128, 138, 248)
63
+ }
64
+ arc(210, 210, 100, 100, 30, -77) {
65
+ background :red
66
+ }
67
+ polygon(250, 210, 260, 170, 270, 210, 290, 230) {
68
+ background :dark_yellow
69
+ }
70
+ polyline(250, 110, 260, 70, 270, 110, 290, 130, 250, 110)
71
+ 3.times { |n|
72
+ line(250, 120 + n*10, 270 + n*10, 80 + n*10) {
73
+ foreground :yellow
74
+ }
75
+ }
76
+ 10.times {|n|
77
+ point(220 + n*5, 100 + n*5) {
78
+ foreground :yellow
79
+ }
80
+ }
81
+ image(@image_object, 205, 55)
82
+
83
+ menu {
84
+ menu_item {
85
+ text 'Change Background Color...'
86
+ enabled bind(self, :selected_shape) {|shape| shape.respond_to?(:background) && shape.background }
87
+ on_widget_selected {
88
+ @selected_shape&.background = color_dialog.open
89
+ self.selected_shape = nil
90
+ }
91
+ }
92
+ menu_item {
93
+ text 'Change Background Pattern Color 1...'
94
+ enabled bind(self, :selected_shape) {|shape| shape.respond_to?(:background_pattern) && shape.background_pattern }
95
+ on_widget_selected {
96
+ if @selected_shape
97
+ background_pattern_args = @selected_shape.background_pattern_args
98
+ background_pattern_args[5] = color_dialog.open
99
+ @selected_shape.background_pattern = background_pattern_args
100
+ self.selected_shape = nil
101
+ end
102
+ }
103
+ }
104
+ menu_item {
105
+ text 'Change Background Pattern Color 2...'
106
+ enabled bind(self, :selected_shape) {|shape| shape.respond_to?(:background_pattern) && shape.background_pattern }
107
+ on_widget_selected {
108
+ if @selected_shape
109
+ background_pattern_args = @selected_shape.background_pattern_args
110
+ background_pattern_args[6] = color_dialog.open
111
+ @selected_shape.background_pattern = background_pattern_args
112
+ self.selected_shape = nil
113
+ end
114
+ }
115
+ }
116
+ menu_item(:separator)
117
+ menu_item {
118
+ text 'Change Foreground Color...'
119
+ enabled bind(self, :selected_shape) {|shape| shape.respond_to?(:foreground) && shape.foreground }
120
+ on_widget_selected {
121
+ @selected_shape&.foreground = color_dialog.open
122
+ self.selected_shape = nil
123
+ }
124
+ }
125
+ }
126
+
127
+ on_mouse_down { |mouse_event|
128
+ @drag_detected = false
129
+ @canvas.cursor = :hand
130
+ self.selected_shape = @canvas.shape_at_location(mouse_event.x, mouse_event.y)
131
+ }
132
+
133
+ on_drag_detected { |drag_detect_event|
134
+ @drag_detected = true
135
+ @drag_current_x = drag_detect_event.x
136
+ @drag_current_y = drag_detect_event.y
137
+ }
138
+
139
+ on_mouse_move { |mouse_event|
140
+ if @drag_detected
141
+ @selected_shape&.move_by(mouse_event.x - @drag_current_x, mouse_event.y - @drag_current_y)
142
+ @drag_current_x = mouse_event.x
143
+ @drag_current_y = mouse_event.y
144
+ end
145
+ }
146
+
147
+ on_menu_detected { |menu_detect_event|
148
+ @menu_detected = true
149
+ }
150
+
151
+ on_mouse_up { |mouse_event|
152
+ @canvas.cursor = :arrow
153
+ @drag_detected = false
154
+ if @menu_detected
155
+ @menu_detected = nil
156
+ else
157
+ self.selected_shape = nil
158
+ end
159
+ }
160
+ }
61
161
  }
62
- polyline(250, 110, 260, 70, 270, 110, 290, 130, 250, 110)
63
162
  }
64
- }.open
163
+ end
164
+
165
+ HelloCanvas.launch
166
+
@@ -24,10 +24,10 @@ class HelloCheckbox
24
24
  attr_accessor :skiing, :snowboarding, :snowmobiling, :snowshoeing
25
25
 
26
26
  def initialize
27
- reset_activities
27
+ reset_activities!
28
28
  end
29
29
 
30
- def reset_activities
30
+ def reset_activities!
31
31
  self.skiing = false
32
32
  self.snowboarding = true
33
33
  self.snowmobiling = false
@@ -35,11 +35,13 @@ class HelloCheckbox
35
35
  end
36
36
  end
37
37
 
38
- include Glimmer
38
+ include Glimmer::UI::CustomShell
39
39
 
40
- def launch
41
- person = Person.new
42
-
40
+ before_body {
41
+ @person = Person.new
42
+ }
43
+
44
+ body {
43
45
  shell {
44
46
  text 'Hello, Checkbox!'
45
47
  row_layout :vertical
@@ -52,22 +54,22 @@ class HelloCheckbox
52
54
  composite {
53
55
  checkbox {
54
56
  text 'Skiing'
55
- selection bind(person, :skiing)
57
+ selection bind(@person, :skiing)
56
58
  }
57
59
 
58
60
  checkbox {
59
61
  text 'Snowboarding'
60
- selection bind(person, :snowboarding)
62
+ selection bind(@person, :snowboarding)
61
63
  }
62
64
 
63
65
  checkbox {
64
66
  text 'Snowmobiling'
65
- selection bind(person, :snowmobiling)
67
+ selection bind(@person, :snowmobiling)
66
68
  }
67
69
 
68
70
  checkbox {
69
71
  text 'Snowshoeing'
70
- selection bind(person, :snowshoeing)
72
+ selection bind(@person, :snowshoeing)
71
73
  }
72
74
  }
73
75
 
@@ -75,11 +77,11 @@ class HelloCheckbox
75
77
  text 'Reset Activities'
76
78
 
77
79
  on_widget_selected do
78
- person.reset_activities
80
+ @person.reset_activities!
79
81
  end
80
82
  }
81
- }.open
82
- end
83
+ }
84
+ }
83
85
  end
84
86
 
85
- HelloCheckbox.new.launch
87
+ HelloCheckbox.launch
@@ -39,11 +39,13 @@ class HelloCheckboxGroup
39
39
  end
40
40
  end
41
41
 
42
- include Glimmer
42
+ include Glimmer::UI::CustomShell
43
43
 
44
- def launch
45
- person = Person.new
46
-
44
+ before_body {
45
+ @person = Person.new
46
+ }
47
+
48
+ body {
47
49
  shell {
48
50
  text 'Hello, Checkbox Group!'
49
51
  row_layout :vertical
@@ -54,18 +56,18 @@ class HelloCheckboxGroup
54
56
  }
55
57
 
56
58
  checkbox_group {
57
- selection bind(person, :activities)
59
+ selection bind(@person, :activities)
58
60
  }
59
61
 
60
62
  button {
61
63
  text 'Reset Activities'
62
64
 
63
65
  on_widget_selected do
64
- person.reset_activities
66
+ @person.reset_activities
65
67
  end
66
68
  }
67
- }.open
68
- end
69
+ }
70
+ }
69
71
  end
70
72
 
71
- HelloCheckboxGroup.new.launch
73
+ HelloCheckboxGroup.launch