shoes-core 4.0.0.pre3 → 4.0.0.pre4
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84a2c73e863ae6a5e1d2c53484822830719a8e3e
|
4
|
+
data.tar.gz: e26555a20033558b5618a6be1821ce73ec0dbf1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 775fbfd5702df09c69a035c02502f1c8db234eef54aaa7f9e72fe46f6fac2af59c698e7d40f86bf9d61ec6dfbc6fd49b2d14fb643a8a473f86fb598aeeb227f0
|
7
|
+
data.tar.gz: b4568bcb40bcc3e4c3e67b63d90b9d70f85905aba5ed0450add252ee22da124b6c4d64e847f81245636ac8d2c5de4a70b5c28fb0c93cd35f43b89ad2f41b61d9
|
data/bin/shoes
CHANGED
data/bin/shoes-picker
CHANGED
@@ -3,4 +3,8 @@ lib_directory = File.expand_path('../../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH << lib_directory
|
4
4
|
|
5
5
|
require 'shoes/ui/picker'
|
6
|
-
|
6
|
+
|
7
|
+
# On Windows getting odd paths with trailing double-quote
|
8
|
+
bin_dir = ARGV[0].gsub('"', '')
|
9
|
+
|
10
|
+
Shoes::UI::Picker.new.run(bin_dir)
|
data/bin/shoes-stub
CHANGED
data/ext/install/shoes.bat
CHANGED
data/lib/rubygems_plugin.rb
CHANGED
@@ -4,7 +4,7 @@ require 'fileutils'
|
|
4
4
|
# See ext/install/Rakefile for why this cleanup is our responsibility.
|
5
5
|
# Decide if user uninstalled executables based on our actual Ruby script.
|
6
6
|
Gem.post_uninstall do |gem|
|
7
|
-
uninstalling_shoes = gem.spec.name == "shoes"
|
7
|
+
uninstalling_shoes = gem.spec.name == "shoes-core"
|
8
8
|
missing_executable = !File.exist?(File.join(Gem.bindir, "shoes-picker")) &&
|
9
9
|
!File.exist?(File.join(Gem.bindir, "shoes-picker.bat"))
|
10
10
|
|
@@ -19,6 +19,6 @@ Gem.post_uninstall do |gem|
|
|
19
19
|
# Everybody potentially has a generated backend file in their bin
|
20
20
|
puts "Removing shoes-backend"
|
21
21
|
backend = File.join(Gem.bindir, "shoes-backend")
|
22
|
-
FileUtils.rm(backend) if File.
|
22
|
+
FileUtils.rm(backend) if File.exist?(backend)
|
23
23
|
end
|
24
24
|
end
|
data/lib/shoes/app.rb
CHANGED
@@ -29,6 +29,7 @@ class Shoes
|
|
29
29
|
include DSL
|
30
30
|
include BuiltinMethods
|
31
31
|
include Common::Inspect
|
32
|
+
extend Forwardable
|
32
33
|
|
33
34
|
# Instantiates a new Shoes app.
|
34
35
|
#
|
@@ -60,38 +61,26 @@ class Shoes
|
|
60
61
|
self.class.new(options, &block)
|
61
62
|
end
|
62
63
|
|
63
|
-
def close
|
64
|
-
quit
|
65
|
-
end
|
66
|
-
|
67
64
|
def quit
|
68
65
|
Shoes.unregister self
|
69
66
|
@__app__.quit
|
70
67
|
end
|
71
68
|
|
69
|
+
alias_method :close, :quit
|
70
|
+
|
72
71
|
def parent
|
73
72
|
@__app__.current_slot.parent
|
74
73
|
end
|
75
74
|
|
76
|
-
%w(
|
75
|
+
delegated_to_internal_app = %w(
|
77
76
|
width height owner started? location left top absolute_left
|
78
77
|
absolute_top click release clear fullscreen fullscreen=
|
79
|
-
contents wait_until_closed
|
80
|
-
)
|
81
|
-
define_method method do |*args, &block|
|
82
|
-
@__app__.public_send method, *args, &block
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
alias_method :fullscreen?, :fullscreen
|
78
|
+
contents wait_until_closed gui
|
79
|
+
)
|
87
80
|
|
88
|
-
|
89
|
-
super.insert(-2, " \"#{@__app__.app_title}\"")
|
90
|
-
end
|
81
|
+
def_delegators :@__app__, *delegated_to_internal_app
|
91
82
|
|
92
|
-
|
93
|
-
super.insert(-2, " \"#{@__app__.app_title}\")")
|
94
|
-
end
|
83
|
+
alias_method :fullscreen?, :fullscreen
|
95
84
|
|
96
85
|
def eval_with_additional_context(context, &blk)
|
97
86
|
@__additional_context__ = context
|
@@ -108,6 +97,16 @@ class Shoes
|
|
108
97
|
end
|
109
98
|
end
|
110
99
|
|
100
|
+
private
|
101
|
+
|
102
|
+
def inspect_details
|
103
|
+
" \"#{@__app__.app_title}\""
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_s_details
|
107
|
+
inspect_details
|
108
|
+
end
|
109
|
+
|
111
110
|
DELEGATE_BLACKLIST = [:parent, :app]
|
112
111
|
|
113
112
|
# class definitions are evaluated top to bottom, want to have all of them
|
data/lib/shoes/arc.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
class Shoes
|
2
2
|
class Arc
|
3
3
|
include Common::UIElement
|
4
|
+
include Common::Fill
|
5
|
+
include Common::Stroke
|
4
6
|
include Common::Style
|
5
7
|
include Common::Clickable
|
6
8
|
|
7
|
-
attr_reader :app, :parent, :dimensions, :gui
|
8
9
|
style_with :angle1, :angle2, :art_styles, :center, :common_styles, :dimensions, :radius, :wedge
|
9
10
|
STYLES = { wedge: false }
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def before_initialize(styles, left, top, width, height, angle1, angle2)
|
13
|
+
styles[:angle1] = angle1
|
14
|
+
styles[:angle2] = angle2
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_dimensions(left, top, width, height, angle1, angle2)
|
15
18
|
@dimensions = Dimensions.new parent, left, top, width, height, @style
|
16
|
-
@parent.add_child self
|
17
|
-
@gui = Shoes.backend_for self
|
18
|
-
register_click blk
|
19
19
|
end
|
20
20
|
|
21
21
|
def wedge?
|
data/lib/shoes/background.rb
CHANGED
@@ -2,19 +2,15 @@ class Shoes
|
|
2
2
|
class Background
|
3
3
|
include Common::UIElement
|
4
4
|
include Common::BackgroundElement
|
5
|
+
include Common::Fill
|
6
|
+
include Common::Stroke
|
5
7
|
include Common::Style
|
6
8
|
|
7
|
-
attr_reader :app, :parent, :dimensions, :gui
|
8
9
|
style_with :angle, :common_styles, :curve, :dimensions, :fill
|
9
10
|
STYLES = { angle: 0, curve: 0 }
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
@parent = parent
|
14
|
-
style_init styles, fill: color
|
15
|
-
@dimensions = ParentDimensions.new parent, @style
|
16
|
-
@parent.add_child self
|
17
|
-
@gui = Shoes.backend_for self
|
12
|
+
def before_initialize(styles, color)
|
13
|
+
styles[:fill] = color
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
data/lib/shoes/border.rb
CHANGED
@@ -2,19 +2,15 @@ class Shoes
|
|
2
2
|
class Border
|
3
3
|
include Common::UIElement
|
4
4
|
include Common::BackgroundElement
|
5
|
+
include Common::Fill
|
6
|
+
include Common::Stroke
|
5
7
|
include Common::Style
|
6
8
|
|
7
|
-
attr_reader :app, :parent, :dimensions, :gui
|
8
9
|
style_with :angle, :common_styles, :curve, :dimensions, :stroke, :strokewidth
|
9
10
|
STYLES = { angle: 0, curve: 0 }
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
@parent = parent
|
14
|
-
style_init styles, stroke: color
|
15
|
-
@dimensions = ParentDimensions.new parent, @style
|
16
|
-
@parent.add_child self
|
17
|
-
@gui = Shoes.backend_for self
|
12
|
+
def before_initialize(styles, color)
|
13
|
+
styles[:stroke] = color
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
@@ -44,7 +44,7 @@ class Shoes
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def ask_save_file
|
47
|
-
Shoes::Dialog.new.dialog_chooser 'Save File...'
|
47
|
+
Shoes::Dialog.new.dialog_chooser 'Save File...', false, :save
|
48
48
|
end
|
49
49
|
|
50
50
|
def ask_open_folder
|
@@ -52,7 +52,7 @@ class Shoes
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def ask_save_folder
|
55
|
-
Shoes::Dialog.new.dialog_chooser 'Save Folder...', :folder
|
55
|
+
Shoes::Dialog.new.dialog_chooser 'Save Folder...', :folder, :save
|
56
56
|
end
|
57
57
|
|
58
58
|
def ask(msg, args = {})
|
data/lib/shoes/button.rb
CHANGED
@@ -4,17 +4,10 @@ class Shoes
|
|
4
4
|
include Common::Style
|
5
5
|
include Common::Clickable
|
6
6
|
|
7
|
-
attr_reader :app, :parent, :dimensions, :gui
|
8
7
|
style_with :click, :common_styles, :dimensions, :state, :text
|
9
8
|
|
10
|
-
def
|
11
|
-
|
12
|
-
@parent = parent
|
13
|
-
style_init styles, text: text
|
14
|
-
@dimensions = Dimensions.new parent, @style
|
15
|
-
@parent.add_child self
|
16
|
-
@gui = Shoes.configuration.backend_for self, @parent.gui
|
17
|
-
register_click blk
|
9
|
+
def before_initialize(styles, text)
|
10
|
+
styles[:text] = text || 'Button'
|
18
11
|
end
|
19
12
|
|
20
13
|
def focus
|
data/lib/shoes/check_button.rb
CHANGED
@@ -4,18 +4,6 @@ class Shoes
|
|
4
4
|
include Common::Style
|
5
5
|
include Common::Clickable
|
6
6
|
|
7
|
-
attr_reader :app, :parent, :dimensions, :gui
|
8
|
-
|
9
|
-
def initialize(app, parent, styles = {}, blk = nil)
|
10
|
-
@app = app
|
11
|
-
@parent = parent
|
12
|
-
style_init styles
|
13
|
-
@dimensions = Dimensions.new parent, @style
|
14
|
-
@parent.add_child self
|
15
|
-
@gui = Shoes.configuration.backend_for self, @parent.gui
|
16
|
-
register_click blk
|
17
|
-
end
|
18
|
-
|
19
7
|
def checked?
|
20
8
|
@gui.checked?
|
21
9
|
end
|
data/lib/shoes/color.rb
CHANGED
@@ -60,7 +60,6 @@ EOS
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def <=>(other)
|
63
|
-
raise_class_mismatch_error(other) unless other.is_a?(self.class)
|
64
63
|
if same_base_color?(other)
|
65
64
|
@alpha <=> other.alpha
|
66
65
|
else
|
@@ -79,12 +78,12 @@ EOS
|
|
79
78
|
"rgb(#{red}, #{green}, #{blue})"
|
80
79
|
end
|
81
80
|
|
82
|
-
def inspect
|
83
|
-
super.insert(-2, " #{self} alpha:#{@alpha}")
|
84
|
-
end
|
85
|
-
|
86
81
|
private
|
87
82
|
|
83
|
+
def inspect_details
|
84
|
+
" #{self} alpha:#{@alpha}"
|
85
|
+
end
|
86
|
+
|
88
87
|
def normalize_rgb(value)
|
89
88
|
rgb = value.is_a?(Fixnum) ? value : (255 * value).round
|
90
89
|
return 255 if rgb > 255
|
@@ -92,17 +91,12 @@ EOS
|
|
92
91
|
rgb
|
93
92
|
end
|
94
93
|
|
95
|
-
def raise_class_mismatch_error(other)
|
96
|
-
fail ArgumentError,
|
97
|
-
"can't compare #{self.class.name} with #{other.class.name}"
|
98
|
-
end
|
99
|
-
|
100
94
|
def same_base_color?(other)
|
101
95
|
@red == other.red && @green == other.green && @blue == other.blue
|
102
96
|
end
|
103
97
|
|
104
98
|
def less_or_greater_than(other)
|
105
|
-
own_sum
|
99
|
+
own_sum = @red + @green + @blue
|
106
100
|
other_sum = other.red + other.green + other.blue
|
107
101
|
if own_sum > other_sum
|
108
102
|
1
|
@@ -111,6 +105,7 @@ EOS
|
|
111
105
|
end
|
112
106
|
end
|
113
107
|
|
108
|
+
|
114
109
|
class HexConverter
|
115
110
|
def initialize(hex)
|
116
111
|
@hex = validate(hex) || fail(ArgumentError, "Bad hex color: #{hex}")
|
@@ -145,16 +140,16 @@ EOS
|
|
145
140
|
if args.length == 1
|
146
141
|
arg = args.first
|
147
142
|
case arg
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
143
|
+
when String
|
144
|
+
image_file?(arg) ? image_pattern(arg) : color(arg)
|
145
|
+
when Shoes::Color
|
146
|
+
color arg
|
147
|
+
when Range, Shoes::Gradient
|
148
|
+
gradient(arg)
|
149
|
+
when Shoes::ImagePattern
|
150
|
+
arg
|
151
|
+
else
|
152
|
+
fail ArgumentError, "Bad pattern: #{arg.inspect}"
|
158
153
|
end
|
159
154
|
else
|
160
155
|
gradient(*args)
|
@@ -186,20 +181,20 @@ EOS
|
|
186
181
|
# @param [Range<String>] range min color to max color
|
187
182
|
def gradient(*args)
|
188
183
|
case args.length
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
else
|
197
|
-
fail ArgumentError, "Can't make gradient out of #{arg.inspect}"
|
198
|
-
end
|
199
|
-
when 2
|
200
|
-
min, max = args[0], args[1]
|
184
|
+
when 1
|
185
|
+
arg = args[0]
|
186
|
+
case arg
|
187
|
+
when Gradient
|
188
|
+
min, max = arg.color1, arg.color2
|
189
|
+
when Range
|
190
|
+
min, max = arg.first, arg.last
|
201
191
|
else
|
202
|
-
fail ArgumentError, "
|
192
|
+
fail ArgumentError, "Can't make gradient out of #{arg.inspect}"
|
193
|
+
end
|
194
|
+
when 2
|
195
|
+
min, max = args[0], args[1]
|
196
|
+
else
|
197
|
+
fail ArgumentError, "Wrong number of arguments (#{args.length} for 1 or 2)"
|
203
198
|
end
|
204
199
|
Shoes::Gradient.new(color(min), color(max))
|
205
200
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Shoes
|
2
|
+
module Common
|
3
|
+
module Initialization
|
4
|
+
attr_reader :app, :parent, :dimensions, :gui
|
5
|
+
|
6
|
+
def initialize(app, parent, *args)
|
7
|
+
blk = args.pop if args.last.is_a?(Proc) || args.last.nil?
|
8
|
+
styles = args.last.is_a?(Hash) ? args.pop : {}
|
9
|
+
|
10
|
+
before_initialize(styles, *args)
|
11
|
+
|
12
|
+
@app = app
|
13
|
+
@parent = parent
|
14
|
+
|
15
|
+
style_init(styles)
|
16
|
+
create_dimensions(*args)
|
17
|
+
update_dimensions if styles_with_dimensions?
|
18
|
+
|
19
|
+
@parent.add_child self
|
20
|
+
@gui = Shoes.backend_for self
|
21
|
+
|
22
|
+
handle_block(blk)
|
23
|
+
update_visibility
|
24
|
+
|
25
|
+
after_initialize(*args)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Set the dimensions for the element. Defaults to using the Dimensions
|
29
|
+
# class, but is expected to be overridden in other types (art elements,
|
30
|
+
# text blocks) that require different dimensioning.
|
31
|
+
def create_dimensions(*_)
|
32
|
+
@dimensions = Dimensions.new @parent, @style
|
33
|
+
end
|
34
|
+
|
35
|
+
# This method will get called with the incoming styles hash and the
|
36
|
+
# other arguments passed to initialize.
|
37
|
+
#
|
38
|
+
# It is intended for performing any additions to the styles hash before
|
39
|
+
# that gets sent on to style_init.
|
40
|
+
def before_initialize(_styles, *_)
|
41
|
+
end
|
42
|
+
|
43
|
+
# This method handles the block passed in at creation of the DSL element.
|
44
|
+
# By default it will treat things as clickable, and assumes the
|
45
|
+
# necessary methods are there.
|
46
|
+
#
|
47
|
+
# Override if DSL element uses that block for something else (i.e. slot)
|
48
|
+
def handle_block(blk)
|
49
|
+
return unless blk
|
50
|
+
register_click blk
|
51
|
+
end
|
52
|
+
|
53
|
+
# Final method called in initialize. Intended for any final setup after
|
54
|
+
# the rest of the object has been set up fully.
|
55
|
+
def after_initialize(*_)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/shoes/common/inspect.rb
CHANGED
@@ -2,12 +2,30 @@ class Shoes
|
|
2
2
|
module Common
|
3
3
|
module Inspect
|
4
4
|
def to_s
|
5
|
-
"(#{self.class.name})"
|
5
|
+
"(#{self.class.name}#{to_s_details})"
|
6
6
|
end
|
7
7
|
|
8
8
|
# Object hex representation from https://github.com/michaeldv/awesome_print
|
9
|
+
# Example:
|
10
|
+
# (Shoes::App:0x01234abc "Hello")
|
9
11
|
def inspect
|
10
|
-
"(#{self.class.name}:#{
|
12
|
+
"(#{self.class.name}:#{hexy_object_id}#{inspect_details})"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# Additional details to include in the inspect representation.
|
18
|
+
def inspect_details
|
19
|
+
''
|
20
|
+
end
|
21
|
+
|
22
|
+
# Additional details to include in the to_s representation.
|
23
|
+
def to_s_details
|
24
|
+
''
|
25
|
+
end
|
26
|
+
|
27
|
+
def hexy_object_id
|
28
|
+
sprintf('0x%08x', object_id * 2)
|
11
29
|
end
|
12
30
|
end
|
13
31
|
end
|
data/lib/shoes/common/style.rb
CHANGED
@@ -8,7 +8,6 @@ class Shoes
|
|
8
8
|
module Common
|
9
9
|
module Style
|
10
10
|
DEFAULT_STYLES = {
|
11
|
-
fill: Shoes::COLORS[:black],
|
12
11
|
rotate: 0,
|
13
12
|
stroke: Shoes::COLORS[:black],
|
14
13
|
strokewidth: 1
|
@@ -29,17 +28,15 @@ class Shoes
|
|
29
28
|
# Adds styles, or just returns current style if no argument
|
30
29
|
def style(new_styles = nil)
|
31
30
|
update_style(new_styles) if need_to_update_style?(new_styles)
|
32
|
-
update_dimensions if styles_with_dimensions?
|
33
31
|
@style
|
34
32
|
end
|
35
33
|
|
36
34
|
def style_init(arg_styles, new_styles = {})
|
37
35
|
default_element_styles = {}
|
38
|
-
default_element_styles = self.class::STYLES if defined?
|
39
|
-
|
36
|
+
default_element_styles = self.class::STYLES if defined?(self.class::STYLES)
|
40
37
|
create_style_hash
|
41
|
-
merge_app_styles
|
42
38
|
@style.merge!(default_element_styles)
|
39
|
+
merge_app_styles
|
43
40
|
@style.merge!(@app.element_styles[self.class]) if @app.element_styles[self.class]
|
44
41
|
@style.merge!(new_styles)
|
45
42
|
@style.merge!(arg_styles)
|
@@ -109,7 +106,8 @@ class Shoes
|
|
109
106
|
end
|
110
107
|
|
111
108
|
private
|
112
|
-
|
109
|
+
|
110
|
+
def support_style(group_style)
|
113
111
|
@supported_styles << group_style
|
114
112
|
end
|
115
113
|
end # end of StyleWith module
|
@@ -123,6 +121,8 @@ class Shoes
|
|
123
121
|
def update_style(new_styles)
|
124
122
|
normalized_style = StyleNormalizer.new.normalize(new_styles)
|
125
123
|
set_dimensions(new_styles)
|
124
|
+
set_visibility(new_styles)
|
125
|
+
set_coloring(new_styles)
|
126
126
|
click(&new_styles[:click]) if new_styles.key?(:click)
|
127
127
|
@style.merge! normalized_style
|
128
128
|
end
|
@@ -134,9 +134,23 @@ class Shoes
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
def set_visibility(new_styles)
|
138
|
+
return unless new_styles.include?(:hidden)
|
139
|
+
@style[:hidden] = new_styles[:hidden]
|
140
|
+
update_visibility
|
141
|
+
end
|
142
|
+
|
143
|
+
def set_coloring(new_styles)
|
144
|
+
update_fill if new_styles.include?(:fill)
|
145
|
+
update_stroke if new_styles.include?(:stroke)
|
146
|
+
end
|
147
|
+
|
137
148
|
def update_dimensions # so that @style hash matches actual values
|
138
149
|
STYLE_GROUPS[:dimensions].each do |style|
|
139
|
-
|
150
|
+
if self.respond_to?(style)
|
151
|
+
value = send(style)
|
152
|
+
@style[style] = value if value
|
153
|
+
end
|
140
154
|
end
|
141
155
|
end
|
142
156
|
|
@@ -5,9 +5,7 @@ class Shoes
|
|
5
5
|
def normalize(orig_style)
|
6
6
|
normalized_style = {}
|
7
7
|
[:fill, :stroke].each do |s|
|
8
|
-
if orig_style[s]
|
9
|
-
normalized_style[s] = pattern(orig_style[s])
|
10
|
-
end
|
8
|
+
normalized_style[s] = pattern(orig_style[s]) if orig_style[s]
|
11
9
|
end
|
12
10
|
orig_style.merge(normalized_style)
|
13
11
|
end
|
@@ -1,11 +1,21 @@
|
|
1
1
|
class Shoes
|
2
2
|
module Common
|
3
3
|
module UIElement
|
4
|
+
include Common::Initialization
|
4
5
|
include Common::Inspect
|
5
6
|
include Common::Visibility
|
6
7
|
include Common::Positioning
|
7
8
|
include Common::Remove
|
9
|
+
include Common::Rotate
|
8
10
|
include DimensionsDelegations
|
11
|
+
|
12
|
+
# Expected to be overridden by pulling in Common::Fill or Common::Stroke
|
13
|
+
# if element needs to actually notify GUI classes of colors changes.
|
14
|
+
def update_fill
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_stroke
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
11
21
|
end
|
@@ -3,12 +3,12 @@ class Shoes
|
|
3
3
|
module Visibility
|
4
4
|
# Hides the element, so that it can't be seen. See also #show and #toggle.
|
5
5
|
def hide
|
6
|
-
|
6
|
+
style[:hidden] = true
|
7
7
|
update_visibility
|
8
8
|
end
|
9
9
|
|
10
10
|
def hidden?
|
11
|
-
|
11
|
+
style[:hidden]
|
12
12
|
end
|
13
13
|
|
14
14
|
alias_method :hidden, :hidden?
|
@@ -19,14 +19,14 @@ class Shoes
|
|
19
19
|
|
20
20
|
# Reveals the element, if it is hidden. See also #hide and #toggle.
|
21
21
|
def show
|
22
|
-
|
22
|
+
style[:hidden] = false
|
23
23
|
update_visibility
|
24
24
|
end
|
25
25
|
|
26
26
|
# Hides an element if it is shown. Or shows the element, if it is hidden.
|
27
27
|
# See also #hide and #show.
|
28
28
|
def toggle
|
29
|
-
|
29
|
+
style[:hidden] = !style[:hidden]
|
30
30
|
update_visibility
|
31
31
|
end
|
32
32
|
|
data/lib/shoes/configuration.rb
CHANGED
@@ -43,8 +43,10 @@ class Shoes
|
|
43
43
|
# Shoes.configuration.backend_class(shoes_button) # => Shoes::Swt::Button
|
44
44
|
def backend_class(shoes_object)
|
45
45
|
class_name = shoes_object.class.name.split("::").last
|
46
|
-
|
47
|
-
|
46
|
+
# Lookup with false to not consult modules higher in the chain Object
|
47
|
+
# 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)
|
49
|
+
backend.const_get(class_name, false)
|
48
50
|
end
|
49
51
|
|
50
52
|
# Creates an appropriate backend object, passing along additional arguments
|