shoes-core 4.0.0.pre4 → 4.0.0.pre5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +5 -0
  3. data/bin/shoes +1 -1
  4. data/bin/shoes-stub +1 -1
  5. data/ext/install/Rakefile +15 -5
  6. data/ext/install/shoes.bat +1 -1
  7. data/lib/shoes/animation.rb +2 -2
  8. data/lib/shoes/arc.rb +1 -0
  9. data/lib/shoes/builtin_methods.rb +5 -18
  10. data/lib/shoes/button.rb +1 -5
  11. data/lib/shoes/check_button.rb +1 -5
  12. data/lib/shoes/color.rb +5 -274
  13. data/lib/shoes/color/dsl.rb +166 -0
  14. data/lib/shoes/color/dsl_helpers.rb +84 -0
  15. data/lib/shoes/color/hex_converter.rb +32 -0
  16. data/lib/shoes/common/background_element.rb +5 -0
  17. data/lib/shoes/common/hover.rb +87 -0
  18. data/lib/shoes/common/initialization.rb +21 -8
  19. data/lib/shoes/common/remove.rb +2 -0
  20. data/lib/shoes/common/state.rb +17 -3
  21. data/lib/shoes/common/style.rb +8 -0
  22. data/lib/shoes/configuration.rb +18 -15
  23. data/lib/shoes/core/version.rb +1 -1
  24. data/lib/shoes/dimension.rb +6 -19
  25. data/lib/shoes/dimensions.rb +8 -0
  26. data/lib/shoes/download.rb +5 -3
  27. data/lib/shoes/dsl.rb +3 -3
  28. data/lib/shoes/image.rb +1 -0
  29. data/lib/shoes/image_pattern.rb +1 -1
  30. data/lib/shoes/input_box.rb +2 -5
  31. data/lib/shoes/internal_app.rb +13 -2
  32. data/lib/shoes/line.rb +1 -0
  33. data/lib/shoes/link.rb +8 -0
  34. data/lib/shoes/list_box.rb +2 -5
  35. data/lib/shoes/mock/check.rb +3 -0
  36. data/lib/shoes/mock/image.rb +6 -0
  37. data/lib/shoes/mock/progress.rb +6 -0
  38. data/lib/shoes/mock/radio.rb +3 -0
  39. data/lib/shoes/mock/sound.rb +1 -1
  40. data/lib/shoes/oval.rb +1 -0
  41. data/lib/shoes/packager.rb +1 -1
  42. data/lib/shoes/rect.rb +1 -0
  43. data/lib/shoes/shape.rb +4 -0
  44. data/lib/shoes/slot.rb +75 -38
  45. data/lib/shoes/slot_contents.rb +4 -0
  46. data/lib/shoes/sound.rb +3 -2
  47. data/lib/shoes/star.rb +1 -0
  48. data/lib/shoes/text_block.rb +18 -2
  49. data/lib/shoes/text_block_dimensions.rb +19 -3
  50. data/lib/shoes/timer.rb +2 -2
  51. data/lib/shoes/ui/picker.rb +4 -4
  52. data/lib/shoes/version.rb +1 -1
  53. data/shoes-core.gemspec +1 -1
  54. data/spec/shoes/animation_spec.rb +2 -2
  55. data/spec/shoes/app_spec.rb +6 -17
  56. data/spec/shoes/arc_spec.rb +2 -1
  57. data/spec/shoes/background_spec.rb +2 -2
  58. data/spec/shoes/border_spec.rb +2 -2
  59. data/spec/shoes/builtin_methods_spec.rb +68 -56
  60. data/spec/shoes/button_spec.rb +3 -3
  61. data/spec/shoes/check_spec.rb +3 -2
  62. data/spec/shoes/color_spec.rb +9 -3
  63. data/spec/shoes/common/remove_spec.rb +0 -1
  64. data/spec/shoes/common/rotate_spec.rb +13 -0
  65. data/spec/shoes/common/style_spec.rb +12 -3
  66. data/spec/shoes/configuration_spec.rb +18 -3
  67. data/spec/shoes/constants_spec.rb +1 -0
  68. data/spec/shoes/dialog_spec.rb +1 -3
  69. data/spec/shoes/dimension_spec.rb +33 -24
  70. data/spec/shoes/dimensions_spec.rb +21 -31
  71. data/spec/shoes/download_spec.rb +14 -3
  72. data/spec/shoes/flow_spec.rb +6 -7
  73. data/spec/shoes/font_spec.rb +2 -3
  74. data/spec/shoes/framework_learning_spec.rb +1 -2
  75. data/spec/shoes/gradient_spec.rb +1 -2
  76. data/spec/shoes/helpers/fake_absolute_element.rb +30 -0
  77. data/spec/shoes/helpers/sample17_helper.rb +0 -1
  78. data/spec/shoes/image_spec.rb +2 -1
  79. data/spec/shoes/input_box_spec.rb +2 -2
  80. data/spec/shoes/integration_spec.rb +0 -1
  81. data/spec/shoes/internal_app_spec.rb +4 -5
  82. data/spec/shoes/keypress_spec.rb +1 -1
  83. data/spec/shoes/keyrelease_spec.rb +1 -2
  84. data/spec/shoes/line_spec.rb +3 -2
  85. data/spec/shoes/link_spec.rb +26 -6
  86. data/spec/shoes/list_box_spec.rb +2 -2
  87. data/spec/shoes/oval_spec.rb +2 -1
  88. data/spec/shoes/packager_spec.rb +1 -1
  89. data/spec/shoes/point_spec.rb +1 -1
  90. data/spec/shoes/progress_spec.rb +1 -1
  91. data/spec/shoes/radio_spec.rb +1 -1
  92. data/spec/shoes/rect_spec.rb +2 -1
  93. data/spec/shoes/renamed_delegate_spec.rb +0 -1
  94. data/spec/shoes/shape_spec.rb +1 -1
  95. data/spec/shoes/shared_examples/common_methods.rb +1 -1
  96. data/spec/shoes/shared_examples/dsl/animate.rb +1 -1
  97. data/spec/shoes/shared_examples/dsl/background.rb +2 -2
  98. data/spec/shoes/shared_examples/dsl/rgb.rb +4 -2
  99. data/spec/shoes/shared_examples/dsl/star.rb +0 -1
  100. data/spec/shoes/shared_examples/dsl/style.rb +1 -1
  101. data/spec/shoes/shared_examples/dsl/text_elements.rb +2 -2
  102. data/spec/shoes/shared_examples/dsl/video.rb +1 -1
  103. data/spec/shoes/shared_examples/dsl_app_context.rb +4 -1
  104. data/spec/shoes/shared_examples/hover.rb +78 -0
  105. data/spec/shoes/shared_examples/slot.rb +34 -4
  106. data/spec/shoes/shared_examples/state.rb +9 -2
  107. data/spec/shoes/shared_examples/style.rb +0 -5
  108. data/spec/shoes/slot_spec.rb +11 -38
  109. data/spec/shoes/sound_spec.rb +3 -2
  110. data/spec/shoes/span_spec.rb +2 -2
  111. data/spec/shoes/spec_helper.rb +1 -1
  112. data/spec/shoes/stack_spec.rb +6 -6
  113. data/spec/shoes/star_spec.rb +2 -1
  114. data/spec/shoes/text_block_dimensions_spec.rb +3 -4
  115. data/spec/shoes/text_block_spec.rb +16 -11
  116. data/spec/shoes/ui/picker_spec.rb +5 -6
  117. data/spec/shoes/url_spec.rb +1 -2
  118. data/spec/shoes/widget_spec.rb +11 -3
  119. data/spec/shoes_spec.rb +1 -4
  120. data/spec/spec_helper.rb +2 -1
  121. metadata +16 -9
  122. data/bin/shoes-guard +0 -8
  123. data/lib/shoes/link_hover.rb +0 -5
  124. data/spec/shoes/shared_examples/hover_leave.rb +0 -11
@@ -41,6 +41,8 @@ class Shoes
41
41
  @style.merge!(new_styles)
42
42
  @style.merge!(arg_styles)
43
43
  @style = StyleNormalizer.new.normalize(@style)
44
+
45
+ set_hovers(@style)
44
46
  end
45
47
 
46
48
  def create_style_hash
@@ -123,6 +125,7 @@ class Shoes
123
125
  set_dimensions(new_styles)
124
126
  set_visibility(new_styles)
125
127
  set_coloring(new_styles)
128
+ set_hovers(new_styles)
126
129
  click(&new_styles[:click]) if new_styles.key?(:click)
127
130
  @style.merge! normalized_style
128
131
  end
@@ -145,6 +148,11 @@ class Shoes
145
148
  update_stroke if new_styles.include?(:stroke)
146
149
  end
147
150
 
151
+ def set_hovers(new_styles)
152
+ hover(&new_styles[:hover]) if new_styles.include?(:hover)
153
+ leave(&new_styles[:leave]) if new_styles.include?(:leave)
154
+ end
155
+
148
156
  def update_dimensions # so that @style hash matches actual values
149
157
  STYLE_GROUPS[:dimensions].each do |style|
150
158
  if self.respond_to?(style)
@@ -29,39 +29,42 @@ class Shoes
29
29
  # @example
30
30
  # Shoes::Configuration.backend = :swt # => Shoes::Swt
31
31
  def backend=(name)
32
+ return if @backend_name == name
33
+
32
34
  unless @backend.nil?
33
35
  fail "Can't switch backend to Shoes::#{name.capitalize}, Shoes::#{backend_name.capitalize} backend already loaded."
34
36
  end
35
37
  @backend_name ||= name
36
38
  end
37
39
 
38
- # Finds the appropriate backend class for the given Shoes object
40
+ # Finds the appropriate backend class for the given Shoes object or class
39
41
  #
40
- # @param [Object] shoes_object A Shoes object
42
+ # @param [Object] object A Shoes object or a class
41
43
  # @return [Object] An appropriate backend class
42
44
  # @example
43
45
  # Shoes.configuration.backend_class(shoes_button) # => Shoes::Swt::Button
44
- def backend_class(shoes_object)
45
- class_name = shoes_object.class.name.split("::").last
46
+ def backend_class(object)
47
+ klazz = object.is_a?(Class) ? object : object.class
48
+ class_name = klazz.name.split("::").last
46
49
  # Lookup with false to not consult modules higher in the chain Object
47
50
  # because Shoes::Swt.const_defined? 'Range' => true
48
- fail ArgumentError, "#{shoes_object} does not have a backend class defined for #{backend}" unless backend.const_defined?(class_name, false)
51
+ fail ArgumentError, "#{object} does not have a backend class defined for #{backend}" unless backend.const_defined?(class_name, false)
49
52
  backend.const_get(class_name, false)
50
53
  end
51
54
 
52
- # Creates an appropriate backend object, passing along additional arguments
55
+ # Creates an appropriate backend object, passing along additional
56
+ # arguments
53
57
  #
54
58
  # @param [Object] shoes_object A Shoes object
55
59
  # @return [Object] An appropriate backend object
60
+ #
56
61
  # @example
57
- # Shoes.configuration.backend_for(button, args) # => <Shoes::Swt::Button:0x12345678>
58
- def backend_for(shoes_object, *args)
59
- backend_factory(shoes_object).call(shoes_object, *args)
60
- end
61
-
62
- # Experimental replacement for #backend_for
63
- def backend_with_app_for(shoes_object, *args, &blk)
64
- backend_factory(shoes_object).call(shoes_object, shoes_object.app.gui, *args, &blk)
62
+ # Shoes.backend_for(button, args) # => <Shoes::Swt::Button:0x12345678>
63
+ def backend_for(shoes_object, *args, &blk)
64
+ # Some element types (packager for instance) legitimately don't have
65
+ # an app. In those cases, don't try to get it to pass along.
66
+ args.unshift(shoes_object.app.gui) if shoes_object.respond_to?(:app)
67
+ backend_factory(shoes_object).call(shoes_object, *args, &blk)
65
68
  end
66
69
 
67
70
  def backend_factory(shoes_object)
@@ -90,7 +93,7 @@ def Shoes.configuration
90
93
  end
91
94
 
92
95
  def Shoes.backend_for(shoes_object, *args, &blk)
93
- Shoes::Configuration.backend_with_app_for(shoes_object, *args, &blk)
96
+ Shoes::Configuration.backend_for(shoes_object, *args, &blk)
94
97
  end
95
98
 
96
99
  def Shoes.backend
@@ -1,5 +1,5 @@
1
1
  class Shoes
2
2
  module Core
3
- VERSION = "4.0.0.pre4"
3
+ VERSION = "4.0.0.pre5"
4
4
  end
5
5
  end
@@ -238,11 +238,7 @@ class Shoes
238
238
 
239
239
  class ParentDimension < Dimension
240
240
  def absolute_start
241
- @absolute_start ? super : parent.absolute_start
242
- end
243
-
244
- def start
245
- @start ? super : parent.start
241
+ parent.element_start
246
242
  end
247
243
 
248
244
  def extent
@@ -253,27 +249,18 @@ class Shoes
253
249
 
254
250
  # Represents the extent, bounded by the parent container's sizing
255
251
  def extent_in_parent
256
- if parent.element_end
257
- # Why subtracting an absolute from an element dimension value? A
258
- # diagram helped me reason out what we wanted.
259
- #
260
- # parent. parent. self. self. parent. parent.
261
- # abs_start elem_start abs_start abs_end elem_end abs_end
262
- # | margin | | | | margin |
263
- #
264
- # To get our extent respecting the parent's margins, it's our absolute
265
- # start, minus parent's element end (so we don't blow past the margin)
266
- parent.element_end - absolute_start - PIXEL_COUNTING_ADJUSTMENT
252
+ if parent.element_extent
253
+ parent.element_extent
267
254
  else
268
255
  # If we hit this, then the extent in parent isn't available and will be
269
- # ignored by the min call below
256
+ # ignored by the min call in extent
270
257
  Float::INFINITY
271
258
  end
272
259
  end
273
260
 
274
261
  # Represents the raw value set for extent, either on element or on parent
275
- def raw_extent(original_value)
276
- original_value || parent.extent
262
+ def raw_extent(own_original_extent)
263
+ own_original_extent || parent.extent
277
264
  end
278
265
  end
279
266
  end
@@ -91,6 +91,10 @@ class Shoes
91
91
  self.margin_right, self.margin_bottom = margin
92
92
  end
93
93
 
94
+ def needs_positioning?
95
+ true
96
+ end
97
+
94
98
  def takes_up_space?
95
99
  true
96
100
  end
@@ -166,6 +170,10 @@ class Shoes
166
170
  def initialize(*args)
167
171
  super(nil, *args)
168
172
  end
173
+
174
+ def takes_up_space?
175
+ false
176
+ end
169
177
  end
170
178
 
171
179
  # for objects that are more defined by their parents, delegates method calls
@@ -2,7 +2,7 @@ class Shoes
2
2
  class HttpResponse
3
3
  # Struct might be better?
4
4
  attr_accessor :headers, :body, :status
5
- def initalize
5
+ def initialize
6
6
  @headers = {}
7
7
  @body = ''
8
8
  @status = []
@@ -10,15 +10,17 @@ class Shoes
10
10
  end
11
11
 
12
12
  class Download
13
- attr_reader :progress, :response, :content_length, :gui, :transferred
13
+ attr_reader :app, :progress, :response, :content_length, :gui, :transferred
14
+
14
15
  UPDATE_STEPS = 100
15
16
 
16
17
  def initialize(app, _parent, url, opts = {}, &blk)
18
+ @app = app
17
19
  @url = url
18
20
  @opts = opts
19
21
  initialize_blocks(app, blk)
20
22
 
21
- @gui = Shoes.configuration.backend_for(self)
23
+ @gui = Shoes.backend_for(self)
22
24
 
23
25
  @response = HttpResponse.new
24
26
  @finished = false
data/lib/shoes/dsl.rb CHANGED
@@ -78,6 +78,7 @@ require 'shoes/common/background_element'
78
78
  require 'shoes/common/changeable'
79
79
  require 'shoes/common/clickable'
80
80
  require 'shoes/common/fill'
81
+ require 'shoes/common/hover'
81
82
  require 'shoes/common/initialization'
82
83
  require 'shoes/common/positioning'
83
84
  require 'shoes/common/remove'
@@ -113,7 +114,6 @@ require 'shoes/image_pattern'
113
114
  require 'shoes/key_event'
114
115
  require 'shoes/line'
115
116
  require 'shoes/link'
116
- require 'shoes/link_hover'
117
117
  require 'shoes/list_box'
118
118
  require 'shoes/logger'
119
119
  require 'shoes/oval'
@@ -567,11 +567,11 @@ EOS
567
567
  # hover and leave just delegate to the current slot as hover and leave
568
568
  # are just defined for slots but self is always the app.
569
569
  def hover(&blk)
570
- @__app__.current_slot.hover(blk)
570
+ @__app__.current_slot.hover(&blk)
571
571
  end
572
572
 
573
573
  def leave(&blk)
574
- @__app__.current_slot.leave(blk)
574
+ @__app__.current_slot.leave(&blk)
575
575
  end
576
576
 
577
577
  def keypress(&blk)
data/lib/shoes/image.rb CHANGED
@@ -3,6 +3,7 @@ class Shoes
3
3
  include Common::UIElement
4
4
  include Common::Style
5
5
  include Common::Clickable
6
+ include Common::Hover
6
7
 
7
8
  BINARY_ENCODING = Encoding.find('binary')
8
9
 
@@ -4,7 +4,7 @@ class Shoes
4
4
 
5
5
  def initialize(path)
6
6
  @path = path
7
- @gui = Shoes.configuration.backend_for(self)
7
+ @gui = Shoes.backend_for(self)
8
8
  end
9
9
 
10
10
  attr_reader :gui, :path
@@ -3,6 +3,8 @@ class Shoes
3
3
  include Common::UIElement
4
4
  include Common::Style
5
5
  include Common::Changeable
6
+ include Common::State
7
+
6
8
 
7
9
  def before_initialize(styles, text)
8
10
  styles[:text] = text.to_s
@@ -13,11 +15,6 @@ class Shoes
13
15
  update_visibility
14
16
  end
15
17
 
16
- def state=(value)
17
- style(state: value)
18
- @gui.enabled value.nil?
19
- end
20
-
21
18
  def focus
22
19
  @gui.focus
23
20
  end
@@ -16,8 +16,7 @@ class Shoes
16
16
  DEFAULT_OPTIONS = { width: 600,
17
17
  height: 500,
18
18
  title: "Shoes 4",
19
- resizable: true,
20
- background: Shoes::COLORS.fetch(:shoes_background) }.freeze
19
+ resizable: true }.freeze
21
20
 
22
21
  def initialize(app, opts, &blk)
23
22
  @app = app
@@ -27,6 +26,7 @@ class Shoes
27
26
  end
28
27
 
29
28
  def setup_gui
29
+ ensure_backend_loaded
30
30
  @gui = Shoes.configuration.backend::App.new self
31
31
 
32
32
  self.current_slot = create_top_slot
@@ -37,6 +37,13 @@ class Shoes
37
37
  register_console_keypress
38
38
  end
39
39
 
40
+ def ensure_backend_loaded
41
+ if !defined?(Shoes.configuration.backend::App)
42
+ backend_const = Shoes.load_backend(Shoes.configuration.backend_name)
43
+ backend_const.initialize_backend
44
+ end
45
+ end
46
+
40
47
  attr_reader :gui, :top_slot, :app, :dimensions,
41
48
  :mouse_motion, :owner, :element_styles, :resize_callbacks
42
49
  attr_accessor :elements, :current_slot, :opts, :blk, :mouse_button,
@@ -102,6 +109,10 @@ class Shoes
102
109
  mouse_hover_controls << element
103
110
  end
104
111
 
112
+ def remove_mouse_hover_control(element)
113
+ mouse_hover_controls.delete(element)
114
+ end
115
+
105
116
  def open_gui
106
117
  gui.open
107
118
  end
data/lib/shoes/line.rb CHANGED
@@ -6,6 +6,7 @@ class Shoes
6
6
  include Common::Stroke
7
7
  include Common::Style
8
8
  include Common::Clickable
9
+ include Common::Hover
9
10
 
10
11
  attr_reader :point_a, :point_b
11
12
 
data/lib/shoes/link.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  class Shoes
2
2
  class Link < Span
3
3
  include Common::Style
4
+ include Common::Fill
5
+ include Common::Stroke
6
+ include Common::Hover
4
7
 
5
8
  attr_reader :app, :gui, :blk
6
9
  style_with :common_styles, :text_block_styles
@@ -15,6 +18,11 @@ class Shoes
15
18
  super texts, @style
16
19
  end
17
20
 
21
+ # Force hovering evaluation up in parent where we have actual dimensions
22
+ def eval_in_parent?
23
+ true
24
+ end
25
+
18
26
  # Doesn't use Common::Clickable because of URL flavor option clicks
19
27
  def setup_click(blk)
20
28
  if blk.nil?
@@ -28,6 +28,7 @@ class Shoes
28
28
  include Common::UIElement
29
29
  include Common::Style
30
30
  include Common::Changeable
31
+ include Common::State
31
32
 
32
33
  style_with :change, :choose, :common_styles, :dimensions, :items, :state, :text
33
34
  STYLES = { width: 200, height: 20, items: [""] }
@@ -37,6 +38,7 @@ class Shoes
37
38
  end
38
39
 
39
40
  def after_initialize
41
+ super
40
42
  proxy_array = Shoes::ProxyArray.new(items, @gui)
41
43
  @style[:items] = proxy_array
42
44
  end
@@ -63,10 +65,5 @@ class Shoes
63
65
  end
64
66
 
65
67
  alias_method :choose=, :choose
66
-
67
- def state=(value)
68
- style(state: value)
69
- @gui.enabled value.nil?
70
- end
71
68
  end
72
69
  end
@@ -5,6 +5,9 @@ class Shoes
5
5
  include Shoes::Mock::Clickable
6
6
 
7
7
  def initialize(*_opts)
8
+ # SWT backend sets a size, so mimic that in the mock
9
+ super
10
+ @dsl.width ||= 22
8
11
  end
9
12
 
10
13
  def checked?
@@ -6,6 +6,12 @@ class Shoes
6
6
 
7
7
  attr_accessor :left, :top
8
8
 
9
+ def initialize(*_)
10
+ # SWT backend sets a size, so mimic that in the mock
11
+ super
12
+ @dsl.width ||= 22
13
+ end
14
+
9
15
  def update_image
10
16
  end
11
17
  end
@@ -3,6 +3,12 @@ class Shoes
3
3
  class Progress
4
4
  include Shoes::Mock::CommonMethods
5
5
 
6
+ def initialize(*_)
7
+ # SWT backend sets a size, so mimic that in the mock
8
+ super
9
+ @dsl.width ||= 140
10
+ end
11
+
6
12
  def fraction=(_fraction)
7
13
  end
8
14
  end
@@ -5,6 +5,9 @@ class Shoes
5
5
  include Shoes::Mock::Clickable
6
6
 
7
7
  def initialize(*_opts)
8
+ # SWT backend sets a size, so mimic that in the mock
9
+ super
10
+ @dsl.width ||= 22
8
11
  end
9
12
 
10
13
  def checked?
@@ -1,7 +1,7 @@
1
1
  class Shoes
2
2
  module Mock
3
3
  class Sound
4
- def initialize(_dsl)
4
+ def initialize(_dsl, _app)
5
5
  end
6
6
  end
7
7
  end
data/lib/shoes/oval.rb CHANGED
@@ -5,6 +5,7 @@ class Shoes
5
5
  include Common::Stroke
6
6
  include Common::Style
7
7
  include Common::Clickable
8
+ include Common::Hover
8
9
 
9
10
  style_with :art_styles, :center, :common_styles, :dimensions, :radius
10
11
  STYLES = { fill: Shoes::COLORS[:black] }
@@ -4,7 +4,7 @@ class Shoes
4
4
 
5
5
  def initialize
6
6
  begin
7
- @backend = Shoes.configuration.backend_for(self)
7
+ @backend = Shoes.backend_for(self)
8
8
  rescue ArgumentError
9
9
  # Packaging unsupported by this backend
10
10
  end