shoes-core 4.0.0.pre3 → 4.0.0.pre4
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/bin/shoes +1 -1
- data/bin/shoes-picker +5 -1
- data/bin/shoes-stub +1 -1
- data/ext/install/shoes.bat +2 -0
- data/lib/rubygems_plugin.rb +2 -2
- data/lib/shoes/app.rb +18 -19
- data/lib/shoes/arc.rb +8 -8
- data/lib/shoes/background.rb +4 -8
- data/lib/shoes/border.rb +4 -8
- data/lib/shoes/builtin_methods.rb +2 -2
- data/lib/shoes/button.rb +2 -9
- data/lib/shoes/check_button.rb +0 -12
- data/lib/shoes/color.rb +29 -34
- data/lib/shoes/common/background_element.rb +4 -0
- data/lib/shoes/common/fill.rb +9 -0
- data/lib/shoes/common/initialization.rb +59 -0
- data/lib/shoes/common/inspect.rb +20 -2
- data/lib/shoes/common/rotate.rb +10 -0
- data/lib/shoes/common/stroke.rb +9 -0
- data/lib/shoes/common/style.rb +21 -7
- data/lib/shoes/common/style_normalizer.rb +1 -3
- data/lib/shoes/common/ui_element.rb +10 -0
- data/lib/shoes/common/visibility.rb +4 -4
- data/lib/shoes/configuration.rb +4 -2
- data/lib/shoes/core/version.rb +1 -1
- data/lib/shoes/dialog.rb +2 -2
- data/lib/shoes/dimension.rb +78 -68
- data/lib/shoes/dimensions.rb +22 -10
- data/lib/shoes/download.rb +26 -10
- data/lib/shoes/dsl.rb +32 -51
- data/lib/shoes/gradient.rb +6 -13
- data/lib/shoes/image.rb +4 -9
- data/lib/shoes/input_box.rb +6 -9
- data/lib/shoes/internal_app.rb +16 -36
- data/lib/shoes/line.rb +29 -10
- data/lib/shoes/link.rb +13 -2
- data/lib/shoes/list_box.rb +33 -11
- data/lib/shoes/logger.rb +12 -13
- data/lib/shoes/mock/arc.rb +2 -0
- data/lib/shoes/mock/common_methods.rb +9 -0
- data/lib/shoes/mock/shape.rb +1 -1
- data/lib/shoes/mock/slot.rb +1 -0
- data/lib/shoes/oval.rb +13 -8
- data/lib/shoes/packager.rb +7 -1
- data/lib/shoes/point.rb +26 -3
- data/lib/shoes/progress.rb +6 -8
- data/lib/shoes/rect.rb +14 -10
- data/lib/shoes/shape.rb +28 -14
- data/lib/shoes/slot.rb +33 -24
- data/lib/shoes/slot_contents.rb +4 -4
- data/lib/shoes/star.rb +7 -16
- data/lib/shoes/text.rb +5 -3
- data/lib/shoes/text_block.rb +17 -16
- data/lib/shoes/text_block_dimensions.rb +1 -1
- data/lib/shoes/ui/cli.rb +12 -3
- data/lib/shoes/ui/picker.rb +64 -19
- data/lib/shoes/version.rb +1 -1
- data/shoes-core.gemspec +2 -2
- data/spec/shoes/animation_spec.rb +1 -1
- data/spec/shoes/app_spec.rb +4 -23
- data/spec/shoes/color_spec.rb +16 -1
- data/spec/shoes/common/style_normalizer_spec.rb +3 -3
- data/spec/shoes/common/style_spec.rb +42 -5
- data/spec/shoes/dimension_spec.rb +5 -7
- data/spec/shoes/dimensions_spec.rb +7 -7
- data/spec/shoes/download_spec.rb +49 -8
- data/spec/shoes/flow_spec.rb +1 -1
- data/spec/shoes/helpers/fake_element.rb +7 -0
- data/spec/shoes/helpers/sample17_helper.rb +3 -3
- data/spec/shoes/integration_spec.rb +1 -1
- data/spec/shoes/internal_app_spec.rb +8 -0
- data/spec/shoes/line_spec.rb +35 -3
- data/spec/shoes/link_spec.rb +24 -12
- data/spec/shoes/list_box_spec.rb +14 -2
- data/spec/shoes/point_spec.rb +28 -0
- data/spec/shoes/renamed_delegate_spec.rb +2 -2
- data/spec/shoes/shape_spec.rb +15 -2
- data/spec/shoes/shared_examples/changeable.rb +1 -1
- data/spec/shoes/shared_examples/common_methods.rb +1 -1
- data/spec/shoes/shared_examples/dsl/style.rb +1 -1
- data/spec/shoes/shared_examples/dsl/text_elements.rb +3 -3
- data/spec/shoes/shared_examples/dsl/video.rb +1 -1
- data/spec/shoes/shared_examples/dsl_app_context.rb +0 -1
- data/spec/shoes/shared_examples/parent.rb +1 -1
- data/spec/shoes/shared_examples/slot.rb +11 -5
- data/spec/shoes/shared_examples/state.rb +2 -2
- data/spec/shoes/shared_examples/style.rb +1 -1
- data/spec/shoes/spec_helper.rb +1 -1
- data/spec/shoes/text_block_spec.rb +20 -3
- data/spec/shoes/ui/picker_spec.rb +70 -0
- metadata +8 -2
data/lib/shoes/core/version.rb
CHANGED
data/lib/shoes/dialog.rb
CHANGED
@@ -12,8 +12,8 @@ class Shoes
|
|
12
12
|
@gui.confirm msg
|
13
13
|
end
|
14
14
|
|
15
|
-
def dialog_chooser(title, folder = false)
|
16
|
-
@gui.dialog_chooser title, folder
|
15
|
+
def dialog_chooser(title, folder = false, style = :open)
|
16
|
+
@gui.dialog_chooser title, folder, style
|
17
17
|
end
|
18
18
|
|
19
19
|
def ask(msg, args)
|
data/lib/shoes/dimension.rb
CHANGED
@@ -16,6 +16,7 @@ class Shoes
|
|
16
16
|
def initialize(parent = nil, start_as_center = false)
|
17
17
|
@parent = parent
|
18
18
|
@start_as_center = start_as_center
|
19
|
+
@combined_margins = 0
|
19
20
|
end
|
20
21
|
|
21
22
|
def start
|
@@ -31,15 +32,19 @@ class Shoes
|
|
31
32
|
def extent
|
32
33
|
result = @extent
|
33
34
|
if @parent
|
34
|
-
result = calculate_relative(result) if
|
35
|
-
result = calculate_negative(result) if
|
35
|
+
result = calculate_relative(result) if @extent_relative
|
36
|
+
result = calculate_negative(result) if @extent_negative
|
36
37
|
end
|
37
38
|
result
|
38
39
|
end
|
39
40
|
|
40
41
|
def extent=(value)
|
41
42
|
@extent = value
|
42
|
-
@extent = parse_from_string @extent if
|
43
|
+
@extent = parse_from_string @extent if string? @extent
|
44
|
+
|
45
|
+
@extent_relative = relative?(@extent)
|
46
|
+
@extent_negative = negative?(@extent)
|
47
|
+
|
43
48
|
@extent
|
44
49
|
end
|
45
50
|
|
@@ -53,7 +58,7 @@ class Shoes
|
|
53
58
|
if my_extent.nil?
|
54
59
|
nil
|
55
60
|
else
|
56
|
-
|
61
|
+
my_extent - @combined_margins
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
@@ -100,35 +105,64 @@ class Shoes
|
|
100
105
|
# getter... reason being that for ParentDimensions we need to be able to
|
101
106
|
# figure out if a value has been modified or if we should consult the
|
102
107
|
# parent value - see ParentDimension implementation
|
103
|
-
|
104
|
-
|
105
|
-
instance_variable_name = '@' + method.to_s
|
106
|
-
value = instance_variable_get(instance_variable_name) || 0
|
107
|
-
value = calculate_relative value if is_relative? value
|
108
|
-
value
|
109
|
-
end
|
108
|
+
def margin_start
|
109
|
+
value_factoring_in_relative(@margin_start, @margin_start_relative)
|
110
110
|
end
|
111
111
|
|
112
|
-
def
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
def margin_end
|
113
|
+
value_factoring_in_relative(@margin_end, @margin_end_relative)
|
114
|
+
end
|
115
|
+
|
116
|
+
def displace_start
|
117
|
+
value_factoring_in_relative(@displace_start, @displace_start_relative)
|
116
118
|
end
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
+
def value_factoring_in_relative(value, relative)
|
121
|
+
value ||= 0
|
122
|
+
value = calculate_relative value if relative
|
123
|
+
value
|
124
|
+
end
|
125
|
+
|
126
|
+
def start=(value)
|
127
|
+
@start_relative = relative?(value)
|
128
|
+
@start = parse_int_value(value)
|
129
|
+
end
|
130
|
+
|
131
|
+
def end=(value)
|
132
|
+
@end = parse_int_value(value)
|
133
|
+
end
|
134
|
+
|
135
|
+
def margin_start=(value)
|
136
|
+
@margin_start_relative = relative?(value)
|
137
|
+
@margin_start = parse_int_value(value)
|
138
|
+
|
139
|
+
@combined_margins = margin_start + margin_end
|
140
|
+
@margin_start
|
141
|
+
end
|
142
|
+
|
143
|
+
def margin_end=(value)
|
144
|
+
@margin_end_relative = relative?(value)
|
145
|
+
@margin_end = parse_int_value(value)
|
146
|
+
|
147
|
+
@combined_margins = margin_start + margin_end
|
148
|
+
@margin_end
|
149
|
+
end
|
150
|
+
|
151
|
+
def displace_start=(value)
|
152
|
+
@displace_start_relative = relative?(value)
|
153
|
+
@displace_start = parse_int_value(value)
|
120
154
|
end
|
121
155
|
|
122
156
|
private
|
123
157
|
|
124
158
|
def basic_start_value
|
125
159
|
value = @start
|
126
|
-
value = calculate_relative value if
|
160
|
+
value = calculate_relative value if @start_relative
|
127
161
|
value = report_relative_to_parent_start if value.nil?
|
128
162
|
value
|
129
163
|
end
|
130
164
|
|
131
|
-
def
|
165
|
+
def relative?(result)
|
132
166
|
# as the value is relative to the parent values bigger than one don't
|
133
167
|
# make much sense and are problematic. E.g. through calculations users
|
134
168
|
# might end up with values like 5.14 meaning 5 pixel which would get
|
@@ -142,11 +176,11 @@ class Shoes
|
|
142
176
|
(result * @parent.element_extent).to_i
|
143
177
|
end
|
144
178
|
|
145
|
-
def
|
179
|
+
def string?(result)
|
146
180
|
result.is_a?(String)
|
147
181
|
end
|
148
182
|
|
149
|
-
def
|
183
|
+
def negative?(result)
|
150
184
|
result && result < 0
|
151
185
|
end
|
152
186
|
|
@@ -158,23 +192,13 @@ class Shoes
|
|
158
192
|
|
159
193
|
def parse_from_string(result)
|
160
194
|
match = result.gsub(/\s+/, "").match(PERCENT_REGEX)
|
161
|
-
if match
|
162
|
-
|
163
|
-
elsif valid_integer_string?(result)
|
164
|
-
int_from_string(result)
|
165
|
-
else
|
166
|
-
nil
|
167
|
-
end
|
195
|
+
return match[1].to_f / 100.0 if match
|
196
|
+
int_from_string(result) if valid_integer_string?(result)
|
168
197
|
end
|
169
198
|
|
170
199
|
def parse_int_value(input)
|
171
|
-
if input.is_a?(Integer) || input.is_a?(Float)
|
172
|
-
|
173
|
-
elsif valid_integer_string?(input)
|
174
|
-
int_from_string(input)
|
175
|
-
else
|
176
|
-
nil
|
177
|
-
end
|
200
|
+
return input if input.is_a?(Integer) || input.is_a?(Float)
|
201
|
+
int_from_string(input) if valid_integer_string?(input)
|
178
202
|
end
|
179
203
|
|
180
204
|
def int_from_string(result)
|
@@ -188,19 +212,19 @@ class Shoes
|
|
188
212
|
end
|
189
213
|
|
190
214
|
def report_relative_to_parent_start
|
191
|
-
|
192
|
-
element_start - parent.element_start
|
193
|
-
else
|
194
|
-
nil
|
195
|
-
end
|
215
|
+
element_start - parent.element_start if start_exists?
|
196
216
|
end
|
197
217
|
|
198
218
|
def report_relative_to_parent_end
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
219
|
+
parent.element_end - element_end if end_exists?
|
220
|
+
end
|
221
|
+
|
222
|
+
def end_exists?
|
223
|
+
element_end && parent && parent.element_end
|
224
|
+
end
|
225
|
+
|
226
|
+
def start_exists?
|
227
|
+
element_start && parent && parent.element_start
|
204
228
|
end
|
205
229
|
|
206
230
|
def start_as_center?
|
@@ -208,26 +232,17 @@ class Shoes
|
|
208
232
|
end
|
209
233
|
|
210
234
|
def adjust_start_for_center(value)
|
211
|
-
|
212
|
-
if my_extent && my_extent > 0
|
213
|
-
value - my_extent / 2
|
214
|
-
else
|
215
|
-
nil
|
216
|
-
end
|
235
|
+
value - extent / 2 if extent && extent > 0
|
217
236
|
end
|
218
237
|
end
|
219
238
|
|
220
239
|
class ParentDimension < Dimension
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
else
|
228
|
-
parent.public_send(method)
|
229
|
-
end
|
230
|
-
end
|
240
|
+
def absolute_start
|
241
|
+
@absolute_start ? super : parent.absolute_start
|
242
|
+
end
|
243
|
+
|
244
|
+
def start
|
245
|
+
@start ? super : parent.start
|
231
246
|
end
|
232
247
|
|
233
248
|
def extent
|
@@ -248,11 +263,11 @@ class Shoes
|
|
248
263
|
#
|
249
264
|
# To get our extent respecting the parent's margins, it's our absolute
|
250
265
|
# start, minus parent's element end (so we don't blow past the margin)
|
251
|
-
|
266
|
+
parent.element_end - absolute_start - PIXEL_COUNTING_ADJUSTMENT
|
252
267
|
else
|
253
268
|
# If we hit this, then the extent in parent isn't available and will be
|
254
269
|
# ignored by the min call below
|
255
|
-
|
270
|
+
Float::INFINITY
|
256
271
|
end
|
257
272
|
end
|
258
273
|
|
@@ -260,10 +275,5 @@ class Shoes
|
|
260
275
|
def raw_extent(original_value)
|
261
276
|
original_value || parent.extent
|
262
277
|
end
|
263
|
-
|
264
|
-
def value_modified?(method)
|
265
|
-
instance_variable = ('@' + method.to_s).to_sym
|
266
|
-
instance_variable_get(instance_variable)
|
267
|
-
end
|
268
278
|
end
|
269
279
|
end
|
data/lib/shoes/dimensions.rb
CHANGED
@@ -95,14 +95,6 @@ class Shoes
|
|
95
95
|
true
|
96
96
|
end
|
97
97
|
|
98
|
-
def inspect
|
99
|
-
nothing = '_'
|
100
|
-
super.insert(-2,
|
101
|
-
" relative:#{Point.new left, top}->#{Point.new right, bottom}" \
|
102
|
-
" absolute:#{Point.new absolute_left, absolute_top}->#{Point.new absolute_right, absolute_bottom}" \
|
103
|
-
" #{width || nothing}x#{height || nothing}")
|
104
|
-
end
|
105
|
-
|
106
98
|
def self.setup_delegations
|
107
99
|
methods_to_rename = Dimension.public_instance_methods false
|
108
100
|
renamed_delegate_to :x_dimension, methods_to_rename, 'start' => 'left',
|
@@ -117,6 +109,13 @@ class Shoes
|
|
117
109
|
|
118
110
|
private
|
119
111
|
|
112
|
+
def inspect_details
|
113
|
+
nothing = '_'
|
114
|
+
" relative:#{Point.new left, top}->#{Point.new right, bottom}" \
|
115
|
+
" absolute:#{Point.new absolute_left, absolute_top}->#{Point.new absolute_right, absolute_bottom}" \
|
116
|
+
" #{width || nothing}x#{height || nothing}"
|
117
|
+
end
|
118
|
+
|
120
119
|
def hash_as_argument?(left)
|
121
120
|
left.respond_to? :fetch
|
122
121
|
end
|
@@ -185,10 +184,23 @@ class Shoes
|
|
185
184
|
extend Forwardable
|
186
185
|
|
187
186
|
UNDELEGATED_METHODS = [:to_s]
|
188
|
-
|
187
|
+
CANDIDATE_METHODS = Dimensions.public_instance_methods(false) - UNDELEGATED_METHODS
|
188
|
+
|
189
|
+
WRITER_METHODS = CANDIDATE_METHODS.select { |meth| meth.to_s.end_with?("=") }
|
190
|
+
DELEGATED_METHODS = CANDIDATE_METHODS - WRITER_METHODS
|
189
191
|
|
190
192
|
def_delegators :dimensions, *DELEGATED_METHODS
|
191
193
|
|
194
|
+
# For performance reasons, it's critical to write out dimension values to
|
195
|
+
# the styles hash directly when they change, so do that here.
|
196
|
+
WRITER_METHODS.each do |meth|
|
197
|
+
key = meth.to_s.sub("=", "").to_sym
|
198
|
+
define_method(meth) do |value|
|
199
|
+
@style[key] = value if @style
|
200
|
+
self.dimensions.send(meth, value)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
192
204
|
def adjust_current_position(*_)
|
193
205
|
# no-op by default for almost all elements
|
194
206
|
end
|
@@ -198,6 +210,6 @@ class Shoes
|
|
198
210
|
module BackendDimensionsDelegations
|
199
211
|
extend Forwardable
|
200
212
|
|
201
|
-
def_delegators :dsl, *DimensionsDelegations::
|
213
|
+
def_delegators :dsl, *DimensionsDelegations::CANDIDATE_METHODS
|
202
214
|
end
|
203
215
|
end
|
data/lib/shoes/download.rb
CHANGED
@@ -31,6 +31,7 @@ class Shoes
|
|
31
31
|
@blk = slot.create_bound_block(blk)
|
32
32
|
@progress_blk = slot.create_bound_block(@opts[:progress])
|
33
33
|
@finish_blk = slot.create_bound_block(@opts[:finish])
|
34
|
+
@error_blk = slot.create_bound_block(@opts[:error] || default_error_proc)
|
34
35
|
end
|
35
36
|
|
36
37
|
def start
|
@@ -51,6 +52,7 @@ class Shoes
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def percent
|
55
|
+
return 0 if @transferred.nil? || @content_length.nil?
|
54
56
|
@transferred * 100 / @content_length
|
55
57
|
end
|
56
58
|
|
@@ -68,20 +70,34 @@ class Shoes
|
|
68
70
|
def start_download
|
69
71
|
require 'open-uri'
|
70
72
|
@thread = Thread.new do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
73
|
+
begin
|
74
|
+
uri_opts = {}
|
75
|
+
uri_opts[:content_length_proc] = content_length_proc
|
76
|
+
uri_opts[:progress_proc] = progress_proc if @progress_blk
|
77
|
+
|
78
|
+
open @url, uri_opts do |download_data|
|
79
|
+
@response.body = download_data.read
|
80
|
+
@response.status = download_data.status
|
81
|
+
@response.headers = download_data.meta
|
82
|
+
save_to_file(@opts[:save]) if @opts[:save]
|
83
|
+
finish_download download_data
|
84
|
+
end
|
85
|
+
rescue SocketError => e
|
86
|
+
Shoes.logger.error e
|
87
|
+
rescue => e
|
88
|
+
eval_block(@error_blk, e)
|
81
89
|
end
|
82
90
|
end
|
83
91
|
end
|
84
92
|
|
93
|
+
def default_error_proc
|
94
|
+
lambda do |exception|
|
95
|
+
Shoes.logger.error "Failure downloading #{@url}. To handle this yourself, pass `:error` option to the download call."
|
96
|
+
Shoes.logger.error exception.message
|
97
|
+
Shoes.logger.error exception.backtrace.join("\n\t")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
85
101
|
def content_length_proc
|
86
102
|
lambda do |content_length|
|
87
103
|
download_started(content_length)
|
data/lib/shoes/dsl.rb
CHANGED
@@ -77,9 +77,13 @@ require 'shoes/color'
|
|
77
77
|
require 'shoes/common/background_element'
|
78
78
|
require 'shoes/common/changeable'
|
79
79
|
require 'shoes/common/clickable'
|
80
|
+
require 'shoes/common/fill'
|
81
|
+
require 'shoes/common/initialization'
|
80
82
|
require 'shoes/common/positioning'
|
81
83
|
require 'shoes/common/remove'
|
84
|
+
require 'shoes/common/rotate'
|
82
85
|
require 'shoes/common/state'
|
86
|
+
require 'shoes/common/stroke'
|
83
87
|
require 'shoes/common/style'
|
84
88
|
require 'shoes/common/style_normalizer'
|
85
89
|
require 'shoes/common/visibility'
|
@@ -245,7 +249,7 @@ class Shoes
|
|
245
249
|
create Shoes::Stack, opts, blk
|
246
250
|
end
|
247
251
|
|
248
|
-
def button(text =
|
252
|
+
def button(text = nil, opts = {}, &blk)
|
249
253
|
create Shoes::Button, text, opts, blk
|
250
254
|
end
|
251
255
|
|
@@ -347,30 +351,20 @@ class Shoes
|
|
347
351
|
# @option styles [Integer] height (0) the height
|
348
352
|
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
349
353
|
# @option styles [Boolean] center (false) is (left, top) the center of the oval
|
354
|
+
OVAL_ALLOWED_ARG_SIZES = [0, 3, 4]
|
350
355
|
def oval(*opts, &blk)
|
351
356
|
oval_style = pop_style(opts)
|
352
357
|
oval_style = style_normalizer.normalize(oval_style)
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
when 4
|
358
|
-
left, top, width, height = opts
|
359
|
-
when 0
|
360
|
-
left = oval_style[:left] || 0
|
361
|
-
top = oval_style[:top] || 0
|
362
|
-
width = oval_style[:diameter] || oval_style[:width] ||
|
363
|
-
(oval_style[:radius] || 0) * 2
|
364
|
-
height = oval_style[:height] || width
|
365
|
-
else
|
366
|
-
message = <<EOS
|
358
|
+
|
359
|
+
left, top, width, height = opts
|
360
|
+
|
361
|
+
message = <<EOS
|
367
362
|
Wrong number of arguments. Must be one of:
|
368
363
|
- oval(left, top, diameter, [opts])
|
369
364
|
- oval(left, top, width, height, [opts])
|
370
365
|
- oval(styles)
|
371
366
|
EOS
|
372
|
-
|
373
|
-
end
|
367
|
+
fail ArgumentError, message unless OVAL_ALLOWED_ARG_SIZES.include? opts.size
|
374
368
|
create Shoes::Oval, left, top, width, height, oval_style, blk
|
375
369
|
end
|
376
370
|
|
@@ -396,58 +390,45 @@ EOS
|
|
396
390
|
# @option styles [Integer] height (0) the height
|
397
391
|
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
398
392
|
# @option styles [Boolean] center (false) is (left, top) the center of the rectangle?
|
393
|
+
RECT_ALLOWED_ARG_SIZES = [0, 3, 4, 5]
|
399
394
|
def rect(*args, &blk)
|
400
395
|
opts = style_normalizer.normalize pop_style(args)
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
when 4
|
407
|
-
left, top, width, height = args
|
408
|
-
opts[:curve] ||= 0
|
409
|
-
when 5
|
410
|
-
left, top, width, height, opts[:curve] = args
|
411
|
-
when 0
|
412
|
-
left = opts[:left] || 0
|
413
|
-
top = opts[:top] || 0
|
414
|
-
width = opts[:width] || 0
|
415
|
-
height = opts[:height] || width
|
416
|
-
opts[:curve] ||= 0
|
417
|
-
else
|
418
|
-
message = <<EOS
|
396
|
+
|
397
|
+
left, top, width, height, curve = args
|
398
|
+
opts[:curve] = curve if curve
|
399
|
+
|
400
|
+
message = <<EOS
|
419
401
|
Wrong number of arguments. Must be one of:
|
420
402
|
- rect(left, top, side, [opts])
|
421
403
|
- rect(left, top, width, height, [opts])
|
422
404
|
- rect(left, top, width, height, curve, [opts])
|
423
405
|
- rect(styles)
|
424
406
|
EOS
|
425
|
-
|
426
|
-
end
|
407
|
+
fail ArgumentError, message unless RECT_ALLOWED_ARG_SIZES.include? args.size
|
427
408
|
create Shoes::Rect, left, top, width, height, style.merge(opts), blk
|
428
409
|
end
|
429
410
|
|
430
411
|
# Creates a new Shoes::Star object
|
431
412
|
#
|
432
|
-
# @overload
|
413
|
+
# @overload star(left, top, styles, &block)
|
433
414
|
# Creates a star at (left, top) with the given style
|
434
415
|
# @param [Integer] left the x-coordinate of the top-left corner
|
435
416
|
# @param [Integer] top the y-coordinate of the top-left corner
|
436
417
|
# @param [Hash] styles optional, additional styling for the element
|
437
|
-
# @overload
|
418
|
+
# @overload star(left, top, points, styles, &block)
|
438
419
|
# Creates a star at (left, top) with the given style
|
439
420
|
# @param [Integer] left the x-coordinate of the top-left corner
|
440
421
|
# @param [Integer] top the y-coordinate of the top-left corner
|
441
422
|
# @param [Integer] points count of points on the star
|
442
423
|
# @param [Hash] styles optional, additional styling for the element
|
443
|
-
# @overload
|
424
|
+
# @overload star(left, top, points, outer, styles, &block)
|
444
425
|
# Creates a star at (left, top) with the given style
|
445
426
|
# @param [Integer] left the x-coordinate of the top-left corner
|
446
427
|
# @param [Integer] top the y-coordinate of the top-left corner
|
447
428
|
# @param [Integer] points count of points on the star
|
448
429
|
# @param [Integer] outer outer radius of star
|
449
430
|
# @param [Hash] styles optional, additional styling for the element
|
450
|
-
# @overload
|
431
|
+
# @overload star(left, top, points, outer, inner, styles, &block)
|
451
432
|
# Creates a star at (left, top) with the given style
|
452
433
|
# @param [Integer] left the x-coordinate of the top-left corner
|
453
434
|
# @param [Integer] top the y-coordinate of the top-left corner
|
@@ -488,6 +469,7 @@ EOS
|
|
488
469
|
# Creates a shape at (0, 0)
|
489
470
|
# @option styles [Integer] left (0) the x-coordinate of the top-left corner
|
490
471
|
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
472
|
+
SHAPE_ALLOWED_ARG_SIZES = [0, 2]
|
491
473
|
def shape(*args, &blk)
|
492
474
|
opts = style_normalizer.normalize pop_style(args)
|
493
475
|
opts[:left], opts[:top] = args if args.length == 2
|
@@ -498,7 +480,7 @@ Wrong number of arguments. Must be one of:
|
|
498
480
|
- shape(left, top, [opts])
|
499
481
|
- shape(styles)
|
500
482
|
EOS
|
501
|
-
fail ArgumentError, message unless
|
483
|
+
fail ArgumentError, message unless SHAPE_ALLOWED_ARG_SIZES.include? args.length
|
502
484
|
create Shoes::Shape, style.merge(opts), blk
|
503
485
|
end
|
504
486
|
|
@@ -507,13 +489,13 @@ EOS
|
|
507
489
|
OTHER_APP_STYLES = [:cap, :rotate, :strokewidth, :transform, :translate]
|
508
490
|
|
509
491
|
PATTERN_APP_STYLES.each do |style|
|
510
|
-
define_method style
|
492
|
+
define_method style do |val|
|
511
493
|
@__app__.style[style] = pattern(val)
|
512
494
|
end
|
513
495
|
end
|
514
496
|
|
515
497
|
OTHER_APP_STYLES.each do |style|
|
516
|
-
define_method style
|
498
|
+
define_method style do |val|
|
517
499
|
@__app__.style[style] = val
|
518
500
|
end
|
519
501
|
end
|
@@ -607,13 +589,12 @@ EOS
|
|
607
589
|
def visit(url)
|
608
590
|
match_data = nil
|
609
591
|
url_data = Shoes::URL.urls.find { |page, _| match_data = page.match url }
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
end
|
592
|
+
return unless url_data
|
593
|
+
action_proc = url_data[1]
|
594
|
+
url_argument = match_data[1]
|
595
|
+
clear do
|
596
|
+
@__app__.location = url
|
597
|
+
action_proc.call self, url_argument
|
617
598
|
end
|
618
599
|
end
|
619
600
|
|
data/lib/shoes/gradient.rb
CHANGED
@@ -10,22 +10,15 @@ class Shoes
|
|
10
10
|
|
11
11
|
attr_reader :alpha, :color1, :color2
|
12
12
|
|
13
|
-
def inspect
|
14
|
-
super.insert(-2, " #{color1}->#{color2}")
|
15
|
-
end
|
16
|
-
|
17
13
|
def <=>(other) # arbitrarily compare 1st non-equal color
|
18
|
-
|
19
|
-
|
20
|
-
@color2 <=> other.color2
|
21
|
-
else
|
22
|
-
@color1 <=> other.color1
|
23
|
-
end
|
14
|
+
return unless other.is_a?(self.class)
|
15
|
+
[color1, color2] <=> [other.color1, other.color2]
|
24
16
|
end
|
25
17
|
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
private
|
19
|
+
|
20
|
+
def inspect_details
|
21
|
+
" #{color1}->#{color2}"
|
29
22
|
end
|
30
23
|
end
|
31
24
|
end
|
data/lib/shoes/image.rb
CHANGED
@@ -6,17 +6,12 @@ class Shoes
|
|
6
6
|
|
7
7
|
BINARY_ENCODING = Encoding.find('binary')
|
8
8
|
|
9
|
-
attr_reader :app, :parent, :dimensions, :gui
|
10
9
|
style_with :art_styles, :common_styles, :dimensions, :file_path
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@dimensions = Dimensions.new parent, @style
|
17
|
-
@parent.add_child self
|
18
|
-
@gui = Shoes.configuration.backend_for self, @parent.gui
|
19
|
-
register_click blk
|
11
|
+
STYLES = { fill: Shoes::COLORS[:black] }
|
12
|
+
|
13
|
+
def before_initialize(styles, file_path_or_data)
|
14
|
+
styles[:file_path] = normalized_source(file_path_or_data)
|
20
15
|
end
|
21
16
|
|
22
17
|
def path
|
data/lib/shoes/input_box.rb
CHANGED
@@ -4,16 +4,13 @@ class Shoes
|
|
4
4
|
include Common::Style
|
5
5
|
include Common::Changeable
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
style_init styles, text: text.to_s
|
13
|
-
@dimensions = Dimensions.new parent, @style
|
14
|
-
@parent.add_child self
|
15
|
-
@gui = Shoes.configuration.backend_for self, @parent.gui
|
7
|
+
def before_initialize(styles, text)
|
8
|
+
styles[:text] = text.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def handle_block(blk)
|
16
12
|
change(&blk) if blk
|
13
|
+
update_visibility
|
17
14
|
end
|
18
15
|
|
19
16
|
def state=(value)
|