shoes-core 4.0.0.pre4 → 4.0.0.pre5
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/Guardfile +5 -0
- data/bin/shoes +1 -1
- data/bin/shoes-stub +1 -1
- data/ext/install/Rakefile +15 -5
- data/ext/install/shoes.bat +1 -1
- data/lib/shoes/animation.rb +2 -2
- data/lib/shoes/arc.rb +1 -0
- data/lib/shoes/builtin_methods.rb +5 -18
- data/lib/shoes/button.rb +1 -5
- data/lib/shoes/check_button.rb +1 -5
- data/lib/shoes/color.rb +5 -274
- data/lib/shoes/color/dsl.rb +166 -0
- data/lib/shoes/color/dsl_helpers.rb +84 -0
- data/lib/shoes/color/hex_converter.rb +32 -0
- data/lib/shoes/common/background_element.rb +5 -0
- data/lib/shoes/common/hover.rb +87 -0
- data/lib/shoes/common/initialization.rb +21 -8
- data/lib/shoes/common/remove.rb +2 -0
- data/lib/shoes/common/state.rb +17 -3
- data/lib/shoes/common/style.rb +8 -0
- data/lib/shoes/configuration.rb +18 -15
- data/lib/shoes/core/version.rb +1 -1
- data/lib/shoes/dimension.rb +6 -19
- data/lib/shoes/dimensions.rb +8 -0
- data/lib/shoes/download.rb +5 -3
- data/lib/shoes/dsl.rb +3 -3
- data/lib/shoes/image.rb +1 -0
- data/lib/shoes/image_pattern.rb +1 -1
- data/lib/shoes/input_box.rb +2 -5
- data/lib/shoes/internal_app.rb +13 -2
- data/lib/shoes/line.rb +1 -0
- data/lib/shoes/link.rb +8 -0
- data/lib/shoes/list_box.rb +2 -5
- data/lib/shoes/mock/check.rb +3 -0
- data/lib/shoes/mock/image.rb +6 -0
- data/lib/shoes/mock/progress.rb +6 -0
- data/lib/shoes/mock/radio.rb +3 -0
- data/lib/shoes/mock/sound.rb +1 -1
- data/lib/shoes/oval.rb +1 -0
- data/lib/shoes/packager.rb +1 -1
- data/lib/shoes/rect.rb +1 -0
- data/lib/shoes/shape.rb +4 -0
- data/lib/shoes/slot.rb +75 -38
- data/lib/shoes/slot_contents.rb +4 -0
- data/lib/shoes/sound.rb +3 -2
- data/lib/shoes/star.rb +1 -0
- data/lib/shoes/text_block.rb +18 -2
- data/lib/shoes/text_block_dimensions.rb +19 -3
- data/lib/shoes/timer.rb +2 -2
- data/lib/shoes/ui/picker.rb +4 -4
- data/lib/shoes/version.rb +1 -1
- data/shoes-core.gemspec +1 -1
- data/spec/shoes/animation_spec.rb +2 -2
- data/spec/shoes/app_spec.rb +6 -17
- data/spec/shoes/arc_spec.rb +2 -1
- data/spec/shoes/background_spec.rb +2 -2
- data/spec/shoes/border_spec.rb +2 -2
- data/spec/shoes/builtin_methods_spec.rb +68 -56
- data/spec/shoes/button_spec.rb +3 -3
- data/spec/shoes/check_spec.rb +3 -2
- data/spec/shoes/color_spec.rb +9 -3
- data/spec/shoes/common/remove_spec.rb +0 -1
- data/spec/shoes/common/rotate_spec.rb +13 -0
- data/spec/shoes/common/style_spec.rb +12 -3
- data/spec/shoes/configuration_spec.rb +18 -3
- data/spec/shoes/constants_spec.rb +1 -0
- data/spec/shoes/dialog_spec.rb +1 -3
- data/spec/shoes/dimension_spec.rb +33 -24
- data/spec/shoes/dimensions_spec.rb +21 -31
- data/spec/shoes/download_spec.rb +14 -3
- data/spec/shoes/flow_spec.rb +6 -7
- data/spec/shoes/font_spec.rb +2 -3
- data/spec/shoes/framework_learning_spec.rb +1 -2
- data/spec/shoes/gradient_spec.rb +1 -2
- data/spec/shoes/helpers/fake_absolute_element.rb +30 -0
- data/spec/shoes/helpers/sample17_helper.rb +0 -1
- data/spec/shoes/image_spec.rb +2 -1
- data/spec/shoes/input_box_spec.rb +2 -2
- data/spec/shoes/integration_spec.rb +0 -1
- data/spec/shoes/internal_app_spec.rb +4 -5
- data/spec/shoes/keypress_spec.rb +1 -1
- data/spec/shoes/keyrelease_spec.rb +1 -2
- data/spec/shoes/line_spec.rb +3 -2
- data/spec/shoes/link_spec.rb +26 -6
- data/spec/shoes/list_box_spec.rb +2 -2
- data/spec/shoes/oval_spec.rb +2 -1
- data/spec/shoes/packager_spec.rb +1 -1
- data/spec/shoes/point_spec.rb +1 -1
- data/spec/shoes/progress_spec.rb +1 -1
- data/spec/shoes/radio_spec.rb +1 -1
- data/spec/shoes/rect_spec.rb +2 -1
- data/spec/shoes/renamed_delegate_spec.rb +0 -1
- data/spec/shoes/shape_spec.rb +1 -1
- data/spec/shoes/shared_examples/common_methods.rb +1 -1
- data/spec/shoes/shared_examples/dsl/animate.rb +1 -1
- data/spec/shoes/shared_examples/dsl/background.rb +2 -2
- data/spec/shoes/shared_examples/dsl/rgb.rb +4 -2
- data/spec/shoes/shared_examples/dsl/star.rb +0 -1
- data/spec/shoes/shared_examples/dsl/style.rb +1 -1
- data/spec/shoes/shared_examples/dsl/text_elements.rb +2 -2
- data/spec/shoes/shared_examples/dsl/video.rb +1 -1
- data/spec/shoes/shared_examples/dsl_app_context.rb +4 -1
- data/spec/shoes/shared_examples/hover.rb +78 -0
- data/spec/shoes/shared_examples/slot.rb +34 -4
- data/spec/shoes/shared_examples/state.rb +9 -2
- data/spec/shoes/shared_examples/style.rb +0 -5
- data/spec/shoes/slot_spec.rb +11 -38
- data/spec/shoes/sound_spec.rb +3 -2
- data/spec/shoes/span_spec.rb +2 -2
- data/spec/shoes/spec_helper.rb +1 -1
- data/spec/shoes/stack_spec.rb +6 -6
- data/spec/shoes/star_spec.rb +2 -1
- data/spec/shoes/text_block_dimensions_spec.rb +3 -4
- data/spec/shoes/text_block_spec.rb +16 -11
- data/spec/shoes/ui/picker_spec.rb +5 -6
- data/spec/shoes/url_spec.rb +1 -2
- data/spec/shoes/widget_spec.rb +11 -3
- data/spec/shoes_spec.rb +1 -4
- data/spec/spec_helper.rb +2 -1
- metadata +16 -9
- data/bin/shoes-guard +0 -8
- data/lib/shoes/link_hover.rb +0 -5
- data/spec/shoes/shared_examples/hover_leave.rb +0 -11
data/lib/shoes/common/style.rb
CHANGED
@@ -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)
|
data/lib/shoes/configuration.rb
CHANGED
@@ -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]
|
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(
|
45
|
-
|
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, "#{
|
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
|
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.
|
58
|
-
def backend_for(shoes_object, *args)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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.
|
96
|
+
Shoes::Configuration.backend_for(shoes_object, *args, &blk)
|
94
97
|
end
|
95
98
|
|
96
99
|
def Shoes.backend
|
data/lib/shoes/core/version.rb
CHANGED
data/lib/shoes/dimension.rb
CHANGED
@@ -238,11 +238,7 @@ class Shoes
|
|
238
238
|
|
239
239
|
class ParentDimension < Dimension
|
240
240
|
def absolute_start
|
241
|
-
|
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.
|
257
|
-
|
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
|
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(
|
276
|
-
|
262
|
+
def raw_extent(own_original_extent)
|
263
|
+
own_original_extent || parent.extent
|
277
264
|
end
|
278
265
|
end
|
279
266
|
end
|
data/lib/shoes/dimensions.rb
CHANGED
@@ -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
|
data/lib/shoes/download.rb
CHANGED
@@ -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
|
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.
|
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
data/lib/shoes/image_pattern.rb
CHANGED
data/lib/shoes/input_box.rb
CHANGED
@@ -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
|
data/lib/shoes/internal_app.rb
CHANGED
@@ -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
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?
|
data/lib/shoes/list_box.rb
CHANGED
@@ -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
|
data/lib/shoes/mock/check.rb
CHANGED
data/lib/shoes/mock/image.rb
CHANGED
data/lib/shoes/mock/progress.rb
CHANGED
data/lib/shoes/mock/radio.rb
CHANGED
data/lib/shoes/mock/sound.rb
CHANGED
data/lib/shoes/oval.rb
CHANGED