lacci 0.2.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +8 -1
  4. data/lib/lacci/scarpe_cli.rb +2 -2
  5. data/lib/lacci/scarpe_core.rb +2 -1
  6. data/lib/lacci/version.rb +1 -1
  7. data/lib/scarpe/niente/app.rb +23 -0
  8. data/lib/scarpe/niente/display_service.rb +66 -0
  9. data/lib/scarpe/niente/drawable.rb +59 -0
  10. data/lib/scarpe/niente/shoes_spec.rb +93 -0
  11. data/lib/scarpe/niente.rb +32 -0
  12. data/lib/shoes/app.rb +111 -72
  13. data/lib/shoes/background.rb +2 -2
  14. data/lib/shoes/border.rb +2 -2
  15. data/lib/shoes/builtins.rb +63 -0
  16. data/lib/shoes/changelog.rb +52 -0
  17. data/lib/shoes/colors.rb +3 -1
  18. data/lib/shoes/constants.rb +41 -2
  19. data/lib/shoes/display_service.rb +80 -18
  20. data/lib/shoes/download.rb +2 -2
  21. data/lib/shoes/drawable.rb +654 -0
  22. data/lib/shoes/drawables/arc.rb +27 -0
  23. data/lib/shoes/drawables/arrow.rb +21 -0
  24. data/lib/shoes/drawables/border.rb +28 -0
  25. data/lib/shoes/drawables/button.rb +57 -0
  26. data/lib/shoes/drawables/check.rb +33 -0
  27. data/lib/shoes/drawables/document_root.rb +20 -0
  28. data/lib/shoes/{widgets → drawables}/edit_box.rb +9 -8
  29. data/lib/shoes/{widgets → drawables}/edit_line.rb +8 -7
  30. data/lib/shoes/drawables/flow.rb +20 -0
  31. data/lib/shoes/drawables/font_helper.rb +62 -0
  32. data/lib/shoes/{widgets → drawables}/image.rb +7 -7
  33. data/lib/shoes/drawables/line.rb +17 -0
  34. data/lib/shoes/drawables/link.rb +31 -0
  35. data/lib/shoes/drawables/list_box.rb +59 -0
  36. data/lib/shoes/drawables/oval.rb +48 -0
  37. data/lib/shoes/drawables/para.rb +206 -0
  38. data/lib/shoes/drawables/progress.rb +15 -0
  39. data/lib/shoes/drawables/radio.rb +35 -0
  40. data/lib/shoes/drawables/rect.rb +18 -0
  41. data/lib/shoes/{widgets → drawables}/shape.rb +8 -8
  42. data/lib/shoes/drawables/slot.rb +178 -0
  43. data/lib/shoes/drawables/stack.rb +21 -0
  44. data/lib/shoes/drawables/star.rb +28 -0
  45. data/lib/shoes/drawables/subscription_item.rb +93 -0
  46. data/lib/shoes/drawables/text_drawable.rb +122 -0
  47. data/lib/shoes/drawables/video.rb +17 -0
  48. data/lib/shoes/drawables/widget.rb +74 -0
  49. data/lib/shoes/drawables.rb +32 -0
  50. data/lib/shoes/errors.rb +38 -0
  51. data/lib/shoes/log.rb +2 -2
  52. data/lib/shoes/margin_helper.rb +79 -0
  53. data/lib/shoes/ruby_extensions.rb +15 -0
  54. data/lib/shoes-spec.rb +93 -0
  55. data/lib/shoes.rb +31 -10
  56. metadata +58 -31
  57. data/lib/shoes/spacing.rb +0 -9
  58. data/lib/shoes/widget.rb +0 -218
  59. data/lib/shoes/widgets/alert.rb +0 -19
  60. data/lib/shoes/widgets/arc.rb +0 -51
  61. data/lib/shoes/widgets/button.rb +0 -35
  62. data/lib/shoes/widgets/check.rb +0 -28
  63. data/lib/shoes/widgets/document_root.rb +0 -20
  64. data/lib/shoes/widgets/flow.rb +0 -22
  65. data/lib/shoes/widgets/font.rb +0 -14
  66. data/lib/shoes/widgets/line.rb +0 -18
  67. data/lib/shoes/widgets/link.rb +0 -25
  68. data/lib/shoes/widgets/list_box.rb +0 -25
  69. data/lib/shoes/widgets/para.rb +0 -68
  70. data/lib/shoes/widgets/radio.rb +0 -35
  71. data/lib/shoes/widgets/slot.rb +0 -75
  72. data/lib/shoes/widgets/span.rb +0 -26
  73. data/lib/shoes/widgets/stack.rb +0 -24
  74. data/lib/shoes/widgets/star.rb +0 -44
  75. data/lib/shoes/widgets/subscription_item.rb +0 -60
  76. data/lib/shoes/widgets/text_widget.rb +0 -51
  77. data/lib/shoes/widgets/video.rb +0 -15
  78. data/lib/shoes/widgets.rb +0 -29
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Shoes
3
+ class Shoes
4
4
  module Background
5
5
  def self.included(includer)
6
- includer.display_property(:background_color)
6
+ includer.shoes_style(:background_color)
7
7
  end
8
8
 
9
9
  # NOTE: this needs to be passed through in order for the styling to work
data/lib/shoes/border.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Shoes
3
+ class Shoes
4
4
  module Border
5
5
  def self.included(includer)
6
- includer.display_properties :border_color, :options
6
+ includer.shoes_styles :border_color, :options
7
7
  end
8
8
 
9
9
  # Considering a signature like this:
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Shoes has a number of built-in methods that are intended to be available everywhere,
4
+ # in every Shoes and non-Shoes class, for every Shoes app.
5
+ module Shoes::Builtins
6
+ # Register the given font with Shoes so that text that wants it can use it.
7
+ # Also add it to the FONTS constant.
8
+ #
9
+ # @param font_file_or_url [String] the filename or URL for the font
10
+ # @return [void]
11
+ def font(font_file_or_url)
12
+ shoes_builtin("font", font_file_or_url)
13
+
14
+ font_name = File.basename(font_file_or_url, ".*")
15
+ Shoes::FONTS << font_name
16
+ end
17
+
18
+ def ask(message_string)
19
+ shoes_builtin("ask", message_string)
20
+ end
21
+
22
+ def alert(message)
23
+ shoes_builtin("alert", message)
24
+ end
25
+
26
+ def ask_color(title_bar)
27
+ shoes_builtin("ask_color", title_bar)
28
+ end
29
+
30
+ def ask_open_file()
31
+ shoes_builtin("ask_open_file")
32
+ end
33
+
34
+ def ask_save_file()
35
+ shoes_builtin("ask_save_file")
36
+ end
37
+
38
+ def ask_open_folder()
39
+ shoes_builtin("ask_open_folder")
40
+ end
41
+
42
+ def ask_save_folder()
43
+ shoes_builtin("ask_save_folder")
44
+ end
45
+
46
+ def confirm(question)
47
+ shoes_builtin("confirm", question)
48
+ end
49
+
50
+ # TO ADD: debug, error, info, warn
51
+ # TO VERIFY OR ADD: gradient, gray, rgb
52
+
53
+ private
54
+
55
+ def shoes_builtin(cmd_name, *args)
56
+ Shoes::DisplayService.dispatch_event("builtin", nil, cmd_name, args)
57
+ nil
58
+ end
59
+ end
60
+
61
+ module Kernel
62
+ include Shoes::Builtins
63
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "log"
4
+ # require "scarpe/components/modular_logger"
5
+
6
+ class Shoes
7
+ class Changelog
8
+ # include Shoes::Log
9
+
10
+ def initialize
11
+ #TODO : refer to https://github.com/scarpe-team/scarpe/pull/400
12
+ # and figure out how to use scarpe logger here without getting duplicate or nil error
13
+ # Shoes::Log.instance = Scarpe::Components::ModularLogImpl.new
14
+ # log_init("Changelog")
15
+ end
16
+
17
+ def get_latest_release_info
18
+ root_dir = File.dirname(__FILE__, 4) # this duplicates constants.rb, but how to share?
19
+
20
+ git_dir = "#{root_dir}/.git"
21
+ revision = nil
22
+ if File.exist?(git_dir)
23
+ revision = `git rev-parse HEAD`.chomp
24
+ end
25
+
26
+ changelog_file = "#{root_dir}/CHANGELOG.md"
27
+ if File.exist?(changelog_file)
28
+ changelog_content = File.read(changelog_file)
29
+ release_name_pattern = /^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2}) - (\w+)$/m
30
+ release_matches = changelog_content.scan(release_name_pattern)
31
+ latest_release = release_matches.max_by { |version, _date, _name| Gem::Version.new(version) }
32
+
33
+ if latest_release
34
+ #puts "Found release #{latest_release[0]} in CHANGELOG.md"
35
+ # @log.debug("Found release #{latest_release[0]} in CHANGELOG.md") # Logger isn't initialized yet
36
+ version_parts = latest_release[0].split(".").map(&:to_i)
37
+ rel_id = ("%02d%02d%02d" % version_parts).to_i
38
+
39
+ return({
40
+ RELEASE_NAME: latest_release[2],
41
+ RELEASE_BUILD_DATE: latest_release[1],
42
+ RELEASE_ID: rel_id,
43
+ REVISION: revision,
44
+ })
45
+ end
46
+ end
47
+
48
+ puts "No release found in CHANGELOG.md"
49
+ { RELEASE_NAME: nil, RELEASE_BUILD_DATE: nil, RELEASE_ID: nil, REVISION: revision }
50
+ end
51
+ end
52
+ end
data/lib/shoes/colors.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Shoes
3
+ class Shoes
4
4
  module Colors
5
+ extend self
6
+
5
7
  COLORS = {
6
8
  aliceblue: [240, 248, 255],
7
9
  antiquewhite: [250, 235, 215],
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Shoes
3
+ require_relative "changelog"
4
+ class Shoes
4
5
  module Constants
5
6
  def self.find_lib_dir
6
7
  begin
@@ -12,18 +13,56 @@ module Shoes
12
13
  [ENV["LOCALAPPDATA"], "Shoes"],
13
14
  [ENV["APPDATA"], "Shoes"],
14
15
  [ENV["HOME"], ".shoes"],
15
- [Dir.tmpdir, "shoes"],
16
16
  ]
17
+
17
18
  top, file = homes.detect { |home_top, _| home_top && File.exist?(home_top) }
19
+ return nil if top.nil?
18
20
  File.join(top, file)
19
21
  end
20
22
 
23
+ # A temp dir for Shoes app files
21
24
  LIB_DIR = find_lib_dir
22
25
 
26
+ # the Shoes library dir
27
+ DIR = File.dirname(__FILE__, 4)
28
+
23
29
  # Math constants from Shoes3
24
30
  RAD2PI = 0.01745329251994329577
25
31
  TWO_PI = 6.28318530717958647693
26
32
  HALF_PI = 1.57079632679489661923
27
33
  PI = 3.14159265358979323846
34
+
35
+ # These should be set up by the Display Service when it loads. They are intentionally
36
+ # *not* frozen so that the Display Service can add to them (and then optionally
37
+ # freeze them.)
38
+
39
+ # Fonts currently loaded and available
40
+ FONTS = []
41
+
42
+ # Standard features available in this display service - see KNOWN_FEATURES.
43
+ # These may or may not require the Shoes.app requesting them per-app.
44
+ FEATURES = []
45
+
46
+ # Nonstandard extensions, e.g. Scarpe extensions, supported by this display lib.
47
+ # An application may have to request the extensions for them to be available so
48
+ # that a casual reader can see Shoes.app(features: :scarpe) and realize why
49
+ # there are nonstandard styles or drawables.
50
+ EXTENSIONS = []
51
+
52
+ # These are all known features supported by this version of Lacci.
53
+ # Features on this list are allowed to be in FEATURES. Anything else
54
+ # goes in EXTENSIONS and is nonstandard.
55
+ KNOWN_FEATURES = [
56
+ :html, # Supports .to_html on display objects, HTML classes on drawables, etc.
57
+ ].freeze
28
58
  end
59
+
60
+ # Access and assign the release constants
61
+ changelog_instance = Shoes::Changelog.new
62
+ RELEASE_INFO = changelog_instance.get_latest_release_info
63
+ RELEASE_NAME = RELEASE_INFO[:RELEASE_NAME]
64
+ RELEASE_ID = RELEASE_INFO[:RELEASE_ID]
65
+ RELEASE_BUILD_DATE = RELEASE_INFO[:RELEASE_BUILD_DATE]
66
+ RELEASE_TYPE = "LOOSE_SHOES" # This isn't really a thing any more
67
+ REVISION = RELEASE_INFO[:REVISION]
29
68
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Lacci Shoes apps operate in multiple layers. A Shoes widget tree exists as fairly
4
- # plain, simple Ruby objects. And then a display-service widget tree integrates with
3
+ # Lacci Shoes apps operate in multiple layers. A Shoes drawable tree exists as fairly
4
+ # plain, simple Ruby objects. And then a display-service drawable tree integrates with
5
5
  # the display technology. This lets us use Ruby as our API while
6
6
  # not tying it too closely to the limitations of Webview, WASM, LibUI, etc.
7
7
  #
@@ -15,24 +15,31 @@
15
15
  #
16
16
  # ## Events
17
17
  #
18
- # Events are a lot of what tie the Shoes widgets and the display service together.
18
+ # Events are a lot of what tie the Shoes drawables and the display service together.
19
19
  #
20
- # Shoes widgets *expect* to operate in a fairly "hands off" mode where they record
20
+ # Shoes drawables *expect* to operate in a fairly "hands off" mode where they record
21
21
  # to an event queue to send to the display service, and the display service records
22
22
  # events to send back.
23
23
  #
24
24
  # When a Shoes handler takes an action (e.g. some_para.replace(),) the relevant
25
25
  # call will be dispatched as a :display event, to be sent to the display service.
26
26
  # And when a display-side event occurs (e.g. user pushes a button,) it will be
27
- # dispatched as a :shoes event, to be sent to the Shoes tree of widgets.
27
+ # dispatched as a :shoes event, to be sent to the Shoes tree of drawables.
28
28
  #
29
- module Shoes
29
+ class Shoes
30
30
  class DisplayService
31
31
  class << self
32
32
  # This is in the eigenclass/metaclass, *not* instances of DisplayService
33
33
  include Shoes::Log
34
34
 
35
+ # Send a Shoes event to all subscribers.
35
36
  # An event_target may be nil, to indicate there is no target.
37
+ #
38
+ # @param event_name [String] the name of the event
39
+ # @param event_target [String] the specific target, if any
40
+ # @param args [Array] arguments to pass to the subscribing block
41
+ # @param args [Array] keyword arguments to pass to the subscribing block
42
+ # @return [void]
36
43
  def dispatch_event(event_name, event_target, *args, **kwargs)
37
44
  @@display_event_handlers ||= {}
38
45
 
@@ -69,10 +76,20 @@ module Shoes
69
76
  kwargs[:event_name] = event_name
70
77
  kwargs[:event_target] = event_target if event_target
71
78
  handlers.each { |h| h[:handler].call(*args, **kwargs) }
79
+ nil
72
80
  end
73
81
 
74
- # It's permitted to subscribe to event_name :any for all event names, and event_target :any for all targets.
75
- # An event_target of nil means "no target", and only matches events dispatched with a nil target.
82
+ # Subscribe to the given event name and target.
83
+ # It's permitted to subscribe to event_name :any for all event names,
84
+ # and event_target :any for all targets. An event_target of nil means
85
+ # "no target", and only matches events dispatched with a nil target.
86
+ # The subscription will return an unsubscribe ID, which can be used
87
+ # later to unsubscribe from the notification.
88
+ #
89
+ # @param event_name [String,Symbol] the event name to subscribe to, or :any for all event names
90
+ # @param event_target [String,Symbol,NilClass] the event target to subscribe to, or :any for all targets - nil is a valid target
91
+ # @block the block to call when the event occurs - it will receive arguments from the event-dispatch call
92
+ # @return [Integer] an unsubscription ID which can be used later to cancel the subscription
76
93
  def subscribe_to_event(event_name, event_target, &handler)
77
94
  @@display_event_handlers ||= {}
78
95
  @@display_event_unsub_id ||= 0
@@ -96,6 +113,10 @@ module Shoes
96
113
  id
97
114
  end
98
115
 
116
+ # Unsubscribe from any event subscriptions matching the unsub ID.
117
+ #
118
+ # @param unsub_id [Integer] the unsub ID returned when subscribing
119
+ # @return [void]
99
120
  def unsub_from_events(unsub_id)
100
121
  raise "Must provide an unsubscribe ID!" if unsub_id.nil?
101
122
 
@@ -106,17 +127,32 @@ module Shoes
106
127
  end
107
128
  end
108
129
 
130
+ # Reset the display service, for instance between unit tests.
131
+ # This destroys all existing subscriptions.
132
+ #
133
+ # @return [void]
109
134
  def full_reset!
110
135
  @@display_event_handlers = {}
111
136
  @json_debug_serialize = nil
112
137
  end
113
138
 
139
+ # Set the Display Service class which will handle display service functions
140
+ # for this process. This can only be set once. The display service can be
141
+ # a subclass of Shoes::DisplayService, but isn't required to be.
142
+ #
143
+ # Shoes will create an instance of this class with no arguments passed to
144
+ # initialize, and use it as the display service for the lifetime of the
145
+ # process.
146
+ #
147
+ # @param klass [Class] the class for the display service
114
148
  def set_display_service_class(klass)
115
149
  raise "Can only set a single display service class!" if @display_service_klass
116
150
 
117
151
  @display_service_klass = klass
118
152
  end
119
153
 
154
+ # Get the current display service instance. This requires a display service
155
+ # class having been set first. @see set_display_service_class
120
156
  def display_service
121
157
  return @service if @service
122
158
 
@@ -126,24 +162,38 @@ module Shoes
126
162
  end
127
163
  end
128
164
 
165
+ def initialize
166
+ @display_drawable_for = {}
167
+ end
168
+
129
169
  # These methods are an interface to DisplayService objects.
130
170
 
131
- def create_display_widget_for(widget_class_name, widget_id, properties)
171
+ def create_display_drawable_for(drawable_class_name, drawable_id, properties, parent_id:, is_widget:)
132
172
  raise "Override in DisplayService implementation!"
133
173
  end
134
174
 
135
- def set_widget_pairing(id, display_widget)
136
- @display_widget_for ||= {}
137
- @display_widget_for[id] = display_widget
175
+ def set_drawable_pairing(id, display_drawable)
176
+ if id.nil?
177
+ raise Shoes::Errors::BadLinkableIdError, "Linkable ID may not be nil!"
178
+ end
179
+
180
+ @display_drawable_for ||= {}
181
+ if @display_drawable_for[id]
182
+ raise Shoes::Errors::DuplicateCreateDrawableError, "There is already a drawable for #{id.inspect}! Not setting a new one."
183
+ end
184
+
185
+ @display_drawable_for[id] = display_drawable
186
+ nil
138
187
  end
139
188
 
140
- def query_display_widget_for(id, nil_ok: false)
141
- display_widget = @display_widget_for[id]
142
- unless display_widget || nil_ok
143
- raise "Could not find display widget for linkable ID #{id.inspect}!"
189
+ def query_display_drawable_for(id, nil_ok: false)
190
+ @display_drawable_for ||= {}
191
+ display_drawable = @display_drawable_for[id]
192
+ unless display_drawable || nil_ok
193
+ raise "Could not find display drawable for linkable ID #{id.inspect}!"
144
194
  end
145
195
 
146
- display_widget
196
+ display_drawable
147
197
  end
148
198
 
149
199
  def destroy
@@ -163,6 +213,7 @@ module Shoes
163
213
 
164
214
  def initialize(linkable_id: object_id)
165
215
  @linkable_id = linkable_id
216
+ @subscriptions = {}
166
217
  end
167
218
 
168
219
  def send_self_event(*args, event_name:, **kwargs)
@@ -174,11 +225,22 @@ module Shoes
174
225
  end
175
226
 
176
227
  def bind_shoes_event(event_name:, target: nil, &handler)
177
- DisplayService.subscribe_to_event(event_name, target, &handler)
228
+ sub = DisplayService.subscribe_to_event(event_name, target, &handler)
229
+ @subscriptions[sub] = true
230
+ sub
178
231
  end
179
232
 
180
233
  def unsub_shoes_event(unsub_id)
234
+ unless @subscriptions[unsub_id]
235
+ $stderr.puts "Unsubscribing from event that isn't in subscriptions! #{unsub_id.inspect}"
236
+ end
181
237
  DisplayService.unsub_from_events(unsub_id)
238
+ @subscriptions.delete unsub_id
239
+ end
240
+
241
+ def unsub_all_shoes_events
242
+ @subscriptions.keys.each { |k| DisplayService.unsub_from_events(k) }
243
+ @subscriptions.clear
182
244
  end
183
245
  end
184
246
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Shoes
4
- class Widget
3
+ class Shoes
4
+ class Drawable
5
5
  class ResponseWrapper
6
6
  attr_reader :response
7
7