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.
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
@@ -0,0 +1,166 @@
1
+ class Shoes
2
+ # Create all of the built-in Shoes colors
3
+ COLORS = {}
4
+
5
+ module DSL
6
+ colors = [
7
+ [:aliceblue, 240, 248, 255],
8
+ [:antiquewhite, 250, 235, 215],
9
+ [:aqua, 0, 255, 255],
10
+ [:aquamarine, 127, 255, 212],
11
+ [:azure, 240, 255, 255],
12
+ [:beige, 245, 245, 220],
13
+ [:bisque, 255, 228, 196],
14
+ [:black, 0, 0, 0],
15
+ [:blanchedalmond, 255, 235, 205],
16
+ [:blue, 0, 0, 255],
17
+ [:blueviolet, 138, 43, 226],
18
+ [:brown, 165, 42, 42],
19
+ [:burlywood, 222, 184, 135],
20
+ [:cadetblue, 95, 158, 160],
21
+ [:chartreuse, 127, 255, 0],
22
+ [:chocolate, 210, 105, 30],
23
+ [:coral, 255, 127, 80],
24
+ [:cornflowerblue, 100, 149, 237],
25
+ [:cornsilk, 255, 248, 220],
26
+ [:crimson, 220, 20, 60],
27
+ [:cyan, 0, 255, 255],
28
+ [:darkblue, 0, 0, 139],
29
+ [:darkcyan, 0, 139, 139],
30
+ [:darkgoldenrod, 184, 134, 11],
31
+ [:darkgray, 169, 169, 169],
32
+ [:darkgrey, 169, 169, 169],
33
+ [:darkgreen, 0, 100, 0],
34
+ [:darkkhaki, 189, 183, 107],
35
+ [:darkmagenta, 139, 0, 139],
36
+ [:darkolivegreen, 85, 107, 47],
37
+ [:darkorange, 255, 140, 0],
38
+ [:darkorchid, 153, 50, 204],
39
+ [:darkred, 139, 0, 0],
40
+ [:darksalmon, 233, 150, 122],
41
+ [:darkseagreen, 143, 188, 143],
42
+ [:darkslateblue, 72, 61, 139],
43
+ [:darkslategray, 47, 79, 79],
44
+ [:darkslategrey, 47, 79, 79],
45
+ [:darkturquoise, 0, 206, 209],
46
+ [:darkviolet, 148, 0, 211],
47
+ [:deeppink, 255, 20, 147],
48
+ [:deepskyblue, 0, 191, 255],
49
+ [:dimgray, 105, 105, 105],
50
+ [:dimgrey, 105, 105, 105],
51
+ [:dodgerblue, 30, 144, 255],
52
+ [:firebrick, 178, 34, 34],
53
+ [:floralwhite, 255, 250, 240],
54
+ [:forestgreen, 34, 139, 34],
55
+ [:fuchsia, 255, 0, 255],
56
+ [:gainsboro, 220, 220, 220],
57
+ [:ghostwhite, 248, 248, 255],
58
+ [:gold, 255, 215, 0],
59
+ [:goldenrod, 218, 165, 32],
60
+ [:green, 0, 128, 0],
61
+ [:greenyellow, 173, 255, 47],
62
+ [:honeydew, 240, 255, 240],
63
+ [:hotpink, 255, 105, 180],
64
+ [:indianred, 205, 92, 92],
65
+ [:indigo, 75, 0, 130],
66
+ [:ivory, 255, 255, 240],
67
+ [:khaki, 240, 230, 140],
68
+ [:lavender, 230, 230, 250],
69
+ [:lavenderblush, 255, 240, 245],
70
+ [:lawngreen, 124, 252, 0],
71
+ [:lemonchiffon, 255, 250, 205],
72
+ [:lightblue, 173, 216, 230],
73
+ [:lightcoral, 240, 128, 128],
74
+ [:lightcyan, 224, 255, 255],
75
+ [:lightgoldenrodyellow, 250, 250, 210],
76
+ [:lightgreen, 144, 238, 144],
77
+ [:lightgray, 211, 211, 211],
78
+ [:lightgrey, 211, 211, 211],
79
+ [:lightpink, 255, 182, 193],
80
+ [:lightsalmon, 255, 160, 122],
81
+ [:lightseagreen, 32, 178, 170],
82
+ [:lightskyblue, 135, 206, 250],
83
+ [:lightslategray, 119, 136, 153],
84
+ [:lightslategrey, 119, 136, 153],
85
+ [:lightsteelblue, 176, 196, 222],
86
+ [:lightyellow, 255, 255, 224],
87
+ [:lime, 0, 255, 0],
88
+ [:limegreen, 50, 205, 50],
89
+ [:linen, 250, 240, 230],
90
+ [:magenta, 255, 0, 255],
91
+ [:maroon, 128, 0, 0],
92
+ [:mediumaquamarine, 102, 205, 170],
93
+ [:mediumblue, 0, 0, 205],
94
+ [:mediumorchid, 186, 85, 211],
95
+ [:mediumpurple, 147, 112, 219],
96
+ [:mediumseagreen, 60, 179, 113],
97
+ [:mediumslateblue, 123, 104, 238],
98
+ [:mediumspringgreen, 0, 250, 154],
99
+ [:mediumturquoise, 72, 209, 204],
100
+ [:mediumvioletred, 199, 21, 133],
101
+ [:midnightblue, 25, 25, 112],
102
+ [:mintcream, 245, 255, 250],
103
+ [:mistyrose, 255, 228, 225],
104
+ [:moccasin, 255, 228, 181],
105
+ [:navajowhite, 255, 222, 173],
106
+ [:navy, 0, 0, 128],
107
+ [:oldlace, 253, 245, 230],
108
+ [:olive, 128, 128, 0],
109
+ [:olivedrab, 107, 142, 35],
110
+ [:orange, 255, 165, 0],
111
+ [:orangered, 255, 69, 0],
112
+ [:orchid, 218, 112, 214],
113
+ [:palegoldenrod, 238, 232, 170],
114
+ [:palegreen, 152, 251, 152],
115
+ [:paleturquoise, 175, 238, 238],
116
+ [:palevioletred, 219, 112, 147],
117
+ [:papayawhip, 255, 239, 213],
118
+ [:peachpuff, 255, 218, 185],
119
+ [:peru, 205, 133, 63],
120
+ [:pink, 255, 192, 203],
121
+ [:plum, 221, 160, 221],
122
+ [:powderblue, 176, 224, 230],
123
+ [:purple, 128, 0, 128],
124
+ [:red, 255, 0, 0],
125
+ [:rosybrown, 188, 143, 143],
126
+ [:royalblue, 65, 105, 225],
127
+ [:saddlebrown, 139, 69, 19],
128
+ [:salmon, 250, 128, 114],
129
+ [:sandybrown, 244, 164, 96],
130
+ [:seagreen, 46, 139, 87],
131
+ [:seashell, 255, 245, 238],
132
+ [:sienna, 160, 82, 45],
133
+ [:silver, 192, 192, 192],
134
+ [:skyblue, 135, 206, 235],
135
+ [:slateblue, 106, 90, 205],
136
+ [:slategray, 112, 128, 144],
137
+ [:slategrey, 112, 128, 144],
138
+ [:snow, 255, 250, 250],
139
+ [:springgreen, 0, 255, 127],
140
+ [:steelblue, 70, 130, 180],
141
+ [:tan, 210, 180, 140],
142
+ [:teal, 0, 128, 128],
143
+ [:thistle, 216, 191, 216],
144
+ [:tomato, 255, 99, 71],
145
+ [:turquoise, 64, 224, 208],
146
+ [:violet, 238, 130, 238],
147
+ [:wheat, 245, 222, 179],
148
+ [:white, 255, 255, 255],
149
+ [:whitesmoke, 245, 245, 245],
150
+ [:yellow, 255, 255, 0],
151
+ [:yellowgreen, 154, 205, 50],
152
+ [:system_background, 237, 237, 237], # fallback value if backend doesn't define it
153
+ ]
154
+
155
+ def self.define_shoes_color(color_name, r, g, b)
156
+ Shoes::COLORS[color_name] = Shoes::Color.new(r, g, b)
157
+ define_method(color_name) do |alpha = Shoes::Color::OPAQUE|
158
+ color = Shoes::COLORS.fetch(color_name)
159
+ return color if alpha == Shoes::Color::OPAQUE
160
+ Shoes::Color.new(color.red, color.green, color.blue, alpha)
161
+ end
162
+ end
163
+
164
+ colors.each { |color_name, r, g, b| define_shoes_color(color_name, r, g, b) }
165
+ end
166
+ end
@@ -0,0 +1,84 @@
1
+ class Shoes
2
+ class Color
3
+ module DSLHelpers
4
+ def pattern(*args)
5
+ if args.length == 1
6
+ arg = args.first
7
+ case arg
8
+ when String
9
+ image_file?(arg) ? image_pattern(arg) : color(arg)
10
+ when Shoes::Color
11
+ color arg
12
+ when Range, Shoes::Gradient
13
+ gradient(arg)
14
+ when Shoes::ImagePattern
15
+ arg
16
+ else
17
+ fail ArgumentError, "Bad pattern: #{arg.inspect}"
18
+ end
19
+ else
20
+ gradient(*args)
21
+ end
22
+ end
23
+
24
+ def color(arg)
25
+ Shoes::Color.create(arg)
26
+ end
27
+
28
+ def rgb(red, green, blue, alpha = Shoes::Color::OPAQUE)
29
+ Shoes::Color.new(red, green, blue, alpha)
30
+ end
31
+
32
+ # Creates a new Shoes::Gradient
33
+ #
34
+ # @overload gradient(from, to)
35
+ # @param [Shoes::Color] from the starting color
36
+ # @param [Shoes::Color] to the ending color
37
+ #
38
+ # @overload gradient(from, to)
39
+ # @param [String] from a hex string representing the starting color
40
+ # @param [String] to a hex string representing the ending color
41
+ #
42
+ # @overload gradient(range)
43
+ # @param [Range<Shoes::Color>] range min color to max color
44
+ #
45
+ # @overload gradient(range)
46
+ # @param [Range<String>] range min color to max color
47
+ def gradient(*args)
48
+ case args.length
49
+ when 1
50
+ arg = args[0]
51
+ case arg
52
+ when Gradient
53
+ min, max = arg.color1, arg.color2
54
+ when Range
55
+ min, max = arg.first, arg.last
56
+ else
57
+ fail ArgumentError, "Can't make gradient out of #{arg.inspect}"
58
+ end
59
+ when 2
60
+ min, max = args[0], args[1]
61
+ else
62
+ fail ArgumentError, "Wrong number of arguments (#{args.length} for 1 or 2)"
63
+ end
64
+ Shoes::Gradient.new(color(min), color(max))
65
+ end
66
+
67
+ def gray(level = 128, alpha = Shoes::Color::OPAQUE)
68
+ Shoes::Color.new(level, level, level, alpha)
69
+ end
70
+
71
+ alias_method :grey, :gray
72
+
73
+ private
74
+
75
+ def image_file?(arg)
76
+ arg =~ /\.gif|jpg|jpeg|png$/
77
+ end
78
+
79
+ def image_pattern(path)
80
+ Shoes::ImagePattern.new path if File.exist?(path)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,32 @@
1
+ class Shoes
2
+ class Color
3
+ class HexConverter
4
+ def initialize(hex)
5
+ @hex = validate(hex) || fail(ArgumentError, "Bad hex color: #{hex}")
6
+ @red, @green, @blue = hex_to_rgb(pad_if_necessary @hex)
7
+ end
8
+
9
+ def to_rgb
10
+ [@red, @green, @blue]
11
+ end
12
+
13
+ private
14
+
15
+ def hex_to_rgb(hex)
16
+ hex.chars.each_slice(2).map { |a| a.join.to_i(16) }
17
+ end
18
+
19
+ def pad_if_necessary(hex)
20
+ return hex unless hex.length == 3
21
+ hex.chars.map { |c| "#{c}#{c}" }.join
22
+ end
23
+
24
+ # Returns a 3- or 6-char hex string for valid input, or nil
25
+ # for invalid input.
26
+ def validate(hex)
27
+ match = /^#?(([0-9a-f]{3}){1,2})$/i.match(hex)
28
+ match && match[1]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -5,6 +5,11 @@ class Shoes
5
5
  @dimensions = ParentDimensions.new @parent, @style
6
6
  end
7
7
 
8
+ # We derive everything from our parent, so we skip slot positioning.
9
+ def needs_positioning?
10
+ false
11
+ end
12
+
8
13
  def takes_up_space?
9
14
  false
10
15
  end
@@ -0,0 +1,87 @@
1
+ class Shoes
2
+ module Common
3
+ module Hover
4
+ attr_reader :hover_blk, :leave_blk
5
+
6
+ def self.included(base)
7
+ clazz = Class.new {}
8
+ name = base.name.split("::").last
9
+ Shoes.const_set("#{name}Hover", clazz)
10
+ end
11
+
12
+ def hover(&blk)
13
+ @hover_blk = blk
14
+ add_mouse_hover_control
15
+ end
16
+
17
+ def leave(&blk)
18
+ @leave_blk = blk
19
+ add_mouse_hover_control
20
+ end
21
+
22
+ def hovered?
23
+ @hovered
24
+ end
25
+
26
+ def eval_in_parent?
27
+ false
28
+ end
29
+
30
+ def hover_class
31
+ return @hover_class if @hover_class
32
+
33
+ name = self.class.name.split("::").last
34
+ @hover_class = Shoes.const_get("#{name}Hover")
35
+ end
36
+
37
+ def mouse_hovered
38
+ return if @hovered
39
+
40
+ @hovered = true
41
+
42
+ apply_style_from_hover_class
43
+ target.eval_hover_block(@hover_blk)
44
+ end
45
+
46
+ def mouse_left
47
+ return unless @hovered
48
+
49
+ @hovered = false
50
+
51
+ apply_style_from_pre_hover
52
+ target.eval_hover_block(@leave_blk)
53
+ end
54
+
55
+ def add_mouse_hover_control
56
+ app.add_mouse_hover_control(self)
57
+ end
58
+
59
+ def target
60
+ target = self
61
+ target = parent if eval_in_parent?
62
+ target
63
+ end
64
+
65
+ def eval_hover_block(blk)
66
+ blk.call(self) if blk
67
+ end
68
+
69
+ def apply_style_from_hover_class
70
+ hover_style = @app.element_styles[self.hover_class]
71
+ return unless hover_style
72
+
73
+ @pre_hover_style = hover_style.inject({}) do |memo, (key, _)|
74
+ memo[key] = self.style[key]
75
+ memo
76
+ end
77
+
78
+ self.style(hover_style)
79
+ end
80
+
81
+ def apply_style_from_pre_hover
82
+ self.style(@pre_hover_style) if @pre_hover_style
83
+ @pre_hover_style = nil
84
+ end
85
+ end
86
+ end
87
+ end
@@ -16,8 +16,8 @@ class Shoes
16
16
  create_dimensions(*args)
17
17
  update_dimensions if styles_with_dimensions?
18
18
 
19
- @parent.add_child self
20
- @gui = Shoes.backend_for self
19
+ create_backend
20
+ add_to_parent(*args)
21
21
 
22
22
  handle_block(blk)
23
23
  update_visibility
@@ -25,12 +25,6 @@ class Shoes
25
25
  after_initialize(*args)
26
26
  end
27
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
28
 
35
29
  # This method will get called with the incoming styles hash and the
36
30
  # other arguments passed to initialize.
@@ -40,6 +34,25 @@ class Shoes
40
34
  def before_initialize(_styles, *_)
41
35
  end
42
36
 
37
+ # Set the dimensions for the element. Defaults to using the Dimensions
38
+ # class, but is expected to be overridden in other types (art elements,
39
+ # text blocks) that require different dimensioning.
40
+ def create_dimensions(*_)
41
+ @dimensions = Dimensions.new @parent, @style
42
+ end
43
+
44
+ # Call to create the backend (aka @gui)
45
+ def create_backend
46
+ @gui = Shoes.backend_for self
47
+ end
48
+
49
+ # Calls to add child in parent, after the backend has been created.
50
+ # Can be overridden for operations that must happen after backend, but
51
+ # before addition to parent (and hence positioning)
52
+ def add_to_parent(*_)
53
+ @parent.add_child self
54
+ end
55
+
43
56
  # This method handles the block passed in at creation of the DSL element.
44
57
  # By default it will treat things as clickable, and assumes the
45
58
  # necessary methods are there.
@@ -4,6 +4,8 @@ class Shoes
4
4
  def remove
5
5
  parent.remove_child self if parent
6
6
  gui.remove if gui && gui.respond_to?(:remove)
7
+
8
+ @app.remove_mouse_hover_control(self) if @app
7
9
  end
8
10
  end
9
11
  end
@@ -1,16 +1,30 @@
1
1
  class Shoes
2
2
  module Common
3
3
  module State
4
- attr_reader :state
4
+ DISABLED_STATE = "disabled"
5
+
6
+ def after_initialize(*_)
7
+ super
8
+ update_enabled
9
+ end
5
10
 
6
11
  def state=(value)
7
- @state = value
8
- @gui.enabled value.nil?
12
+ style(state: value)
13
+ update_enabled
9
14
  end
10
15
 
11
16
  def state_options(opts)
12
17
  self.state = opts[:state]
13
18
  end
19
+
20
+ private
21
+ def enabled?
22
+ !(state.to_s == DISABLED_STATE)
23
+ end
24
+
25
+ def update_enabled
26
+ @gui.enabled(enabled?)
27
+ end
14
28
  end
15
29
  end
16
30
  end