glimmer-dsl-swt 4.20.15.5 → 4.21.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/README.md +15 -10
  4. data/RUBY_VERSION +1 -1
  5. data/VERSION +1 -1
  6. data/docs/reference/GLIMMER_COMMAND.md +1 -1
  7. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +0 -2
  8. data/docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md +87 -91
  9. data/glimmer-dsl-swt.gemspec +0 -0
  10. data/lib/glimmer/data_binding/widget_binding.rb +3 -3
  11. data/lib/glimmer/rake_task/package.rb +20 -22
  12. data/lib/glimmer/rake_task/scaffold.rb +45 -28
  13. data/lib/glimmer/swt/image_proxy.rb +3 -3
  14. data/lib/glimmer/swt/shell_proxy.rb +6 -4
  15. data/lib/glimmer/swt/widget_proxy.rb +4 -0
  16. data/samples/elaborate/battleship/view/grid.rb +3 -3
  17. data/samples/elaborate/battleship/view/ship.rb +1 -1
  18. data/samples/elaborate/meta_sample.rb +12 -5
  19. data/samples/elaborate/tetris/view/tetris_menu_bar.rb +2 -2
  20. data/samples/elaborate/tetris.rb +12 -14
  21. data/samples/elaborate/tic_tac_toe.rb +6 -3
  22. data/samples/elaborate/timer.rb +0 -1
  23. data/samples/elaborate/weather.rb +3 -0
  24. data/samples/hello/hello_canvas.rb +1 -1
  25. data/samples/hello/hello_canvas_transform.rb +1 -1
  26. data/samples/hello/hello_cool_bar.rb +5 -60
  27. data/samples/hello/hello_scale.rb +1 -4
  28. data/samples/hello/hello_slider.rb +1 -4
  29. data/samples/hello/hello_tool_bar.rb +7 -53
  30. data/samples/hello/images/copy.png +0 -0
  31. data/samples/hello/images/cut.png +0 -0
  32. data/samples/hello/images/paste.png +0 -0
  33. data/vendor/swt/linux/swt.jar +0 -0
  34. data/vendor/swt/linux_aarch64/swt.jar +0 -0
  35. data/vendor/swt/mac/swt.jar +0 -0
  36. data/vendor/swt/mac_aarch64/swt.jar +0 -0
  37. data/vendor/swt/windows/swt.jar +0 -0
  38. metadata +23 -7
@@ -167,20 +167,25 @@ module Glimmer
167
167
  custom_shell('AppView', current_dir_name, shell_type)
168
168
  end
169
169
 
170
- mkdir_p 'package/windows'
171
- icon_file = "package/windows/#{human_name(app_name)}.ico"
170
+ mkdir_p 'icons/windows'
171
+ icon_file = "icons/windows/#{human_name(app_name)}.ico"
172
172
  cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file
173
173
  puts "Created #{current_dir_name}/#{icon_file}"
174
174
 
175
- mkdir_p 'package/macosx'
176
- icon_file = "package/macosx/#{human_name(app_name)}.icns"
175
+ mkdir_p 'icons/macosx'
176
+ icon_file = "icons/macosx/#{human_name(app_name)}.icns"
177
177
  cp File.expand_path('../../../../icons/scaffold_app.icns', __FILE__), icon_file
178
178
  puts "Created #{current_dir_name}/#{icon_file}"
179
179
 
180
- mkdir_p 'package/linux'
181
- icon_file = "package/linux/#{human_name(app_name)}.png"
180
+ mkdir_p 'icons/linux'
181
+ icon_file = "icons/linux/#{human_name(app_name)}.png"
182
182
  cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
183
183
  puts "Created #{current_dir_name}/#{icon_file}"
184
+
185
+ write "Resource.java", resource_java_file(app_name)
186
+ cd '..'
187
+ system "javac #{file_name(app_name)}/Resource.java"
188
+ cd gem_name
184
189
 
185
190
  mkdir_p "app/#{file_name(app_name)}"
186
191
  write "app/#{file_name(app_name)}/launch.rb", app_launch_file(app_name)
@@ -195,14 +200,14 @@ module Glimmer
195
200
  end
196
201
  write 'spec/spec_helper.rb', spec_helper_file
197
202
  if OS.windows?
198
- system "glimmer \"package[image]\"" # TODO handle Windows with batch file
203
+ system "glimmer package" # TODO handle Windows with batch file
199
204
  system "\"packages/bundles/#{human_name(app_name)}/#{human_name(app_name)}.exe\""
200
205
  else
201
206
  system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer package\n'"
202
207
  if OS.mac?
203
- system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
208
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n JRUBY_OPTS=\"$JRUBY_OPTS -J-XstartOnFirstThread\" glimmer run\n'"
204
209
  else
205
- system "glimmer run"
210
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer run\n'"
206
211
  end
207
212
  end
208
213
  end
@@ -278,30 +283,35 @@ module Glimmer
278
283
  end
279
284
  write 'spec/spec_helper.rb', spec_helper_file
280
285
 
281
- mkdir_p 'package/windows'
282
- icon_file = "package/windows/#{human_name(custom_shell_name)}.ico"
286
+ mkdir_p 'icons/windows'
287
+ icon_file = "icons/windows/#{human_name(custom_shell_name)}.ico"
283
288
  cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file
284
289
  puts "Created #{current_dir_name}/#{icon_file}"
285
290
 
286
- mkdir_p 'package/macosx'
287
- icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
291
+ mkdir_p 'icons/macosx'
292
+ icon_file = "icons/macosx/#{human_name(custom_shell_name)}.icns"
288
293
  cp File.expand_path('../../../../icons/scaffold_app.icns', __FILE__), icon_file
289
294
  puts "Created #{current_dir_name}/#{icon_file}"
290
295
 
291
- mkdir_p 'package/linux'
292
- icon_file = "package/linux/#{human_name(custom_shell_name)}.png"
296
+ mkdir_p 'icons/linux'
297
+ icon_file = "icons/linux/#{human_name(custom_shell_name)}.png"
293
298
  cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
294
299
  puts "Created #{current_dir_name}/#{icon_file}"
295
300
 
301
+ write "Resource.java", resource_java_file(custom_shell_name)
302
+ cd '..'
303
+ system "javac #{file_name(custom_shell_name)}/Resource.java"
304
+ cd gem_name
305
+
296
306
  if OS.windows?
297
- system "glimmer package[image]" # TODO handle windows properly with batch file
307
+ system "glimmer package" # TODO handle windows properly with batch file
298
308
  system "\"packages/bundles/#{human_name(custom_shell_name)}/#{human_name(custom_shell_name)}.exe\""
299
309
  else
300
310
  system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer package\n'"
301
311
  if OS.mac?
302
- system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app"
312
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n JRUBY_OPTS=\"$JRUBY_OPTS -J-XstartOnFirstThread\" glimmer run\n'"
303
313
  else
304
- system "glimmer run"
314
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer run\n'"
305
315
  end
306
316
  end
307
317
  puts "Finished creating #{gem_name} Ruby gem."
@@ -485,6 +495,16 @@ module Glimmer
485
495
  #{class_name(app_name)}::View::AppView.launch
486
496
  MULTI_LINE_STRING
487
497
  end
498
+
499
+ def resource_java_file(app_name)
500
+ <<~MULTI_LINE_STRING
501
+ package #{file_name(app_name)};
502
+
503
+ /** The soul purpose of this class is to retrieve icons for uri:classloader paths used from JAR */
504
+ class Resource {
505
+ }
506
+ MULTI_LINE_STRING
507
+ end
488
508
 
489
509
  def app_bin_command_file(app_name_or_gem_name, custom_shell_name=nil, namespace=nil)
490
510
  if custom_shell_name.nil?
@@ -525,7 +545,7 @@ module Glimmer
525
545
  lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
526
546
  gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
527
547
  if custom_shell_name
528
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'app/**/*', 'bin/**/*', 'config/**/*', 'db/**/*', 'docs/**/*', 'fonts/**/*', 'icons/**/*', 'images/**/*', 'lib/**/*', 'package/**/*', 'script/**/*', 'sounds/**/*', 'vendor/**/*', 'videos/**/*']")
548
+ lines.insert(gem_files_line_index, " gem.files = Dir['Resource.class', 'VERSION', 'LICENSE.txt', 'app/**/*', 'bin/**/*', 'config/**/*', 'db/**/*', 'docs/**/*', 'fonts/**/*', 'icons/**/*', 'images/**/*', 'lib/**/*', 'script/**/*', 'sounds/**/*', 'vendor/**/*', 'videos/**/*']")
529
549
  # the second executable is needed for warbler as it matches the gem name, which is the default expected file (alternatively in the future, we could do away with it and configure warbler to use the other file)
530
550
  lines.insert(gem_files_line_index+1, " gem.require_paths = ['vendor', 'lib', 'app']")
531
551
  lines.insert(gem_files_line_index+2, " gem.executables = ['#{file_name(custom_shell_name)}']") if custom_shell_name
@@ -538,14 +558,10 @@ module Glimmer
538
558
  file_content = lines.join("\n")
539
559
  if custom_shell_name
540
560
  file_content << <<~MULTI_LINE_STRING
541
- Glimmer::RakeTask::Package.javapackager_extra_args =
542
- " -name '#{human_name(custom_shell_name)}'" +
543
- " -title '#{human_name(custom_shell_name)}'" +
544
- " -Bmac.CFBundleName='#{human_name(custom_shell_name)}'" +
545
- " -Bmac.CFBundleIdentifier='org.#{namespace ? compact_name(namespace) : compact_name(custom_shell_name)}.application.#{compact_name(custom_shell_name).camelcase(:upper)}'"
546
- # " -BlicenseType=" +
547
- # " -Bmac.category=" +
548
- # " -Bmac.signing-key-developer-id-app="
561
+ Glimmer::RakeTask::Package.jpackage_extra_args =
562
+ " --name '#{human_name(custom_shell_name)}'" +
563
+ " --description '#{human_name(custom_shell_name)}'"
564
+ # You can add more options from https://docs.oracle.com/en/java/javase/14/jpackage/packaging-tool-user-guide.pdf
549
565
  MULTI_LINE_STRING
550
566
  end
551
567
  file_content
@@ -643,7 +659,8 @@ module Glimmer
643
659
  shell#{'(:fill_screen)' if shell_type == :desktopify} {
644
660
  # Replace example content below with custom shell content
645
661
  minimum_size #{shell_type == :desktopify ? '768, 432' : '420, 240'}
646
- image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
662
+ image File.join(APP_ROOT, 'icons', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
663
+ image File.join(APP_ROOT, 'icons', 'linux', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.png") unless OS.windows?
647
664
  text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
648
665
 
649
666
  MULTI_LINE_STRING
@@ -122,9 +122,9 @@ module Glimmer
122
122
  def input_stream
123
123
  if @file_path.start_with?('uri:classloader')
124
124
  @jar_file_path = @file_path
125
- file_path = @jar_file_path.sub(/^uri\:classloader\:/, '').sub('//', '/') # the latter sub is needed for Mac
126
- object = java.lang.Object.new
127
- file_input_stream = object.java_class.resource_as_stream(file_path)
125
+ file_path = @jar_file_path.sub(/^uri\:classloader\:/, '').sub('//', '') # the latter sub is needed for Mac
126
+ project_name = java.lang.System.getProperty('project_name')
127
+ file_input_stream = java_import("#{project_name}.Resource").last.java_class.resource_as_stream(file_path)
128
128
  else
129
129
  file_input_stream = java.io.FileInputStream.new(@file_path)
130
130
  end
@@ -32,10 +32,11 @@ module Glimmer
32
32
  include_package 'org.eclipse.swt.widgets'
33
33
  include_package 'org.eclipse.swt.layout'
34
34
 
35
- WIDTH_MIN = 130
35
+ WIDTH_MIN = 190
36
36
  HEIGHT_MIN = 0
37
37
 
38
- attr_reader :opened_before
38
+ attr_reader :opened_before, :last_shell_closing
39
+ alias last_shell_closing? last_shell_closing
39
40
  alias opened_before? opened_before
40
41
 
41
42
  # Instantiates ShellProxy with same arguments expected by SWT Shell
@@ -85,9 +86,10 @@ module Glimmer
85
86
  end
86
87
  end
87
88
  end
88
- on_widget_disposed {
89
+ on_widget_disposed do
90
+ @last_shell_closing = true if @display.shells.count == 1 && @display.shells.first == @swt_widget
89
91
  clear_shapes
90
- }
92
+ end
91
93
  @display ||= @swt_widget.getDisplay
92
94
  end
93
95
  end
@@ -198,6 +198,10 @@ module Glimmer
198
198
  @finished_add_content = true
199
199
  end
200
200
 
201
+ def shell_proxy
202
+ @swt_widget.shell.get_data('proxy')
203
+ end
204
+
201
205
  def extract_args(underscored_widget_name, args)
202
206
  @arg_extractor_mapping ||= {
203
207
  'menu_item' => lambda do |args|
@@ -45,21 +45,21 @@ class Battleship
45
45
  }
46
46
 
47
47
  text player.to_s.capitalize
48
- font height: 20, style: :bold
48
+ font height: OS.windows? ? 18 : 20, style: :bold
49
49
  }
50
50
 
51
51
  label # filler
52
52
  Model::Grid::WIDTH.times do |column_index|
53
53
  label {
54
54
  text (column_index + 1).to_s
55
- font height: 16
55
+ font height: OS.windows? ? 14 : 16
56
56
  }
57
57
  end
58
58
 
59
59
  Model::Grid::HEIGHT.times do |row_index|
60
60
  label {
61
61
  text Model::Grid::ROW_ALPHABETS[row_index]
62
- font height: 16
62
+ font height: OS.windows? ? 14 : 16
63
63
  }
64
64
  Model::Grid::WIDTH.times do |column_index|
65
65
  cell(game: game, player: player, row_index: row_index, column_index: column_index) {
@@ -38,7 +38,7 @@ class Battleship
38
38
 
39
39
  label {
40
40
  text ship_name.to_s.titlecase
41
- font height: 16
41
+ font height: OS.windows? ? 14 : 16
42
42
  }
43
43
 
44
44
  composite {
@@ -23,8 +23,6 @@ require 'glimmer-dsl-swt'
23
23
  require 'fileutils'
24
24
 
25
25
  class Sample
26
- include Glimmer::DataBinding::ObservableModel
27
-
28
26
  class << self
29
27
  def glimmer_directory
30
28
  File.expand_path('../../..', __FILE__)
@@ -42,6 +40,10 @@ class Sample
42
40
  end
43
41
  end
44
42
  end
43
+
44
+ include Glimmer::DataBinding::ObservableModel
45
+
46
+ UNEDITABLE = ['meta_sample.rb'] + (OS.windows? ? ['calculator.rb', 'weather.rb'] : []) # Windows StyledText does not support unicode characters found in certain samples
45
47
 
46
48
  attr_accessor :sample_directory, :file, :selected
47
49
 
@@ -74,9 +76,13 @@ class Sample
74
76
  end
75
77
 
76
78
  def editable
79
+ !UNEDITABLE.include?(File.basename(file))
80
+ end
81
+ alias editable? editable
82
+
83
+ def launchable
77
84
  File.basename(file) != 'meta_sample.rb'
78
85
  end
79
- alias launchable editable
80
86
 
81
87
  def file_relative_path
82
88
  file.sub(self.class.glimmer_directory, '')
@@ -97,6 +103,7 @@ class Sample
97
103
  def launch(modified_code)
98
104
  launch_file = user_file
99
105
  begin
106
+ raise 'Unsupported through editor!' unless editable?
100
107
  FileUtils.cp_r(file, user_file_parent_directory)
101
108
  FileUtils.cp_r(directory, user_file_parent_directory) if File.exist?(directory)
102
109
  File.write(user_file, modified_code)
@@ -202,12 +209,12 @@ class MetaSampleApplication
202
209
 
203
210
  body {
204
211
  shell(:fill_screen) {
205
- minimum_size 1280, 768
212
+ minimum_size 640, 384
206
213
  text 'Glimmer Meta-Sample (The Sample of Samples)'
207
214
  image File.expand_path('../../icons/scaffold_app.png', __dir__)
208
215
 
209
216
  sash_form {
210
- weights 4, 14
217
+ weights 1, 2
211
218
 
212
219
  composite {
213
220
  grid_layout(1, false) {
@@ -45,8 +45,8 @@ class Tetris
45
45
  menu_item(:check) {
46
46
  text '&Pause'
47
47
  accelerator COMMAND_KEY, :p
48
- enabled <= [game, :game_over, on_read: ->(value) { value && !game.show_high_scores }]
49
- enabled <= [game, :show_high_scores, on_read: ->(value) { value && !game.game_over }]
48
+ enabled <= [game, :game_over, on_read: ->(value) { !value && !game.show_high_scores }]
49
+ enabled <= [game, :show_high_scores, on_read: ->(value) { !value && !game.game_over }]
50
50
  selection <=> [game, :paused]
51
51
  }
52
52
  menu_item {
@@ -57,7 +57,17 @@ class Tetris
57
57
  on_swt_keydown { |key_event|
58
58
  case key_event.keyCode
59
59
  when swt(:arrow_down), 's'.bytes.first
60
- game.down! if OS.mac?
60
+ if OS.mac?
61
+ game.down!
62
+ else
63
+ # rate limit downs in Windows/Linux as they go too fast when key is held
64
+ @queued_downs ||= 0
65
+ @queued_downs += 1
66
+ async_exec do
67
+ game.down! if @queued_downs < 3
68
+ @queued_downs -= 1
69
+ end
70
+ end
61
71
  when swt(:arrow_up)
62
72
  case game.up_arrow_action
63
73
  when :instant_down
@@ -80,16 +90,6 @@ class Tetris
80
90
  end
81
91
  }
82
92
 
83
- # invoke game.down! on keyup with Windows/Linux since they seem to group-render similar events, preventing intermediate renders (causing invisiblity while holding keys)
84
- if !OS.mac?
85
- on_swt_keyup { |key_event|
86
- case key_event.keyCode
87
- when swt(:arrow_down), 's'.bytes.first
88
- game.down!
89
- end
90
- }
91
- end
92
-
93
93
  # if running in app mode, set the Mac app about dialog (ignored in platforms)
94
94
  on_about {
95
95
  show_about_dialog
@@ -170,9 +170,7 @@ class Tetris
170
170
  sleep @game.delay
171
171
  break if @game.game_over? || body_root.disposed?
172
172
  # ensure entire game tetromino down movement happens as one GUI update event with sync_exec (to avoid flicker/stutter)
173
- sync_exec {
174
- @game.down! unless @game.paused?
175
- }
173
+ sync_exec { @game.down! unless @game.paused? }
176
174
  end
177
175
  end
178
176
  end
@@ -41,18 +41,21 @@ class TicTacToe
41
41
  shell {
42
42
  text "Tic-Tac-Toe"
43
43
  minimum_size 176, 200
44
+
44
45
  composite {
45
46
  grid_layout 3, true
47
+
46
48
  (1..3).each { |row|
47
49
  (1..3).each { |column|
48
50
  button {
49
51
  layout_data :fill, :fill, true, true
50
52
  text <= [@tic_tac_toe_board[row, column], :sign]
51
53
  enabled <= [@tic_tac_toe_board[row, column], :empty]
52
- font style: :bold, height: 20
53
- on_widget_selected {
54
+ font style: :bold, height: (OS.windows? ? 18 : 20)
55
+
56
+ on_widget_selected do
54
57
  @tic_tac_toe_board.mark(row, column)
55
- }
58
+ end
56
59
  }
57
60
  }
58
61
  }
@@ -67,7 +67,6 @@ class Timer
67
67
 
68
68
  # Replace example content below with custom shell content
69
69
  minimum_size (OS.windows? ? 214 : 200), 114
70
- image File.join(APP_ROOT, 'package', 'windows', "Timer.ico") if OS.windows?
71
70
  text "Glimmer Timer"
72
71
 
73
72
  timer_menu_bar
@@ -102,6 +102,7 @@ class Weather
102
102
  layout_data(:fill, :center, true, false)
103
103
  text <= [self, field_name, on_read: ->(t) { "#{kelvin_to_temp_unit(t, temp_unit).to_f.round}°" }]
104
104
  font height: DEFAULT_FONT_HEIGHT
105
+ background DEFAULT_BACKGROUND
105
106
  foreground DEFAULT_FOREGROUND
106
107
  }
107
108
  end
@@ -112,6 +113,7 @@ class Weather
112
113
  layout_data(:fill, :center, true, false)
113
114
  text <= [self, 'humidity', on_read: ->(h) { "#{h.to_f.round}%" }]
114
115
  font height: DEFAULT_FONT_HEIGHT
116
+ background DEFAULT_BACKGROUND
115
117
  foreground DEFAULT_FOREGROUND
116
118
  }
117
119
  end
@@ -121,6 +123,7 @@ class Weather
121
123
  layout_data :fill, :center, false, false
122
124
  text field_name.titlecase
123
125
  font height: DEFAULT_FONT_HEIGHT
126
+ background DEFAULT_BACKGROUND
124
127
  foreground DEFAULT_FOREGROUND
125
128
  }
126
129
  end
@@ -65,7 +65,7 @@ class HelloCanvas
65
65
  y :default, 1 # add 1 pixel to default y (shape centered within parent vertically)
66
66
  background :yellow
67
67
  foreground :dark_magenta
68
- font name: 'Courier', height: 30
68
+ font name: 'Courier', height: (OS.windows? ? 26 : 30)
69
69
  }
70
70
  }
71
71
  rectangle(155, 30) { # width and height are assumed to be the default (calculated from children)
@@ -6,7 +6,7 @@ glimmer_logo = File.expand_path('../../icons/scaffold_app.png', __dir__)
6
6
 
7
7
  shell {
8
8
  text 'Hello, Canvas Transform!'
9
- minimum_size 330, 352
9
+ minimum_size (OS.windows? ? 347 : 330), (OS.windows? ? 372 : 352)
10
10
 
11
11
  canvas {
12
12
  background :white
@@ -40,27 +40,28 @@ class HelloCoolBar
40
40
  margin_width 0
41
41
  margin_height 0
42
42
  }
43
-
43
+
44
44
  text 'Hello, Cool Bar!'
45
+ minimum_size 280, 50
45
46
 
46
47
  cool_bar { # optionally takes a :flat style and/or :vertical style if you need vertical layout
47
48
  tool_bar {
48
49
  tool_item {
49
- image cut_image # alternatively you can pass an image file path
50
+ image File.expand_path('./images/cut.png', __dir__), height: 16
50
51
 
51
52
  on_widget_selected do
52
53
  self.operation = 'Cut'
53
54
  end
54
55
  }
55
56
  tool_item {
56
- image copy_image # alternatively you can pass an image file path
57
+ image File.expand_path('./images/copy.png', __dir__), height: 16
57
58
 
58
59
  on_widget_selected do
59
60
  self.operation = 'Copy'
60
61
  end
61
62
  }
62
63
  tool_item {
63
- image paste_image # alternatively you can pass an image file path
64
+ image File.expand_path('./images/paste.png', __dir__), height: 16
64
65
 
65
66
  on_widget_selected do
66
67
  self.operation = 'Paste'
@@ -86,62 +87,6 @@ class HelloCoolBar
86
87
  }
87
88
  }
88
89
  }
89
-
90
- def cut_image
91
- # building image on the fly with Canvas Shape DSL
92
- image(25, 25) {
93
- rectangle(0, 0, 25, 25) {
94
- background_pattern 0, 0, 0, 25, :white, :gray
95
- line(20, 2, 9, 15) {
96
- line_width 2
97
- }
98
- line(5, 2, 16, 15) {
99
- line_width 2
100
- }
101
- oval(2, 15, 8, 8) {
102
- line_width 2
103
- }
104
- oval(16, 15, 8, 8) {
105
- line_width 2
106
- }
107
- }
108
- }
109
- end
110
-
111
- def copy_image
112
- # building image on the fly with Canvas Shape DSL
113
- image(25, 25) {
114
- rectangle(0, 0, 25, 25) {
115
- background_pattern 0, 0, 0, 25, :white, :gray
116
- rectangle([:default, 2], [:default, -2], 14, 14, 5, 5) {
117
- line_width 2
118
- }
119
- rectangle([:default, -2], [:default, 2], 14, 14, 5, 5) {
120
- line_width 2
121
- }
122
- }
123
- }
124
- end
125
-
126
- def paste_image
127
- image(25, 25) {
128
- rectangle(0, 0, 25, 25) {
129
- background_pattern 0, 0, 0, 25, :white, :gray
130
- rectangle(:default, [:default, 1], 15, 20, 5, 5) {
131
- line_width 2
132
- }
133
- line(7, 8, 18, 8) {
134
- line_width 2
135
- }
136
- line(7, 13, 18, 13) {
137
- line_width 2
138
- }
139
- line(7, 18, 18, 18) {
140
- line_width 2
141
- }
142
- }
143
- }
144
- end
145
90
  end
146
91
 
147
92
  HelloCoolBar.launch
@@ -32,10 +32,7 @@ class HelloScale
32
32
 
33
33
  body {
34
34
  shell {
35
- row_layout(:vertical) {
36
- fill true
37
- center true
38
- }
35
+ fill_layout :vertical
39
36
 
40
37
  text 'Hello, Scale!'
41
38
 
@@ -32,10 +32,7 @@ class HelloSlider
32
32
 
33
33
  body {
34
34
  shell {
35
- row_layout(:vertical) {
36
- fill true
37
- center true
38
- }
35
+ fill_layout :vertical
39
36
 
40
37
  text 'Hello, Slider!'
41
38
 
@@ -42,33 +42,31 @@ class HelloToolBar
42
42
  }
43
43
 
44
44
  text 'Hello, Tool Bar!'
45
+ minimum_size 280, 50
45
46
 
46
47
  tool_bar { # optionally takes a :flat style, :wrap style if you need wrapping upon shrinking window, and :vertical style if you need vertical layout
47
48
  tool_item {
48
- image cut_image # alternatively you can pass an image file path
49
+ image File.expand_path('./images/cut.png', __dir__), height: 16
49
50
 
50
51
  on_widget_selected do
51
52
  self.operation = 'Cut'
52
53
  end
53
54
  }
54
55
  tool_item {
55
- image copy_image # alternatively you can pass an image file path
56
+ image File.expand_path('./images/copy.png', __dir__), height: 16
56
57
 
57
58
  on_widget_selected do
58
59
  self.operation = 'Copy'
59
60
  end
60
61
  }
61
62
  tool_item {
62
- image paste_image # alternatively you can pass an image file path
63
+ image File.expand_path('./images/paste.png', __dir__), height: 16
63
64
 
64
65
  on_widget_selected do
65
66
  self.operation = 'Paste'
66
67
  end
67
68
  }
68
69
  tool_item(:separator)
69
- tool_item {
70
- text 'Font Size'
71
- }
72
70
  # a combo can be nested in a tool_bar (it auto-generates a tool_item for itself behind the scenes)
73
71
  combo {
74
72
  selection <=> [self, :font_size]
@@ -84,59 +82,15 @@ class HelloToolBar
84
82
  }
85
83
 
86
84
  def cut_image
87
- # building image on the fly with Canvas Shape DSL
88
- image(25, 25) {
89
- rectangle(0, 0, 25, 25) {
90
- background_pattern 0, 0, 0, 25, :white, :gray
91
- line(20, 2, 9, 15) {
92
- line_width 2
93
- }
94
- line(5, 2, 16, 15) {
95
- line_width 2
96
- }
97
- oval(2, 15, 8, 8) {
98
- line_width 2
99
- }
100
- oval(16, 15, 8, 8) {
101
- line_width 2
102
- }
103
- }
104
- }
85
+ File.expand_path('./images/cut.png', __dir__)
105
86
  end
106
87
 
107
88
  def copy_image
108
- # building image on the fly with Canvas Shape DSL
109
- image(25, 25) {
110
- rectangle(0, 0, 25, 25) {
111
- background_pattern 0, 0, 0, 25, :white, :gray
112
- rectangle([:default, 2], [:default, -2], 14, 14, 5, 5) {
113
- line_width 2
114
- }
115
- rectangle([:default, -2], [:default, 2], 14, 14, 5, 5) {
116
- line_width 2
117
- }
118
- }
119
- }
89
+ File.expand_path('./images/copy.png', __dir__)
120
90
  end
121
91
 
122
92
  def paste_image
123
- image(25, 25) {
124
- rectangle(0, 0, 25, 25) {
125
- background_pattern 0, 0, 0, 25, :white, :gray
126
- rectangle(:default, [:default, 1], 15, 20, 5, 5) {
127
- line_width 2
128
- }
129
- line(7, 8, 18, 8) {
130
- line_width 2
131
- }
132
- line(7, 13, 18, 13) {
133
- line_width 2
134
- }
135
- line(7, 18, 18, 18) {
136
- line_width 2
137
- }
138
- }
139
- }
93
+ File.expand_path('./images/paste.png', __dir__)
140
94
  end
141
95
  end
142
96
 
Binary file
Binary file
Binary file
Binary file