shoes-swt 4.0.0.pre3 → 4.0.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/bin/shoes-swt +2 -2
  3. data/lib/shoes/swt.rb +90 -72
  4. data/lib/shoes/swt/app.rb +5 -0
  5. data/lib/shoes/swt/click_listener.rb +0 -1
  6. data/lib/shoes/swt/color.rb +7 -7
  7. data/lib/shoes/swt/common/fill.rb +9 -3
  8. data/lib/shoes/swt/common/painter.rb +14 -11
  9. data/lib/shoes/swt/common/stroke.rb +9 -3
  10. data/lib/shoes/swt/dialog.rb +2 -2
  11. data/lib/shoes/swt/gradient.rb +13 -11
  12. data/lib/shoes/swt/image.rb +1 -3
  13. data/lib/shoes/swt/image_pattern.rb +2 -2
  14. data/lib/shoes/swt/line.rb +0 -2
  15. data/lib/shoes/swt/list_box.rb +6 -1
  16. data/lib/shoes/swt/progress.rb +9 -8
  17. data/lib/shoes/swt/redrawing_aspect.rb +1 -1
  18. data/lib/shoes/swt/shape.rb +3 -1
  19. data/lib/shoes/swt/shoes_layout.rb +38 -24
  20. data/lib/shoes/swt/text_block.rb +41 -12
  21. data/lib/shoes/swt/text_block/cursor_painter.rb +1 -1
  22. data/lib/shoes/swt/text_block/fitter.rb +8 -3
  23. data/lib/shoes/swt/text_block/painter.rb +9 -28
  24. data/lib/shoes/swt/text_block/text_segment.rb +16 -6
  25. data/lib/shoes/swt/text_block/text_segment_collection.rb +17 -5
  26. data/lib/shoes/swt/tooling/leak_hunter.rb +1 -1
  27. data/lib/shoes/swt/version.rb +1 -1
  28. data/shoes-swt.gemspec +2 -2
  29. data/spec/shoes/cli_spec.rb +1 -1
  30. data/spec/shoes/swt/app_spec.rb +15 -6
  31. data/spec/shoes/swt/color_spec.rb +8 -7
  32. data/spec/shoes/swt/common/painter_spec.rb +30 -5
  33. data/spec/shoes/swt/disposed_protection_spec.rb +0 -1
  34. data/spec/shoes/swt/font_spec.rb +2 -2
  35. data/spec/shoes/swt/gradient_spec.rb +5 -2
  36. data/spec/shoes/swt/image_pattern_spec.rb +11 -1
  37. data/spec/shoes/swt/list_box_spec.rb +24 -4
  38. data/spec/shoes/swt/mouse_move_listener_spec.rb +1 -1
  39. data/spec/shoes/swt/oval_spec.rb +0 -1
  40. data/spec/shoes/swt/progress_spec.rb +3 -4
  41. data/spec/shoes/swt/radio_group_spec.rb +4 -4
  42. data/spec/shoes/swt/radio_spec.rb +1 -1
  43. data/spec/shoes/swt/shape_spec.rb +8 -1
  44. data/spec/shoes/swt/shared_examples/paintable.rb +0 -1
  45. data/spec/shoes/swt/shared_examples/pattern.rb +2 -6
  46. data/spec/shoes/swt/shared_examples/swt_app_context.rb +0 -1
  47. data/spec/shoes/swt/shell_control_listener_spec.rb +4 -4
  48. data/spec/shoes/swt/shoes_layout_spec.rb +84 -0
  49. data/spec/shoes/swt/slot_spec.rb +1 -1
  50. data/spec/shoes/swt/spec_helper.rb +2 -0
  51. data/spec/shoes/swt/text_block/cursor_painter_spec.rb +2 -2
  52. data/spec/shoes/swt/text_block/fitter_spec.rb +19 -4
  53. data/spec/shoes/swt/text_block/painter_spec.rb +15 -189
  54. data/spec/shoes/swt/text_block/text_segment_collection_spec.rb +10 -5
  55. data/spec/shoes/swt/text_block/text_segment_spec.rb +4 -4
  56. data/spec/shoes/swt/text_block_spec.rb +28 -15
  57. metadata +8 -6
@@ -27,7 +27,7 @@ Hometown.undisposed_report_at_exit
27
27
 
28
28
  # Register an internal keystroke for closing the app, making sure to clear
29
29
  # out the contents first (to avoid false positives for still-exiting elements.
30
- Shoes::InternalApp.add_global_keypress(:'control_alt_q') do
30
+ Shoes::InternalApp.add_global_keypress(:control_alt_q) do
31
31
  clear
32
32
  quit
33
33
  end
@@ -1,5 +1,5 @@
1
1
  class Shoes
2
2
  module Swt
3
- VERSION = "4.0.0.pre3"
3
+ VERSION = "4.0.0.pre4"
4
4
  end
5
5
  end
data/shoes-swt.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Team Shoes"]
9
9
  s.email = ["shoes@librelist.com"]
10
10
  s.homepage = "https://github.com/shoes/shoes4"
11
- s.summary = %q{A JRuby and Swt backend for Shoes, the best little GUI toolkit for Ruby.}
12
- s.description = %q{A JRuby and Swt backend for Shoes, the best little GUI toolkit for Ruby. Shoes makes building for Mac, Windows, and Linux super simple.}
11
+ s.summary = 'A JRuby and Swt backend for Shoes, the best little GUI toolkit for Ruby.'
12
+ s.description = 'A JRuby and Swt backend for Shoes, the best little GUI toolkit for Ruby. Shoes makes building for Mac, Windows, and Linux super simple.'
13
13
  s.license = 'MIT'
14
14
 
15
15
  s.files = `git ls-files`.split($/)
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Shoes::CLI do
4
- subject {Shoes::CLI.new}
4
+ subject {Shoes::CLI.new("swt")}
5
5
 
6
6
  before :each do
7
7
  allow(subject.packager).to receive :run
@@ -2,11 +2,12 @@ require "shoes/swt/spec_helper"
2
2
 
3
3
  describe Shoes::Swt::App do
4
4
  let(:opts) { {:background => Shoes::COLORS[:salmon], :resizable => true} }
5
- let(:app) { double('app', :opts => opts,
6
- :width => width,
7
- :height => 0,
8
- :app_title => 'double') }
9
- let(:dsl) { app }
5
+ let(:app) { double('app') }
6
+ let(:dsl) { double('dsl', :app => app,
7
+ :opts => opts,
8
+ :width => width,
9
+ :height => 0,
10
+ :app_title => 'double') }
10
11
 
11
12
  let(:opts_unresizable) { {:background => Shoes::COLORS[:salmon],
12
13
  :resizable => false} }
@@ -16,7 +17,7 @@ describe Shoes::Swt::App do
16
17
  :app_title => 'double') }
17
18
  let(:width) {0}
18
19
 
19
- subject { Shoes::Swt::App.new(app) }
20
+ subject { Shoes::Swt::App.new(dsl) }
20
21
 
21
22
  it { is_expected.to respond_to :clipboard }
22
23
  it { is_expected.to respond_to :clipboard= }
@@ -43,6 +44,14 @@ describe Shoes::Swt::App do
43
44
  expect(Shoes::Swt.apps.length).to eq(old_apps_length + 1)
44
45
  expect(Shoes::Swt.apps.include?(subject)).to be_truthy
45
46
  end
47
+
48
+ it "unregisters" do
49
+ old_apps_length = Shoes::Swt.apps.length
50
+ expect(Shoes).to receive(:unregister)
51
+
52
+ subject.send(:unregister_app).call()
53
+ expect(Shoes::Swt.apps.length).to eq(old_apps_length)
54
+ end
46
55
  end
47
56
 
48
57
  context "when running on a mac" do
@@ -1,7 +1,8 @@
1
1
  require 'shoes/swt/spec_helper'
2
2
 
3
3
  describe Shoes::Swt::Color do
4
- subject(:color) { Shoes::Swt::Color.create(Shoes::COLORS[:salmon]) }
4
+ subject(:color) { Shoes::Swt::Color.create(Shoes::COLORS[:salmon]) }
5
+ let(:applied_to) { double("applied to") }
5
6
 
6
7
  it_behaves_like "an swt pattern"
7
8
 
@@ -33,19 +34,20 @@ describe Shoes::Swt::Color do
33
34
  it "sets background" do
34
35
  allow(gc).to receive(:set_alpha)
35
36
  expect(gc).to receive(:set_background).with(color.real)
36
- color.apply_as_fill(gc)
37
+ color.apply_as_fill(gc, applied_to)
37
38
  end
38
39
 
39
40
  it "sets alpha" do
40
41
  allow(gc).to receive(:set_background)
41
42
  expect(gc).to receive(:set_alpha)
42
- color.apply_as_fill(gc, 10, 20, 100, 200)
43
+ color.apply_as_fill(gc, applied_to)
43
44
  end
44
45
  end
45
46
  end
46
47
 
47
48
  describe Shoes::Swt::NullColor do
48
- subject(:color) { Shoes::Swt::Color.create(nil) }
49
+ subject(:color) { Shoes::Swt::Color.create(nil) }
50
+ let(:applied_to) { double("applied to") }
49
51
 
50
52
  it { is_expected.to be_instance_of(Shoes::Swt::NullColor) }
51
53
  its(:real) { is_expected.to be_nil }
@@ -56,12 +58,11 @@ describe Shoes::Swt::NullColor do
56
58
  let(:gc) { double("graphics context") }
57
59
 
58
60
  it "sends no messages in #apply_as_fill" do
59
- color.apply_as_fill(gc)
61
+ color.apply_as_fill(gc, applied_to)
60
62
  end
61
63
 
62
64
  it "sends no messages in #apply_as_stroke" do
63
- color.apply_as_stroke(gc)
65
+ color.apply_as_stroke(gc, applied_to)
64
66
  end
65
67
  end
66
68
  end
67
-
@@ -1,10 +1,12 @@
1
1
  require 'shoes/swt/spec_helper'
2
2
 
3
3
  describe Shoes::Swt::Common::Painter do
4
- let(:object) {double 'object', dsl: dsl}
5
- let(:dsl) {double 'dsl', visible?: true, positioned?: true}
4
+ let(:object) {double 'object', dsl: dsl, transform: transform,
5
+ apply_fill: nil, apply_stroke: nil}
6
+ let(:dsl) {double 'dsl', visible?: true, positioned?: true, style: Hash.new}
6
7
  let(:event) {double 'paint event', gc: graphics_context}
7
8
  let(:graphics_context) { double 'graphics_context',
9
+ dispose: nil,
8
10
  set_antialias: nil, set_line_cap: nil,
9
11
  set_transform: nil, setTransform: nil }
10
12
  let(:transform) { double 'transform', disposed?: false }
@@ -32,13 +34,31 @@ describe Shoes::Swt::Common::Painter do
32
34
  subject.paint_control event
33
35
  end
34
36
 
37
+ it 'rotates' do
38
+ allow(dsl).to receive(:needs_rotate?) { true }
39
+ allow(dsl).to receive(:rotate) { 10 }
40
+ allow(dsl).to receive(:element_left) { 0 }
41
+ allow(dsl).to receive(:element_width) { 0 }
42
+ allow(dsl).to receive(:element_top) { 0 }
43
+ allow(dsl).to receive(:element_height) { 0 }
44
+
45
+ expect_transform_for_rotate
46
+
47
+ subject.paint_control event
48
+ end
49
+
50
+ it "doesn't rotate if doesn't need it" do
51
+ allow(dsl).to receive(:needs_rotate?) { false }
52
+
53
+ expect(transform).not_to receive(:translate)
54
+ expect(transform).not_to receive(:rotate)
55
+ subject.paint_control event
56
+ end
35
57
  end
36
58
 
37
59
  context "set_rotate" do
38
60
  it "disposes of transform" do
39
- expect(transform).to receive(:dispose)
40
- expect(transform).to receive(:translate).at_least(:once)
41
- expect(transform).to receive(:rotate).at_least(:once)
61
+ expect_transform_for_rotate
42
62
 
43
63
  subject.set_rotate graphics_context, 0, 0, 0 do
44
64
  #no-op
@@ -46,4 +66,9 @@ describe Shoes::Swt::Common::Painter do
46
66
  end
47
67
  end
48
68
 
69
+ def expect_transform_for_rotate
70
+ expect(transform).to receive(:dispose)
71
+ expect(transform).to receive(:translate).at_least(:once)
72
+ expect(transform).to receive(:rotate).at_least(:once)
73
+ end
49
74
  end
@@ -46,4 +46,3 @@ describe Shoes::Swt::DisposedProtection do
46
46
  end
47
47
  end
48
48
  end
49
-
@@ -29,5 +29,5 @@ describe Shoes::Swt::Font do
29
29
  subject.add_font font_path
30
30
  end
31
31
  end
32
-
33
- end
32
+
33
+ end
@@ -3,6 +3,9 @@ require 'shoes/swt/spec_helper'
3
3
  describe Shoes::Swt::Gradient do
4
4
  let(:color1) { Shoes::Color.create(Shoes::COLORS[:honeydew]) }
5
5
  let(:color2) { Shoes::Color.create(Shoes::COLORS[:salmon]) }
6
+ let(:applied_to) { double("applied to",
7
+ element_left: 0, element_top: 0, angle: 0,
8
+ element_width: 10, element_height: 10) }
6
9
  let(:dsl) { Shoes::Gradient.new(color1, color2) }
7
10
  let(:gc) { double("gc", set_background_pattern: nil) }
8
11
 
@@ -13,7 +16,7 @@ describe Shoes::Swt::Gradient do
13
16
  describe "#dispose" do
14
17
  it "lets subresources do" do
15
18
  # Prime the object's lazy colors
16
- subject.apply_as_fill(gc, 10, 20, 100, 200)
19
+ subject.apply_as_fill(gc, applied_to)
17
20
 
18
21
  expect(subject.color1).to receive(:dispose)
19
22
  expect(subject.color2).to receive(:dispose)
@@ -25,7 +28,7 @@ describe Shoes::Swt::Gradient do
25
28
  describe "#apply_as_fill" do
26
29
  it "sets background" do
27
30
  expect(gc).to receive(:set_background_pattern)
28
- subject.apply_as_fill(gc, 10, 20, 100, 200)
31
+ subject.apply_as_fill(gc, applied_to)
29
32
  end
30
33
  end
31
34
  end
@@ -2,6 +2,7 @@ require 'shoes/swt/spec_helper'
2
2
 
3
3
  describe Shoes::Swt::ImagePattern do
4
4
  let(:dsl) { Shoes::ImagePattern.new("some/path/to") }
5
+ let(:applied_to) { double("applied to") }
5
6
  let(:swt_image) { double("swt image") }
6
7
  let(:swt_pattern) { double("swt pattern") }
7
8
 
@@ -24,12 +25,21 @@ describe Shoes::Swt::ImagePattern do
24
25
  end
25
26
  end
26
27
 
28
+ describe "#apply_as_stroke" do
29
+ let(:gc) { double("gc") }
30
+
31
+ it "sets foreground" do
32
+ expect(gc).to receive(:set_foreground_pattern)
33
+ subject.apply_as_stroke(gc, applied_to)
34
+ end
35
+ end
36
+
27
37
  describe "#apply_as_fill" do
28
38
  let(:gc) { double("gc") }
29
39
 
30
40
  it "sets background" do
31
41
  expect(gc).to receive(:set_background_pattern)
32
- subject.apply_as_fill(gc, 10, 20, 100, 200)
42
+ subject.apply_as_fill(gc, applied_to)
33
43
  end
34
44
  end
35
45
  end
@@ -8,9 +8,10 @@ describe Shoes::Swt::ListBox do
8
8
  items: items, opts: {},
9
9
  element_width: 200, element_height: 20).as_null_object }
10
10
  let(:block) { ->(){} }
11
- let(:real) { double('real', text: "", :items= => true,
11
+ let(:real) { double('real', text: "",
12
+ :items= => true, :text= => true,
12
13
  set_size: true, add_selection_listener: true,
13
- disposed?: false ) }
14
+ disposed?: false) }
14
15
 
15
16
  subject { Shoes::Swt::ListBox.new dsl, parent, &block }
16
17
 
@@ -26,10 +27,16 @@ describe Shoes::Swt::ListBox do
26
27
  end
27
28
 
28
29
  it "should call 'items' when updating values" do
29
- subject # creation already calls update_items once
30
30
  allow(dsl).to receive(:items).and_return ["hello"]
31
31
  subject.update_items
32
- expect(real).to have_received(:items=).with(["hello"])
32
+ # creation already calls update_items once
33
+ expect(real).to have_received(:items=).with(["hello"]).twice
34
+ end
35
+
36
+ it "should set real text if initialized with choose option" do
37
+ allow(dsl).to receive(:style) { { choose: "Apple" } }
38
+ subject
39
+ expect(real).to have_received(:text=).with("Apple")
33
40
  end
34
41
 
35
42
  it "should respond to choose" do
@@ -41,11 +48,24 @@ describe Shoes::Swt::ListBox do
41
48
  subject.choose "Bacon"
42
49
  end
43
50
 
51
+ it "should notify dsl of changes when choosing" do
52
+ allow(real).to receive(:text=)
53
+ expect(dsl).to receive(:call_change_listeners)
54
+ subject.choose "Bacon"
55
+ end
56
+
44
57
  it 'sets the items on real upon initialization' do
45
58
  subject
46
59
  expect(real).to have_received(:items=).with(items)
47
60
  end
48
61
 
62
+ it 'converts array to string' do
63
+ allow(dsl).to receive(:items).and_return [1,2,3]
64
+ subject.update_items
65
+ # creation already calls update_items once
66
+ expect(real).to have_received(:items=).with(%w(1 2 3)).twice
67
+ end
68
+
49
69
  describe "when the backend notifies us that the selection has changed" do
50
70
  it "should call the change listeners" do
51
71
  expect(dsl).to receive(:call_change_listeners)
@@ -12,7 +12,7 @@ describe Shoes::Swt::MouseMoveListener do
12
12
  let(:x) {10}
13
13
  let(:y) {42}
14
14
  let(:block) {double 'Block', call: nil}
15
- let(:mouse_event) {double'mouse event', x: x, y: y}
15
+ let(:mouse_event) {double 'mouse event', x: x, y: y}
16
16
 
17
17
  subject {Shoes::Swt::MouseMoveListener.new(app)}
18
18
  before :each do
@@ -48,4 +48,3 @@ describe Shoes::Swt::Oval do
48
48
  end
49
49
  end
50
50
  end
51
-
@@ -5,7 +5,8 @@ describe Shoes::Swt::Progress do
5
5
 
6
6
  let(:text) { "TEXT" }
7
7
  let(:dsl) { double('dsl', app: shoes_app).as_null_object }
8
- let(:real) { double('real', disposed?: false, :disposed? => false).as_null_object }
8
+ let(:real) { double('real', disposed?: real_disposed).as_null_object }
9
+ let(:real_disposed) {false}
9
10
 
10
11
  subject { Shoes::Swt::Progress.new dsl, parent }
11
12
 
@@ -32,9 +33,7 @@ describe Shoes::Swt::Progress do
32
33
  end
33
34
 
34
35
  context "with disposed real element" do
35
- before :each do
36
- allow(real).to receive(:disposed?) { true }
37
- end
36
+ let(:real_disposed) {true}
38
37
 
39
38
  it "shouldn't set selection" do
40
39
  expect(real).not_to receive(:selection=)
@@ -15,7 +15,7 @@ describe Shoes::Swt::RadioGroup do
15
15
 
16
16
  describe "#add" do
17
17
  it "monitors selection" do
18
- expect(real).to receive(:add_selection_listener)
18
+ expect(real).to receive(:add_selection_listener)
19
19
  subject.add(radio)
20
20
  end
21
21
 
@@ -57,12 +57,12 @@ describe Shoes::Swt::RadioGroup do
57
57
  subject.add(radio)
58
58
  subject.add(radio_selected)
59
59
  end
60
- after :each do
61
- subject.select_only_one_radio_in_group(radio_selected)
60
+ after :each do
61
+ subject.select_only_one_radio_in_group(radio_selected)
62
62
  end
63
63
 
64
64
  it "turns on the selected radio" do
65
- expect(real_selected).to receive(:set_selection).with(true)
65
+ expect(real_selected).to receive(:set_selection).with(true)
66
66
  end
67
67
 
68
68
  it "turns off the non-selected radios" do
@@ -33,7 +33,7 @@ describe Shoes::Swt::Radio do
33
33
  let(:radio_group) { double("radio_group").as_null_object }
34
34
  let(:group_lookup) { double('group_lookup', :[] => radio_group).as_null_object }
35
35
  before :each do
36
- allow(Shoes::Swt::RadioGroup).to receive(:group_lookup) { group_lookup }
36
+ allow(Shoes::Swt::RadioGroup).to receive(:group_lookup) { group_lookup }
37
37
  end
38
38
 
39
39
  it "changes the group" do
@@ -3,7 +3,8 @@ require 'shoes/swt/spec_helper'
3
3
  describe Shoes::Swt::Shape do
4
4
  include_context "swt app"
5
5
 
6
- let(:dsl) { instance_double("Shoes::Shape", hidden: false, style: {}).as_null_object }
6
+ let(:dsl) { instance_double("Shoes::Shape", hidden: false,
7
+ needs_rotate?: false,style: {}).as_null_object }
7
8
  subject { Shoes::Swt::Shape.new dsl, swt_app }
8
9
 
9
10
  shared_examples_for "Swt::Shape" do
@@ -20,6 +21,7 @@ describe Shoes::Swt::Shape do
20
21
  it_behaves_like "Swt::Shape"
21
22
  it_behaves_like "paintable"
22
23
  it_behaves_like "removable"
24
+ it_behaves_like 'clickable backend'
23
25
 
24
26
  it "properly disposes" do
25
27
  expect(subject.transform).to receive(:dispose)
@@ -43,6 +45,11 @@ describe Shoes::Swt::Shape do
43
45
  expect(element).to receive(:line_to).with(20, 30)
44
46
  subject.line_to 20, 30
45
47
  end
48
+
49
+ it "delegates #arc_to" do
50
+ expect(element).to receive(:add_arc).with(25, 45, 50, 20, 0.0, -90.0)
51
+ subject.arc_to 50, 55, 50, 20, 0, Shoes::PI/2
52
+ end
46
53
  end
47
54
 
48
55
  describe "moving" do
@@ -4,4 +4,3 @@ shared_examples_for "paintable" do
4
4
  subject
5
5
  end
6
6
  end
7
-
@@ -4,10 +4,6 @@ shared_examples_for "an swt pattern" do
4
4
 
5
5
  describe "#apply_as_stroke" do
6
6
  let(:gc) { double("graphics context") }
7
- let(:left) { 0 }
8
- let(:top) { 0 }
9
- let(:width) { 10 }
10
- let(:height) { 10 }
11
7
 
12
8
  it "sets foreground" do
13
9
  if subject.is_a? Shoes::Swt::Color
@@ -16,7 +12,7 @@ shared_examples_for "an swt pattern" do
16
12
  else
17
13
  expect(gc).to receive(:set_foreground_pattern)
18
14
  end
19
- subject.apply_as_stroke(gc, left, top, width, height)
15
+ subject.apply_as_stroke(gc, applied_to)
20
16
  end
21
17
 
22
18
  it "sets alpha" do
@@ -26,7 +22,7 @@ shared_examples_for "an swt pattern" do
26
22
  else
27
23
  expect(gc).to receive(:set_foreground_pattern)
28
24
  end
29
- subject.apply_as_stroke(gc, left, top, width, height)
25
+ subject.apply_as_stroke(gc, applied_to)
30
26
  end
31
27
  end
32
28
  end