shoes-core 4.0.0.pre7 → 4.0.0.pre8

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