shoes-core 4.0.0.pre12 → 4.0.0.rc1

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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/bin/shoes-picker +1 -0
  3. data/fonts/FiraMono.otf +0 -0
  4. data/lib/shoes.rb +1 -0
  5. data/lib/shoes/animation.rb +1 -0
  6. data/lib/shoes/app.rb +4 -3
  7. data/lib/shoes/arc.rb +3 -0
  8. data/lib/shoes/arrow.rb +34 -2
  9. data/lib/shoes/background.rb +1 -0
  10. data/lib/shoes/border.rb +1 -0
  11. data/lib/shoes/builtin_methods.rb +2 -1
  12. data/lib/shoes/button.rb +1 -0
  13. data/lib/shoes/check_button.rb +1 -0
  14. data/lib/shoes/color.rb +7 -6
  15. data/lib/shoes/color/dsl.rb +1 -0
  16. data/lib/shoes/color/dsl_helpers.rb +1 -0
  17. data/lib/shoes/color/hex_converter.rb +1 -0
  18. data/lib/shoes/common/art_element.rb +5 -0
  19. data/lib/shoes/common/attachable.rb +1 -0
  20. data/lib/shoes/common/background_element.rb +5 -0
  21. data/lib/shoes/common/changeable.rb +1 -0
  22. data/lib/shoes/common/clickable.rb +1 -0
  23. data/lib/shoes/common/fill.rb +1 -0
  24. data/lib/shoes/common/focus.rb +9 -0
  25. data/lib/shoes/common/hover.rb +8 -7
  26. data/lib/shoes/common/image_handling.rb +1 -0
  27. data/lib/shoes/common/inspect.rb +1 -0
  28. data/lib/shoes/common/link_finder.rb +1 -0
  29. data/lib/shoes/common/positioning.rb +1 -0
  30. data/lib/shoes/common/registration.rb +1 -0
  31. data/lib/shoes/common/remove.rb +2 -2
  32. data/lib/shoes/common/rotate.rb +1 -0
  33. data/lib/shoes/common/safely_evaluate.rb +1 -0
  34. data/lib/shoes/common/state.rb +1 -0
  35. data/lib/shoes/common/stroke.rb +1 -0
  36. data/lib/shoes/common/style.rb +3 -1
  37. data/lib/shoes/common/style_normalizer.rb +1 -0
  38. data/lib/shoes/common/translate.rb +1 -0
  39. data/lib/shoes/common/ui_element.rb +24 -0
  40. data/lib/shoes/common/visibility.rb +21 -1
  41. data/lib/shoes/configuration.rb +1 -0
  42. data/lib/shoes/console.rb +2 -1
  43. data/lib/shoes/core.rb +1 -0
  44. data/lib/shoes/core/version.rb +1 -1
  45. data/lib/shoes/dialog.rb +2 -1
  46. data/lib/shoes/dimension.rb +17 -7
  47. data/lib/shoes/dimensions.rb +12 -1
  48. data/lib/shoes/download.rb +1 -0
  49. data/lib/shoes/dsl.rb +2 -1
  50. data/lib/shoes/dsl/animate.rb +1 -0
  51. data/lib/shoes/dsl/art.rb +51 -50
  52. data/lib/shoes/dsl/element.rb +1 -0
  53. data/lib/shoes/dsl/interaction.rb +1 -0
  54. data/lib/shoes/dsl/media.rb +4 -3
  55. data/lib/shoes/dsl/setup.rb +1 -0
  56. data/lib/shoes/dsl/style.rb +1 -0
  57. data/lib/shoes/dsl/text.rb +3 -2
  58. data/lib/shoes/file_not_found_error.rb +1 -0
  59. data/lib/shoes/font.rb +1 -0
  60. data/lib/shoes/gradient.rb +1 -0
  61. data/lib/shoes/image.rb +1 -0
  62. data/lib/shoes/image_pattern.rb +1 -0
  63. data/lib/shoes/input_box.rb +1 -0
  64. data/lib/shoes/internal_app.rb +7 -4
  65. data/lib/shoes/key_event.rb +1 -0
  66. data/lib/shoes/line.rb +19 -2
  67. data/lib/shoes/link.rb +1 -0
  68. data/lib/shoes/list_box.rb +1 -0
  69. data/lib/shoes/mock/animation.rb +1 -0
  70. data/lib/shoes/mock/app.rb +1 -0
  71. data/lib/shoes/mock/arc.rb +1 -0
  72. data/lib/shoes/mock/arrow.rb +1 -0
  73. data/lib/shoes/mock/background.rb +1 -0
  74. data/lib/shoes/mock/border.rb +1 -0
  75. data/lib/shoes/mock/button.rb +1 -0
  76. data/lib/shoes/mock/check.rb +1 -0
  77. data/lib/shoes/mock/clickable.rb +1 -0
  78. data/lib/shoes/mock/common_methods.rb +1 -0
  79. data/lib/shoes/mock/dialog.rb +1 -0
  80. data/lib/shoes/mock/download.rb +1 -0
  81. data/lib/shoes/mock/font.rb +1 -0
  82. data/lib/shoes/mock/image.rb +1 -0
  83. data/lib/shoes/mock/image_pattern.rb +1 -0
  84. data/lib/shoes/mock/input_box.rb +1 -0
  85. data/lib/shoes/mock/keypress.rb +1 -0
  86. data/lib/shoes/mock/keyrelease.rb +1 -0
  87. data/lib/shoes/mock/line.rb +1 -0
  88. data/lib/shoes/mock/link.rb +1 -0
  89. data/lib/shoes/mock/list_box.rb +1 -0
  90. data/lib/shoes/mock/oval.rb +1 -0
  91. data/lib/shoes/mock/packager.rb +1 -0
  92. data/lib/shoes/mock/progress.rb +1 -0
  93. data/lib/shoes/mock/radio.rb +1 -0
  94. data/lib/shoes/mock/rect.rb +1 -0
  95. data/lib/shoes/mock/shape.rb +1 -0
  96. data/lib/shoes/mock/slot.rb +1 -0
  97. data/lib/shoes/mock/sound.rb +1 -0
  98. data/lib/shoes/mock/star.rb +1 -0
  99. data/lib/shoes/mock/text_block.rb +1 -0
  100. data/lib/shoes/mock/timer.rb +1 -0
  101. data/lib/shoes/not_implemented_error.rb +1 -0
  102. data/lib/shoes/oval.rb +1 -0
  103. data/lib/shoes/packager.rb +1 -0
  104. data/lib/shoes/point.rb +1 -0
  105. data/lib/shoes/progress.rb +1 -0
  106. data/lib/shoes/radio.rb +1 -0
  107. data/lib/shoes/rect.rb +3 -2
  108. data/lib/shoes/renamed_delegate.rb +1 -0
  109. data/lib/shoes/shape.rb +31 -0
  110. data/lib/shoes/slot.rb +52 -14
  111. data/lib/shoes/slot_contents.rb +1 -0
  112. data/lib/shoes/sound.rb +1 -0
  113. data/lib/shoes/span.rb +1 -0
  114. data/lib/shoes/standard_logger.rb +1 -0
  115. data/lib/shoes/star.rb +29 -2
  116. data/lib/shoes/text.rb +1 -0
  117. data/lib/shoes/text_block.rb +11 -1
  118. data/lib/shoes/text_block_dimensions.rb +9 -0
  119. data/lib/shoes/timer.rb +1 -0
  120. data/lib/shoes/ui/cli.rb +1 -0
  121. data/lib/shoes/ui/cli/base_command.rb +1 -0
  122. data/lib/shoes/ui/cli/default_command.rb +1 -0
  123. data/lib/shoes/ui/cli/help_command.rb +4 -3
  124. data/lib/shoes/ui/cli/manual_command.rb +4 -3
  125. data/lib/shoes/ui/cli/package_command.rb +1 -0
  126. data/lib/shoes/ui/cli/samples_command.rb +1 -0
  127. data/lib/shoes/ui/cli/select_backend_command.rb +5 -4
  128. data/lib/shoes/ui/cli/version_command.rb +4 -3
  129. data/lib/shoes/ui/picker.rb +1 -0
  130. data/lib/shoes/url.rb +1 -0
  131. data/lib/shoes/version.rb +1 -1
  132. data/lib/shoes/widget.rb +1 -0
  133. data/lib/shoes/window.rb +1 -0
  134. data/static/shoes-icon.png +0 -0
  135. metadata +3 -2
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  class Shape < Common::ArtElement
4
5
  attr_reader :blk, :x, :y, :left_bound, :top_bound, :right_bound, :bottom_bound
@@ -6,6 +7,16 @@ class Shoes
6
7
  style_with :art_styles, :center, :common_styles, :dimensions
7
8
  STYLES = { fill: Shoes::COLORS[:black] }.freeze
8
9
 
10
+ def initialize(*args)
11
+ @bottom_bound = nil
12
+ @left_bound = nil
13
+ @right_bound = nil
14
+ @top_bound = nil
15
+ @x = nil
16
+ @y = nil
17
+ super
18
+ end
19
+
9
20
  def create_dimensions(left, top)
10
21
  left ||= @style[:left] || 0
11
22
  top ||= @style[:top] || 0
@@ -50,6 +61,26 @@ class Shoes
50
61
  false
51
62
  end
52
63
 
64
+ def redraw_left
65
+ return 0 unless @left_bound
66
+ @left_bound - strokewidth.to_i
67
+ end
68
+
69
+ def redraw_top
70
+ return 0 unless @top_bound
71
+ @top_bound - strokewidth.to_i
72
+ end
73
+
74
+ def redraw_width
75
+ return 0 unless element_width
76
+ element_width + 2 * strokewidth.to_i
77
+ end
78
+
79
+ def redraw_height
80
+ return 0 unless element_height
81
+ element_height + 2 * strokewidth.to_i
82
+ end
83
+
53
84
  # Moves the shape
54
85
  #
55
86
  # @param [Integer] left The new left value
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  class Slot < Common::UIElement
4
5
  include Common::Clickable
@@ -11,6 +12,9 @@ class Shoes
11
12
 
12
13
  attr_reader :parent, :dimensions, :gui, :contents, :blk
13
14
 
15
+ attr_reader :scroll_top
16
+ attr_accessor :scroll_height
17
+
14
18
  style_with :art_styles, :attach, :common_styles, :dimensions, :scroll
15
19
  STYLES = { scroll: false, fill: Shoes::COLORS[:black] }.freeze
16
20
 
@@ -25,16 +29,21 @@ class Shoes
25
29
 
26
30
  def before_initialize(*_)
27
31
  @contents = SlotContents.new
32
+ @last_hidden_state = nil
28
33
  end
29
34
 
30
35
  def handle_block(blk)
31
- @current_position = Position.new element_left,
32
- element_top,
33
- element_top
36
+ snapshot_current_position
37
+
34
38
  @blk = blk
35
39
  eval_block blk
36
40
  end
37
41
 
42
+ def snapshot_current_position
43
+ top = element_top - scroll_offset
44
+ @current_position = Position.new element_left, top, top
45
+ end
46
+
38
47
  def set_default_dimension_values
39
48
  self.width ||= 1.0
40
49
  self.height ||= 0
@@ -129,6 +138,9 @@ class Shoes
129
138
 
130
139
  def contents_alignment(_ = nil)
131
140
  position_contents
141
+ update_child_visibility
142
+
143
+ # Layout code expects height returned!
132
144
  determine_slot_height
133
145
  end
134
146
 
@@ -136,17 +148,22 @@ class Shoes
136
148
  @app.add_mouse_hover_control(self)
137
149
  end
138
150
 
139
- def scroll_height
140
- position_contents.y
141
- end
151
+ def scroll_top=(value)
152
+ unless scroll
153
+ Shoes.logger.warn "You've set scroll_top on a slot (#<#{self.class}:0x#{hash.to_s(16)}...>) that isn't scrollable. This will be ignored."
154
+ return
155
+ end
142
156
 
143
- def scroll_max
144
- scroll_height - height
157
+ value = 0 if value.negative?
158
+ @scroll_top = [value, scroll_max].min
145
159
  end
146
160
 
147
- attr_reader :scroll_top
161
+ def scroll_max
162
+ contents_alignment
163
+ return 0 unless scroll_height && height
148
164
 
149
- attr_writer :scroll_top
165
+ [scroll_height - height, 0].max
166
+ end
150
167
 
151
168
  def app
152
169
  @app.app # return the Shoes::App not the internal app
@@ -169,14 +186,13 @@ class Shoes
169
186
  Position = Struct.new(:x, :y, :next_line_start)
170
187
 
171
188
  def position_contents
172
- @current_position = Position.new element_left,
173
- element_top,
174
- element_top
189
+ snapshot_current_position
175
190
 
176
191
  contents.each do |element|
177
192
  next if element.hidden?
178
193
  @current_position = positioning(element, @current_position)
179
194
  end
195
+
180
196
  @current_position
181
197
  end
182
198
 
@@ -309,6 +325,7 @@ class Shoes
309
325
 
310
326
  def determine_slot_height
311
327
  content_height = compute_content_height
328
+ self.scroll_height = content_height
312
329
  self.element_height = content_height if variable_height?
313
330
  content_height
314
331
  end
@@ -321,11 +338,32 @@ class Shoes
321
338
  .max
322
339
 
323
340
  if max_bottom
324
- max_bottom - element_top + NEXT_ELEMENT_OFFSET
341
+ max_bottom - (element_top - scroll_offset) + NEXT_ELEMENT_OFFSET
325
342
  else
326
343
  0
327
344
  end
328
345
  end
346
+
347
+ def update_visibility
348
+ # Always update our backend via common implementation
349
+ super
350
+
351
+ # Only alter contents on a visibility change
352
+ if @last_hidden_state != hidden?
353
+ @last_hidden_state = hidden?
354
+ update_child_visibility
355
+ end
356
+
357
+ self
358
+ end
359
+
360
+ def update_child_visibility
361
+ contents.each(&:update_visibility)
362
+ end
363
+
364
+ def scroll_offset
365
+ scroll ? @scroll_top : 0
366
+ end
329
367
  end
330
368
 
331
369
  class Flow < Slot
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  class SlotContents < SimpleDelegator
4
5
  include Common::Inspect
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  class Sound
4
5
  include Common::Inspect
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  class Span < Text
4
5
  def initialize(texts, styles = {})
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'logger'
3
4
 
4
5
  class Shoes
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  class Star < Common::ArtElement
4
- style_with :angle, :art_styles, :common_styles, :dimensions, :inner, :outer, :points
5
- STYLES = { angle: 0, fill: Shoes::COLORS[:black] }.freeze
5
+ style_with :art_styles, :center, :common_styles, :dimensions, :inner, :outer, :points
6
+ STYLES = { fill: Shoes::COLORS[:black] }.freeze
6
7
 
7
8
  # Don't use param defaults as DSL explicit passes nil for missing params
8
9
  def create_dimensions(left, top, points, outer, inner)
@@ -35,5 +36,31 @@ class Shoes
35
36
  element_left - dx <= x && x <= element_right - dx &&
36
37
  element_top - dy <= y && y <= element_bottom - dy
37
38
  end
39
+
40
+ def redraw_left
41
+ return 0 unless element_left
42
+ if center
43
+ element_left - width * 0.5 - style[:strokewidth].to_i
44
+ else
45
+ super
46
+ end
47
+ end
48
+
49
+ def redraw_top
50
+ return 0 unless element_top
51
+ if center
52
+ element_top - width * 0.5 - style[:strokewidth].to_i
53
+ else
54
+ super
55
+ end
56
+ end
57
+
58
+ def redraw_width
59
+ element_width + style[:strokewidth].to_i * 2
60
+ end
61
+
62
+ def redraw_height
63
+ element_height + style[:strokewidth].to_i * 2
64
+ end
38
65
  end
39
66
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  class Text
4
5
  include Common::Inspect
@@ -1,8 +1,14 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  CENTER = "center"
4
5
  DEFAULT_TEXTBLOCK_FONT = "Arial"
5
6
 
7
+ FONT_ALIASES = {
8
+ "Monospace" => "Fira Mono",
9
+ "Sans Serif" => "Lucida console",
10
+ }.freeze
11
+
6
12
  class TextBlock < Common::UIElement
7
13
  include Common::Clickable
8
14
  include Common::Hover
@@ -11,7 +17,8 @@ class Shoes
11
17
  include TextBlockDimensionsDelegations
12
18
 
13
19
  attr_reader :text, :contents, :text_styles
14
- attr_accessor :cursor, :textcursor
20
+ attr_writer :textcursor
21
+ attr_accessor :cursor
15
22
 
16
23
  style_with :common_styles, :dimensions, :text_block_styles, :translate
17
24
  STYLES = { font: DEFAULT_TEXTBLOCK_FONT }.freeze # used in TextBlock specs only
@@ -133,6 +140,9 @@ class Shoes
133
140
  @style[:font] = font_family.first unless (font_family.size == 1 &&
134
141
  font_family[0] == "") || font_family.empty?
135
142
 
143
+ aliased_font = FONT_ALIASES[@style[:font]]
144
+ @style[:font] = aliased_font if aliased_font
145
+
136
146
  fsize = size_regex.match(type)
137
147
  @style[:size] = fsize[1].to_i unless fsize.nil?
138
148
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  # We take over a bunch of the absolute_* measurements since the jagged
4
5
  # shape of a flowed TextBlock doesn't follow the usual rules for dimensions
@@ -7,6 +8,14 @@ class Shoes
7
8
  attr_writer :absolute_right, :absolute_bottom,
8
9
  :calculated_width, :calculated_height
9
10
 
11
+ def initialize(*args)
12
+ @absolute_right = nil
13
+ @absolute_bottom = nil
14
+ @calculated_width = nil
15
+ @calculated_height = nil
16
+ super
17
+ end
18
+
10
19
  def absolute_right
11
20
  @absolute_right || super
12
21
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  class Timer
4
5
  include Common::Inspect
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'optparse'
3
4
  require 'shoes'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  module UI
4
5
  class CLI
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  module UI
4
5
  class CLI
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  module UI
4
5
  class CLI
@@ -22,9 +23,9 @@ class Shoes
22
23
  end
23
24
 
24
25
  def help
25
- <<-EOS
26
- shoes help
27
- Displays this help text
26
+ <<~EOS
27
+ shoes help
28
+ Displays this help text
28
29
  EOS
29
30
  end
30
31
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  module UI
4
5
  class CLI
@@ -9,9 +10,9 @@ class Shoes
9
10
  end
10
11
 
11
12
  def help
12
- <<-EOS
13
- shoes manual
14
- Run the interactive Shoes manual
13
+ <<~EOS
14
+ shoes manual
15
+ Run the interactive Shoes manual
15
16
  EOS
16
17
  end
17
18
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  module UI
4
5
  class CLI
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'fileutils'
3
4
  require 'shoes/samples'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  module UI
4
5
  class CLI
@@ -10,10 +11,10 @@ class Shoes
10
11
  end
11
12
 
12
13
  def help
13
- <<-EOS
14
- shoes select_backend [backend]
15
- Select a Shoes backend to use. A backend can be specified, or Shoes will
16
- attempt to auto-detect available backends to select from.
14
+ <<~EOS
15
+ shoes select_backend [backend]
16
+ Select a Shoes backend to use. A backend can be specified, or Shoes will
17
+ attempt to auto-detect available backends to select from.
17
18
  EOS
18
19
  end
19
20
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shoes
3
4
  module UI
4
5
  class CLI
@@ -8,9 +9,9 @@ class Shoes
8
9
  end
9
10
 
10
11
  def help
11
- <<-EOS
12
- shoes version
13
- Prints the current Shoes version
12
+ <<~EOS
13
+ shoes version
14
+ Prints the current Shoes version
14
15
  EOS
15
16
  end
16
17
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  #
3
4
  # This class is used for interactively (if necessary) picking the Shoes
4
5
  # backend that the user will run their Shoes app with.