lacci 0.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +8 -1
- data/lib/lacci/scarpe_cli.rb +2 -2
- data/lib/lacci/scarpe_core.rb +2 -1
- data/lib/lacci/version.rb +1 -1
- data/lib/scarpe/niente/app.rb +23 -0
- data/lib/scarpe/niente/display_service.rb +66 -0
- data/lib/scarpe/niente/drawable.rb +59 -0
- data/lib/scarpe/niente/shoes_spec.rb +93 -0
- data/lib/scarpe/niente.rb +32 -0
- data/lib/shoes/app.rb +111 -72
- data/lib/shoes/background.rb +2 -2
- data/lib/shoes/border.rb +2 -2
- data/lib/shoes/builtins.rb +63 -0
- data/lib/shoes/changelog.rb +52 -0
- data/lib/shoes/colors.rb +3 -1
- data/lib/shoes/constants.rb +41 -2
- data/lib/shoes/display_service.rb +80 -18
- data/lib/shoes/download.rb +2 -2
- data/lib/shoes/drawable.rb +654 -0
- data/lib/shoes/drawables/arc.rb +27 -0
- data/lib/shoes/drawables/arrow.rb +21 -0
- data/lib/shoes/drawables/border.rb +28 -0
- data/lib/shoes/drawables/button.rb +57 -0
- data/lib/shoes/drawables/check.rb +33 -0
- data/lib/shoes/drawables/document_root.rb +20 -0
- data/lib/shoes/{widgets → drawables}/edit_box.rb +9 -8
- data/lib/shoes/{widgets → drawables}/edit_line.rb +8 -7
- data/lib/shoes/drawables/flow.rb +20 -0
- data/lib/shoes/drawables/font_helper.rb +62 -0
- data/lib/shoes/{widgets → drawables}/image.rb +7 -7
- data/lib/shoes/drawables/line.rb +17 -0
- data/lib/shoes/drawables/link.rb +31 -0
- data/lib/shoes/drawables/list_box.rb +59 -0
- data/lib/shoes/drawables/oval.rb +48 -0
- data/lib/shoes/drawables/para.rb +206 -0
- data/lib/shoes/drawables/progress.rb +15 -0
- data/lib/shoes/drawables/radio.rb +35 -0
- data/lib/shoes/drawables/rect.rb +18 -0
- data/lib/shoes/{widgets → drawables}/shape.rb +8 -8
- data/lib/shoes/drawables/slot.rb +178 -0
- data/lib/shoes/drawables/stack.rb +21 -0
- data/lib/shoes/drawables/star.rb +28 -0
- data/lib/shoes/drawables/subscription_item.rb +93 -0
- data/lib/shoes/drawables/text_drawable.rb +122 -0
- data/lib/shoes/drawables/video.rb +17 -0
- data/lib/shoes/drawables/widget.rb +74 -0
- data/lib/shoes/drawables.rb +32 -0
- data/lib/shoes/errors.rb +38 -0
- data/lib/shoes/log.rb +2 -2
- data/lib/shoes/margin_helper.rb +79 -0
- data/lib/shoes/ruby_extensions.rb +15 -0
- data/lib/shoes-spec.rb +93 -0
- data/lib/shoes.rb +31 -10
- metadata +58 -31
- data/lib/shoes/spacing.rb +0 -9
- data/lib/shoes/widget.rb +0 -218
- data/lib/shoes/widgets/alert.rb +0 -19
- data/lib/shoes/widgets/arc.rb +0 -51
- data/lib/shoes/widgets/button.rb +0 -35
- data/lib/shoes/widgets/check.rb +0 -28
- data/lib/shoes/widgets/document_root.rb +0 -20
- data/lib/shoes/widgets/flow.rb +0 -22
- data/lib/shoes/widgets/font.rb +0 -14
- data/lib/shoes/widgets/line.rb +0 -18
- data/lib/shoes/widgets/link.rb +0 -25
- data/lib/shoes/widgets/list_box.rb +0 -25
- data/lib/shoes/widgets/para.rb +0 -68
- data/lib/shoes/widgets/radio.rb +0 -35
- data/lib/shoes/widgets/slot.rb +0 -75
- data/lib/shoes/widgets/span.rb +0 -26
- data/lib/shoes/widgets/stack.rb +0 -24
- data/lib/shoes/widgets/star.rb +0 -44
- data/lib/shoes/widgets/subscription_item.rb +0 -60
- data/lib/shoes/widgets/text_widget.rb +0 -51
- data/lib/shoes/widgets/video.rb +0 -15
- data/lib/shoes/widgets.rb +0 -29
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Shoes
|
4
|
+
class Progress < Shoes::Drawable
|
5
|
+
shoes_styles :fraction
|
6
|
+
shoes_events # No Progress-specific events yet
|
7
|
+
|
8
|
+
init_args # No positional args
|
9
|
+
def initialize(**kwargs)
|
10
|
+
super
|
11
|
+
|
12
|
+
create_display_drawable
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Shoes
|
4
|
+
# A Radio button drawable. Only a single radio button may be checked in each
|
5
|
+
# group. If no group is specified, or the group is nil, default to all
|
6
|
+
# radio buttons in the same slot being treated as being in the same group.
|
7
|
+
class Radio < Shoes::Drawable
|
8
|
+
shoes_styles :group, :checked
|
9
|
+
shoes_events :click
|
10
|
+
|
11
|
+
init_args
|
12
|
+
opt_init_args :group
|
13
|
+
def initialize(*args, **kwargs, &block)
|
14
|
+
@block = block
|
15
|
+
|
16
|
+
super
|
17
|
+
|
18
|
+
bind_self_event("click") { click }
|
19
|
+
create_display_drawable
|
20
|
+
end
|
21
|
+
|
22
|
+
def click(&block)
|
23
|
+
@block = block
|
24
|
+
self.checked = !checked?
|
25
|
+
end
|
26
|
+
|
27
|
+
def checked?
|
28
|
+
@checked ? true : false
|
29
|
+
end
|
30
|
+
|
31
|
+
def checked(value)
|
32
|
+
self.checked = value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Shoes
|
4
|
+
class Rect < Shoes::Drawable
|
5
|
+
shoes_styles :draw_context, :curve, :stroke, :fill
|
6
|
+
shoes_events # No Rect-specific events
|
7
|
+
|
8
|
+
init_args :left, :top, :width, :height
|
9
|
+
opt_init_args :curve
|
10
|
+
def initialize(*args, **kwargs)
|
11
|
+
@draw_context = Shoes::App.instance.current_draw_context
|
12
|
+
|
13
|
+
super
|
14
|
+
|
15
|
+
create_display_drawable
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
class Shoes
|
4
4
|
# A Shape acts as a sort of union type for drawn shapes. In Shoes you can use it to merge multiple
|
5
5
|
# ovals, arcs, stars, etc. into a single drawn shape.
|
6
6
|
#
|
7
7
|
# In Shoes3, a Shape isn't really a Slot. It's a kind of DSL with drawing commands that happen
|
8
|
-
# to have the same name as the Art
|
9
|
-
# a slot containing those
|
8
|
+
# to have the same name as the Art drawables like star, arc, etc. Here we're treating it as
|
9
|
+
# a slot containing those drawables, which is wrong but not *too* wrong.
|
10
10
|
#
|
11
11
|
# @incompatibility A Shoes3 Shape is *not* a slot; Scarpe does *not* do union shapes
|
12
12
|
class Shape < Shoes::Slot
|
13
|
-
|
13
|
+
shoes_styles :left, :top, :shape_commands, :draw_context
|
14
|
+
shoes_events # No Shape-specific events yet
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
@top = top
|
16
|
+
init_args # No positional args
|
17
|
+
def initialize(**kwargs, &block)
|
18
18
|
@shape_commands = []
|
19
19
|
@draw_context = Shoes::App.instance.current_draw_context
|
20
20
|
|
21
21
|
super
|
22
|
-
|
22
|
+
create_display_drawable
|
23
23
|
|
24
24
|
Shoes::App.instance.with_slot(self, &block) if block_given?
|
25
25
|
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Shoes::Slot < Shoes::Drawable
|
4
|
+
# @incompatibility Shoes uses #content, not #children, for this. Scarpe does both.
|
5
|
+
attr_reader :children
|
6
|
+
|
7
|
+
shoes_events # No Slot-specific events
|
8
|
+
|
9
|
+
# This only shows this specific slot's settings, not its parent's.
|
10
|
+
# Use current_draw_context to allow inheritance.
|
11
|
+
attr_reader :draw_context
|
12
|
+
|
13
|
+
|
14
|
+
def initialize(...)
|
15
|
+
# The draw context tracks current settings like fill and stroke,
|
16
|
+
# plus potentially other current state that changes from drawable
|
17
|
+
# to drawable and slot to slot.
|
18
|
+
@draw_context = {
|
19
|
+
"fill" => nil,
|
20
|
+
"stroke" => nil,
|
21
|
+
"strokewidth" => nil,
|
22
|
+
"rotate" => nil,
|
23
|
+
# "transform" => nil, # "corner",
|
24
|
+
# "translate" => nil, # [0, 0],
|
25
|
+
}
|
26
|
+
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
# Do not call directly, use set_parent
|
31
|
+
def remove_child(child)
|
32
|
+
@children ||= []
|
33
|
+
unless @children.include?(child)
|
34
|
+
@log.warn("remove_child: no such child(#{child.inspect}) for parent(#{parent.inspect})!")
|
35
|
+
end
|
36
|
+
@children.delete(child)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Do not call directly, use set_parent
|
40
|
+
def add_child(child)
|
41
|
+
@children ||= []
|
42
|
+
@children << child
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get a list of child drawables
|
46
|
+
def contents
|
47
|
+
@children ||= []
|
48
|
+
@children.dup
|
49
|
+
end
|
50
|
+
|
51
|
+
# We use method_missing for drawable-creating methods like "button".
|
52
|
+
# The parent's method_missing will auto-create Shoes style getters and setters.
|
53
|
+
# This is similar to the method_missing in Shoes::App, but differs in where
|
54
|
+
# the new drawable will appear.
|
55
|
+
def method_missing(name, *args, **kwargs, &block)
|
56
|
+
klass = ::Shoes::Drawable.drawable_class_by_name(name)
|
57
|
+
return super unless klass
|
58
|
+
|
59
|
+
::Shoes::Slot.define_method(name) do |*args, **kwargs, &block|
|
60
|
+
instance = nil
|
61
|
+
|
62
|
+
# Look up the Shoes drawable and create it. But first set
|
63
|
+
# this slot as the current one so that draw context
|
64
|
+
# is handled properly.
|
65
|
+
Shoes::App.instance.with_slot(self) do
|
66
|
+
instance = klass.new(*args, **kwargs, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
instance
|
70
|
+
end
|
71
|
+
|
72
|
+
send(name, *args, **kwargs, &block)
|
73
|
+
end
|
74
|
+
|
75
|
+
def respond_to_missing?(name, include_private = false)
|
76
|
+
return true if ::Shoes::Drawable.drawable_class_by_name(name.to_s)
|
77
|
+
|
78
|
+
false
|
79
|
+
end
|
80
|
+
|
81
|
+
# Draw context methods
|
82
|
+
|
83
|
+
# Set the default fill color in this slot and child slots.
|
84
|
+
# Pass nil for "no setting", so that it can inherit defaults.
|
85
|
+
#
|
86
|
+
# @param color [Nil,Color] a Shoes color for the fill color or nil to use parent setting
|
87
|
+
# @return [void]
|
88
|
+
def fill(color)
|
89
|
+
@draw_context["fill"] = color
|
90
|
+
end
|
91
|
+
|
92
|
+
# Set the default fill in this slot and child slots to transparent.
|
93
|
+
#
|
94
|
+
# @return [void]
|
95
|
+
def nofill
|
96
|
+
@draw_context["fill"] = rgb(0, 0, 0, 0)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Set the default stroke color in this slot and child slots.
|
100
|
+
# Pass nil for "no setting" so it can inherit defaults.
|
101
|
+
#
|
102
|
+
# @param color [Nil,Color] a Shoes color for the stroke color or nil to use parent setting
|
103
|
+
# @return [void]
|
104
|
+
def stroke(color)
|
105
|
+
@draw_context["stroke"] = color
|
106
|
+
end
|
107
|
+
|
108
|
+
# Set the default strokewidth in this slot and child slots.
|
109
|
+
# Pass nil for "no setting".
|
110
|
+
#
|
111
|
+
# @param width [Numeric,Nil] the new width, or nil to use parent setting
|
112
|
+
# @return [void]
|
113
|
+
def strokewidth(width)
|
114
|
+
@draw_context["strokewidth"] = width
|
115
|
+
end
|
116
|
+
|
117
|
+
# Set the default stroke in this slot and child slots
|
118
|
+
# to transparent.
|
119
|
+
#
|
120
|
+
# @return [void]
|
121
|
+
def nostroke
|
122
|
+
@draw_context["stroke"] = rgb(0, 0, 0, 0)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Set the current rotation in this slot and any child slots.
|
126
|
+
# Pass nil to reset the angle to default.
|
127
|
+
#
|
128
|
+
# @param angle [Numeric,Nil] the new default rotation for shapes or nil to use parent setting
|
129
|
+
# @return [void]
|
130
|
+
def rotate(angle)
|
131
|
+
@draw_context["rotate"] = angle
|
132
|
+
end
|
133
|
+
|
134
|
+
# Get the current draw context styles, based on this slot and its parent slots.
|
135
|
+
#
|
136
|
+
# @return [Hash] a hash of Shoes styles for the context
|
137
|
+
def current_draw_context
|
138
|
+
s = @parent ? @parent.current_draw_context : {}
|
139
|
+
@draw_context.each { |k, v| s[k] = v unless v.nil? }
|
140
|
+
|
141
|
+
s
|
142
|
+
end
|
143
|
+
|
144
|
+
# Methods to add or remove children
|
145
|
+
|
146
|
+
# Remove all children from this drawable. If a block
|
147
|
+
# is given, call the block to replace the children with
|
148
|
+
# new contents from that block.
|
149
|
+
#
|
150
|
+
# Should only be called on Slots, which can
|
151
|
+
# have children.
|
152
|
+
#
|
153
|
+
# @incompatibility Shoes Classic calls the clear block with current self, while Scarpe uses the Shoes::App as self
|
154
|
+
#
|
155
|
+
# @yield The block to call to replace the contents of the drawable (optional)
|
156
|
+
# @return [void]
|
157
|
+
def clear(&block)
|
158
|
+
@children ||= []
|
159
|
+
@children.dup.each(&:destroy)
|
160
|
+
append(&block) if block_given?
|
161
|
+
nil
|
162
|
+
end
|
163
|
+
|
164
|
+
# Call the block to append new children to a Slot.
|
165
|
+
#
|
166
|
+
# Should only be called on a Slot, since only Slots can have children.
|
167
|
+
#
|
168
|
+
# @incompatibility Shoes Classic calls the append block with current self, while Scarpe uses the Shoes::App as self
|
169
|
+
#
|
170
|
+
# @yield the block to call to replace children; will be called on the Shoes::App, appending to the called Slot as the current slot
|
171
|
+
# @return [void]
|
172
|
+
def append(&block)
|
173
|
+
raise(Shoes::Errors::InvalidAttributeValueError, "append requires a block!") unless block_given?
|
174
|
+
raise(Shoes::Errors::InvalidAttributeValueError, "Don't append to something that isn't a slot!") unless self.is_a?(Shoes::Slot)
|
175
|
+
|
176
|
+
Shoes::App.instance.with_slot(self, &block)
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Shoes
|
4
|
+
class Stack < Shoes::Slot
|
5
|
+
include Shoes::Background
|
6
|
+
|
7
|
+
shoes_styles :scroll
|
8
|
+
|
9
|
+
shoes_events # No Stack-specific events
|
10
|
+
|
11
|
+
def initialize(*args, **kwargs, &block)
|
12
|
+
super
|
13
|
+
|
14
|
+
create_display_drawable
|
15
|
+
|
16
|
+
# Create the display-side drawable *before* running the block.
|
17
|
+
# Then child drawables have a parent to add themselves to.
|
18
|
+
Shoes::App.instance.with_slot(self, &block) if block_given?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Shoes
|
4
|
+
class Star < Shoes::Drawable
|
5
|
+
shoes_styles :left, :top, :draw_context
|
6
|
+
|
7
|
+
shoes_style(:points) { |val| convert_to_integer(val, "points") }
|
8
|
+
shoes_style(:outer) { |val| convert_to_float(val, "outer") }
|
9
|
+
shoes_style(:inner) { |val| convert_to_float(val, "inner") }
|
10
|
+
|
11
|
+
Shoes::Drawable.drawable_default_styles[Shoes::Star][:points] = 10
|
12
|
+
Shoes::Drawable.drawable_default_styles[Shoes::Star][:outer] = 100
|
13
|
+
Shoes::Drawable.drawable_default_styles[Shoes::Star][:inner] = 50
|
14
|
+
|
15
|
+
shoes_events # No Star-specific events
|
16
|
+
|
17
|
+
init_args :left, :top
|
18
|
+
opt_init_args :points, :outer, :inner
|
19
|
+
def initialize(*args, **kwargs)
|
20
|
+
super
|
21
|
+
|
22
|
+
@draw_context = Shoes::App.instance.current_draw_context
|
23
|
+
|
24
|
+
create_display_drawable
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Certain Shoes calls like motion and keydown are basically an
|
4
|
+
# event subscription, with no other visible presence. However,
|
5
|
+
# they have a place in the drawable tree and can be deleted.
|
6
|
+
#
|
7
|
+
# Depending on the display library they may not have any
|
8
|
+
# direct visual (or similar) presence there either.
|
9
|
+
#
|
10
|
+
# Inheriting from Drawable gives these a parent slot and a
|
11
|
+
# linkable_id automatically.
|
12
|
+
#
|
13
|
+
# Events not yet implemented: start, finish events for slots -
|
14
|
+
# start is first draw, finish is drawable destroyed
|
15
|
+
class Shoes::SubscriptionItem < Shoes::Drawable
|
16
|
+
shoes_styles :shoes_api_name, :args
|
17
|
+
shoes_events :animate, :every, :timer, :hover, :leave, :motion, :click, :release, :keypress
|
18
|
+
|
19
|
+
def initialize(args: [], shoes_api_name:, &block)
|
20
|
+
super
|
21
|
+
|
22
|
+
@callback = block
|
23
|
+
|
24
|
+
case shoes_api_name
|
25
|
+
when "animate"
|
26
|
+
@unsub_id = bind_self_event("animate") do |frame|
|
27
|
+
@callback.call(frame)
|
28
|
+
end
|
29
|
+
when "every"
|
30
|
+
@unsub_id = bind_self_event("every") do |count|
|
31
|
+
@callback.call(count)
|
32
|
+
end
|
33
|
+
when "timer"
|
34
|
+
@unsub_id = bind_self_event("timer") do
|
35
|
+
@callback.call
|
36
|
+
end
|
37
|
+
when "hover"
|
38
|
+
# Hover passes the Shoes drawable as the block param
|
39
|
+
@unsub_id = bind_self_event("hover") do
|
40
|
+
@callback&.call(self)
|
41
|
+
end
|
42
|
+
when "leave"
|
43
|
+
# Leave passes the Shoes drawable as the block param
|
44
|
+
@unsub_id = bind_self_event("leave") do
|
45
|
+
@callback&.call(self)
|
46
|
+
end
|
47
|
+
when "motion"
|
48
|
+
# Shoes sends back x, y, mods as the args.
|
49
|
+
# Shoes3 uses the strings "control" "shift" and
|
50
|
+
# "control_shift" as the mods arg.
|
51
|
+
@unsub_id = bind_self_event("motion") do |x, y, ctrl_key, shift_key, **_kwargs|
|
52
|
+
mods = [ctrl_key ? "control" : nil, shift_key ? "shift" : nil].compact.join("_")
|
53
|
+
@callback&.call(x, y, mods)
|
54
|
+
end
|
55
|
+
when "click"
|
56
|
+
# Click has block params button, left, top
|
57
|
+
# button is the button number, left and top are coords
|
58
|
+
@unsub_id = bind_self_event("click") do |button, x, y, **_kwargs|
|
59
|
+
@callback&.call(button, x, y)
|
60
|
+
end
|
61
|
+
when "release"
|
62
|
+
# Click has block params button, left, top
|
63
|
+
# button is the button number, left and top are coords
|
64
|
+
@unsub_id = bind_self_event("release") do |button, x, y, **_kwargs|
|
65
|
+
@callback&.call(button, x, y)
|
66
|
+
end
|
67
|
+
when "keypress"
|
68
|
+
# Keypress passes the key string or symbol to the handler
|
69
|
+
# Do anything special for serialisation here?
|
70
|
+
@unsub_id = bind_self_event("keypress") do |key|
|
71
|
+
@callback&.call(key)
|
72
|
+
end
|
73
|
+
else
|
74
|
+
raise "Unknown Shoes event #{shoes_api_name.inspect} passed to SubscriptionItem!"
|
75
|
+
end
|
76
|
+
|
77
|
+
@unsub_id = bind_self_event(shoes_api_name) do |*args|
|
78
|
+
@callback&.call(*args)
|
79
|
+
end
|
80
|
+
|
81
|
+
# This won't create a visible display drawable, but will turn into
|
82
|
+
# an invisible drawable and a stream of events.
|
83
|
+
create_display_drawable
|
84
|
+
end
|
85
|
+
|
86
|
+
def destroy
|
87
|
+
# TODO: we need a better way to do this automatically. See https://github.com/scarpe-team/scarpe/issues/291
|
88
|
+
unsub_shoes_event(@unsub_id) if @unsub_id
|
89
|
+
@unsub_id = nil
|
90
|
+
|
91
|
+
super
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Shoes
|
4
|
+
# TextDrawable is the parent class of various classes of
|
5
|
+
# text that can go inside a para. This includes normal
|
6
|
+
# text, but also links, italic text, bold text, etc.
|
7
|
+
#
|
8
|
+
# In Shoes3 this corresponds to cText, and it would
|
9
|
+
# have methods app, contents, children, parent,
|
10
|
+
# style, to_s, text, text= and replace.
|
11
|
+
#
|
12
|
+
# Much of what this does and how is similar to Para.
|
13
|
+
# It's a very similar API.
|
14
|
+
class TextDrawable < Shoes::Drawable
|
15
|
+
shoes_styles :text_items, :size, :stroke, :strokewidth, :fill, :undercolor, :font
|
16
|
+
|
17
|
+
STRIKETHROUGH_VALUES = [nil, "none", "single"]
|
18
|
+
shoes_style :strikethrough do |val, _name|
|
19
|
+
unless STRIKETHROUGH_VALUES.include?(val)
|
20
|
+
raise Shoes::Errors::InvalidAttributeValueError, "Strikethrough must be one of: #{STRIKETHROUGH_VALUES.inspect}!"
|
21
|
+
end
|
22
|
+
val
|
23
|
+
end
|
24
|
+
|
25
|
+
UNDERLINE_VALUES = [nil, "none", "single", "double", "low", "error"]
|
26
|
+
shoes_style :underline do |val, _name|
|
27
|
+
unless UNDERLINE_VALUES.include?(val)
|
28
|
+
raise Shoes::Errors::InvalidAttributeValueError, "Underline must be one of: #{UNDERLINE_VALUES.inspect}!"
|
29
|
+
end
|
30
|
+
val
|
31
|
+
end
|
32
|
+
|
33
|
+
shoes_events # No TextDrawable-specific events yet
|
34
|
+
|
35
|
+
def initialize(*args, **kwargs)
|
36
|
+
# Don't pass text_children args to Drawable#initialize
|
37
|
+
super(*[], **kwargs)
|
38
|
+
|
39
|
+
# Text_children alternates strings and TextDrawables, so we can't just pass
|
40
|
+
# it as a Shoes style. It won't serialize.
|
41
|
+
update_text_children(args)
|
42
|
+
|
43
|
+
create_display_drawable
|
44
|
+
end
|
45
|
+
|
46
|
+
def text_children_to_items(text_children)
|
47
|
+
text_children.map { |arg| arg.is_a?(TextDrawable) ? arg.linkable_id : arg.to_s }
|
48
|
+
end
|
49
|
+
|
50
|
+
# Sets the paragraph text to a new value, which can
|
51
|
+
# include {TextDrawable}s like em(), strong(), etc.
|
52
|
+
#
|
53
|
+
# @param children [Array] the arguments can be Strings and/or TextDrawables
|
54
|
+
# @return [void]
|
55
|
+
def replace(*children)
|
56
|
+
update_text_children(children)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Set the paragraph text to a single String.
|
60
|
+
# To use bold, italics, etc. use {Para#replace} instead.
|
61
|
+
#
|
62
|
+
# @param child [String] the new text to use for this Para
|
63
|
+
# @return [void]
|
64
|
+
def text=(*children)
|
65
|
+
update_text_children(children)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Return the text, but not the styling, of the para's
|
69
|
+
# contents. For example, if the contents had strong
|
70
|
+
# and emphasized text, the bold and emphasized would
|
71
|
+
# be removed but the text would be returned.
|
72
|
+
#
|
73
|
+
# @return [String] the text from this para
|
74
|
+
def text
|
75
|
+
@text_children.map(&:to_s).join
|
76
|
+
end
|
77
|
+
|
78
|
+
# Return the text but not styling from the para. This
|
79
|
+
# is the same as #text.
|
80
|
+
#
|
81
|
+
# @return [String] the text from this para
|
82
|
+
def to_s
|
83
|
+
self.text
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
# Text_children alternates strings and TextDrawables, so we can't just pass
|
89
|
+
# it as a Shoes style. It won't serialize.
|
90
|
+
def update_text_children(children)
|
91
|
+
@text_children = children.flatten
|
92
|
+
# This should signal the display drawable to change
|
93
|
+
self.text_items = text_children_to_items(@text_children)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class << self
|
98
|
+
def default_text_drawable_with(element)
|
99
|
+
class_name = element.capitalize
|
100
|
+
|
101
|
+
drawable_class = Class.new(Shoes::TextDrawable) do
|
102
|
+
shoes_events # No specific events
|
103
|
+
|
104
|
+
init_args # We're going to pass an empty array to super
|
105
|
+
end
|
106
|
+
Shoes.const_set class_name, drawable_class
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
Shoes.default_text_drawable_with(:code)
|
112
|
+
Shoes.default_text_drawable_with(:del)
|
113
|
+
Shoes.default_text_drawable_with(:em)
|
114
|
+
Shoes.default_text_drawable_with(:strong)
|
115
|
+
Shoes.default_text_drawable_with(:span)
|
116
|
+
Shoes.default_text_drawable_with(:sub)
|
117
|
+
Shoes.default_text_drawable_with(:sup)
|
118
|
+
Shoes.default_text_drawable_with(:ins) # in Shoes3, looks like "ins" is just underline
|
119
|
+
|
120
|
+
# Defaults must come *after* classes are defined
|
121
|
+
|
122
|
+
Shoes::Drawable.drawable_default_styles[Shoes::Ins][:underline] = "single"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Shoes
|
4
|
+
class Video < Shoes::Drawable
|
5
|
+
shoes_styles :url
|
6
|
+
shoes_events # No specific events yet
|
7
|
+
|
8
|
+
init_args :url
|
9
|
+
def initialize(*args, **kwargs)
|
10
|
+
super
|
11
|
+
|
12
|
+
create_display_drawable
|
13
|
+
end
|
14
|
+
|
15
|
+
# other methods
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A Shoes::Widget is mostly a Slot (related to the
|
4
|
+
# old Shoes concepts of Canvas) that creates drawables
|
5
|
+
# inside itself. When a subclass of Widget is created,
|
6
|
+
# it adds a method to create new objects of that type
|
7
|
+
# on Shoes::App and all Shoes slots.
|
8
|
+
#
|
9
|
+
# The hardest part with a Shoes::Widget is that it
|
10
|
+
# should work fine even if initialize() doesn't call
|
11
|
+
# super, which would make it hard to set up a Shoes
|
12
|
+
# linkable_id, create a display widget, etc.
|
13
|
+
#
|
14
|
+
# It would be possible to add an extra method to set
|
15
|
+
# these up and call it on every created drawable
|
16
|
+
# in case a Widget's initialize method doesn't call
|
17
|
+
# super, which happens quite often. But then we wouldn't
|
18
|
+
# support automatic setting of styles (e.g. padding)
|
19
|
+
# for the widget object itself, which is mostly a Flow.
|
20
|
+
# We also couldn't support default styles -- I can't tell
|
21
|
+
# whether Shoes supports these things either.
|
22
|
+
#
|
23
|
+
# But there's another way to do all of this. When a
|
24
|
+
# subclass of Widget defines an initialize method,
|
25
|
+
# we can catch the method_added hook, save a copy of
|
26
|
+
# that initialize method, and substitute our own
|
27
|
+
# initialize that calls super. We have to be a little
|
28
|
+
# careful -- if the widget's initialize *does* call
|
29
|
+
# super that shouldn't be an error. But that's
|
30
|
+
# workable by defining an extra method with the
|
31
|
+
# copied-method name that does nothing.
|
32
|
+
|
33
|
+
##### TODO: when this is subclassed, grab :initialize out
|
34
|
+
# of the subclass, put it into :initialize_widget, and
|
35
|
+
# replace with an initialize that creates the display
|
36
|
+
# widget propertly, sets the linkable_id, etc.
|
37
|
+
|
38
|
+
class Shoes::Widget < Shoes::Slot
|
39
|
+
include Shoes::Background
|
40
|
+
|
41
|
+
shoes_events
|
42
|
+
|
43
|
+
def self.inherited(subclass)
|
44
|
+
super
|
45
|
+
|
46
|
+
# Widgets are special - we can't know in advance what sort of initialize args they take
|
47
|
+
subclass.init_args :any
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.method_added(name)
|
51
|
+
# We're only looking for the initialize() method, and only on subclasses
|
52
|
+
# of Shoes::Widget, not Shoes::Widget itself.
|
53
|
+
return if self == ::Shoes::Widget || name != :initialize
|
54
|
+
|
55
|
+
# Need to avoid infinite adding of initialize() if we're re-adding the default initialize
|
56
|
+
return if @midway_through_adding_initialize
|
57
|
+
|
58
|
+
# Take the user-provided initialize method and save a copy named __widget_initialize
|
59
|
+
alias_method :__widget_initialize, :initialize
|
60
|
+
|
61
|
+
# And add the default initialize back where it belongs
|
62
|
+
@midway_through_adding_initialize = true
|
63
|
+
define_method(:initialize) do |*args, **kwargs, &block|
|
64
|
+
super(*args, **kwargs, &block)
|
65
|
+
@options = kwargs # Get rid of options?
|
66
|
+
create_display_drawable
|
67
|
+
__widget_initialize(*args, **kwargs, &block)
|
68
|
+
|
69
|
+
# Do Widgets do this?
|
70
|
+
Shoes::App.instance.with_slot(self, &block) if block
|
71
|
+
end
|
72
|
+
@midway_through_adding_initialize = false
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "shoes/drawables/slot"
|
4
|
+
require "shoes/drawables/stack"
|
5
|
+
require "shoes/drawables/flow"
|
6
|
+
require "shoes/drawables/widget"
|
7
|
+
require "shoes/drawables/document_root"
|
8
|
+
|
9
|
+
require "shoes/drawables/text_drawable"
|
10
|
+
|
11
|
+
require "shoes/drawables/subscription_item"
|
12
|
+
|
13
|
+
require "shoes/drawables/arc"
|
14
|
+
require "shoes/drawables/line"
|
15
|
+
require "shoes/drawables/rect"
|
16
|
+
require "shoes/drawables/shape"
|
17
|
+
require "shoes/drawables/star"
|
18
|
+
require "shoes/drawables/oval"
|
19
|
+
require "shoes/drawables/arrow"
|
20
|
+
|
21
|
+
require "shoes/drawables/button"
|
22
|
+
require "shoes/drawables/check"
|
23
|
+
require "shoes/drawables/edit_box"
|
24
|
+
require "shoes/drawables/edit_line"
|
25
|
+
require "shoes/drawables/image"
|
26
|
+
require "shoes/drawables/link"
|
27
|
+
require "shoes/drawables/list_box"
|
28
|
+
require "shoes/drawables/para"
|
29
|
+
require "shoes/drawables/radio"
|
30
|
+
require "shoes/drawables/video"
|
31
|
+
require "shoes/drawables/progress"
|
32
|
+
require "shoes/drawables/border"
|