shoes-swt 4.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +84 -0
- data/Gemfile +24 -0
- data/Guardfile +11 -0
- data/LICENSE +31 -0
- data/README.md +201 -0
- data/lib/shoes/swt.rb +118 -0
- data/lib/shoes/swt/animation.rb +46 -0
- data/lib/shoes/swt/app.rb +314 -0
- data/lib/shoes/swt/arc.rb +71 -0
- data/lib/shoes/swt/background.rb +41 -0
- data/lib/shoes/swt/border.rb +41 -0
- data/lib/shoes/swt/button.rb +18 -0
- data/lib/shoes/swt/check.rb +14 -0
- data/lib/shoes/swt/check_button.rb +19 -0
- data/lib/shoes/swt/color.rb +49 -0
- data/lib/shoes/swt/color_factory.rb +32 -0
- data/lib/shoes/swt/common/child.rb +16 -0
- data/lib/shoes/swt/common/clickable.rb +68 -0
- data/lib/shoes/swt/common/container.rb +28 -0
- data/lib/shoes/swt/common/fill.rb +38 -0
- data/lib/shoes/swt/common/painter.rb +92 -0
- data/lib/shoes/swt/common/painter_updates_position.rb +12 -0
- data/lib/shoes/swt/common/remove.rb +30 -0
- data/lib/shoes/swt/common/resource.rb +29 -0
- data/lib/shoes/swt/common/selection_listener.rb +14 -0
- data/lib/shoes/swt/common/stroke.rb +42 -0
- data/lib/shoes/swt/common/update_position.rb +15 -0
- data/lib/shoes/swt/common/visibility.rb +13 -0
- data/lib/shoes/swt/dialog.rb +90 -0
- data/lib/shoes/swt/disposed_protection.rb +23 -0
- data/lib/shoes/swt/download.rb +24 -0
- data/lib/shoes/swt/font.rb +32 -0
- data/lib/shoes/swt/gradient.rb +92 -0
- data/lib/shoes/swt/image.rb +128 -0
- data/lib/shoes/swt/image_pattern.rb +31 -0
- data/lib/shoes/swt/input_box.rb +73 -0
- data/lib/shoes/swt/key_listener.rb +145 -0
- data/lib/shoes/swt/line.rb +60 -0
- data/lib/shoes/swt/link.rb +31 -0
- data/lib/shoes/swt/link_segment.rb +111 -0
- data/lib/shoes/swt/list_box.rb +48 -0
- data/lib/shoes/swt/mouse_move_listener.rb +67 -0
- data/lib/shoes/swt/oval.rb +52 -0
- data/lib/shoes/swt/progress.rb +35 -0
- data/lib/shoes/swt/radio.rb +29 -0
- data/lib/shoes/swt/radio_group.rb +54 -0
- data/lib/shoes/swt/rect.rb +30 -0
- data/lib/shoes/swt/rect_painter.rb +23 -0
- data/lib/shoes/swt/redrawing_aspect.rb +123 -0
- data/lib/shoes/swt/shape.rb +133 -0
- data/lib/shoes/swt/shoes_layout.rb +43 -0
- data/lib/shoes/swt/slot.rb +39 -0
- data/lib/shoes/swt/sound.rb +119 -0
- data/lib/shoes/swt/star.rb +50 -0
- data/lib/shoes/swt/support/jl1.0.1.jar +0 -0
- data/lib/shoes/swt/support/jogg-0.0.7.jar +0 -0
- data/lib/shoes/swt/support/jorbis-0.0.15.jar +0 -0
- data/lib/shoes/swt/support/log4j-1.2.16.jar +0 -0
- data/lib/shoes/swt/support/mp3spi1.9.5.jar +0 -0
- data/lib/shoes/swt/support/tritonus_share.jar +0 -0
- data/lib/shoes/swt/support/vorbisspi1.0.3.jar +0 -0
- data/lib/shoes/swt/swt_button.rb +56 -0
- data/lib/shoes/swt/text_block.rb +124 -0
- data/lib/shoes/swt/text_block/centered_text_segment.rb +22 -0
- data/lib/shoes/swt/text_block/cursor_painter.rb +53 -0
- data/lib/shoes/swt/text_block/fitter.rb +212 -0
- data/lib/shoes/swt/text_block/painter.rb +47 -0
- data/lib/shoes/swt/text_block/text_font_factory.rb +50 -0
- data/lib/shoes/swt/text_block/text_segment.rb +108 -0
- data/lib/shoes/swt/text_block/text_segment_collection.rb +160 -0
- data/lib/shoes/swt/text_block/text_style_factory.rb +88 -0
- data/lib/shoes/swt/timer.rb +19 -0
- data/lib/shoes/swt/tooling/leak_hunter.rb +35 -0
- data/lib/shoes/swt/version.rb +5 -0
- data/manifests/common.rb +34 -0
- data/manifests/shoes-swt.rb +29 -0
- data/shoes-swt.gemspec +24 -0
- data/spec/code_coverage.rb +14 -0
- data/spec/shoes/animation_spec.rb +65 -0
- data/spec/shoes/app_spec.rb +484 -0
- data/spec/shoes/arc_spec.rb +51 -0
- data/spec/shoes/background_spec.rb +53 -0
- data/spec/shoes/border_spec.rb +47 -0
- data/spec/shoes/builtin_methods_spec.rb +110 -0
- data/spec/shoes/button_spec.rb +44 -0
- data/spec/shoes/check_spec.rb +35 -0
- data/spec/shoes/cli_spec.rb +15 -0
- data/spec/shoes/color_spec.rb +408 -0
- data/spec/shoes/common/inspect_spec.rb +26 -0
- data/spec/shoes/common/remove_spec.rb +38 -0
- data/spec/shoes/common/style_normalizer_spec.rb +28 -0
- data/spec/shoes/common/style_spec.rb +147 -0
- data/spec/shoes/configuration_spec.rb +36 -0
- data/spec/shoes/constants_spec.rb +38 -0
- data/spec/shoes/dialog_spec.rb +163 -0
- data/spec/shoes/dimension_spec.rb +407 -0
- data/spec/shoes/dimensions_spec.rb +837 -0
- data/spec/shoes/download_spec.rb +142 -0
- data/spec/shoes/flow_spec.rb +133 -0
- data/spec/shoes/font_spec.rb +37 -0
- data/spec/shoes/framework_learning_spec.rb +30 -0
- data/spec/shoes/gradient_spec.rb +32 -0
- data/spec/shoes/helpers/fake_element.rb +17 -0
- data/spec/shoes/helpers/inspect_helpers.rb +5 -0
- data/spec/shoes/helpers/sample17_helper.rb +66 -0
- data/spec/shoes/image_spec.rb +49 -0
- data/spec/shoes/images/shoe.jpg +0 -0
- data/spec/shoes/input_box_spec.rb +80 -0
- data/spec/shoes/integration_spec.rb +20 -0
- data/spec/shoes/internal_app_spec.rb +141 -0
- data/spec/shoes/keypress_spec.rb +11 -0
- data/spec/shoes/keyrelease_spec.rb +12 -0
- data/spec/shoes/line_spec.rb +49 -0
- data/spec/shoes/link_spec.rb +105 -0
- data/spec/shoes/list_box_spec.rb +74 -0
- data/spec/shoes/logger/ruby_spec.rb +8 -0
- data/spec/shoes/logger_spec.rb +45 -0
- data/spec/shoes/oval_spec.rb +24 -0
- data/spec/shoes/point_spec.rb +71 -0
- data/spec/shoes/progress_spec.rb +54 -0
- data/spec/shoes/radio_spec.rb +32 -0
- data/spec/shoes/rect_spec.rb +39 -0
- data/spec/shoes/renamed_delegate_spec.rb +70 -0
- data/spec/shoes/shape_spec.rb +95 -0
- data/spec/shoes/shared_examples/button.rb +6 -0
- data/spec/shoes/shared_examples/changeable.rb +26 -0
- data/spec/shoes/shared_examples/clickable.rb +5 -0
- data/spec/shoes/shared_examples/common_methods.rb +35 -0
- data/spec/shoes/shared_examples/dimensions.rb +32 -0
- data/spec/shoes/shared_examples/dsl.rb +44 -0
- data/spec/shoes/shared_examples/dsl/animate.rb +29 -0
- data/spec/shoes/shared_examples/dsl/arc.rb +45 -0
- data/spec/shoes/shared_examples/dsl/background.rb +26 -0
- data/spec/shoes/shared_examples/dsl/border.rb +10 -0
- data/spec/shoes/shared_examples/dsl/button.rb +5 -0
- data/spec/shoes/shared_examples/dsl/cap.rb +6 -0
- data/spec/shoes/shared_examples/dsl/check.rb +11 -0
- data/spec/shoes/shared_examples/dsl/edit_box.rb +8 -0
- data/spec/shoes/shared_examples/dsl/edit_line.rb +8 -0
- data/spec/shoes/shared_examples/dsl/editable_element.rb +29 -0
- data/spec/shoes/shared_examples/dsl/fill.rb +27 -0
- data/spec/shoes/shared_examples/dsl/flow.rb +15 -0
- data/spec/shoes/shared_examples/dsl/gradient.rb +62 -0
- data/spec/shoes/shared_examples/dsl/image.rb +21 -0
- data/spec/shoes/shared_examples/dsl/line.rb +9 -0
- data/spec/shoes/shared_examples/dsl/nofill.rb +6 -0
- data/spec/shoes/shared_examples/dsl/nostroke.rb +6 -0
- data/spec/shoes/shared_examples/dsl/oval.rb +88 -0
- data/spec/shoes/shared_examples/dsl/pattern.rb +34 -0
- data/spec/shoes/shared_examples/dsl/progress.rb +7 -0
- data/spec/shoes/shared_examples/dsl/rect.rb +92 -0
- data/spec/shoes/shared_examples/dsl/rgb.rb +26 -0
- data/spec/shoes/shared_examples/dsl/shape.rb +21 -0
- data/spec/shoes/shared_examples/dsl/star.rb +48 -0
- data/spec/shoes/shared_examples/dsl/stroke.rb +30 -0
- data/spec/shoes/shared_examples/dsl/strokewidth.rb +19 -0
- data/spec/shoes/shared_examples/dsl/style.rb +32 -0
- data/spec/shoes/shared_examples/dsl/text_elements.rb +81 -0
- data/spec/shoes/shared_examples/dsl/video.rb +5 -0
- data/spec/shoes/shared_examples/dsl_app_context.rb +8 -0
- data/spec/shoes/shared_examples/hover_leave.rb +11 -0
- data/spec/shoes/shared_examples/parent.rb +6 -0
- data/spec/shoes/shared_examples/scroll.rb +41 -0
- data/spec/shoes/shared_examples/shared_element_method.rb +60 -0
- data/spec/shoes/shared_examples/slot.rb +331 -0
- data/spec/shoes/shared_examples/state.rb +19 -0
- data/spec/shoes/shared_examples/style.rb +82 -0
- data/spec/shoes/slot_spec.rb +130 -0
- data/spec/shoes/sound_spec.rb +15 -0
- data/spec/shoes/span_spec.rb +112 -0
- data/spec/shoes/spec_helper.rb +24 -0
- data/spec/shoes/stack_spec.rb +79 -0
- data/spec/shoes/star_spec.rb +31 -0
- data/spec/shoes/text_block_dimensions_spec.rb +75 -0
- data/spec/shoes/text_block_spec.rb +270 -0
- data/spec/shoes/url_spec.rb +68 -0
- data/spec/shoes/widget_spec.rb +70 -0
- data/spec/shoes_spec.rb +44 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/swt_shoes/animation_spec.rb +86 -0
- data/spec/swt_shoes/app_spec.rb +84 -0
- data/spec/swt_shoes/arc_spec.rb +103 -0
- data/spec/swt_shoes/background_spec.rb +67 -0
- data/spec/swt_shoes/border_spec.rb +52 -0
- data/spec/swt_shoes/button_spec.rb +101 -0
- data/spec/swt_shoes/check_spec.rb +28 -0
- data/spec/swt_shoes/color_factory_spec.rb +49 -0
- data/spec/swt_shoes/color_spec.rb +67 -0
- data/spec/swt_shoes/common/painter_spec.rb +49 -0
- data/spec/swt_shoes/common/remove_spec.rb +53 -0
- data/spec/swt_shoes/configuration_spec.rb +12 -0
- data/spec/swt_shoes/dialog_spec.rb +106 -0
- data/spec/swt_shoes/disposed_protection_spec.rb +49 -0
- data/spec/swt_shoes/flow_spec.rb +36 -0
- data/spec/swt_shoes/font_spec.rb +33 -0
- data/spec/swt_shoes/gradient_spec.rb +31 -0
- data/spec/swt_shoes/image_pattern_spec.rb +35 -0
- data/spec/swt_shoes/image_spec.rb +100 -0
- data/spec/swt_shoes/input_box_spec.rb +116 -0
- data/spec/swt_shoes/integration_spec.rb +27 -0
- data/spec/swt_shoes/key_listener_spec.rb +325 -0
- data/spec/swt_shoes/line_spec.rb +49 -0
- data/spec/swt_shoes/link_segment_spec.rb +120 -0
- data/spec/swt_shoes/link_spec.rb +54 -0
- data/spec/swt_shoes/list_box_spec.rb +56 -0
- data/spec/swt_shoes/minimal.png +0 -0
- data/spec/swt_shoes/mouse_move_listener_spec.rb +123 -0
- data/spec/swt_shoes/oval_spec.rb +51 -0
- data/spec/swt_shoes/progress_spec.rb +44 -0
- data/spec/swt_shoes/radio_group_spec.rb +73 -0
- data/spec/swt_shoes/radio_spec.rb +56 -0
- data/spec/swt_shoes/rect_painter_spec.rb +45 -0
- data/spec/swt_shoes/rect_spec.rb +19 -0
- data/spec/swt_shoes/shape_spec.rb +84 -0
- data/spec/swt_shoes/shared_examples/button.rb +21 -0
- data/spec/swt_shoes/shared_examples/clickable.rb +85 -0
- data/spec/swt_shoes/shared_examples/movable.rb +36 -0
- data/spec/swt_shoes/shared_examples/paintable.rb +7 -0
- data/spec/swt_shoes/shared_examples/painter.rb +83 -0
- data/spec/swt_shoes/shared_examples/pattern.rb +32 -0
- data/spec/swt_shoes/shared_examples/removable.rb +41 -0
- data/spec/swt_shoes/shared_examples/swt_app_context.rb +23 -0
- data/spec/swt_shoes/shared_examples/visibility.rb +15 -0
- data/spec/swt_shoes/shell_control_listener_spec.rb +23 -0
- data/spec/swt_shoes/slot_spec.rb +24 -0
- data/spec/swt_shoes/sound.rb +10 -0
- data/spec/swt_shoes/spec_helper.rb +31 -0
- data/spec/swt_shoes/star_spec.rb +47 -0
- data/spec/swt_shoes/text_block/centered_text_segment_spec.rb +16 -0
- data/spec/swt_shoes/text_block/cursor_painter_spec.rb +120 -0
- data/spec/swt_shoes/text_block/fitter_spec.rb +213 -0
- data/spec/swt_shoes/text_block/painter_spec.rb +212 -0
- data/spec/swt_shoes/text_block/text_font_factory_spec.rb +40 -0
- data/spec/swt_shoes/text_block/text_segment_collection_spec.rb +256 -0
- data/spec/swt_shoes/text_block/text_segment_spec.rb +135 -0
- data/spec/swt_shoes/text_block_spec.rb +199 -0
- metadata +496 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
shared_examples_for "text element DSL methods" do
|
2
|
+
it "should set banner font size to 48" do
|
3
|
+
text_block = dsl.banner("hello!")
|
4
|
+
expect(text_block.size).to eql 48
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should set title font size to 34" do
|
8
|
+
text_block = dsl.title("hello!")
|
9
|
+
expect(text_block.size).to eql 34
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set subtitle font size to 26" do
|
13
|
+
text_block = dsl.subtitle("hello!")
|
14
|
+
expect(text_block.size).to eql 26
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set tagline font size to 18" do
|
18
|
+
text_block = dsl.tagline("hello!")
|
19
|
+
expect(text_block.size).to eql 18
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set caption font size to 14" do
|
23
|
+
text_block = dsl.caption("hello!")
|
24
|
+
expect(text_block.size).to eql 14
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should set para font size to 12" do
|
28
|
+
text_block = dsl.para("hello!")
|
29
|
+
expect(text_block.size).to eql 12
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set inscription font size to 10" do
|
33
|
+
text_block = dsl.inscription("hello!")
|
34
|
+
expect(text_block.size).to eql 10
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'span' do
|
38
|
+
it 'should parse the color' do
|
39
|
+
span = dsl.span 'Hello', stroke: '#ccc'
|
40
|
+
expect(span.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should handle a splatted array of links' do
|
44
|
+
expect{dsl.span *[dsl.link('foo'), dsl.link('foo')]}.not_to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should handle a splatted array of links and parse the color' do
|
48
|
+
span = dsl.span *[dsl.link('foo'), dsl.link('foo')], stroke: '#ccc'
|
49
|
+
expect(span.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should handle a splatted array of links with a block' do
|
53
|
+
link = dsl.link('foo') { "Bar" }
|
54
|
+
expect{dsl.span *[link, link]}.not_to raise_error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'link' do
|
59
|
+
it 'handles multiple texts' do
|
60
|
+
link = dsl.link('one', 'two')
|
61
|
+
expect(link.to_s).to eql('onetwo')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'handles trailing options' do
|
65
|
+
link = dsl.link('one', 'two', stroke: '#ccc')
|
66
|
+
expect(link.to_s).to eql('onetwo')
|
67
|
+
expect(link.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'para' do
|
72
|
+
context "with nested text fragments with parameters" do
|
73
|
+
Shoes::DSL::TEXT_STYLES.keys.each do |style|
|
74
|
+
it "handles opts properly for #{style}" do
|
75
|
+
para = dsl.para(dsl.send(style, style, stroke: '#ccc'))
|
76
|
+
expect(para.text).to eq(style.to_s)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
shared_context "dsl app" do
|
2
|
+
let(:input_block) { Proc.new {} }
|
3
|
+
let(:input_opts) { Hash.new }
|
4
|
+
let(:user_facing_app) { Shoes::App.new input_opts, &input_block }
|
5
|
+
let(:app) { user_facing_app.instance_variable_get(:@__app__) }
|
6
|
+
let(:parent) { Shoes::Flow.new app, app }
|
7
|
+
end
|
8
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
shared_examples "hover and leave events" do
|
2
|
+
let(:proc) {Proc.new do end}
|
3
|
+
|
4
|
+
it 'can execute hover without raising an error' do
|
5
|
+
expect{subject.hover proc}.not_to raise_error
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'can execute leave without raising an error' do
|
9
|
+
expect{subject.leave proc}.not_to raise_error
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
shared_examples_for "scrollable slot" do
|
2
|
+
its(:scroll) { should be_truthy }
|
3
|
+
it "initializes scroll_top to 0" do
|
4
|
+
expect(subject.scroll_top).to eq(0)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
shared_examples_for "scrollable slot with overflowing content" do
|
9
|
+
it "retains the same height" do
|
10
|
+
expect(subject.height).to eq(height)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has scroll_height larger than height" do
|
14
|
+
expect(subject.scroll_height).to be > height
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has scroll_max = (scroll_height - height)" do
|
18
|
+
expect(subject.scroll_max).to eq(subject.scroll_height - subject.height)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'adjusts scroll_top' do
|
22
|
+
expect(subject.scroll_top).to eq(new_position)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
shared_context "scroll" do
|
27
|
+
let(:height) { 200 }
|
28
|
+
let(:input_opts) { {left: 40, top: 20, width: 400, height: height} }
|
29
|
+
let(:opts) { input_opts.merge(scroll: scroll) }
|
30
|
+
end
|
31
|
+
|
32
|
+
shared_context "overflowing content" do
|
33
|
+
let(:new_position) { 300 }
|
34
|
+
|
35
|
+
before :each do
|
36
|
+
200.times do
|
37
|
+
Shoes::TextBlock.new(app, subject, "Fourteen fat chimichangas", size: 18)
|
38
|
+
end
|
39
|
+
subject.scroll_top = new_position
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'shoes/color'
|
2
|
+
|
3
|
+
shared_examples_for "object with stroke" do
|
4
|
+
let(:color) { Shoes::COLORS.fetch :tomato }
|
5
|
+
let(:color2) { Shoes::COLORS.fetch :forestgreen }
|
6
|
+
let(:gradient) { Shoes::Gradient.new(color, color2) }
|
7
|
+
|
8
|
+
specify "returns a color" do
|
9
|
+
c = subject.stroke = color
|
10
|
+
expect(c.class).to eq(Shoes::Color)
|
11
|
+
end
|
12
|
+
|
13
|
+
specify "sets on receiver" do
|
14
|
+
subject.stroke = color
|
15
|
+
expect(subject.stroke).to eq(color)
|
16
|
+
expect(subject.style[:stroke]).to eq(color)
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "sets with a gradient" do
|
20
|
+
subject.stroke = gradient
|
21
|
+
expect(subject.stroke).to eq(gradient)
|
22
|
+
expect(subject.style[:stroke]).to eq(gradient)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Be sure the subject does *not* have the stroke set previously
|
26
|
+
specify "defaults to black" do
|
27
|
+
expect(subject.stroke).to eq(Shoes::COLORS.fetch :black)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "strokewidth" do
|
31
|
+
specify "defaults to 1" do
|
32
|
+
expect(subject.strokewidth).to eq(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "sets" do
|
36
|
+
subject.strokewidth = 2
|
37
|
+
expect(subject.strokewidth).to eq(2)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
shared_examples_for "object with fill" do
|
43
|
+
let(:color) { Shoes::COLORS.fetch :honeydew }
|
44
|
+
|
45
|
+
specify "returns a color" do
|
46
|
+
c = subject.fill = color
|
47
|
+
expect(c.class).to eq(Shoes::Color)
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "sets on receiver" do
|
51
|
+
subject.fill = color
|
52
|
+
expect(subject.fill).to eq(color)
|
53
|
+
expect(subject.style[:fill]).to eq(color)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Be sure the subject does *not* have the stroke set previously
|
57
|
+
specify "defaults to black" do
|
58
|
+
expect(subject.fill).to eq(Shoes::COLORS.fetch :black)
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,331 @@
|
|
1
|
+
shared_examples_for "Slot" do
|
2
|
+
it "should be able to append" do
|
3
|
+
expect(subject.contents).to be_empty
|
4
|
+
our_subject = subject
|
5
|
+
app.execute_block Proc.new { our_subject.append {para "foo"} }
|
6
|
+
expect(subject.contents.size).to eq(1)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has a height of 0 as it is empty although it has a top' do
|
10
|
+
subject.absolute_top = 100
|
11
|
+
subject.contents_alignment
|
12
|
+
expect(subject.height).to eq 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it_behaves_like 'prepending'
|
16
|
+
it_behaves_like 'clearing'
|
17
|
+
it_behaves_like 'element one positioned with bottom and right'
|
18
|
+
it_behaves_like 'growing although relatively positioned elements'
|
19
|
+
end
|
20
|
+
|
21
|
+
shared_context 'one slot child' do
|
22
|
+
let(:ele_opts) {Hash.new}
|
23
|
+
let(:element) {Shoes::FakeElement.new(nil, {height: 100,width: 50}.merge(ele_opts))}
|
24
|
+
|
25
|
+
before :each do
|
26
|
+
subject.add_child element
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
shared_context 'two slot children' do
|
31
|
+
include_context 'one slot child'
|
32
|
+
let(:element2) {Shoes::FakeElement.new nil, height: 200, width: 70}
|
33
|
+
|
34
|
+
before :each do
|
35
|
+
subject.add_child element2
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
shared_context 'hidden child' do
|
40
|
+
let(:hidden_element) {Shoes::FakeElement.new nil, height: 200, width: 70}
|
41
|
+
|
42
|
+
before :each do
|
43
|
+
subject.add_child hidden_element
|
44
|
+
hidden_element.gui = double("hidden gui", update_visibility: nil)
|
45
|
+
hidden_element.hide
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
shared_context 'three slot children' do
|
50
|
+
include_context 'two slot children'
|
51
|
+
let(:element3) {Shoes::FakeElement.new(nil, height: 50, width: 20)}
|
52
|
+
|
53
|
+
before :each do
|
54
|
+
subject.add_child element3
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
shared_context 'contents_alignment' do
|
59
|
+
before :each do
|
60
|
+
subject.contents_alignment
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
shared_context 'element one with top and left' do
|
65
|
+
let(:ele_top) {22}
|
66
|
+
let(:ele_left) {47}
|
67
|
+
let(:ele_opts) {{left: ele_left, top: ele_top}}
|
68
|
+
end
|
69
|
+
|
70
|
+
shared_context 'slot with set height and width' do
|
71
|
+
let(:input_opts) {{width: 250, height: 300}}
|
72
|
+
end
|
73
|
+
|
74
|
+
shared_context 'element one with bottom and right' do
|
75
|
+
let(:ele_bottom) {24}
|
76
|
+
let(:ele_right) {49}
|
77
|
+
let(:ele_opts) {{right: ele_right, bottom: ele_bottom}}
|
78
|
+
end
|
79
|
+
|
80
|
+
shared_examples_for 'positioning through :_position' do
|
81
|
+
|
82
|
+
let(:element) {Shoes::FakeElement.new nil, height: 100, width: 50}
|
83
|
+
|
84
|
+
def add_child_and_align
|
85
|
+
subject.add_child element
|
86
|
+
subject.contents_alignment
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'sends the child the :_position method to position it' do
|
90
|
+
expect(element).to receive(:_position).and_call_original
|
91
|
+
add_child_and_align
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'does not send _position again if the position did not change' do
|
95
|
+
add_child_and_align
|
96
|
+
expect(element).not_to receive(:_position)
|
97
|
+
subject.contents_alignment
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'does not position an element if it does not need positioning' do
|
101
|
+
my_element = element
|
102
|
+
allow(my_element).to receive_messages needs_to_be_positioned?: false
|
103
|
+
expect(my_element).not_to receive :_position
|
104
|
+
subject.add_child my_element
|
105
|
+
subject.contents_alignment
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
shared_examples_for 'element one positioned with top and left' do
|
110
|
+
it 'positions the element at its left value' do
|
111
|
+
expect(element.absolute_left).to eq subject.absolute_left + ele_left
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'positions the element at its top value' do
|
115
|
+
expect(element.absolute_top).to eq subject.absolute_top + ele_top
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
shared_examples_for 'element one positioned with bottom and right' do
|
120
|
+
include_context 'one slot child'
|
121
|
+
include_context 'contents_alignment'
|
122
|
+
include_context 'element one with bottom and right'
|
123
|
+
include_context 'slot with set height and width'
|
124
|
+
|
125
|
+
it 'positions the element from its right' do
|
126
|
+
expect(element.absolute_right).to eq (subject.absolute_right - ele_right - 1)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'positions the element from its bottom' do
|
130
|
+
expect(element.absolute_bottom).to eq (subject.absolute_bottom - ele_bottom - 1)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
shared_examples_for 'positions the first element in the top left' do
|
135
|
+
include_context 'one slot child'
|
136
|
+
include_context 'contents_alignment'
|
137
|
+
it 'positions a single object at the same top as self' do
|
138
|
+
expect(element.absolute_top).to eq subject.element_top
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'positions a single object at the same left as self' do
|
142
|
+
expect(element.absolute_left).to eq subject.element_left
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'has a slot height of the element height' do
|
146
|
+
expect(subject.height).to eq element.height
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'top and left' do
|
150
|
+
include_context 'element one with top and left'
|
151
|
+
it_behaves_like 'element one positioned with top and left'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
shared_examples_for 'arranges elements underneath each other' do
|
156
|
+
include_context 'two slot children'
|
157
|
+
include_context 'contents_alignment'
|
158
|
+
|
159
|
+
it 'positions an element beneath a previous element' do
|
160
|
+
expect(element2.absolute_top).to eq element.absolute_bottom + 1
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'still positions it at the start of the line (e.g. self.left)' do
|
164
|
+
expect(element2.absolute_left).to eq subject.absolute_left
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'has a stack height according to its contents' do
|
168
|
+
expect(subject.height).to eq (element.height + element2.height)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'has an absolute_bottom of top + height' do
|
172
|
+
expect(subject.absolute_bottom).to eq (subject.absolute_top + subject.height - 1)
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'element one with top and left' do
|
176
|
+
include_context 'element one with top and left'
|
177
|
+
it_behaves_like 'element one positioned with top and left'
|
178
|
+
|
179
|
+
describe 'positions element2 disregarding element1' do
|
180
|
+
it 'has the same absolute left as the slot' do
|
181
|
+
expect(element2.absolute_left).to eq subject.absolute_left
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'has the same absolute top as the slot' do
|
185
|
+
expect(element2.absolute_top).to eq subject.absolute_top
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
shared_examples_for 'set height and contents alignment' do
|
192
|
+
include_context 'two slot children'
|
193
|
+
|
194
|
+
it 'contents_alignment returns the height of the content' do
|
195
|
+
expect(subject.contents_alignment).to eq (element.height + element2.height)
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'still has the same height though' do
|
199
|
+
old_height = subject.height
|
200
|
+
subject.contents_alignment
|
201
|
+
expect(subject.height).to eq old_height
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
shared_examples_for 'taking care of margin' do
|
206
|
+
include_context 'two slot children'
|
207
|
+
include_context 'contents_alignment'
|
208
|
+
|
209
|
+
it 'respects the left margin for the first element' do
|
210
|
+
expect(element.absolute_left).to eq input_opts[:margin]
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'respects the left margin for the second element' do
|
214
|
+
expect(element2.absolute_left).to eq input_opts[:margin]
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'respects the top margin for the first element' do
|
218
|
+
expect(element.absolute_top).to eq input_opts[:margin]
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
shared_examples_for 'growing although relatively positioned elements' do
|
223
|
+
include_context 'one slot child'
|
224
|
+
include_context 'contents_alignment'
|
225
|
+
|
226
|
+
describe 'positioned at the very beginning' do
|
227
|
+
let(:ele_opts) {{top: 0}}
|
228
|
+
|
229
|
+
it 'grows the slot height' do
|
230
|
+
expect(subject.height).to eq element.height
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe 'positioned with a good offset' do
|
235
|
+
let(:ele_opts) {{top: 70}}
|
236
|
+
|
237
|
+
it 'grows the height even further' do
|
238
|
+
expect(subject.height).to eq element.height + 70
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe 'positioning with hidden elements' do
|
243
|
+
include_context 'hidden child'
|
244
|
+
|
245
|
+
it 'grows only to height of first child' do
|
246
|
+
subject.contents_alignment
|
247
|
+
expect(subject.height).to eq element.height
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
shared_examples_for 'prepending' do
|
253
|
+
include_context 'two slot children'
|
254
|
+
let(:prepend1) {double 'prepend1'}
|
255
|
+
let(:prepend2) {double 'prepend2'}
|
256
|
+
|
257
|
+
describe 'one element' do
|
258
|
+
before :each do
|
259
|
+
subject.prepend do
|
260
|
+
subject.add_child prepend1
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'as the first' do
|
265
|
+
expect(subject.contents.first).to eq prepend1
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'has a total of 3 elements then' do
|
269
|
+
expect(subject.contents.size).to eq(3)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe 'two elements' do
|
274
|
+
before :each do
|
275
|
+
subject.prepend do
|
276
|
+
subject.add_child prepend1
|
277
|
+
subject.add_child prepend2
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'has prepend1 as the first child' do
|
282
|
+
expect(subject.contents.first).to eq prepend1
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'has prepend2 as the second child' do
|
286
|
+
expect(subject.contents[1]).to eq prepend2
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'has a total of 4 children' do
|
290
|
+
expect(subject.contents.size).to eq(4)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
describe 'two times' do
|
295
|
+
before :each do
|
296
|
+
subject.prepend { subject.add_child prepend1 }
|
297
|
+
subject.prepend {subject.add_child prepend2 }
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'has the last prepended element as the first' do
|
301
|
+
expect(subject.contents.first).to eq prepend2
|
302
|
+
end
|
303
|
+
|
304
|
+
it 'has the first prepended element as the second' do
|
305
|
+
expect(subject.contents[1]).to eq prepend1
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'has a total of 4 children' do
|
309
|
+
expect(subject.contents.size).to eq(4)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
shared_examples_for 'clearing' do
|
315
|
+
include_context 'two slot children'
|
316
|
+
|
317
|
+
describe '#clear' do
|
318
|
+
it 'removes all contents' do
|
319
|
+
subject.clear
|
320
|
+
expect(subject.contents).to be_empty
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
describe 'Element#remove' do
|
325
|
+
it 'removees the element' do
|
326
|
+
element.parent = subject
|
327
|
+
element.remove
|
328
|
+
expect(subject.contents).not_to include element
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|