shoes-swt 4.0.0.pre6 → 4.0.0.pre7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +1 -1
  3. data/lib/shoes/swt.rb +8 -0
  4. data/lib/shoes/swt/app.rb +5 -7
  5. data/lib/shoes/swt/arc.rb +3 -28
  6. data/lib/shoes/swt/arc_painter.rb +34 -0
  7. data/lib/shoes/swt/arrow.rb +35 -0
  8. data/lib/shoes/swt/arrow_painter.rb +59 -0
  9. data/lib/shoes/swt/background.rb +1 -0
  10. data/lib/shoes/swt/border.rb +1 -0
  11. data/lib/shoes/swt/check_button.rb +17 -17
  12. data/lib/shoes/swt/click_listener.rb +6 -6
  13. data/lib/shoes/swt/common/painter.rb +4 -2
  14. data/lib/shoes/swt/common/translate.rb +15 -0
  15. data/lib/shoes/swt/{generate-backend.rb → generate_backend.rb} +1 -3
  16. data/lib/shoes/swt/gradient.rb +3 -4
  17. data/lib/shoes/swt/key_listener.rb +9 -7
  18. data/lib/shoes/swt/line.rb +5 -13
  19. data/lib/shoes/swt/line_painter.rb +16 -0
  20. data/lib/shoes/swt/link.rb +4 -0
  21. data/lib/shoes/swt/link_segment.rb +1 -1
  22. data/lib/shoes/swt/oval.rb +2 -21
  23. data/lib/shoes/swt/oval_painter.rb +27 -0
  24. data/lib/shoes/swt/packager.rb +1 -1
  25. data/lib/shoes/swt/radio_group.rb +1 -1
  26. data/lib/shoes/swt/rect.rb +1 -0
  27. data/lib/shoes/swt/rect_painter.rb +27 -9
  28. data/lib/shoes/swt/redrawing_aspect.rb +30 -17
  29. data/lib/shoes/swt/shape.rb +13 -18
  30. data/lib/shoes/swt/shape_painter.rb +13 -0
  31. data/lib/shoes/swt/shoes_layout.rb +1 -1
  32. data/lib/shoes/swt/slot.rb +12 -1
  33. data/lib/shoes/swt/sound.rb +21 -23
  34. data/lib/shoes/swt/star.rb +2 -46
  35. data/lib/shoes/swt/star_painter.rb +51 -0
  36. data/lib/shoes/swt/text_block.rb +4 -3
  37. data/lib/shoes/swt/text_block/fitter.rb +3 -4
  38. data/lib/shoes/swt/text_block/text_font_factory.rb +1 -1
  39. data/lib/shoes/swt/text_block/text_segment.rb +8 -3
  40. data/lib/shoes/swt/text_block/text_segment_collection.rb +1 -1
  41. data/lib/shoes/swt/text_block/text_style_factory.rb +1 -3
  42. data/lib/shoes/swt/timer.rb +1 -3
  43. data/lib/shoes/swt/version.rb +3 -1
  44. data/shoes-swt.gemspec +1 -1
  45. data/spec/shoes/cli_spec.rb +2 -2
  46. data/spec/shoes/swt/animation_spec.rb +4 -3
  47. data/spec/shoes/swt/app_spec.rb +17 -17
  48. data/spec/shoes/swt/arc_painter_spec.rb +80 -0
  49. data/spec/shoes/swt/arc_spec.rb +7 -68
  50. data/spec/shoes/swt/arrow_painter_spec.rb +37 -0
  51. data/spec/shoes/swt/arrow_spec.rb +27 -0
  52. data/spec/shoes/swt/background_spec.rb +13 -11
  53. data/spec/shoes/swt/border_spec.rb +8 -5
  54. data/spec/shoes/swt/button_spec.rb +4 -4
  55. data/spec/shoes/swt/check_spec.rb +19 -8
  56. data/spec/shoes/swt/click_listener_spec.rb +1 -1
  57. data/spec/shoes/swt/common/painter_spec.rb +29 -14
  58. data/spec/shoes/swt/common/remove_spec.rb +2 -2
  59. data/spec/shoes/swt/dialog_spec.rb +1 -1
  60. data/spec/shoes/swt/flow_spec.rb +5 -3
  61. data/spec/shoes/swt/font_spec.rb +1 -1
  62. data/spec/shoes/swt/gradient_spec.rb +6 -3
  63. data/spec/shoes/swt/image_spec.rb +9 -9
  64. data/spec/shoes/swt/input_box_spec.rb +20 -15
  65. data/spec/shoes/swt/integration_spec.rb +1 -1
  66. data/spec/shoes/swt/key_listener_spec.rb +34 -33
  67. data/spec/shoes/swt/line_painter_spec.rb +26 -0
  68. data/spec/shoes/swt/line_spec.rb +2 -25
  69. data/spec/shoes/swt/link_segment_spec.rb +20 -18
  70. data/spec/shoes/swt/link_spec.rb +11 -8
  71. data/spec/shoes/swt/list_box_spec.rb +15 -11
  72. data/spec/shoes/swt/mouse_move_listener_spec.rb +55 -39
  73. data/spec/shoes/swt/oval_painter_spec.rb +40 -0
  74. data/spec/shoes/swt/oval_spec.rb +3 -34
  75. data/spec/shoes/swt/progress_spec.rb +2 -2
  76. data/spec/shoes/swt/radio_group_spec.rb +1 -1
  77. data/spec/shoes/swt/radio_spec.rb +7 -4
  78. data/spec/shoes/swt/rect_painter_spec.rb +13 -8
  79. data/spec/shoes/swt/rect_spec.rb +2 -4
  80. data/spec/shoes/swt/shape_painter_spec.rb +27 -0
  81. data/spec/shoes/swt/shape_spec.rb +7 -24
  82. data/spec/shoes/swt/shared_examples/clickable.rb +2 -2
  83. data/spec/shoes/swt/shared_examples/swt_app_context.rb +21 -12
  84. data/spec/shoes/swt/shell_control_listener_spec.rb +9 -9
  85. data/spec/shoes/swt/shoes_layout_spec.rb +18 -13
  86. data/spec/shoes/swt/slot_spec.rb +15 -4
  87. data/spec/shoes/swt/spec_helper.rb +1 -1
  88. data/spec/shoes/swt/star_painter_spec.rb +36 -0
  89. data/spec/shoes/swt/star_spec.rb +0 -25
  90. data/spec/shoes/swt/text_block/centered_text_segment_spec.rb +2 -2
  91. data/spec/shoes/swt/text_block/cursor_painter_spec.rb +17 -13
  92. data/spec/shoes/swt/text_block/fitter_spec.rb +25 -18
  93. data/spec/shoes/swt/text_block/painter_spec.rb +7 -4
  94. data/spec/shoes/swt/text_block/text_font_factory_spec.rb +3 -3
  95. data/spec/shoes/swt/text_block/text_segment_collection_spec.rb +22 -15
  96. data/spec/shoes/swt/text_block/text_segment_spec.rb +15 -12
  97. data/spec/shoes/swt/text_block_spec.rb +12 -10
  98. data/spec/spec_helper.rb +3 -1
  99. metadata +30 -8
@@ -13,7 +13,7 @@ describe Shoes::App do
13
13
  app = nil
14
14
  begin
15
15
  expect do
16
- app = Shoes.app do para 'me no fail' end
16
+ app = Shoes.app { para 'me no fail' }
17
17
  app.quit
18
18
  end.not_to raise_error
19
19
  ensure
@@ -4,8 +4,8 @@ require 'spec_helper'
4
4
  describe Shoes::Swt::Keypress do
5
5
  let(:app) { double('app', add_key_listener: nil, remove_key_listener: nil) }
6
6
  let(:dsl) { double('dsl') }
7
- let(:block) { proc { |key| key} }
8
- let(:key_listener) {Shoes::Swt::Keypress.new(dsl, app, &block)}
7
+ let(:block) { proc { |key| key } }
8
+ let(:key_listener) { Shoes::Swt::Keypress.new(dsl, app, &block) }
9
9
 
10
10
  describe '.get_swt_constant' do
11
11
  it 'gets the swt constant' do
@@ -39,7 +39,7 @@ describe Shoes::Swt::Keypress do
39
39
  SHIFT = ::Swt::SWT::SHIFT
40
40
  COMMAND = ::Swt::SWT::COMMAND
41
41
 
42
- subject {key_listener}
42
+ subject { key_listener }
43
43
 
44
44
  def test_character_press(character, state_modifier = 0, result_char = character)
45
45
  expect(block).to receive(:call).with(result_char)
@@ -275,75 +275,76 @@ describe Shoes::Swt::Keypress do
275
275
 
276
276
  describe 'Mac command key' do
277
277
  it 'fixes crash of shift option command #584' do
278
- event = double 'key event', stateMask: 196608,
279
- keyCode: 4194304,
278
+ event = double 'key event', stateMask: 196_608,
279
+ keyCode: 4_194_304,
280
280
  character: "don't care atm"
281
- expect {subject.handle_key_event(event)}.not_to raise_error
281
+ expect { subject.handle_key_event(event) }.not_to raise_error
282
282
  end
283
283
  end
284
284
 
285
285
  describe '#ignore_event?' do
286
- let(:character) {'a'}
287
- let(:event) {double 'key event',
288
- widget: widget,
289
- stateMask: 0,
290
- keyCode: keyCode,
291
- character: character.ord }
292
- let(:shell) {Java::OrgEclipseSwtWidgets::Shell.new}
293
- let(:style) {0}
294
- let(:keyCode) {character.downcase.ord}
295
-
296
- subject {key_listener.ignore_event? event}
286
+ let(:character) { 'a' }
287
+
288
+ let(:event) do
289
+ double 'key event', widget: widget, stateMask: 0, keyCode: keyCode,
290
+ character: character.ord
291
+ end
292
+
293
+ let(:shell) { Java::OrgEclipseSwtWidgets::Shell.new }
294
+ let(:style) { 0 }
295
+ let(:keyCode) { character.downcase.ord }
296
+
297
+ subject { key_listener.ignore_event? event }
297
298
 
298
299
  shared_examples_for 'ignores space and enter' do
299
300
  describe 'with a space' do
300
- let(:character) {' '}
301
- it {is_expected.to be_truthy}
301
+ let(:character) { ' ' }
302
+ it { is_expected.to be_truthy }
302
303
  end
303
304
 
304
305
  describe 'with enter' do
305
- let(:keyCode) {::Swt::SWT::CR}
306
- it {is_expected.to be_truthy}
306
+ let(:keyCode) { ::Swt::SWT::CR }
307
+ it { is_expected.to be_truthy }
307
308
  end
308
309
  end
309
310
 
310
311
  shared_examples_for 'accepts normal characters' do
311
312
  describe 'with a normal character' do
312
- let(:character) {'a'}
313
- it {is_expected.to be_falsey}
313
+ let(:character) { 'a' }
314
+ it { is_expected.to be_falsey }
314
315
  end
315
316
  end
316
317
 
317
318
  context 'on a Shell' do
318
- let(:widget) {shell}
319
- it {is_expected.to be_falsey}
319
+ let(:widget) { shell }
320
+ it { is_expected.to be_falsey }
320
321
 
321
322
  describe 'even with enter' do
322
- let(:keyCode) {::Swt::SWT::CR}
323
- it {is_expected.to be_falsey}
323
+ let(:keyCode) { ::Swt::SWT::CR }
324
+ it { is_expected.to be_falsey }
324
325
  end
325
326
  end
326
327
 
327
328
  context 'on a Text' do
328
- let(:widget) {Java::OrgEclipseSwtWidgets::Text.new(shell, style)}
329
- it {is_expected.to be_truthy}
329
+ let(:widget) { Java::OrgEclipseSwtWidgets::Text.new(shell, style) }
330
+ it { is_expected.to be_truthy }
330
331
  end
331
332
 
332
333
  context 'on a button' do
333
- let(:widget) {Java::OrgEclipseSwtWidgets::Button.new(shell, style)}
334
+ let(:widget) { Java::OrgEclipseSwtWidgets::Button.new(shell, style) }
334
335
 
335
336
  it_behaves_like 'ignores space and enter'
336
337
  it_behaves_like 'accepts normal characters'
337
338
  end
338
339
 
339
340
  context 'on a Combo' do
340
- let(:widget) {Java::OrgEclipseSwtWidgets::Combo.new(shell, style)}
341
+ let(:widget) { Java::OrgEclipseSwtWidgets::Combo.new(shell, style) }
341
342
 
342
343
  it_behaves_like 'ignores space and enter'
343
344
 
344
345
  describe 'with up' do
345
- let(:keyCode) {::Swt::SWT::ARROW_UP}
346
- it {is_expected.to be_truthy}
346
+ let(:keyCode) { ::Swt::SWT::ARROW_UP }
347
+ it { is_expected.to be_truthy }
347
348
  end
348
349
 
349
350
  it_behaves_like 'accepts normal characters'
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoes::Swt::LinePainter do
4
+ include_context "swt app"
5
+ include_context "painter context"
6
+
7
+ let(:dsl) { Shoes::Line.new shoes_app, parent, point_a, point_b }
8
+ let(:point_a) { Shoes::Point.new(10, 100) }
9
+ let(:point_b) { Shoes::Point.new(300, 10) }
10
+
11
+ let(:shape) { Shoes::Swt::Line.new(dsl, swt_app) }
12
+ subject { Shoes::Swt::LinePainter.new(shape) }
13
+
14
+ before(:each) do
15
+ dsl.absolute_left = point_a.x
16
+ dsl.absolute_top = point_a.y
17
+ allow(dsl).to receive_messages(positioned?: true)
18
+ end
19
+
20
+ it_behaves_like "stroke painter"
21
+
22
+ specify "draws line" do
23
+ expect(gc).to receive(:draw_line).with(10, 100, 300, 10)
24
+ subject.paint_control(event)
25
+ end
26
+ end
@@ -3,14 +3,11 @@ require 'spec_helper'
3
3
  describe Shoes::Swt::Line do
4
4
  include_context "swt app"
5
5
 
6
- let(:container) { double('container', disposed?: false).as_null_object }
7
6
  let(:dsl) { Shoes::Line.new shoes_app, parent, point_a, point_b }
8
7
  let(:point_a) { Shoes::Point.new(10, 100) }
9
8
  let(:point_b) { Shoes::Point.new(300, 10) }
10
9
 
11
- subject {
12
- Shoes::Swt::Line.new(dsl, swt_app)
13
- }
10
+ subject { Shoes::Swt::Line.new(dsl, swt_app) }
14
11
 
15
12
  context "#initialize" do
16
13
  it { is_expected.to be_instance_of(Shoes::Swt::Line) }
@@ -21,25 +18,5 @@ describe Shoes::Swt::Line do
21
18
  it_behaves_like "updating visibility"
22
19
  it_behaves_like "clickable backend"
23
20
 
24
- it {is_expected.to respond_to :remove}
25
-
26
- describe "painter" do
27
- include_context "painter context"
28
-
29
- let(:shape) { Shoes::Swt::Line.new(dsl, swt_app) }
30
- subject { Shoes::Swt::Line::Painter.new(shape) }
31
-
32
- before(:each) do
33
- dsl.absolute_left = point_a.x
34
- dsl.absolute_top = point_a.y
35
- allow(dsl).to receive_messages(positioned?: true)
36
- end
37
-
38
- it_behaves_like "stroke painter"
39
-
40
- specify "draws line" do
41
- expect(gc).to receive(:draw_line).with(10, 100, 300, 10)
42
- subject.paint_control(event)
43
- end
44
- end
21
+ it { is_expected.to respond_to :remove }
45
22
  end
@@ -5,13 +5,15 @@ describe Shoes::Swt::LinkSegment do
5
5
  let(:line_width) { 20 }
6
6
  let(:line_height) { 14 }
7
7
  let(:layout) { double('swt layout', width: line_width, line_count: 10) }
8
- let(:text_segment) { double('text segment', layout: layout,
9
- element_left: 0, element_top: 0) }
8
+
9
+ let(:text_segment) do
10
+ double('text segment', layout: layout, element_left: 0, element_top: 0)
11
+ end
10
12
 
11
13
  subject { Shoes::Swt::LinkSegment.new(text_segment, range) }
12
14
 
13
15
  before(:each) do
14
- 10.times {|i| stub_line_bounds(i)}
16
+ 10.times { |i| stub_line_bounds(i) }
15
17
  end
16
18
 
17
19
  # ....................
@@ -37,18 +39,18 @@ describe Shoes::Swt::LinkSegment do
37
39
  stub_start_and_end_locations([0, 0], [5, line_height])
38
40
 
39
41
  expect_bounded_box(0, 0, line_width, line_height)
40
- expect_bounded_box(0, line_height, 5, 2*line_height)
42
+ expect_bounded_box(0, line_height, 5, 2 * line_height)
41
43
  end
42
44
 
43
45
  # .....xxxxxxxxxxxxxxx
44
46
  # xxxxxxxxxxxxxxxxxxxx
45
47
  # xxxxx...............
46
48
  it "sets bounds wrapping over three lines" do
47
- stub_start_and_end_locations([5, 0], [5, 2*line_height])
49
+ stub_start_and_end_locations([5, 0], [5, 2 * line_height])
48
50
 
49
51
  expect_bounded_box(5, 0, line_width, line_height)
50
- expect_bounded_box(0, line_height, line_width, 2*line_height)
51
- expect_bounded_box(0, 2*line_height, 5, 3*line_height)
52
+ expect_bounded_box(0, line_height, line_width, 2 * line_height)
53
+ expect_bounded_box(0, 2 * line_height, 5, 3 * line_height)
52
54
  end
53
55
 
54
56
  # ....................
@@ -56,17 +58,17 @@ describe Shoes::Swt::LinkSegment do
56
58
  it "sets bounds with single line beginning further down" do
57
59
  stub_start_and_end_locations([5, line_height], [15, line_height])
58
60
 
59
- expect_bounded_box(5, line_height, 15, 2*line_height)
61
+ expect_bounded_box(5, line_height, 15, 2 * line_height)
60
62
  end
61
63
 
62
64
  # ....................
63
65
  # ...............xxxxx
64
66
  # xxxxx...............
65
67
  it "sets bounds with two lines beginning further down" do
66
- stub_start_and_end_locations([15, line_height], [5, 2*line_height])
68
+ stub_start_and_end_locations([15, line_height], [5, 2 * line_height])
67
69
 
68
- expect_bounded_box(15, line_height, 15, 2*line_height)
69
- expect_bounded_box(0, 2*line_height, 5, 3*line_height)
70
+ expect_bounded_box(15, line_height, 15, 2 * line_height)
71
+ expect_bounded_box(0, 2 * line_height, 5, 3 * line_height)
70
72
  end
71
73
 
72
74
  # ....................
@@ -74,26 +76,26 @@ describe Shoes::Swt::LinkSegment do
74
76
  # xxxxxxxxxxxxxxxxxxxx
75
77
  # xxxxx...............
76
78
  it "sets bounds with three lines beginning further down" do
77
- stub_start_and_end_locations([15, line_height], [5, 3*line_height])
79
+ stub_start_and_end_locations([15, line_height], [5, 3 * line_height])
78
80
 
79
- expect_bounded_box(15, line_height, 15, 2*line_height)
80
- expect_bounded_box(0, 2*line_height, line_width, 3*line_height)
81
- expect_bounded_box(0, 3*line_height, 5, 4*line_height)
81
+ expect_bounded_box(15, line_height, 15, 2 * line_height)
82
+ expect_bounded_box(0, 2 * line_height, line_width, 3 * line_height)
83
+ expect_bounded_box(0, 3 * line_height, 5, 4 * line_height)
82
84
  end
83
85
 
84
86
  def expect_bounded_box(left, top, right, bottom)
85
87
  expect_in_bounds([left, top], [right, top],
86
- [left, bottom], [right,bottom])
88
+ [left, bottom], [right, bottom])
87
89
  end
88
90
 
89
91
  def expect_in_bounds(*points)
90
- points.each do |(x,y)|
92
+ points.each do |(x, y)|
91
93
  expect(subject.in_bounds?(x, y)).to be_truthy, "with #{x}, #{y}"
92
94
  end
93
95
  end
94
96
 
95
97
  def expect_not_in_bounds(*points)
96
- points.each do |(x,y)|
98
+ points.each do |(x, y)|
97
99
  expect(subject.in_bounds?(x, y)).to be_falsey, "with #{x}, #{y}"
98
100
  end
99
101
  end
@@ -7,18 +7,21 @@ describe Shoes::Swt::Link do
7
7
 
8
8
  subject { Shoes::Swt::Link.new(dsl, swt_app) }
9
9
 
10
- its(:dsl) {is_expected.to eq dsl}
10
+ its(:dsl) { is_expected.to eq dsl }
11
11
 
12
12
  it_behaves_like "clickable backend"
13
13
 
14
14
  context "creating link segments" do
15
- let(:bounds) { double("bounds", x: 0, y: 0, height: 0) }
16
- let(:inner_layout) { double("inner layout",
17
- get_line_bounds: bounds, line_count: 1) }
18
- let(:layout) { double("layout",
19
- get_location: double("position", x: 0, y: 0),
20
- element_left: 0, element_top: 0,
21
- layout: inner_layout) }
15
+ let(:bounds) { double("bounds", x: 0, y: 0, height: 0) }
16
+
17
+ let(:inner_layout) do
18
+ double("inner layout", get_line_bounds: bounds, line_count: 1)
19
+ end
20
+
21
+ let(:layout) do
22
+ double("layout", get_location: double("position", x: 0, y: 0),
23
+ element_left: 0, element_top: 0, layout: inner_layout)
24
+ end
22
25
 
23
26
  it "clears existing" do
24
27
  subject.link_segments << double("segment")
@@ -3,15 +3,19 @@ require 'spec_helper'
3
3
  describe Shoes::Swt::ListBox do
4
4
  include_context "swt app"
5
5
 
6
- let(:items) { ["Pie", "Apple", "Sand"] }
7
- let(:dsl) { double('dsl', app: shoes_app,
8
- items: items, opts: {},
9
- element_width: 200, element_height: 20).as_null_object }
10
- let(:block) { ->() {} }
11
- let(:real) { double('real', text: "",
12
- :items= => true, :text= => true,
13
- set_size: true, add_selection_listener: true,
14
- disposed?: false) }
6
+ let(:items) { ["Pie", "Apple", "Sand"] }
7
+
8
+ let(:dsl) do
9
+ double('dsl', app: shoes_app, items: items, opts: {}, element_width: 200,
10
+ element_height: 20).as_null_object
11
+ end
12
+
13
+ let(:block) { ->() {} }
14
+
15
+ let(:real) do
16
+ double('real', text: "", :items= => true, :text= => true, set_size: true,
17
+ add_selection_listener: true, disposed?: false)
18
+ end
15
19
 
16
20
  subject { Shoes::Swt::ListBox.new dsl, swt_app, &block }
17
21
 
@@ -59,7 +63,7 @@ describe Shoes::Swt::ListBox do
59
63
  end
60
64
 
61
65
  it 'converts array to string' do
62
- allow(dsl).to receive(:items).and_return [1,2,3]
66
+ allow(dsl).to receive(:items).and_return [1, 2, 3]
63
67
  subject.update_items
64
68
  # creation already calls update_items once
65
69
  expect(real).to have_received(:items=).with(%w(1 2 3)).twice
@@ -69,7 +73,7 @@ describe Shoes::Swt::ListBox do
69
73
  it "should call the change listeners" do
70
74
  expect(dsl).to receive(:call_change_listeners)
71
75
  expect(real).to receive(:add_selection_listener) do |&blk|
72
- blk.call()
76
+ blk.call
73
77
  end
74
78
  subject
75
79
  end
@@ -1,20 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Shoes::Swt::MouseMoveListener do
4
- let(:app) {double 'SWT App', dsl: dsl_app, shell: shell,
5
- clickable_elements: clickable_elements}
6
- let(:clickable_elements) {[]}
7
- let(:mouse_hover_controls) {[]}
8
- let(:mouse_motion) {[]}
9
- let(:shell) {double 'Shell', setCursor: nil}
10
- let(:dsl_app) {double('DSL App', mouse_hover_controls: mouse_hover_controls,
11
- mouse_motion: mouse_motion).as_null_object}
12
- let(:x) {10}
13
- let(:y) {42}
14
- let(:block) {double 'Block', call: nil}
15
- let(:mouse_event) {double 'mouse event', x: x, y: y}
16
-
17
- subject {Shoes::Swt::MouseMoveListener.new(app)}
4
+ let(:app) do
5
+ double 'SWT App', dsl: dsl_app, shell: shell,
6
+ clickable_elements: clickable_elements
7
+ end
8
+
9
+ let(:clickable_elements) { [] }
10
+ let(:mouse_hover_controls) { [] }
11
+ let(:mouse_motion) { [] }
12
+ let(:shell) { double 'Shell', setCursor: nil }
13
+
14
+ let(:dsl_app) do
15
+ double('DSL App', mouse_hover_controls: mouse_hover_controls,
16
+ mouse_motion: mouse_motion).as_null_object
17
+ end
18
+
19
+ let(:x) { 10 }
20
+ let(:y) { 42 }
21
+ let(:block) { double 'Block', call: nil }
22
+ let(:mouse_event) { double 'mouse event', x: x, y: y }
23
+
24
+ subject { Shoes::Swt::MouseMoveListener.new(app) }
18
25
  before :each do
19
26
  subject.mouse_move(mouse_event)
20
27
  end
@@ -26,7 +33,7 @@ describe Shoes::Swt::MouseMoveListener do
26
33
  end
27
34
 
28
35
  describe 'mouse motion' do
29
- let(:mouse_motion) {[block]}
36
+ let(:mouse_motion) { [block] }
30
37
 
31
38
  it 'calls the block with the position' do
32
39
  expect(block).to have_received(:call).with(x, y)
@@ -34,18 +41,18 @@ describe Shoes::Swt::MouseMoveListener do
34
41
  end
35
42
 
36
43
  describe 'shape control' do
37
- let(:hand_cursor) {Shoes::Swt::Shoes.display.getSystemCursor(::Swt::SWT::CURSOR_HAND)}
38
- let(:arrow_cursor) {Shoes::Swt::Shoes.display.getSystemCursor(::Swt::SWT::CURSOR_ARROW)}
44
+ let(:hand_cursor) { Shoes::Swt::Shoes.display.getSystemCursor(::Swt::SWT::CURSOR_HAND) }
45
+ let(:arrow_cursor) { Shoes::Swt::Shoes.display.getSystemCursor(::Swt::SWT::CURSOR_ARROW) }
39
46
 
40
47
  context 'over a clickable element' do
41
- let(:clickable_elements) {[double('element', visible?: true, in_bounds?: true)]}
48
+ let(:clickable_elements) { [double('element', visible?: true, in_bounds?: true)] }
42
49
  it 'should set the curser hand' do
43
50
  expect(shell).to have_received(:setCursor).with(hand_cursor)
44
51
  end
45
52
  end
46
53
 
47
54
  context 'not over a clickable element' do
48
- let(:clickable_elements) {[double('element', visible?: true, in_bounds?: false)]}
55
+ let(:clickable_elements) { [double('element', visible?: true, in_bounds?: false)] }
49
56
  it 'should set the curser hand' do
50
57
  expect(shell).to have_received(:setCursor).with(arrow_cursor)
51
58
  end
@@ -53,9 +60,12 @@ describe Shoes::Swt::MouseMoveListener do
53
60
  end
54
61
 
55
62
  describe 'hover control' do
56
- let(:element) {double 'element', in_bounds?: in_bounds?, hovered?: hovered?,
57
- visible?: true, mouse_left: nil, mouse_hovered: nil}
58
- let(:mouse_hover_controls) {[element]}
63
+ let(:element) do
64
+ double 'element', in_bounds?: in_bounds?, hovered?: hovered?,
65
+ visible?: true, mouse_left: nil, mouse_hovered: nil
66
+ end
67
+
68
+ let(:mouse_hover_controls) { [element] }
59
69
 
60
70
  shared_examples_for 'does not do anything' do
61
71
  it 'calls no hover related methods whatsoever' do
@@ -65,22 +75,22 @@ describe Shoes::Swt::MouseMoveListener do
65
75
  end
66
76
 
67
77
  context 'in bounds and hovered' do
68
- let(:in_bounds?) {true}
69
- let(:hovered?) {true}
78
+ let(:in_bounds?) { true }
79
+ let(:hovered?) { true }
70
80
 
71
81
  it_behaves_like 'does not do anything'
72
82
  end
73
83
 
74
84
  context 'out of bounds and not hovered' do
75
- let(:in_bounds?) {false}
76
- let(:hovered?) {false}
85
+ let(:in_bounds?) { false }
86
+ let(:hovered?) { false }
77
87
 
78
88
  it_behaves_like 'does not do anything'
79
89
  end
80
90
 
81
91
  context 'in bounds and not hovered' do
82
- let(:in_bounds?) {true}
83
- let(:hovered?) {false}
92
+ let(:in_bounds?) { true }
93
+ let(:hovered?) { false }
84
94
 
85
95
  it 'calls the hovered method' do
86
96
  expect(element).to have_received :mouse_hovered
@@ -88,8 +98,8 @@ describe Shoes::Swt::MouseMoveListener do
88
98
  end
89
99
 
90
100
  context 'out of bounds and hovered' do
91
- let(:in_bounds?) {false}
92
- let(:hovered?) {true}
101
+ let(:in_bounds?) { false }
102
+ let(:hovered?) { true }
93
103
 
94
104
  it 'calls the mouse_left method' do
95
105
  expect(element).to have_received :mouse_left
@@ -97,21 +107,27 @@ describe Shoes::Swt::MouseMoveListener do
97
107
  end
98
108
 
99
109
  describe 'in bounds, not hovered but hidden' do
100
- let(:in_bounds?) {true}
101
- let(:hovered?) {false}
102
- let(:element) {double 'element', in_bounds?: in_bounds?, hovered?: hovered?,
103
- visible?: false, mouse_left: nil, mouse_hovered: nil}
110
+ let(:in_bounds?) { true }
111
+ let(:hovered?) { false }
112
+
113
+ let(:element) do
114
+ double 'element', in_bounds?: in_bounds?, hovered?: hovered?,
115
+ visible?: false, mouse_left: nil, mouse_hovered: nil
116
+ end
104
117
 
105
118
  it_behaves_like 'does not do anything'
106
119
  end
107
120
 
108
121
  describe 'with 2 elements' do
109
- let(:in_bounds?) {false}
110
- let(:hovered?) {true}
122
+ let(:in_bounds?) { false }
123
+ let(:hovered?) { true }
124
+
125
+ let(:element2) do
126
+ double 'element 2', in_bounds?: true, hovered?: false, visible?: true,
127
+ mouse_left: nil, mouse_hovered: nil
128
+ end
111
129
 
112
- let(:element2) {double 'element 2', in_bounds?: true, hovered?: false,
113
- visible?: true, mouse_left: nil, mouse_hovered: nil}
114
- let(:mouse_hover_controls) {[element, element2]}
130
+ let(:mouse_hover_controls) { [element, element2] }
115
131
 
116
132
  it 'calls leave for element 1 before calling hover for element 2' do
117
133
  expect(element).to receive(:mouse_left).ordered