shoes-core 4.0.0.pre7 → 4.0.0.pre8

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24b91fee87f3e41db5ff2dfea086583143fa478f
4
- data.tar.gz: 90f1c1286744dec7e681972691c6f14abb838573
3
+ metadata.gz: f1b7205ad873a89bbd6ed14d91f485200cf83f15
4
+ data.tar.gz: eec9c9656150201d5c0fcce0b9425c6f2c842fef
5
5
  SHA512:
6
- metadata.gz: e34d82bc1902bd05f440d69cc8b56cac7f30be8367edbca11e8870996691307bd402084a09e0c9dbfc33b87abcf9b8d8d24e6c230c8c5392a043e7b882ac537b
7
- data.tar.gz: 699dd3055e4bfdbcf0498af1be251f88835d870591e6019e04e9a82bdd9f40c87c2189000fcce042f85f1e873833c57cde925cab0ff49be7df04799bb95baf3c
6
+ metadata.gz: f10912fc2b305ce9296d58358b0b1de4553f291ab1e9471a5cecff13a9838b595ef650ebd36bdb266f0a5f699cf2e361f30e8c3196ccdbb68ee73e4b8b747e3b
7
+ data.tar.gz: e7de5b6d95f8b7ff98ade674141b42ccdf02e311b6afaa724459e9e0c69e7ca741f169757bee91f6e2155fb0e4fa312760b76e75364d9afd81b2234b3798246e
data/lib/shoes/arc.rb CHANGED
@@ -1,22 +1,19 @@
1
1
  class Shoes
2
2
  class Arc
3
- include Common::UIElement
4
- include Common::Clickable
5
- include Common::Hover
6
- include Common::Fill
7
- include Common::Stroke
8
- include Common::Style
9
- include Common::Translate
3
+ include Common::ArtElement
10
4
 
11
5
  style_with :angle1, :angle2, :art_styles, :center, :common_styles, :dimensions, :radius, :wedge
12
- STYLES = { wedge: false }.freeze
6
+ STYLES = { wedge: false, fill: Shoes::COLORS[:black] }.freeze
13
7
 
14
- def before_initialize(styles, _left, _top, _width, _height, angle1, angle2)
15
- styles[:angle1] = angle1
16
- styles[:angle2] = angle2
17
- end
8
+ def create_dimensions(left, top, width, height, angle1, angle2)
9
+ @style[:angle1] = angle1 || @style[:angle1] || 0
10
+ @style[:angle2] = angle2 || @style[:angle2] || 0
11
+
12
+ left ||= @style[:left] || 0
13
+ top ||= @style[:top] || 0
14
+ width ||= @style[:width] || 0
15
+ height ||= @style[:height] || 0
18
16
 
19
- def create_dimensions(left, top, width, height, _angle1, _angle2)
20
17
  @dimensions = Dimensions.new parent, left, top, width, height, @style
21
18
  end
22
19
 
data/lib/shoes/arrow.rb CHANGED
@@ -1,12 +1,6 @@
1
1
  class Shoes
2
2
  class Arrow
3
- include Common::UIElement
4
- include Common::Clickable
5
- include Common::Fill
6
- include Common::Hover
7
- include Common::Stroke
8
- include Common::Style
9
- include Common::Translate
3
+ include Common::ArtElement
10
4
 
11
5
  style_with :angle, :art_styles, :curve, :common_styles, :dimensions
12
6
  STYLES = { angle: 0, fill: Shoes::COLORS[:black] }.freeze
@@ -19,10 +13,6 @@ class Shoes
19
13
  @dimensions = AbsoluteDimensions.new left, top, width, width, @style
20
14
  end
21
15
 
22
- def needs_rotate?
23
- rotate && rotate.nonzero?
24
- end
25
-
26
16
  def width=(*_)
27
17
  super
28
18
  gui.update_position
@@ -1,10 +1,7 @@
1
1
  class Shoes
2
2
  class Background
3
- include Common::UIElement
4
3
  include Common::BackgroundElement
5
4
  include Common::Fill
6
- include Common::Stroke
7
- include Common::Style
8
5
 
9
6
  style_with :angle, :common_styles, :curve, :dimensions, :fill
10
7
  STYLES = { angle: 0, curve: 0 }.freeze
data/lib/shoes/border.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  class Shoes
2
2
  class Border
3
- include Common::UIElement
4
3
  include Common::BackgroundElement
5
- include Common::Fill
6
4
  include Common::Stroke
7
- include Common::Style
8
5
 
9
6
  style_with :angle, :common_styles, :curve, :dimensions, :stroke, :strokewidth
10
7
  STYLES = { angle: 0, curve: 0 }.freeze
data/lib/shoes/button.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  class Shoes
2
2
  class Button
3
3
  include Common::UIElement
4
- include Common::Style
5
4
  include Common::Clickable
6
5
  include Common::State
7
6
 
7
+ # We don't actually support release from buttons, but want to use the
8
+ # shared infrastructure for clicking. So just get rid of release post def.
9
+ undef release
10
+
8
11
  style_with :click, :common_styles, :dimensions, :state, :text
9
12
 
10
13
  def before_initialize(styles, text)
@@ -1,7 +1,6 @@
1
1
  class Shoes
2
2
  class CheckButton
3
3
  include Common::UIElement
4
- include Common::Style
5
4
  include Common::Clickable
6
5
  include Common::State
7
6
 
@@ -0,0 +1,21 @@
1
+ class Shoes
2
+ module Common
3
+ module ArtElement
4
+ include Common::UIElement
5
+ include Common::Clickable
6
+ include Common::Fill
7
+ include Common::Rotate
8
+ include Common::Stroke
9
+ include Common::Translate
10
+
11
+ # Modules that muck with class methods need to be included like this
12
+ #
13
+ # We also can't rely on Common::UIElement providing these, as it gets
14
+ # ArtElement, not the destination class to add things to!
15
+ def self.included(base)
16
+ base.include Common::Hover
17
+ base.include Common::Style
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,16 @@
1
1
  class Shoes
2
2
  module Common
3
3
  module BackgroundElement
4
+ include Common::UIElement
5
+
6
+ # Modules that muck with class methods need to be included like this
7
+ #
8
+ # We also can't rely on Common::UIElement providing these, as it gets
9
+ # BackgroundElement, not the destination class to add things to!
10
+ def self.included(base)
11
+ base.include Common::Style
12
+ end
13
+
4
14
  def create_dimensions(*_)
5
15
  @dimensions = ParentDimensions.new @parent, @style
6
16
  end
@@ -5,10 +5,12 @@ class Shoes
5
5
 
6
6
  def click(&blk)
7
7
  @gui.click blk
8
+ self
8
9
  end
9
10
 
10
11
  def release(&blk)
11
12
  @gui.release blk
13
+ self
12
14
  end
13
15
 
14
16
  def register_click(blk = nil)
@@ -1,9 +1,8 @@
1
1
  class Shoes
2
2
  module Common
3
3
  module Rotate
4
- # By default no one can rotate. Have to enable in particular classes.
5
4
  def needs_rotate?
6
- false
5
+ rotate && rotate.nonzero?
7
6
  end
8
7
  end
9
8
  end
@@ -7,9 +7,18 @@ class Shoes
7
7
  include Common::Visibility
8
8
  include Common::Positioning
9
9
  include Common::Remove
10
- include Common::Rotate
11
10
  include DimensionsDelegations
12
11
 
12
+ # Modules that muck with class methods need to be included like this
13
+ def self.included(base)
14
+ base.include Common::Style
15
+ end
16
+
17
+ # Nobody rotates by default, but we need to let you check
18
+ def needs_rotate?
19
+ false
20
+ end
21
+
13
22
  # Expected to be overridden by pulling in Common::Fill or Common::Stroke
14
23
  # if element needs to actually notify GUI classes of colors changes.
15
24
  def update_fill
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Shoes
4
4
  module Core
5
- VERSION = "4.0.0.pre7"
5
+ VERSION = "4.0.0.pre8"
6
6
  end
7
7
  end
@@ -17,7 +17,12 @@ class Shoes
17
17
  def initialize(app, _parent, url, opts = {}, &blk)
18
18
  @app = app
19
19
  @url = url
20
+
20
21
  @opts = opts
22
+ @body = opts[:body]
23
+ @headers = opts[:headers] || {}
24
+ @method = opts[:method] || "GET"
25
+
21
26
  initialize_blocks(app, blk)
22
27
 
23
28
  @gui = Shoes.backend_for(self)
@@ -70,20 +75,16 @@ class Shoes
70
75
  private
71
76
 
72
77
  def start_download
73
- require 'open-uri'
74
78
  @thread = Thread.new do
75
79
  begin
76
- uri_opts = {}
77
- uri_opts[:content_length_proc] = content_length_proc
78
- uri_opts[:progress_proc] = progress_proc if @progress_blk
79
-
80
- open @url, uri_opts do |download_data|
81
- @response.body = download_data.read
82
- @response.status = download_data.status
83
- @response.headers = download_data.meta
84
- save_to_file(@opts[:save]) if @opts[:save]
85
- finish_download download_data
80
+ request = Shoes::HttpRequest.new(download_started_proc)
81
+ request.read_chunks(@url, @method, @body, @headers) do |chunk|
82
+ @response.body += chunk
83
+ try_progress(@response.body.length)
86
84
  end
85
+
86
+ save_to_file(@opts[:save]) if @opts[:save]
87
+ finish_download
87
88
  rescue SocketError => e
88
89
  Shoes.logger.error e
89
90
  rescue => e
@@ -100,26 +101,25 @@ class Shoes
100
101
  end
101
102
  end
102
103
 
103
- def content_length_proc
104
- lambda do |content_length|
105
- download_started(content_length)
106
- eval_block(@progress_blk, self)
104
+ def try_progress(size)
105
+ if should_mark_progress?(size)
106
+ @transferred = size
107
+ mark_progress
107
108
  end
108
109
  end
109
110
 
110
- def progress_proc
111
- lambda do |size|
112
- if !content_length.nil? &&
113
- (size - transferred) > (content_length / UPDATE_STEPS) &&
114
- !@gui.busy?
115
- @gui.busy = true
116
- eval_block(@progress_blk, self)
117
- @transferred = size
118
- end
119
- end
111
+ def mark_progress
112
+ @gui.busy = true
113
+ eval_block(@progress_blk, self)
114
+ end
115
+
116
+ def should_mark_progress?(size)
117
+ !content_length.nil? &&
118
+ (size - transferred) > (content_length / UPDATE_STEPS) &&
119
+ !@gui.busy?
120
120
  end
121
121
 
122
- def finish_download(_download_data)
122
+ def finish_download
123
123
  @finished = true
124
124
 
125
125
  # In case backend didn't catch the 100%
@@ -140,9 +140,27 @@ class Shoes
140
140
  open(file_path, 'wb') { |fw| fw.print @response.body }
141
141
  end
142
142
 
143
- def download_started(content_length)
144
- @content_length = content_length
145
- @started = true
143
+ def download_started_proc
144
+ lambda do |response|
145
+ download_started(response)
146
+ end
147
+ end
148
+
149
+ def download_started(response)
150
+ @started = true
151
+ @content_length = read_content_length(response)
152
+
153
+ @response.status = [response.code, response.message]
154
+ response.each_header do |key|
155
+ @response.headers[key] = response[key]
156
+ end
157
+
158
+ mark_progress
159
+ end
160
+
161
+ def read_content_length(response)
162
+ len = response["Content-Length"]
163
+ len.nil? ? nil : len.to_i
146
164
  end
147
165
  end
148
166
  end
data/lib/shoes/dsl.rb CHANGED
@@ -68,14 +68,14 @@ require 'shoes/renamed_delegate'
68
68
  require 'shoes/common/inspect'
69
69
  require 'shoes/dimension'
70
70
  require 'shoes/dimensions'
71
- require 'shoes/not_implemented_error'
72
71
  require 'shoes/file_not_found_error'
72
+ require 'shoes/http_request'
73
+ require 'shoes/not_implemented_error'
73
74
  require 'shoes/text_block_dimensions'
74
75
 
75
76
  require 'shoes/color'
76
77
 
77
78
  require 'shoes/common/attachable'
78
- require 'shoes/common/background_element'
79
79
  require 'shoes/common/changeable'
80
80
  require 'shoes/common/clickable'
81
81
  require 'shoes/common/fill'
@@ -93,6 +93,8 @@ require 'shoes/common/translate'
93
93
  require 'shoes/common/visibility'
94
94
 
95
95
  require 'shoes/common/ui_element'
96
+ require 'shoes/common/art_element'
97
+ require 'shoes/common/background_element'
96
98
 
97
99
  require 'shoes/builtin_methods'
98
100
  require 'shoes/check_button'
@@ -148,7 +150,6 @@ class Shoes
148
150
  # #element_styles: a hash of {Class => styles}, where styles is
149
151
  # a hash of default styles for elements of Class,
150
152
  module DSL
151
- include Common::Style
152
153
  include Color::DSLHelpers
153
154
 
154
155
  # Set default style for elements of a particular class, or for all
@@ -308,15 +309,37 @@ class Shoes
308
309
  Shoes::Sound.new @__app__, soundfile, opts, &blk
309
310
  end
310
311
 
311
- # Creates an arrow centered at (left, top)
312
+ # Creates an arrow
312
313
  #
313
- # @param [Integer] left the x-coordinate of the element center
314
- # @param [Integer] top the y-coordinate of the element center
315
- # @param [Integer] width width of the arrow
316
- # @param [Hash] opts Arrow style options
317
- # @option opts [Integer] rotate (false)
318
- def arrow(left, top, width, styles = {}, &blk)
319
- create Shoes::Arrow, left, top, width, styles, blk
314
+ # @overload arrow(left, top, width, opts)
315
+ # Creates an arrow centered at (left, top)
316
+ # @param [Integer] left the x-coordinate of the element center
317
+ # @param [Integer] top the y-coordinate of the element center
318
+ # @param [Integer] width the width of the arrow
319
+ # @param [Hash] opts Arrow style options
320
+ # @option opts [Integer] rotate (false)
321
+ # @overload arrow(opts)
322
+ # Creates an arrow using values from the opts Hash.
323
+ # @param [Hash] opts
324
+ # @option styles [Integer] left (0) the x-coordinate of the top-left corner
325
+ # @option styles [Integer] top (0) the y-coordinate of the top-left corner
326
+ # @option styles [Integer] width (0) the width
327
+ # @option styles [Integer] rotate (false)
328
+ def arrow(*args, &blk)
329
+ opts = style_normalizer.normalize pop_style(args)
330
+
331
+ left, top, width, *leftovers = args
332
+
333
+ message = <<EOS
334
+ Too many arguments. Must be one of:
335
+ - arrow(left, top, width, [opts])
336
+ - arrow(left, top, [opts])
337
+ - arrow(left, [opts])
338
+ - arrow([opts])
339
+ EOS
340
+ raise ArgumentError, message if leftovers.any?
341
+
342
+ create Shoes::Arrow, left, top, width, opts, blk
320
343
  end
321
344
 
322
345
  # Creates an arc at (left, top)
@@ -330,8 +353,24 @@ class Shoes
330
353
  # @param [Hash] opts Arc style options
331
354
  # @option opts [Boolean] wedge (false)
332
355
  # @option opts [Boolean] center (false) is (left, top) the center of the rectangle?
333
- def arc(left, top, width, height, angle1, angle2, styles = {}, &blk)
334
- create Shoes::Arc, left, top, width, height, angle1, angle2, styles, blk
356
+ def arc(*args, &blk)
357
+ opts = style_normalizer.normalize pop_style(args)
358
+
359
+ left, top, width, height, angle1, angle2, *leftovers = args
360
+
361
+ message = <<EOS
362
+ Too many arguments. Must be one of:
363
+ - arc(left, top, width, height, angle1, angle2, [opts])
364
+ - arc(left, top, width, height, angle1, [opts])
365
+ - arc(left, top, width, height, [opts])
366
+ - arc(left, top, width, [opts])
367
+ - arc(left, top, [opts])
368
+ - arc(left, [opts])
369
+ - arc([opts])
370
+ EOS
371
+ raise ArgumentError, message if leftovers.any?
372
+
373
+ create Shoes::Arc, left, top, width, height, angle1, angle2, opts, blk
335
374
  end
336
375
 
337
376
  # Draws a line from point A (x1,y1) to point B (x2,y2)
@@ -341,8 +380,22 @@ class Shoes
341
380
  # @param [Integer] x2 The x-value of point B
342
381
  # @param [Integer] y2 The y-value of point B
343
382
  # @param [Hash] opts Style options
344
- def line(x1, y1, x2, y2, styles = {}, &blk)
345
- create Shoes::Line, Shoes::Point.new(x1, y1), Shoes::Point.new(x2, y2), styles, blk
383
+ def line(*args, &blk)
384
+ opts = style_normalizer.normalize pop_style(args)
385
+
386
+ x1, y1, x2, y2, *leftovers = args
387
+
388
+ message = <<EOS
389
+ Too many arguments. Must be one of:
390
+ - line(x1, y1, x2, y2, [opts])
391
+ - line(x1, y1, x2, [opts])
392
+ - line(x1, y1, [opts])
393
+ - line(x1, [opts])
394
+ - line([opts])
395
+ EOS
396
+ raise ArgumentError, message if leftovers.any?
397
+
398
+ create Shoes::Line, x1, y1, x2, y2, opts, blk
346
399
  end
347
400
 
348
401
  # Creates an oval at (left, top)
@@ -367,21 +420,22 @@ class Shoes
367
420
  # @option styles [Integer] height (0) the height
368
421
  # @option styles [Integer] top (0) the y-coordinate of the top-left corner
369
422
  # @option styles [Boolean] center (false) is (left, top) the center of the oval
370
- OVAL_ALLOWED_ARG_SIZES = [0, 3, 4].freeze
371
- def oval(*opts, &blk)
372
- oval_style = pop_style(opts)
373
- oval_style = style_normalizer.normalize(oval_style)
423
+ def oval(*args, &blk)
424
+ opts = style_normalizer.normalize pop_style(args)
374
425
 
375
- left, top, width, height = opts
426
+ left, top, width, height, *leftovers = args
376
427
 
377
428
  message = <<EOS
378
429
  Wrong number of arguments. Must be one of:
379
- - oval(left, top, diameter, [opts])
380
430
  - oval(left, top, width, height, [opts])
431
+ - oval(left, top, diameter, [opts])
432
+ - oval(left, top, [opts])
433
+ - oval(left, [opts])
381
434
  - oval(styles)
382
435
  EOS
383
- raise ArgumentError, message unless OVAL_ALLOWED_ARG_SIZES.include? opts.size
384
- create Shoes::Oval, left, top, width, height, oval_style, blk
436
+ raise ArgumentError, message if leftovers.any?
437
+
438
+ create Shoes::Oval, left, top, width, height, opts, blk
385
439
  end
386
440
 
387
441
  # Creates a rectangle
@@ -406,21 +460,24 @@ EOS
406
460
  # @option styles [Integer] height (0) the height
407
461
  # @option styles [Integer] top (0) the y-coordinate of the top-left corner
408
462
  # @option styles [Boolean] center (false) is (left, top) the center of the rectangle?
409
- RECT_ALLOWED_ARG_SIZES = [0, 3, 4, 5].freeze
410
463
  def rect(*args, &blk)
411
464
  opts = style_normalizer.normalize pop_style(args)
412
465
 
413
- left, top, width, height, curve = args
466
+ left, top, width, height, curve, *leftovers = args
414
467
  opts[:curve] = curve if curve
415
468
 
416
469
  message = <<EOS
417
470
  Wrong number of arguments. Must be one of:
418
- - rect(left, top, side, [opts])
419
- - rect(left, top, width, height, [opts])
420
471
  - rect(left, top, width, height, curve, [opts])
472
+ - rect(left, top, width, height, [opts])
473
+ - rect(left, top, side, [opts])
474
+ - rect(left, top, [opts])
475
+ - rect(left, [opts])
421
476
  - rect(styles)
422
477
  EOS
423
- raise ArgumentError, message unless RECT_ALLOWED_ARG_SIZES.include? args.size
478
+
479
+ raise ArgumentError, message if leftovers.any?
480
+
424
481
  create Shoes::Rect, left, top, width, height, style.merge(opts), blk
425
482
  end
426
483
 
@@ -452,21 +509,21 @@ EOS
452
509
  # @param [Integer] outer outer radius of star
453
510
  # @param [Integer] inner inner radius of star
454
511
  # @param [Hash] styles optional, additional styling for the element
455
- def star(left, top, *args, &blk)
512
+ def star(*args, &blk)
456
513
  styles = style_normalizer.normalize pop_style(args)
457
514
 
458
- points, outer, inner, extras = args
515
+ left, top, points, outer, inner, *leftovers = args
459
516
 
460
- if extras
461
- message = <<EOS
517
+ message = <<EOS
462
518
  Wrong number of arguments. Must be one of:
519
+ - star([styles])
520
+ - star(left, [styles])
463
521
  - star(left, top, [styles])
464
522
  - star(left, top, points, [styles])
465
523
  - star(left, top, points, outer, [styles])
466
524
  - star(left, top, points, outer, inner, [styles])
467
525
  EOS
468
- raise ArgumentError, message
469
- end
526
+ raise ArgumentError, message if leftovers.any?
470
527
 
471
528
  create Shoes::Star, left, top, points, outer, inner, styles, blk
472
529
  end
@@ -485,19 +542,21 @@ EOS
485
542
  # Creates a shape at (0, 0)
486
543
  # @option styles [Integer] left (0) the x-coordinate of the top-left corner
487
544
  # @option styles [Integer] top (0) the y-coordinate of the top-left corner
488
- SHAPE_ALLOWED_ARG_SIZES = [0, 2].freeze
489
545
  def shape(*args, &blk)
490
546
  opts = style_normalizer.normalize pop_style(args)
491
- opts[:left], opts[:top] = args if args.length == 2
547
+
548
+ left, top, *leftovers = args
492
549
 
493
550
  message = <<EOS
494
551
  Wrong number of arguments. Must be one of:
495
- - shape()
496
552
  - shape(left, top, [opts])
497
- - shape(styles)
553
+ - shape(left, [opts])
554
+ - shape([opts])
498
555
  EOS
499
- raise ArgumentError, message unless SHAPE_ALLOWED_ARG_SIZES.include? args.length
500
- create Shoes::Shape, style.merge(opts), blk
556
+
557
+ raise ArgumentError, message if leftovers.any?
558
+
559
+ create Shoes::Shape, left, top, opts, blk
501
560
  end
502
561
 
503
562
  # Define app-level setter methods