shoes-swt 4.0.0.pre2 → 4.0.0.pre3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -200
- data/Rakefile +1 -0
- data/bin/shoes-swt +11 -0
- data/lib/shoes/swt.rb +5 -2
- data/lib/shoes/swt/animation.rb +2 -2
- data/lib/shoes/swt/app.rb +45 -50
- data/lib/shoes/swt/arc.rb +7 -7
- data/lib/shoes/swt/background.rb +1 -1
- data/lib/shoes/swt/border.rb +1 -2
- data/lib/shoes/swt/click_listener.rb +70 -0
- data/lib/shoes/swt/color.rb +5 -5
- data/lib/shoes/swt/common/clickable.rb +2 -53
- data/lib/shoes/swt/common/fill.rb +1 -1
- data/lib/shoes/swt/common/painter.rb +7 -7
- data/lib/shoes/swt/common/painter_updates_position.rb +2 -2
- data/lib/shoes/swt/common/remove.rb +2 -3
- data/lib/shoes/swt/common/resource.rb +1 -1
- data/lib/shoes/swt/common/selection_listener.rb +14 -14
- data/lib/shoes/swt/common/stroke.rb +1 -2
- data/lib/shoes/swt/common/update_position.rb +1 -1
- data/lib/shoes/swt/dialog.rb +3 -45
- data/lib/shoes/swt/disposed_protection.rb +1 -1
- data/lib/shoes/swt/download.rb +0 -1
- data/lib/shoes/swt/font.rb +4 -4
- data/lib/shoes/swt/generate-backend.rb +9 -0
- data/lib/shoes/swt/gradient.rb +17 -16
- data/lib/shoes/swt/image.rb +3 -5
- data/lib/shoes/swt/image_pattern.rb +2 -2
- data/lib/shoes/swt/input_box.rb +3 -3
- data/lib/shoes/swt/key_listener.rb +6 -6
- data/lib/shoes/swt/line.rb +4 -24
- data/lib/shoes/swt/link.rb +2 -2
- data/lib/shoes/swt/link_segment.rb +3 -3
- data/lib/shoes/swt/list_box.rb +4 -4
- data/lib/shoes/swt/mouse_move_listener.rb +6 -5
- data/lib/shoes/swt/oval.rb +2 -3
- data/lib/shoes/swt/packager.rb +82 -0
- data/lib/shoes/swt/progress.rb +2 -2
- data/lib/shoes/swt/radio.rb +0 -2
- data/lib/shoes/swt/radio_group.rb +54 -54
- data/lib/shoes/swt/rect_painter.rb +7 -7
- data/lib/shoes/swt/redrawing_aspect.rb +32 -34
- data/lib/shoes/swt/shape.rb +1 -1
- data/lib/shoes/swt/shoes_layout.rb +5 -2
- data/lib/shoes/swt/slot.rb +2 -3
- data/lib/shoes/swt/sound.rb +17 -22
- data/lib/shoes/swt/star.rb +30 -8
- data/lib/shoes/swt/swt_button.rb +3 -2
- data/lib/shoes/swt/text_block.rb +3 -3
- data/lib/shoes/swt/text_block/cursor_painter.rb +2 -2
- data/lib/shoes/swt/text_block/fitter.rb +5 -3
- data/lib/shoes/swt/text_block/painter.rb +9 -9
- data/lib/shoes/swt/text_block/text_font_factory.rb +3 -3
- data/lib/shoes/swt/text_block/text_segment.rb +9 -9
- data/lib/shoes/swt/text_block/text_segment_collection.rb +2 -0
- data/lib/shoes/swt/text_block/text_style_factory.rb +9 -3
- data/lib/shoes/swt/timer.rb +1 -1
- data/lib/shoes/swt/version.rb +1 -1
- data/shoes-swt.gemspec +7 -6
- data/spec/shoes/cli_spec.rb +2 -2
- data/spec/{swt_shoes → shoes/swt}/animation_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/app_spec.rb +36 -3
- data/spec/{swt_shoes → shoes/swt}/arc_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/background_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/border_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/button_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/check_spec.rb +1 -1
- data/spec/shoes/swt/click_listener_spec.rb +162 -0
- data/spec/{swt_shoes → shoes/swt}/color_factory_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/color_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/common/painter_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/common/remove_spec.rb +4 -11
- data/spec/{swt_shoes → shoes/swt}/configuration_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/dialog_spec.rb +1 -7
- data/spec/{swt_shoes → shoes/swt}/disposed_protection_spec.rb +0 -0
- data/spec/{swt_shoes → shoes/swt}/flow_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/font_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/gradient_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/image_pattern_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/image_spec.rb +4 -3
- data/spec/{swt_shoes → shoes/swt}/input_box_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/integration_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/key_listener_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/line_spec.rb +4 -8
- data/spec/{swt_shoes → shoes/swt}/link_segment_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/link_spec.rb +3 -10
- data/spec/{swt_shoes → shoes/swt}/list_box_spec.rb +5 -3
- data/spec/{swt_shoes → shoes/swt}/minimal.png +0 -0
- data/spec/{swt_shoes → shoes/swt}/mouse_move_listener_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/oval_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/progress_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/radio_group_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/radio_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/rect_painter_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/rect_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/shape_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/shared_examples/button.rb +0 -0
- data/spec/shoes/swt/shared_examples/clickable.rb +13 -0
- data/spec/{swt_shoes → shoes/swt}/shared_examples/movable.rb +0 -0
- data/spec/{swt_shoes → shoes/swt}/shared_examples/paintable.rb +0 -0
- data/spec/{swt_shoes → shoes/swt}/shared_examples/painter.rb +0 -0
- data/spec/{swt_shoes → shoes/swt}/shared_examples/pattern.rb +0 -0
- data/spec/{swt_shoes → shoes/swt}/shared_examples/removable.rb +1 -3
- data/spec/{swt_shoes → shoes/swt}/shared_examples/swt_app_context.rb +11 -3
- data/spec/{swt_shoes → shoes/swt}/shared_examples/visibility.rb +0 -0
- data/spec/{swt_shoes → shoes/swt}/shell_control_listener_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/slot_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/spec_helper.rb +0 -1
- data/spec/{swt_shoes → shoes/swt}/star_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/text_block/centered_text_segment_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/text_block/cursor_painter_spec.rb +8 -4
- data/spec/{swt_shoes → shoes/swt}/text_block/fitter_spec.rb +5 -5
- data/spec/{swt_shoes → shoes/swt}/text_block/painter_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/text_block/text_font_factory_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/text_block/text_segment_collection_spec.rb +7 -2
- data/spec/{swt_shoes → shoes/swt}/text_block/text_segment_spec.rb +1 -1
- data/spec/{swt_shoes → shoes/swt}/text_block_spec.rb +2 -5
- data/spec/spec_helper.rb +7 -3
- metadata +132 -331
- data/CHANGELOG +0 -84
- data/Gemfile +0 -24
- data/Guardfile +0 -11
- data/manifests/common.rb +0 -34
- data/manifests/shoes-swt.rb +0 -29
- data/spec/code_coverage.rb +0 -14
- data/spec/shoes/animation_spec.rb +0 -65
- data/spec/shoes/app_spec.rb +0 -484
- data/spec/shoes/arc_spec.rb +0 -51
- data/spec/shoes/background_spec.rb +0 -53
- data/spec/shoes/border_spec.rb +0 -47
- data/spec/shoes/builtin_methods_spec.rb +0 -110
- data/spec/shoes/button_spec.rb +0 -44
- data/spec/shoes/check_spec.rb +0 -35
- data/spec/shoes/color_spec.rb +0 -408
- data/spec/shoes/common/inspect_spec.rb +0 -26
- data/spec/shoes/common/remove_spec.rb +0 -38
- data/spec/shoes/common/style_normalizer_spec.rb +0 -28
- data/spec/shoes/common/style_spec.rb +0 -147
- data/spec/shoes/configuration_spec.rb +0 -36
- data/spec/shoes/constants_spec.rb +0 -38
- data/spec/shoes/dialog_spec.rb +0 -163
- data/spec/shoes/dimension_spec.rb +0 -407
- data/spec/shoes/dimensions_spec.rb +0 -837
- data/spec/shoes/download_spec.rb +0 -142
- data/spec/shoes/flow_spec.rb +0 -133
- data/spec/shoes/font_spec.rb +0 -37
- data/spec/shoes/framework_learning_spec.rb +0 -30
- data/spec/shoes/gradient_spec.rb +0 -32
- data/spec/shoes/helpers/fake_element.rb +0 -17
- data/spec/shoes/helpers/inspect_helpers.rb +0 -5
- data/spec/shoes/helpers/sample17_helper.rb +0 -66
- data/spec/shoes/image_spec.rb +0 -49
- data/spec/shoes/images/shoe.jpg +0 -0
- data/spec/shoes/input_box_spec.rb +0 -80
- data/spec/shoes/integration_spec.rb +0 -20
- data/spec/shoes/internal_app_spec.rb +0 -141
- data/spec/shoes/keypress_spec.rb +0 -11
- data/spec/shoes/keyrelease_spec.rb +0 -12
- data/spec/shoes/line_spec.rb +0 -49
- data/spec/shoes/link_spec.rb +0 -105
- data/spec/shoes/list_box_spec.rb +0 -74
- data/spec/shoes/logger/ruby_spec.rb +0 -8
- data/spec/shoes/logger_spec.rb +0 -45
- data/spec/shoes/oval_spec.rb +0 -24
- data/spec/shoes/point_spec.rb +0 -71
- data/spec/shoes/progress_spec.rb +0 -54
- data/spec/shoes/radio_spec.rb +0 -32
- data/spec/shoes/rect_spec.rb +0 -39
- data/spec/shoes/renamed_delegate_spec.rb +0 -70
- data/spec/shoes/shape_spec.rb +0 -95
- data/spec/shoes/shared_examples/button.rb +0 -6
- data/spec/shoes/shared_examples/changeable.rb +0 -26
- data/spec/shoes/shared_examples/clickable.rb +0 -5
- data/spec/shoes/shared_examples/common_methods.rb +0 -35
- data/spec/shoes/shared_examples/dimensions.rb +0 -32
- data/spec/shoes/shared_examples/dsl.rb +0 -44
- data/spec/shoes/shared_examples/dsl/animate.rb +0 -29
- data/spec/shoes/shared_examples/dsl/arc.rb +0 -45
- data/spec/shoes/shared_examples/dsl/background.rb +0 -26
- data/spec/shoes/shared_examples/dsl/border.rb +0 -10
- data/spec/shoes/shared_examples/dsl/button.rb +0 -5
- data/spec/shoes/shared_examples/dsl/cap.rb +0 -6
- data/spec/shoes/shared_examples/dsl/check.rb +0 -11
- data/spec/shoes/shared_examples/dsl/edit_box.rb +0 -8
- data/spec/shoes/shared_examples/dsl/edit_line.rb +0 -8
- data/spec/shoes/shared_examples/dsl/editable_element.rb +0 -29
- data/spec/shoes/shared_examples/dsl/fill.rb +0 -27
- data/spec/shoes/shared_examples/dsl/flow.rb +0 -15
- data/spec/shoes/shared_examples/dsl/gradient.rb +0 -62
- data/spec/shoes/shared_examples/dsl/image.rb +0 -21
- data/spec/shoes/shared_examples/dsl/line.rb +0 -9
- data/spec/shoes/shared_examples/dsl/nofill.rb +0 -6
- data/spec/shoes/shared_examples/dsl/nostroke.rb +0 -6
- data/spec/shoes/shared_examples/dsl/oval.rb +0 -88
- data/spec/shoes/shared_examples/dsl/pattern.rb +0 -34
- data/spec/shoes/shared_examples/dsl/progress.rb +0 -7
- data/spec/shoes/shared_examples/dsl/rect.rb +0 -92
- data/spec/shoes/shared_examples/dsl/rgb.rb +0 -26
- data/spec/shoes/shared_examples/dsl/shape.rb +0 -21
- data/spec/shoes/shared_examples/dsl/star.rb +0 -48
- data/spec/shoes/shared_examples/dsl/stroke.rb +0 -30
- data/spec/shoes/shared_examples/dsl/strokewidth.rb +0 -19
- data/spec/shoes/shared_examples/dsl/style.rb +0 -32
- data/spec/shoes/shared_examples/dsl/text_elements.rb +0 -81
- data/spec/shoes/shared_examples/dsl/video.rb +0 -5
- data/spec/shoes/shared_examples/dsl_app_context.rb +0 -8
- data/spec/shoes/shared_examples/hover_leave.rb +0 -11
- data/spec/shoes/shared_examples/parent.rb +0 -6
- data/spec/shoes/shared_examples/scroll.rb +0 -41
- data/spec/shoes/shared_examples/shared_element_method.rb +0 -60
- data/spec/shoes/shared_examples/slot.rb +0 -331
- data/spec/shoes/shared_examples/state.rb +0 -19
- data/spec/shoes/shared_examples/style.rb +0 -82
- data/spec/shoes/slot_spec.rb +0 -130
- data/spec/shoes/sound_spec.rb +0 -15
- data/spec/shoes/span_spec.rb +0 -112
- data/spec/shoes/spec_helper.rb +0 -24
- data/spec/shoes/stack_spec.rb +0 -79
- data/spec/shoes/star_spec.rb +0 -31
- data/spec/shoes/text_block_dimensions_spec.rb +0 -75
- data/spec/shoes/text_block_spec.rb +0 -270
- data/spec/shoes/url_spec.rb +0 -68
- data/spec/shoes/widget_spec.rb +0 -70
- data/spec/shoes_spec.rb +0 -44
- data/spec/swt_shoes/shared_examples/clickable.rb +0 -85
- data/spec/swt_shoes/sound.rb +0 -10
@@ -1,407 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Shoes::Dimension do
|
4
|
-
|
5
|
-
subject {Shoes::Dimension.new parent_dimension}
|
6
|
-
let(:start) {10}
|
7
|
-
let(:extent) {21}
|
8
|
-
let(:parent_element_start) {34}
|
9
|
-
let(:parent_element_end) {83}
|
10
|
-
let(:parent_element_extent) {600}
|
11
|
-
let(:parent_dimension) { double 'parent_dimension',
|
12
|
-
element_start: parent_element_start,
|
13
|
-
element_end: parent_element_end,
|
14
|
-
element_extent: parent_element_extent }
|
15
|
-
|
16
|
-
ONE_PIXEL = 1 unless const_defined?(:ONE_PIXEL) && ONE_PIXEL == 1
|
17
|
-
|
18
|
-
describe 'initialization' do
|
19
|
-
describe 'without arguments (even no parent)' do
|
20
|
-
subject {Shoes::Dimension.new nil}
|
21
|
-
|
22
|
-
its(:start) {should eq nil}
|
23
|
-
its(:end) {should eq nil}
|
24
|
-
its(:extent) {should eq nil}
|
25
|
-
its(:margin_start) {should eq 0}
|
26
|
-
its(:margin_end) {should eq 0}
|
27
|
-
its(:displace_start) {should eq 0}
|
28
|
-
it {is_expected.not_to be_positioned}
|
29
|
-
it {is_expected.not_to be_absolute_position}
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'with a parent and being positioned itself' do
|
33
|
-
subject {Shoes::Dimension.new parent_dimension}
|
34
|
-
|
35
|
-
TESTING_OFFSET = 11
|
36
|
-
|
37
|
-
before :each do
|
38
|
-
subject.absolute_start = parent_element_start + TESTING_OFFSET
|
39
|
-
subject.extent = 10
|
40
|
-
end
|
41
|
-
|
42
|
-
its(:start) {should eq TESTING_OFFSET}
|
43
|
-
its(:end) {should eq parent_element_end - subject.element_end}
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'start as center' do
|
47
|
-
subject {Shoes::Dimension.new parent_dimension, true}
|
48
|
-
|
49
|
-
it 'takes start as the center' do
|
50
|
-
subject.extent = 100
|
51
|
-
subject.start = 60
|
52
|
-
expect(subject.start).to eq 10
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#extent' do
|
58
|
-
let(:parent_element_extent) {600}
|
59
|
-
let(:parent_extent) {580}
|
60
|
-
let(:parent) {double 'parent', element_extent: parent_element_extent,
|
61
|
-
extent: parent_extent}
|
62
|
-
|
63
|
-
subject {Shoes::Dimension.new parent}
|
64
|
-
|
65
|
-
it 'gets and sets' do
|
66
|
-
subject.extent = extent
|
67
|
-
expect(subject.extent).to eq extent
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'negative values' do
|
71
|
-
it 'subtracts them from the parent taking margins into account' do
|
72
|
-
subject.extent = -70
|
73
|
-
expect(subject.extent).to eq parent_element_extent - 70
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe 'relative values from the parent taking margins into account' do
|
78
|
-
it 'takes them relative to the parent for smaller values' do
|
79
|
-
subject.extent = 0.8
|
80
|
-
expect(subject.extent).to be_within(ONE_PIXEL).of 0.8 *
|
81
|
-
parent_element_extent
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'handles negative relative values' do
|
85
|
-
subject.extent = -0.3
|
86
|
-
expect(subject.extent).to be_within(ONE_PIXEL).of 0.7 *
|
87
|
-
parent_element_extent
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'equal parent extent for 1.0' do
|
91
|
-
subject.extent = 1.0
|
92
|
-
expect(subject.extent).to eq parent_element_extent
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'does not take them relative to the parent for bigger values' do
|
96
|
-
subject.extent = 1.3
|
97
|
-
expect(subject.extent).to eq 1.3
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe 'string values' do
|
102
|
-
it 'handles pure number strings' do
|
103
|
-
subject.extent = '100'
|
104
|
-
expect(subject.extent).to eq 100
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'handles px strings' do
|
108
|
-
subject.extent = '80px'
|
109
|
-
expect(subject.extent).to eq 80
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'takes care of some px white space' do
|
113
|
-
subject.extent = '70 px'
|
114
|
-
expect(subject.extent).to eq 70
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'also handles negative values' do
|
118
|
-
subject.extent = '-50px'
|
119
|
-
expect(subject.extent).to eq parent_element_extent - 50
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'handles percent as relative value' do
|
123
|
-
subject.extent = '75%'
|
124
|
-
expect(subject.extent).to be_within(ONE_PIXEL).of 0.75 *
|
125
|
-
parent_element_extent
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'handles negative percent values' do
|
129
|
-
subject.extent = '-10%'
|
130
|
-
expect(subject.extent).to be_within(ONE_PIXEL).of 0.9 *
|
131
|
-
parent_element_extent
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'handles percent values with floats' do
|
135
|
-
subject.extent = '20.5%'
|
136
|
-
expect(subject.extent).to be_within(ONE_PIXEL).of 0.205 *
|
137
|
-
parent_element_extent
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'returns nil for invalid strings' do
|
141
|
-
subject.extent = 'hell0'
|
142
|
-
expect(subject.extent).to be_nil
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe '#start' do
|
148
|
-
let(:start) {23}
|
149
|
-
|
150
|
-
before :each do
|
151
|
-
subject.start = start
|
152
|
-
end
|
153
|
-
|
154
|
-
its(:start) {should eq start}
|
155
|
-
it {is_expected.to be_absolute_position}
|
156
|
-
|
157
|
-
it 'can set a start relative to parent element_extent' do
|
158
|
-
subject.start = 0.3
|
159
|
-
expected = 0.3 * parent_element_extent
|
160
|
-
expect(subject.start).to be_within(ONE_PIXEL).of expected
|
161
|
-
end
|
162
|
-
|
163
|
-
# might be surprising if people do calculations that result in a float
|
164
|
-
# and all of a sudden they have 10.4 and the button is nowhere to be found
|
165
|
-
it 'uses literal float values for values over 1.0' do
|
166
|
-
subject.start = 1.01
|
167
|
-
expect(subject.start).to eq 1.01
|
168
|
-
end
|
169
|
-
|
170
|
-
context '#without a parent' do
|
171
|
-
let(:parent_dimension) {nil}
|
172
|
-
|
173
|
-
it 'just takes the relative value' do
|
174
|
-
subject.start = 0.8
|
175
|
-
expect(subject.start).to eq 0.8
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe 'with no parent but set dimensions' do
|
181
|
-
subject {Shoes::Dimension.new}
|
182
|
-
|
183
|
-
before :each do
|
184
|
-
subject.absolute_start = 23
|
185
|
-
subject.extent = 45
|
186
|
-
end
|
187
|
-
|
188
|
-
its(:end) {should be_nil}
|
189
|
-
its(:start) {should be_nil}
|
190
|
-
end
|
191
|
-
|
192
|
-
describe '#absolute_start' do
|
193
|
-
let(:absolute_start) {8}
|
194
|
-
|
195
|
-
before :each do
|
196
|
-
subject.absolute_start = absolute_start
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'gets and sets absolute_start' do
|
200
|
-
expect(subject.absolute_start).to eq absolute_start
|
201
|
-
end
|
202
|
-
|
203
|
-
it {is_expected.to be_positioned}
|
204
|
-
end
|
205
|
-
|
206
|
-
describe '#absolute_end' do
|
207
|
-
it 'is the sum of start and extent' do
|
208
|
-
subject.absolute_start = 7
|
209
|
-
subject.extent = 22
|
210
|
-
expect(subject.absolute_end).to eq 29 - ONE_PIXEL # pixel counting adjustment
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'returns nil if absolute_start is nil but extent is set' do
|
214
|
-
subject.absolute_start = nil
|
215
|
-
subject.extent = 100
|
216
|
-
expect(subject.absolute_end).to be_nil
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe '#margins' do
|
221
|
-
|
222
|
-
let(:margin_start) {11}
|
223
|
-
let(:margin_end) {17}
|
224
|
-
|
225
|
-
before :each do
|
226
|
-
subject.margin_start = margin_start
|
227
|
-
subject.margin_end = margin_end
|
228
|
-
end
|
229
|
-
|
230
|
-
its(:margin_start) {should eq margin_start}
|
231
|
-
its(:margin_end) {should eq margin_end}
|
232
|
-
|
233
|
-
context 'absolute_start set' do
|
234
|
-
let(:absolute_start) {7}
|
235
|
-
|
236
|
-
before :each do
|
237
|
-
subject.absolute_start = absolute_start
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'does not influence absolute_start' do
|
241
|
-
expect(subject.absolute_start).to eq absolute_start
|
242
|
-
end
|
243
|
-
|
244
|
-
it 'does influence element_start' do
|
245
|
-
expect(subject.element_start).to eq absolute_start + margin_start
|
246
|
-
end
|
247
|
-
|
248
|
-
context 'extent set' do
|
249
|
-
let(:extent) {67}
|
250
|
-
|
251
|
-
before :each do
|
252
|
-
subject.extent = extent
|
253
|
-
end
|
254
|
-
|
255
|
-
it 'does not influence absolute_end' do
|
256
|
-
expect(subject.absolute_end).to eq absolute_start + extent - ONE_PIXEL
|
257
|
-
end
|
258
|
-
|
259
|
-
it 'does influence element_end' do
|
260
|
-
expect(subject.element_end).to eq absolute_start + extent -
|
261
|
-
margin_end - ONE_PIXEL
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
context 'element_extent set' do
|
266
|
-
let(:element_extent) {77}
|
267
|
-
|
268
|
-
before :each do
|
269
|
-
subject.element_extent = element_extent
|
270
|
-
end
|
271
|
-
|
272
|
-
its(:element_extent) {should eq element_extent}
|
273
|
-
its(:extent) {should eq element_extent + margin_start + margin_end}
|
274
|
-
its(:element_end) {should eq subject.element_start + element_extent -
|
275
|
-
ONE_PIXEL}
|
276
|
-
end
|
277
|
-
|
278
|
-
describe 'relative margins' do
|
279
|
-
let(:margin_start) {0.1}
|
280
|
-
let(:margin_end) {0.2}
|
281
|
-
|
282
|
-
its(:margin_start) {should be_within(ONE_PIXEL).of 0.1 *
|
283
|
-
parent_element_extent}
|
284
|
-
its(:margin_end) {should be_within(ONE_PIXEL).of 0.2 *
|
285
|
-
parent_element_extent}
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
describe '#in_bounds?' do
|
291
|
-
let(:absolute_start) {20}
|
292
|
-
let(:extent) {100}
|
293
|
-
let(:absolute_end) {20 + 100 -ONE_PIXEL} # -1 due to pixel counting adjustment
|
294
|
-
|
295
|
-
before :each do
|
296
|
-
subject.absolute_start = absolute_start
|
297
|
-
subject.extent = extent
|
298
|
-
end
|
299
|
-
|
300
|
-
its(:absolute_end) {should eq absolute_end}
|
301
|
-
|
302
|
-
it {is_expected.to be_in_bounds absolute_start}
|
303
|
-
it {is_expected.to be_in_bounds absolute_end}
|
304
|
-
it {is_expected.to be_in_bounds absolute_start + ONE_PIXEL}
|
305
|
-
it {is_expected.to be_in_bounds absolute_end - ONE_PIXEL}
|
306
|
-
it {is_expected.to be_in_bounds 40}
|
307
|
-
it {is_expected.to be_in_bounds 105}
|
308
|
-
it {is_expected.to be_in_bounds 20.021}
|
309
|
-
it {is_expected.not_to be_in_bounds absolute_end + ONE_PIXEL}
|
310
|
-
it {is_expected.not_to be_in_bounds absolute_start - ONE_PIXEL
|
311
|
-
}
|
312
|
-
it {is_expected.not_to be_in_bounds -5}
|
313
|
-
it {is_expected.not_to be_in_bounds 0}
|
314
|
-
it {is_expected.not_to be_in_bounds 150}
|
315
|
-
it {is_expected.not_to be_in_bounds 123178}
|
316
|
-
end
|
317
|
-
|
318
|
-
it 'can displace the placement' do
|
319
|
-
subject.displace_start = 5
|
320
|
-
subject.absolute_start = 10
|
321
|
-
expect(subject.element_start).to eq 15
|
322
|
-
end
|
323
|
-
|
324
|
-
describe 'start/end/margin and other values parse simple string values' do
|
325
|
-
it 'parses a normal number' do
|
326
|
-
subject.start = '50'
|
327
|
-
expect(subject.start).to eq 50
|
328
|
-
end
|
329
|
-
|
330
|
-
it 'parses pixel values' do
|
331
|
-
subject.start = '77px'
|
332
|
-
expect(subject.start).to eq 77
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'parses negative values' do
|
336
|
-
subject.start = '-13'
|
337
|
-
expect(subject.start).to eq -13
|
338
|
-
end
|
339
|
-
|
340
|
-
it 'even parses negative values with px' do
|
341
|
-
subject.start = '-22px'
|
342
|
-
expect(subject.start).to eq -22
|
343
|
-
end
|
344
|
-
|
345
|
-
it 'returns nil for unknown values' do
|
346
|
-
subject.start = []
|
347
|
-
expect(subject.start).to be_nil
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
describe Shoes::ParentDimension do
|
352
|
-
let(:parent) {Shoes::Dimension.new}
|
353
|
-
let(:parent_start) {7}
|
354
|
-
let(:parent_extent) {27}
|
355
|
-
let(:margin) {5}
|
356
|
-
|
357
|
-
subject {Shoes::ParentDimension.new parent}
|
358
|
-
|
359
|
-
before :each do
|
360
|
-
parent.start = parent_start
|
361
|
-
parent.extent = parent_extent
|
362
|
-
parent.margin_start = margin
|
363
|
-
parent.margin_end = margin
|
364
|
-
end
|
365
|
-
|
366
|
-
describe 'it takes its parent values if no values are set' do
|
367
|
-
its(:start) {should eq parent_start}
|
368
|
-
its(:extent) {should eq parent_extent}
|
369
|
-
its(:margin_start) {should eq margin}
|
370
|
-
its(:margin_end) {should eq margin}
|
371
|
-
|
372
|
-
context 'with parent absolute_start set' do
|
373
|
-
before :each do
|
374
|
-
parent.absolute_start = 11
|
375
|
-
end
|
376
|
-
|
377
|
-
its(:absolute_start) {should eq 11}
|
378
|
-
its(:element_start) {should eq parent.element_start}
|
379
|
-
its(:element_end) {should eq parent.element_end}
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
describe 'otherwise it takes its own values' do
|
384
|
-
before :each do
|
385
|
-
subject.start = start
|
386
|
-
subject.extent = extent
|
387
|
-
subject.absolute_start = 17
|
388
|
-
end
|
389
|
-
|
390
|
-
its(:start) {should eq start}
|
391
|
-
its(:extent) {should eq extent}
|
392
|
-
its(:absolute_start) {should eq 17}
|
393
|
-
|
394
|
-
it 'can still handle special values like a negative extent' do
|
395
|
-
subject.extent = -10
|
396
|
-
expect(subject.extent).to eq (parent_extent - 2 * margin) - 10
|
397
|
-
end
|
398
|
-
|
399
|
-
it 'can also still handle special values like relative values' do
|
400
|
-
subject.extent = 0.8
|
401
|
-
expect(subject.extent).to be_within(ONE_PIXEL).of(0.8 * parent.element_extent)
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
end
|
407
|
-
|
@@ -1,837 +0,0 @@
|
|
1
|
-
require 'shoes/spec_helper'
|
2
|
-
|
3
|
-
describe Shoes::Dimensions do
|
4
|
-
|
5
|
-
let(:parent_left) {left}
|
6
|
-
let(:parent_top) {top}
|
7
|
-
let(:parent_width) {width}
|
8
|
-
let(:parent_height) {height}
|
9
|
-
let(:parent) {Shoes::AbsoluteDimensions.new parent_left, parent_top, parent_width, parent_height}
|
10
|
-
|
11
|
-
let(:left) {10}
|
12
|
-
let(:top) {20}
|
13
|
-
let(:width) {100}
|
14
|
-
let(:height) {150}
|
15
|
-
let(:right) {17}
|
16
|
-
let(:bottom) {23}
|
17
|
-
let(:opts) { {} }
|
18
|
-
subject {Shoes::Dimensions.new parent, left, top, width, height, opts}
|
19
|
-
|
20
|
-
shared_context 'margins' do
|
21
|
-
let(:margin_left) {3}
|
22
|
-
let(:margin_top) {5}
|
23
|
-
let(:margin_right) {7}
|
24
|
-
let(:margin_bottom) {11}
|
25
|
-
let(:opts) { {margin_left: margin_left, margin_top: margin_top,
|
26
|
-
margin_right: margin_right, margin_bottom: margin_bottom } }
|
27
|
-
end
|
28
|
-
|
29
|
-
shared_context 'element dimensions set' do
|
30
|
-
let(:element_width) {43}
|
31
|
-
let(:element_height) {29}
|
32
|
-
|
33
|
-
before :each do
|
34
|
-
subject.element_width = element_width
|
35
|
-
subject.element_height = element_height
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
ONE_PIXEL = 1 unless const_defined?(:ONE_PIXEL) && ONE_PIXEL == 1
|
40
|
-
|
41
|
-
describe 'initialization' do
|
42
|
-
include InspectHelpers
|
43
|
-
|
44
|
-
describe 'without arguments (defaults)' do
|
45
|
-
subject {Shoes::Dimensions.new parent}
|
46
|
-
|
47
|
-
its(:left) {should be_nil}
|
48
|
-
its(:top) {should be_nil}
|
49
|
-
its(:width) {should eq nil}
|
50
|
-
its(:height) {should eq nil}
|
51
|
-
its(:absolutely_positioned?) {should be_falsey}
|
52
|
-
its(:absolute_x_position?) {should be_falsey}
|
53
|
-
its(:absolute_y_position?) {should be_falsey}
|
54
|
-
its(:absolute_left_position?) {should be_falsey}
|
55
|
-
its(:absolute_top_position?) {should be_falsey}
|
56
|
-
its(:absolute_right_position?) {should be_falsey}
|
57
|
-
its(:absolute_bottom_position?) {should be_falsey}
|
58
|
-
its(:margin) {should == [0, 0, 0, 0]}
|
59
|
-
its(:margin_left) {should == 0}
|
60
|
-
its(:margin_top) {should == 0}
|
61
|
-
its(:margin_right) {should == 0}
|
62
|
-
its(:margin_bottom) {should == 0}
|
63
|
-
its(:element_width) {should == nil}
|
64
|
-
its(:element_height) {should == nil}
|
65
|
-
its(:to_s) {should == "(Shoes::Dimensions)"}
|
66
|
-
its(:inspect) {should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]_,_[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] _x_[)]/)}
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'with 2 arguments' do
|
70
|
-
subject {Shoes::Dimensions.new parent, left, top}
|
71
|
-
|
72
|
-
its(:left) {should eq left}
|
73
|
-
its(:top) {should eq top}
|
74
|
-
its(:width) {should eq nil}
|
75
|
-
its(:height) {should eq nil}
|
76
|
-
its(:absolutely_positioned?) {should be_truthy}
|
77
|
-
its(:absolute_x_position?) {should be_truthy}
|
78
|
-
its(:absolute_y_position?) {should be_truthy}
|
79
|
-
its(:absolute_left_position?) {should be_truthy}
|
80
|
-
its(:absolute_top_position?) {should be_truthy}
|
81
|
-
its(:absolute_right_position?) {should be_falsey}
|
82
|
-
its(:absolute_bottom_position?) {should be_falsey}
|
83
|
-
its(:inspect) {should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]#{left},#{top}[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] _x_[)]/)}
|
84
|
-
end
|
85
|
-
|
86
|
-
describe 'with 4 arguments' do
|
87
|
-
subject {Shoes::Dimensions.new parent, left, top, width, height}
|
88
|
-
|
89
|
-
its(:left) {should eq left}
|
90
|
-
its(:top) {should eq top}
|
91
|
-
its(:width) {should eq width}
|
92
|
-
its(:height) {should eq height}
|
93
|
-
its(:element_width) {should == width}
|
94
|
-
its(:element_height) {should == height}
|
95
|
-
its(:inspect) {should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]#{left},#{top}[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] #{width}x#{height}[)]/)}
|
96
|
-
end
|
97
|
-
|
98
|
-
describe 'with relative width and height' do
|
99
|
-
subject {Shoes::Dimensions.new parent, left, top, 0.5, 0.5}
|
100
|
-
|
101
|
-
its(:left) {should eq left}
|
102
|
-
its(:top) {should eq top}
|
103
|
-
its(:width) {should be_within(ONE_PIXEL).of 0.5 * parent.width}
|
104
|
-
its(:height) {should be_within(ONE_PIXEL).of 0.5 * parent.height}
|
105
|
-
|
106
|
-
describe 'width/height change of the parent' do
|
107
|
-
|
108
|
-
# note that here the first assertion/call is necessary as otherwise
|
109
|
-
# the subject will only lazily get initialized after the parent width
|
110
|
-
# is already adjusted and therefore wrong impls WILL PASS the tests
|
111
|
-
# (jay for red/green/refactor :-) )
|
112
|
-
it 'adapts width' do
|
113
|
-
expect(subject.width).to be_within(ONE_PIXEL).of 0.5 * parent.width
|
114
|
-
parent.width = 700
|
115
|
-
expect(subject.width).to be_within(ONE_PIXEL).of 350
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'adapts height' do
|
119
|
-
expect(subject.height).to be_within(ONE_PIXEL).of 0.5 * parent.height
|
120
|
-
parent.height = 800
|
121
|
-
expect(subject.height).to be_within(ONE_PIXEL).of 400
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe 'a parent with margins' do
|
126
|
-
let(:parent) {Shoes::AbsoluteDimensions.new parent_left,
|
127
|
-
parent_top,
|
128
|
-
parent_width,
|
129
|
-
parent_height,
|
130
|
-
margin: 20}
|
131
|
-
subject {Shoes::Dimensions.new parent, left, top, 1.0, 1.0}
|
132
|
-
|
133
|
-
it 'uses the element_width to calculate its own relative width' do
|
134
|
-
expect(subject.width).to eq parent.element_width
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'has a smaller width than the parent element (due to margins)' do
|
138
|
-
expect(subject.width).to be < parent.width
|
139
|
-
end
|
140
|
-
|
141
|
-
its(:height) {should eq parent.element_height}
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
describe 'with percentages' do
|
147
|
-
describe 'with whole integers' do
|
148
|
-
subject {Shoes::Dimensions.new parent, left, top, "50%", "50%"}
|
149
|
-
its(:width) {should be_within(ONE_PIXEL).of 0.5 * parent.width}
|
150
|
-
its(:height) {should be_within(ONE_PIXEL).of 0.5 * parent.height}
|
151
|
-
end
|
152
|
-
|
153
|
-
describe 'with floats' do
|
154
|
-
subject {Shoes::Dimensions.new parent, left, top, "50.0%", "50.00%"}
|
155
|
-
its(:width) {should be_within(ONE_PIXEL).of 0.5 * parent.width}
|
156
|
-
its(:height) {should be_within(ONE_PIXEL).of 0.5 * parent.height}
|
157
|
-
end
|
158
|
-
|
159
|
-
describe 'with negatives' do
|
160
|
-
subject {Shoes::Dimensions.new parent, left, top, "-10.0%", "-10.00%"}
|
161
|
-
its(:width) {should be_within(ONE_PIXEL).of 0.9 * parent.width}
|
162
|
-
its(:height) {should be_within(ONE_PIXEL).of 0.9 * parent.height}
|
163
|
-
end
|
164
|
-
|
165
|
-
describe 'with padded strings' do
|
166
|
-
subject {Shoes::Dimensions.new parent, left, top, " 50 % ", "\t- 50 %\n"}
|
167
|
-
its(:width) {should be_within(ONE_PIXEL).of 0.5 * parent.width}
|
168
|
-
its(:height) {should be_within(ONE_PIXEL).of 0.5 * parent.height}
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe 'with strings' do
|
173
|
-
describe 'with integer strings' do
|
174
|
-
subject {Shoes::Dimensions.new parent, "22", "20", "10", "10"}
|
175
|
-
|
176
|
-
its(:left) {should eq 22}
|
177
|
-
its(:top) {should eq 20}
|
178
|
-
its(:width) {should eq 10}
|
179
|
-
its(:height) {should eq 10}
|
180
|
-
end
|
181
|
-
|
182
|
-
describe 'with strings px' do
|
183
|
-
subject {Shoes::Dimensions.new parent, "10px", "10px", "0px", "100px"}
|
184
|
-
|
185
|
-
its(:left) {should eq 10}
|
186
|
-
its(:top) {should eq 10}
|
187
|
-
its(:width) {should eq 0}
|
188
|
-
its(:height) {should eq 100}
|
189
|
-
end
|
190
|
-
|
191
|
-
describe 'white space with px is also ok' do
|
192
|
-
subject {Shoes::Dimensions.new parent, "10 px", "20 px", "30px", "55 px"}
|
193
|
-
|
194
|
-
its(:left) {should eq 10}
|
195
|
-
its(:top) {should eq 20}
|
196
|
-
its(:width) {should eq 30}
|
197
|
-
its(:height) {should eq 55}
|
198
|
-
end
|
199
|
-
|
200
|
-
describe 'with invalid integer strings' do
|
201
|
-
subject {Shoes::Dimensions.new parent, "p100px", "Hell0", "hell0", "glob"}
|
202
|
-
|
203
|
-
its(:left) {should be_nil}
|
204
|
-
its(:top) {should be_nil}
|
205
|
-
its(:width) {should be_nil}
|
206
|
-
its(:height) {should be_nil}
|
207
|
-
end
|
208
|
-
|
209
|
-
describe 'with negative values' do
|
210
|
-
let(:parent_width) {200}
|
211
|
-
let(:parent_height) {300}
|
212
|
-
subject {Shoes::Dimensions.new parent, "- 100", "-20px", "- 50px", "- 80"}
|
213
|
-
|
214
|
-
its(:left) {should eq -100}
|
215
|
-
its(:top) {should eq -20}
|
216
|
-
its(:width) {should eq (parent_width - 50)}
|
217
|
-
its(:height) {should eq (parent_height - 80)}
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe 'with negative width and height' do
|
222
|
-
let(:width) { -50 }
|
223
|
-
let(:height) { -50 }
|
224
|
-
subject {Shoes::Dimensions.new parent, left, top, width, height}
|
225
|
-
|
226
|
-
its(:width) {should eq parent.width + width}
|
227
|
-
its(:height) {should eq parent.height + height}
|
228
|
-
end
|
229
|
-
|
230
|
-
describe 'with relative negative width and height' do
|
231
|
-
let(:width) {-0.2}
|
232
|
-
let(:height) {-0.2}
|
233
|
-
|
234
|
-
its(:width) {should be_within(ONE_PIXEL).of 0.8 * parent.width}
|
235
|
-
its(:height) {should be_within(ONE_PIXEL).of 0.8 * parent.height}
|
236
|
-
end
|
237
|
-
|
238
|
-
describe 'with a hash' do
|
239
|
-
subject { Shoes::Dimensions.new parent, left: left,
|
240
|
-
top: top,
|
241
|
-
width: width,
|
242
|
-
height: height }
|
243
|
-
|
244
|
-
its(:left) {should eq left}
|
245
|
-
its(:top) {should eq top}
|
246
|
-
its(:width) {should eq width}
|
247
|
-
its(:height) {should eq height}
|
248
|
-
its(:absolutely_positioned?) {should be_truthy}
|
249
|
-
its(:absolute_x_position?) {should be_truthy}
|
250
|
-
its(:absolute_y_position?) {should be_truthy}
|
251
|
-
|
252
|
-
context 'missing width' do
|
253
|
-
subject { Shoes::Dimensions.new parent, left: left,
|
254
|
-
top: top,
|
255
|
-
height: height }
|
256
|
-
|
257
|
-
its(:width) {should eq nil}
|
258
|
-
end
|
259
|
-
|
260
|
-
describe 'with right and bottom' do
|
261
|
-
subject {Shoes::Dimensions.new parent, right: right, bottom: bottom}
|
262
|
-
|
263
|
-
its(:right) {should eq right}
|
264
|
-
its(:bottom) {should eq bottom}
|
265
|
-
its(:absolute_x_position?) {should be_truthy}
|
266
|
-
its(:absolute_y_position?) {should be_truthy}
|
267
|
-
its(:absolute_left_position?) {should be_falsey}
|
268
|
-
its(:absolute_top_position?) {should be_falsey}
|
269
|
-
its(:absolute_right_position?) {should be_truthy}
|
270
|
-
its(:absolute_bottom_position?) {should be_truthy}
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
describe 'absolute_left and _top' do
|
275
|
-
its(:absolute_left) {should eq nil}
|
276
|
-
its(:absolute_top) {should eq nil}
|
277
|
-
it {is_expected.not_to be_positioned}
|
278
|
-
end
|
279
|
-
|
280
|
-
describe 'absolute extra values' do
|
281
|
-
let(:absolute_left) {7}
|
282
|
-
let(:absolute_top) {13}
|
283
|
-
|
284
|
-
before :each do
|
285
|
-
subject.absolute_left = absolute_left
|
286
|
-
subject.absolute_top = absolute_top
|
287
|
-
end
|
288
|
-
|
289
|
-
# in case you wonder about the -1... say left is 20 and we have a width of
|
290
|
-
# 100 then the right must be 119, because you have to take pixel number 20
|
291
|
-
# into account so 20..119 is 100 while 20..120 is 101. E.g.:
|
292
|
-
# (20..119).size => 100
|
293
|
-
it 'has an appropriate absolute_right' do
|
294
|
-
expect(subject.absolute_right).to eq width + absolute_left - ONE_PIXEL
|
295
|
-
end
|
296
|
-
|
297
|
-
it 'has an appropriate absolute_bottom' do
|
298
|
-
expect(subject.absolute_bottom).to eq height + absolute_top - ONE_PIXEL
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'has an element left which is the same' do
|
302
|
-
expect(subject.element_left).to eq subject.absolute_left
|
303
|
-
end
|
304
|
-
|
305
|
-
it 'has an element top which is the same' do
|
306
|
-
expect(subject.element_top).to eq subject.absolute_top
|
307
|
-
end
|
308
|
-
|
309
|
-
it 'considers itself positioned' do
|
310
|
-
expect(subject.positioned?).to be_truthy
|
311
|
-
end
|
312
|
-
|
313
|
-
describe 'with margins' do
|
314
|
-
include_context 'margins'
|
315
|
-
include_context 'element dimensions set'
|
316
|
-
|
317
|
-
it 'adjusts element_left' do
|
318
|
-
expect(subject.element_left).to eq subject.absolute_left + margin_left
|
319
|
-
end
|
320
|
-
|
321
|
-
it 'adjusts element_top' do
|
322
|
-
expect(subject.element_top).to eq subject.absolute_top + margin_top
|
323
|
-
end
|
324
|
-
|
325
|
-
it 'returns an element_right' do
|
326
|
-
expect(subject.element_right).to eq subject.element_left +
|
327
|
-
element_width - ONE_PIXEL
|
328
|
-
end
|
329
|
-
|
330
|
-
it 'returns an element_bottom' do
|
331
|
-
expect(subject.element_bottom).to eq subject.element_top +
|
332
|
-
element_height - ONE_PIXEL
|
333
|
-
end
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
|
339
|
-
describe 'setting ' do
|
340
|
-
it 'has a setter for left' do
|
341
|
-
subject.left = 66
|
342
|
-
expect(subject.left).to eq 66
|
343
|
-
end
|
344
|
-
|
345
|
-
it 'has a setter for right' do
|
346
|
-
subject.right = 77
|
347
|
-
expect(subject.right).to eq 77
|
348
|
-
end
|
349
|
-
|
350
|
-
it 'has a setter for bottom' do
|
351
|
-
subject.bottom = 87
|
352
|
-
expect(subject.bottom).to eq 87
|
353
|
-
end
|
354
|
-
|
355
|
-
describe 'element_*' do
|
356
|
-
include_context 'element dimensions set'
|
357
|
-
|
358
|
-
it 'sets width to that value' do
|
359
|
-
expect(subject.width).to eq element_width
|
360
|
-
end
|
361
|
-
|
362
|
-
it 'responds that value for element_width' do
|
363
|
-
expect(subject.element_width).to eq element_width
|
364
|
-
end
|
365
|
-
|
366
|
-
it 'sets height to that value' do
|
367
|
-
expect(subject.height).to eq element_height
|
368
|
-
end
|
369
|
-
|
370
|
-
it 'sets element_height to that value' do
|
371
|
-
expect(subject.element_height).to eq element_height
|
372
|
-
end
|
373
|
-
|
374
|
-
it 'can set element_width to nil' do
|
375
|
-
subject.element_width = nil
|
376
|
-
expect(subject.element_width).to eq nil
|
377
|
-
end
|
378
|
-
|
379
|
-
it 'can set element_height to nil' do
|
380
|
-
subject.element_height = nil
|
381
|
-
expect(subject.element_height).to eq nil
|
382
|
-
end
|
383
|
-
|
384
|
-
describe 'with margins' do
|
385
|
-
include_context 'margins'
|
386
|
-
|
387
|
-
it 'sets width to element_width plus margins' do
|
388
|
-
expect(subject.width).to eq margin_left + element_width + margin_right
|
389
|
-
end
|
390
|
-
|
391
|
-
it 'sets height to element_height plus margins' do
|
392
|
-
expect(subject.height).to eq margin_top + element_height + margin_bottom
|
393
|
-
end
|
394
|
-
|
395
|
-
it 'sets that value for element_width' do
|
396
|
-
expect(subject.element_width).to eq element_width
|
397
|
-
end
|
398
|
-
|
399
|
-
it 'sets element_height to that value' do
|
400
|
-
expect(subject.element_height).to eq element_height
|
401
|
-
end
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
describe 'centered (e.g. left and top are seen as coords for the center)' do
|
407
|
-
describe '5 arguments' do
|
408
|
-
subject {Shoes::Dimensions.new parent, 100, 50, 40, 20, :center => true}
|
409
|
-
|
410
|
-
its(:left) {should eq 80}
|
411
|
-
its(:top) {should eq 40}
|
412
|
-
its(:width) {should eq 40}
|
413
|
-
its(:height) {should eq 20}
|
414
|
-
|
415
|
-
it 'reacts to a width change' do
|
416
|
-
expect(subject.left).to eq(80)
|
417
|
-
subject.width = 100
|
418
|
-
expect(subject.left).to eq(50)
|
419
|
-
end
|
420
|
-
|
421
|
-
it 'reacts to a height change' do
|
422
|
-
expect(subject.top).to eq(40)
|
423
|
-
subject.height = 40
|
424
|
-
expect(subject.top).to eq(30)
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
describe 'hash' do
|
429
|
-
subject {Shoes::Dimensions.new parent, left: 100,
|
430
|
-
top: 50,
|
431
|
-
width: 40,
|
432
|
-
height: 20,
|
433
|
-
center: true }
|
434
|
-
|
435
|
-
its(:left) {should eq 80}
|
436
|
-
its(:top) {should eq 40}
|
437
|
-
its(:width) {should eq 40}
|
438
|
-
its(:height) {should eq 20}
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
describe 'additional dimension methods' do
|
443
|
-
describe 'without height and width' do
|
444
|
-
let(:width) {nil}
|
445
|
-
let(:height) {nil}
|
446
|
-
end
|
447
|
-
end
|
448
|
-
|
449
|
-
describe 'in_bounds?' do
|
450
|
-
|
451
|
-
let(:left) {10}
|
452
|
-
let(:top) {20}
|
453
|
-
let(:width) {100}
|
454
|
-
let(:height) {150}
|
455
|
-
|
456
|
-
describe 'absolute position same as offset' do
|
457
|
-
before :each do
|
458
|
-
subject.absolute_left = left
|
459
|
-
subject.absolute_top = top
|
460
|
-
end
|
461
|
-
|
462
|
-
it {is_expected.to be_in_bounds 30, 40}
|
463
|
-
it {is_expected.to be_in_bounds left, top}
|
464
|
-
it {is_expected.to be_in_bounds left + width - ONE_PIXEL,
|
465
|
-
top + height - ONE_PIXEL}
|
466
|
-
it {is_expected.not_to be_in_bounds left + width, top + height}
|
467
|
-
it {is_expected.not_to be_in_bounds 30, top + height}
|
468
|
-
it {is_expected.not_to be_in_bounds left + width, 40}
|
469
|
-
it {is_expected.not_to be_in_bounds 0, 0}
|
470
|
-
it {is_expected.not_to be_in_bounds 0, 40}
|
471
|
-
it {is_expected.not_to be_in_bounds 40, 0}
|
472
|
-
it {is_expected.not_to be_in_bounds 200, 50}
|
473
|
-
it {is_expected.not_to be_in_bounds 80, 400}
|
474
|
-
it {is_expected.not_to be_in_bounds 1000, 1000}
|
475
|
-
end
|
476
|
-
|
477
|
-
describe 'with absolute position differing from relative' do
|
478
|
-
let(:absolute_left) {150}
|
479
|
-
let(:absolute_top) {50}
|
480
|
-
|
481
|
-
before :each do
|
482
|
-
subject.absolute_left = absolute_left
|
483
|
-
subject.absolute_top = absolute_top
|
484
|
-
end
|
485
|
-
|
486
|
-
it {is_expected.not_to be_in_bounds 30, 40}
|
487
|
-
it {is_expected.not_to be_in_bounds left, top}
|
488
|
-
it {is_expected.not_to be_in_bounds 149, 75}
|
489
|
-
it {is_expected.to be_in_bounds 200, absolute_top}
|
490
|
-
it {is_expected.to be_in_bounds absolute_left, absolute_top}
|
491
|
-
it {is_expected.to be_in_bounds absolute_left + width - ONE_PIXEL,
|
492
|
-
absolute_top + height - ONE_PIXEL
|
493
|
-
}
|
494
|
-
it {is_expected.not_to be_in_bounds 80, 400}
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
describe 'absolute positioning' do
|
499
|
-
subject {Shoes::Dimensions.new parent}
|
500
|
-
its(:absolutely_positioned?) {should be_falsey}
|
501
|
-
|
502
|
-
shared_examples_for 'absolute_x_position' do
|
503
|
-
its(:absolute_x_position?) {should be_truthy}
|
504
|
-
its(:absolute_y_position?) {should be_falsey}
|
505
|
-
its(:absolutely_positioned?) {should be_truthy}
|
506
|
-
end
|
507
|
-
|
508
|
-
describe 'changing left' do
|
509
|
-
before :each do subject.left = left end
|
510
|
-
it_behaves_like 'absolute_x_position'
|
511
|
-
end
|
512
|
-
|
513
|
-
describe 'chaning right' do
|
514
|
-
before :each do subject.right = right end
|
515
|
-
it_behaves_like 'absolute_x_position'
|
516
|
-
end
|
517
|
-
|
518
|
-
shared_examples_for 'absolute_y_position' do
|
519
|
-
its(:absolute_x_position?) {should be_falsey}
|
520
|
-
its(:absolute_y_position?) {should be_truthy}
|
521
|
-
its(:absolutely_positioned?) {should be_truthy}
|
522
|
-
end
|
523
|
-
|
524
|
-
describe 'changing top' do
|
525
|
-
before :each do subject.top = top end
|
526
|
-
it_behaves_like 'absolute_y_position'
|
527
|
-
end
|
528
|
-
|
529
|
-
describe 'changing bottom' do
|
530
|
-
before :each do subject.bottom = bottom end
|
531
|
-
it_behaves_like 'absolute_y_position'
|
532
|
-
end
|
533
|
-
|
534
|
-
end
|
535
|
-
|
536
|
-
describe 'margins' do
|
537
|
-
describe 'creation with single margin value' do
|
538
|
-
let(:margin) {13}
|
539
|
-
subject {Shoes::Dimensions.new parent, width: width, height: height,
|
540
|
-
margin: margin}
|
541
|
-
|
542
|
-
its(:margin) {should == [margin, margin, margin, margin]}
|
543
|
-
its(:margin_left) {should == margin}
|
544
|
-
its(:margin_top) {should == margin}
|
545
|
-
its(:margin_right) {should == margin}
|
546
|
-
its(:margin_bottom) {should == margin}
|
547
|
-
its(:width) {should == width}
|
548
|
-
its(:height) {should == height}
|
549
|
-
its(:element_width) {should == width - 2 * margin}
|
550
|
-
its(:element_height) {should == height - 2 * margin}
|
551
|
-
|
552
|
-
it 'adapts margin when one of the margins is changed' do
|
553
|
-
subject.margin_right = 7
|
554
|
-
expect(subject.margin).to eq([margin, margin, 7, margin])
|
555
|
-
end
|
556
|
-
|
557
|
-
it 'adapts margins when margin is changed with single value' do
|
558
|
-
subject.margin = 7
|
559
|
-
expect(subject.margin).to eq([7, 7, 7, 7])
|
560
|
-
end
|
561
|
-
|
562
|
-
it 'adapts margin when margin is changed with array' do
|
563
|
-
subject.margin = [7, 7, 7, 7]
|
564
|
-
expect(subject.margin).to eq([7, 7, 7, 7])
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
describe 'creation with all distinct margin values' do
|
569
|
-
let(:margin_left) {3}
|
570
|
-
let(:margin_top) {7}
|
571
|
-
let(:margin_right) {11}
|
572
|
-
let(:margin_bottom) {17}
|
573
|
-
|
574
|
-
shared_examples_for 'all distinct margins' do
|
575
|
-
its(:margin){should == [margin_left, margin_top, margin_right, margin_bottom]}
|
576
|
-
its(:margin_left) {should == margin_left}
|
577
|
-
its(:margin_top) {should == margin_top}
|
578
|
-
its(:margin_right) {should == margin_right}
|
579
|
-
its(:margin_bottom) {should == margin_bottom}
|
580
|
-
its(:width) {should == width}
|
581
|
-
its(:height) {should == height}
|
582
|
-
its(:element_width) {should == width - (margin_left + margin_right)}
|
583
|
-
its(:element_height) {should == height - (margin_top + margin_bottom)}
|
584
|
-
end
|
585
|
-
|
586
|
-
describe 'setting margins separetely through hash' do
|
587
|
-
subject {Shoes::Dimensions.new parent, width: width,
|
588
|
-
height: height,
|
589
|
-
margin_left: margin_left,
|
590
|
-
margin_top: margin_top,
|
591
|
-
margin_right: margin_right,
|
592
|
-
margin_bottom: margin_bottom}
|
593
|
-
it_behaves_like 'all distinct margins'
|
594
|
-
end
|
595
|
-
|
596
|
-
describe 'setting margins through margin array' do
|
597
|
-
subject {Shoes::Dimensions.new parent,
|
598
|
-
width: width,
|
599
|
-
height: height,
|
600
|
-
margin: [margin_left, margin_top,
|
601
|
-
margin_right, margin_bottom]}
|
602
|
-
it_behaves_like 'all distinct margins'
|
603
|
-
end
|
604
|
-
end
|
605
|
-
end
|
606
|
-
|
607
|
-
describe 'displace' do
|
608
|
-
|
609
|
-
before :each do
|
610
|
-
# need to have a rough positon
|
611
|
-
subject.absolute_left = 0
|
612
|
-
subject.absolute_top = 0
|
613
|
-
end
|
614
|
-
|
615
|
-
describe 'displace_left' do
|
616
|
-
let(:displace_left) {3}
|
617
|
-
it 'modifies the value of element_left' do
|
618
|
-
expect do
|
619
|
-
subject.displace_left = displace_left
|
620
|
-
end.to change{subject.element_left}.by(displace_left)
|
621
|
-
end
|
622
|
-
|
623
|
-
it 'does not modify the value of absolute_left' do
|
624
|
-
expect do
|
625
|
-
subject.displace_left = displace_left
|
626
|
-
end.not_to change {subject.absolute_left}
|
627
|
-
end
|
628
|
-
|
629
|
-
context 'via opts' do
|
630
|
-
subject { Shoes::Dimensions.new(nil, 0, 0, 0, 0, displace_left: 10)}
|
631
|
-
it 'modifies element_left' do
|
632
|
-
expect(subject.element_left).to eql(10)
|
633
|
-
end
|
634
|
-
end
|
635
|
-
end
|
636
|
-
|
637
|
-
describe 'displace_top' do
|
638
|
-
let(:displace_top) {7}
|
639
|
-
|
640
|
-
it 'modifies the value of element_top' do
|
641
|
-
expect do
|
642
|
-
subject.displace_top = displace_top
|
643
|
-
end.to change{subject.element_top}.by(displace_top)
|
644
|
-
end
|
645
|
-
|
646
|
-
it 'does not modify the value of absolute_top' do
|
647
|
-
expect do
|
648
|
-
subject.displace_top = displace_top
|
649
|
-
end.not_to change {subject.absolute_top}
|
650
|
-
end
|
651
|
-
|
652
|
-
context 'via opts' do
|
653
|
-
subject { Shoes::Dimensions.new(nil, 0, 0, 0, 0, displace_top: 10)}
|
654
|
-
it 'modifies element_top' do
|
655
|
-
expect(subject.element_top).to eql(10)
|
656
|
-
end
|
657
|
-
end
|
658
|
-
end
|
659
|
-
|
660
|
-
end
|
661
|
-
|
662
|
-
it {is_expected.to be_needs_to_be_positioned}
|
663
|
-
it {is_expected.to be_takes_up_space}
|
664
|
-
|
665
|
-
describe 'left/top/right/bottom not set so get them relative to parent' do
|
666
|
-
let(:parent) {double 'parent', x_dimension: x_dimension,
|
667
|
-
y_dimension: y_dimension}
|
668
|
-
|
669
|
-
let(:x_dimension) {double 'parent x dimension', element_start: parent_left,
|
670
|
-
element_end: parent_right}
|
671
|
-
let(:y_dimension) {double 'parent y dimension', element_start: parent_top,
|
672
|
-
element_end: parent_bottom}
|
673
|
-
let(:parent_right) {parent_left + 20}
|
674
|
-
let(:parent_bottom) {parent_top + 30}
|
675
|
-
|
676
|
-
let(:width) {3}
|
677
|
-
let(:height) {5}
|
678
|
-
|
679
|
-
subject {Shoes::Dimensions.new parent, width: width, height: height}
|
680
|
-
|
681
|
-
describe 'positioned at the start' do
|
682
|
-
before :each do
|
683
|
-
# there is no setter for element_* but with no margin it's the same
|
684
|
-
subject.absolute_left = parent_left
|
685
|
-
subject.absolute_top = parent_top
|
686
|
-
end
|
687
|
-
|
688
|
-
its(:left) {should eq 0}
|
689
|
-
its(:top) {should eq 0}
|
690
|
-
its(:right) {should eq parent_right - subject.element_right}
|
691
|
-
its(:bottom) {should eq parent_bottom - subject.element_bottom}
|
692
|
-
end
|
693
|
-
|
694
|
-
describe 'positioned with an offset' do
|
695
|
-
TEST_OFFSET = 7
|
696
|
-
|
697
|
-
before :each do
|
698
|
-
subject.absolute_left = parent_left + TEST_OFFSET
|
699
|
-
subject.absolute_top = parent_top + TEST_OFFSET
|
700
|
-
end
|
701
|
-
|
702
|
-
its(:left) {should eq TEST_OFFSET}
|
703
|
-
its(:top) {should eq TEST_OFFSET}
|
704
|
-
its(:right) {should eq parent_right - subject.element_right}
|
705
|
-
its(:bottom) {should eq parent_bottom - subject.element_bottom}
|
706
|
-
end
|
707
|
-
end
|
708
|
-
|
709
|
-
describe Shoes::AbsoluteDimensions do
|
710
|
-
subject {Shoes::AbsoluteDimensions.new left, top, width, height}
|
711
|
-
describe 'not adapting floats to parent values' do
|
712
|
-
subject {Shoes::AbsoluteDimensions.new left, top, 1.04, 2.10}
|
713
|
-
it 'does not adapt width' do
|
714
|
-
expect(subject.width).to be_within(0.01).of 1.04
|
715
|
-
end
|
716
|
-
|
717
|
-
it 'does not adapt height' do
|
718
|
-
expect(subject.height).to be_within(0.01).of 2.10
|
719
|
-
end
|
720
|
-
end
|
721
|
-
end
|
722
|
-
|
723
|
-
describe Shoes::ParentDimensions do
|
724
|
-
describe 'takes parent values if not specified' do
|
725
|
-
let(:parent) {Shoes::Dimensions.new nil, parent_left, parent_top,
|
726
|
-
parent_width, parent_height,
|
727
|
-
margin: 20}
|
728
|
-
subject {Shoes::ParentDimensions.new parent}
|
729
|
-
|
730
|
-
its(:left) {should eq parent.left}
|
731
|
-
its(:top) {should eq parent.top}
|
732
|
-
its(:width) {should eq parent.width}
|
733
|
-
its(:height) {should eq parent.height}
|
734
|
-
its(:margin_left) {should eq parent.margin_left}
|
735
|
-
its(:margin_top) {should eq parent.margin_top}
|
736
|
-
its(:margin_right) {should eq parent.margin_right}
|
737
|
-
its(:margin_bottom) {should eq parent.margin_bottom}
|
738
|
-
|
739
|
-
context 'with parent absolute_left/top set' do
|
740
|
-
before :each do
|
741
|
-
parent.absolute_left = left
|
742
|
-
parent.absolute_top = top
|
743
|
-
end
|
744
|
-
|
745
|
-
its(:absolute_left) {should eq parent.absolute_left}
|
746
|
-
its(:absolute_top) {should eq parent.absolute_top}
|
747
|
-
its(:element_left) {should eq parent.element_left}
|
748
|
-
its(:element_top) {should eq parent.element_top}
|
749
|
-
end
|
750
|
-
end
|
751
|
-
|
752
|
-
describe 'otherwise it takes its own values' do
|
753
|
-
subject {Shoes::ParentDimensions.new parent, left, top, width, height}
|
754
|
-
|
755
|
-
its(:left) {should eq left}
|
756
|
-
its(:top) {should eq top}
|
757
|
-
its(:width) {should eq width}
|
758
|
-
its(:height) {should eq height}
|
759
|
-
|
760
|
-
it 'can also still handle special values like a negative width' do
|
761
|
-
subject.width = -10
|
762
|
-
expect(subject.width).to eq (parent.width - 10)
|
763
|
-
end
|
764
|
-
|
765
|
-
it 'can also still handle special values like a relative height' do
|
766
|
-
subject.height = 0.8
|
767
|
-
expect(subject.height).to be_within(ONE_PIXEL).of(0.8 * parent.height)
|
768
|
-
end
|
769
|
-
end
|
770
|
-
end
|
771
|
-
end
|
772
|
-
|
773
|
-
describe Shoes::DimensionsDelegations do
|
774
|
-
|
775
|
-
describe 'with a DSL class and a dimensions method' do
|
776
|
-
let(:dimensions) {double('dimensions')}
|
777
|
-
|
778
|
-
class DummyClass
|
779
|
-
include Shoes::DimensionsDelegations
|
780
|
-
def dimensions
|
781
|
-
end
|
782
|
-
end
|
783
|
-
|
784
|
-
subject do
|
785
|
-
dummy = DummyClass.new
|
786
|
-
allow(dummy).to receive_messages dimensions: dimensions
|
787
|
-
dummy
|
788
|
-
end
|
789
|
-
|
790
|
-
it 'forwards left calls to dimensions' do
|
791
|
-
expect(dimensions).to receive :left
|
792
|
-
subject.left
|
793
|
-
end
|
794
|
-
|
795
|
-
it 'forwards bottom calls to dimensions' do
|
796
|
-
expect(dimensions).to receive :bottom
|
797
|
-
subject.bottom
|
798
|
-
end
|
799
|
-
|
800
|
-
it 'forwards setter calls like left= do dimensions' do
|
801
|
-
expect(dimensions).to receive :left=
|
802
|
-
subject.left = 66
|
803
|
-
end
|
804
|
-
|
805
|
-
it 'forwards absolutely_positioned? calls to the dimensions' do
|
806
|
-
expect(dimensions).to receive :absolutely_positioned?
|
807
|
-
subject.absolutely_positioned?
|
808
|
-
end
|
809
|
-
end
|
810
|
-
|
811
|
-
describe 'with any backend class that has a defined dsl method' do
|
812
|
-
let(:dsl){double 'dsl'}
|
813
|
-
|
814
|
-
class AnotherDummyClass
|
815
|
-
include Shoes::BackendDimensionsDelegations
|
816
|
-
def dsl
|
817
|
-
end
|
818
|
-
end
|
819
|
-
|
820
|
-
subject do
|
821
|
-
dummy = AnotherDummyClass.new
|
822
|
-
allow(dummy).to receive_messages dsl: dsl
|
823
|
-
dummy
|
824
|
-
end
|
825
|
-
|
826
|
-
it 'forwards calls to dsl' do
|
827
|
-
expect(dsl).to receive :left
|
828
|
-
subject.left
|
829
|
-
end
|
830
|
-
|
831
|
-
it 'does not forward calls to parent' do
|
832
|
-
expect(dsl).not_to receive :parent
|
833
|
-
expect {subject.parent}.to raise_error
|
834
|
-
end
|
835
|
-
end
|
836
|
-
|
837
|
-
end
|