glimmer-dsl-libui 0.3.4 → 0.4.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +4114 -3756
- data/VERSION +1 -1
- data/examples/area_gallery.rb +15 -15
- data/examples/area_gallery2.rb +35 -36
- data/examples/area_gallery3.rb +15 -15
- data/examples/area_gallery4.rb +35 -35
- data/examples/button_counter.rb +27 -0
- data/examples/color_the_circles.rb +2 -2
- data/examples/meta_example.rb +1 -1
- data/examples/method_based_custom_keyword.rb +2 -2
- data/examples/midi_player.rb +2 -6
- data/examples/snake/model/game.rb +2 -2
- data/examples/snake/presenter/grid.rb +5 -3
- data/examples/snake.rb +11 -21
- data/examples/tetris.rb +12 -12
- data/examples/tic_tac_toe.rb +3 -12
- data/examples/timer.rb +2 -6
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/bind_expression.rb +36 -0
- data/lib/glimmer/dsl/libui/data_binding_expression.rb +47 -0
- data/lib/glimmer/dsl/libui/dsl.rb +3 -0
- data/lib/glimmer/dsl/libui/observe_expression.rb +35 -0
- data/lib/glimmer/dsl/libui/shine_data_binding_expression.rb +42 -0
- data/lib/glimmer/dsl/libui/string_expression.rb +4 -5
- data/lib/glimmer/libui/attributed_string.rb +19 -6
- data/lib/glimmer/libui/control_proxy/area_proxy.rb +52 -46
- data/lib/glimmer/libui/control_proxy/image_proxy.rb +4 -5
- data/lib/glimmer/libui/control_proxy/table_proxy.rb +1 -1
- data/lib/glimmer/libui/control_proxy.rb +4 -1
- data/lib/glimmer/libui/shape.rb +6 -3
- metadata +9 -4
@@ -0,0 +1,35 @@
|
|
1
|
+
# Copyright (c) 2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/dsl/static_expression'
|
23
|
+
require 'glimmer/dsl/top_level_expression'
|
24
|
+
require 'glimmer/dsl/observe_expression'
|
25
|
+
|
26
|
+
module Glimmer
|
27
|
+
module DSL
|
28
|
+
module SWT
|
29
|
+
class ObserveExpression < StaticExpression
|
30
|
+
include TopLevelExpression
|
31
|
+
include Glimmer::DSL::ObserveExpression
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (c) 2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/dsl/expression'
|
23
|
+
require 'glimmer/data_binding/model_binding'
|
24
|
+
require 'glimmer/data_binding/shine'
|
25
|
+
|
26
|
+
module Glimmer
|
27
|
+
module DSL
|
28
|
+
module Libui
|
29
|
+
class ShineDataBindingExpression < Expression
|
30
|
+
def can_interpret?(parent, keyword, *args, &block)
|
31
|
+
args.size == 0 and
|
32
|
+
block.nil? and
|
33
|
+
parent.respond_to?(keyword, *args, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def interpret(parent, keyword, *args, &block)
|
37
|
+
Glimmer::DataBinding::Shine.new(parent, keyword)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -19,7 +19,6 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
-
require 'glimmer/dsl/static_expression'
|
23
22
|
require 'glimmer/dsl/parent_expression'
|
24
23
|
require 'glimmer/libui/control_proxy/text_proxy'
|
25
24
|
require 'glimmer/libui/attributed_string'
|
@@ -27,14 +26,14 @@ require 'glimmer/libui/attributed_string'
|
|
27
26
|
module Glimmer
|
28
27
|
module DSL
|
29
28
|
module Libui
|
30
|
-
class StringExpression <
|
29
|
+
class StringExpression < Expression
|
31
30
|
include ParentExpression
|
32
31
|
|
33
32
|
def can_interpret?(parent, keyword, *args, &block)
|
34
|
-
|
33
|
+
keyword == 'string' and
|
35
34
|
(
|
36
35
|
parent.is_a?(Glimmer::LibUI::ControlProxy::TextProxy) or
|
37
|
-
parent.is_a?(Glimmer::LibUI::AttributedString)
|
36
|
+
(parent.is_a?(Glimmer::LibUI::AttributedString) and !args.empty?)
|
38
37
|
)
|
39
38
|
end
|
40
39
|
|
@@ -47,7 +46,7 @@ module Glimmer
|
|
47
46
|
end
|
48
47
|
|
49
48
|
def add_content(parent, keyword, *args, &block)
|
50
|
-
parent.post_add_content
|
49
|
+
parent.post_add_content(block)
|
51
50
|
end
|
52
51
|
end
|
53
52
|
end
|
@@ -27,7 +27,8 @@ require 'glimmer/libui/control_proxy/transformable'
|
|
27
27
|
module Glimmer
|
28
28
|
module LibUI
|
29
29
|
class AttributedString
|
30
|
-
attr_reader :
|
30
|
+
attr_reader :keyword, :parent_proxy, :args
|
31
|
+
attr_accessor :block
|
31
32
|
|
32
33
|
def initialize(keyword, parent_proxy, args, &block)
|
33
34
|
@keyword = keyword
|
@@ -115,10 +116,14 @@ module Glimmer
|
|
115
116
|
alias open_type_features= open_type_features
|
116
117
|
alias set_open_type_features open_type_features
|
117
118
|
|
118
|
-
def post_add_content
|
119
|
-
|
120
|
-
|
121
|
-
@
|
119
|
+
def post_add_content(block = nil)
|
120
|
+
block ||= @block
|
121
|
+
block_result = block&.call
|
122
|
+
unless @content_added
|
123
|
+
@string = block_result if block_result.is_a?(String)
|
124
|
+
@parent_proxy&.post_initialize_child(self)
|
125
|
+
@content_added = true
|
126
|
+
end
|
122
127
|
end
|
123
128
|
|
124
129
|
def post_initialize_child(child)
|
@@ -185,12 +190,20 @@ module Glimmer
|
|
185
190
|
end
|
186
191
|
|
187
192
|
def redraw
|
188
|
-
area_proxy&.
|
193
|
+
area_proxy&.redraw
|
194
|
+
end
|
195
|
+
|
196
|
+
def request_auto_redraw
|
197
|
+
area_proxy&.request_auto_redraw
|
189
198
|
end
|
190
199
|
|
191
200
|
def area_proxy
|
192
201
|
@parent_proxy.parent_proxy
|
193
202
|
end
|
203
|
+
|
204
|
+
def content(&block)
|
205
|
+
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::StringExpression.new, @keyword, &block)
|
206
|
+
end
|
194
207
|
end
|
195
208
|
end
|
196
209
|
end
|
@@ -86,14 +86,17 @@ module Glimmer
|
|
86
86
|
|
87
87
|
def post_add_content
|
88
88
|
unless parent_proxy.is_a?(Box)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
unless @content_added
|
90
|
+
original_parent_proxy = @parent_proxy
|
91
|
+
@vertical_box_parent_proxy = ControlProxy.create('vertical_box', parent_proxy, []) {} # block prevents calling post add content
|
92
|
+
append_properties.each do |property|
|
93
|
+
@vertical_box_parent_proxy.append_property(property, append_property(property))
|
94
|
+
end
|
95
|
+
@vertical_box_parent_proxy.post_add_content
|
96
|
+
@parent_proxy = @vertical_box_parent_proxy
|
97
|
+
@vertical_box_parent_proxy.post_initialize_child(self)
|
98
|
+
@content_added = true
|
93
99
|
end
|
94
|
-
@vertical_box_parent_proxy.post_add_content
|
95
|
-
@parent_proxy = @vertical_box_parent_proxy
|
96
|
-
@vertical_box_parent_proxy.post_initialize_child(self)
|
97
100
|
else
|
98
101
|
super
|
99
102
|
end
|
@@ -142,48 +145,51 @@ module Glimmer
|
|
142
145
|
end
|
143
146
|
|
144
147
|
def install_listeners
|
145
|
-
@
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
@area_handler.MouseEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_mouse_event|
|
153
|
-
area_mouse_event = ::LibUI::FFI::AreaMouseEvent.new(area_mouse_event)
|
154
|
-
area_mouse_event = area_mouse_event_hash(area_mouse_event)
|
155
|
-
on_mouse_event.each { |listener| listener.call(area_mouse_event)}
|
156
|
-
on_mouse_move.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:x].between?(0, area_mouse_event[:area_width]) && area_mouse_event[:y].between?(0, area_mouse_event[:area_height])
|
157
|
-
unless @last_area_mouse_event.nil?
|
158
|
-
on_mouse_down.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:down] > 0 && @last_area_mouse_event[:down] == 0
|
159
|
-
on_mouse_up.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:up] > 0 && @last_area_mouse_event[:up] == 0
|
160
|
-
on_mouse_drag_start.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0 && @last_area_mouse_event[:held] == 0
|
161
|
-
on_mouse_drag.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0
|
162
|
-
on_mouse_drop.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] == 0 && @last_area_mouse_event[:held] > 0
|
148
|
+
unless @listeners_installed
|
149
|
+
@area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params|
|
150
|
+
area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params)
|
151
|
+
area_draw_params = area_draw_params_hash(area_draw_params)
|
152
|
+
AreaProxy.current_area_draw_params = area_draw_params
|
153
|
+
draw(area_draw_params)
|
154
|
+
AreaProxy.current_area_draw_params = nil
|
163
155
|
end
|
164
|
-
@
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
156
|
+
@area_handler.MouseEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_mouse_event|
|
157
|
+
area_mouse_event = ::LibUI::FFI::AreaMouseEvent.new(area_mouse_event)
|
158
|
+
area_mouse_event = area_mouse_event_hash(area_mouse_event)
|
159
|
+
on_mouse_event.each { |listener| listener.call(area_mouse_event)}
|
160
|
+
on_mouse_move.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:x].between?(0, area_mouse_event[:area_width]) && area_mouse_event[:y].between?(0, area_mouse_event[:area_height])
|
161
|
+
unless @last_area_mouse_event.nil?
|
162
|
+
on_mouse_down.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:down] > 0 && @last_area_mouse_event[:down] == 0
|
163
|
+
on_mouse_up.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:up] > 0 && @last_area_mouse_event[:up] == 0
|
164
|
+
on_mouse_drag_start.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0 && @last_area_mouse_event[:held] == 0
|
165
|
+
on_mouse_drag.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0
|
166
|
+
on_mouse_drop.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] == 0 && @last_area_mouse_event[:held] > 0
|
167
|
+
end
|
168
|
+
@last_area_mouse_event = area_mouse_event
|
173
169
|
end
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
170
|
+
@area_handler.MouseCrossed = fiddle_closure_block_caller(0, [1, 1, 4]) do |_, _, left|
|
171
|
+
left = Glimmer::LibUI.integer_to_boolean(left)
|
172
|
+
on_mouse_crossed.each { |listener| listener.call(left) }
|
173
|
+
if left
|
174
|
+
on_mouse_exit.each { |listener| listener.call(left) }
|
175
|
+
else
|
176
|
+
on_mouse_enter.each { |listener| listener.call(left) }
|
177
|
+
end
|
178
|
+
end
|
179
|
+
@area_handler.DragBroken = fiddle_closure_block_caller(0, [1, 1]) do |_, _|
|
180
|
+
on_drag_broken.each { |listener| listener.call }
|
181
|
+
end
|
182
|
+
@area_handler.KeyEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_key_event|
|
183
|
+
area_key_event = ::LibUI::FFI::AreaKeyEvent.new(area_key_event)
|
184
|
+
area_key_event = area_key_event_hash(area_key_event)
|
185
|
+
on_key_event.each { |listener| listener.call(area_key_event) }
|
186
|
+
if area_key_event[:up]
|
187
|
+
on_key_up.each { |listener| listener.call(area_key_event) }
|
188
|
+
else
|
189
|
+
on_key_down.each { |listener| listener.call(area_key_event) }
|
190
|
+
end
|
186
191
|
end
|
192
|
+
@listeners_installed = true
|
187
193
|
end
|
188
194
|
end
|
189
195
|
|
@@ -56,9 +56,8 @@ module Glimmer
|
|
56
56
|
draw(AreaProxy.current_area_draw_params)
|
57
57
|
destroy
|
58
58
|
end
|
59
|
-
@content_added = true
|
60
59
|
else # image object not control
|
61
|
-
build_control
|
60
|
+
build_control unless @content_added
|
62
61
|
super
|
63
62
|
end
|
64
63
|
end
|
@@ -68,7 +67,7 @@ module Glimmer
|
|
68
67
|
@args[0]
|
69
68
|
else
|
70
69
|
@args[0] = value
|
71
|
-
if @content_added
|
70
|
+
if area_image? && @content_added
|
72
71
|
post_add_content
|
73
72
|
request_auto_redraw
|
74
73
|
end
|
@@ -167,8 +166,8 @@ module Glimmer
|
|
167
166
|
end
|
168
167
|
canvas.resample_nearest_neighbor!(width, height) if width && height
|
169
168
|
@data = canvas.to_rgba_stream
|
170
|
-
|
171
|
-
|
169
|
+
@args[1] = canvas.width
|
170
|
+
@args[2] = canvas.height
|
172
171
|
[@data, width, height]
|
173
172
|
end
|
174
173
|
|
@@ -136,7 +136,10 @@ module Glimmer
|
|
136
136
|
|
137
137
|
# Subclasses may override to perform post add_content work (normally must call super)
|
138
138
|
def post_add_content
|
139
|
-
@
|
139
|
+
unless @content_added
|
140
|
+
@parent_proxy&.post_initialize_child(self)
|
141
|
+
@content_added = true
|
142
|
+
end
|
140
143
|
end
|
141
144
|
|
142
145
|
# Subclasses may override to perform post initialization work on an added child
|
data/lib/glimmer/libui/shape.rb
CHANGED
@@ -79,8 +79,11 @@ module Glimmer
|
|
79
79
|
|
80
80
|
# Subclasses may override to perform post add_content work (normally must call super)
|
81
81
|
def post_add_content
|
82
|
-
@
|
83
|
-
|
82
|
+
unless @content_added
|
83
|
+
@parent&.post_initialize_child(self)
|
84
|
+
@parent.post_add_content if implicit_path? && dynamic?
|
85
|
+
@content_added = true
|
86
|
+
end
|
84
87
|
end
|
85
88
|
|
86
89
|
def post_initialize_child(child, add_child: true)
|
@@ -102,7 +105,7 @@ module Glimmer
|
|
102
105
|
end
|
103
106
|
|
104
107
|
def redraw
|
105
|
-
area_proxy&.
|
108
|
+
area_proxy&.redraw
|
106
109
|
end
|
107
110
|
|
108
111
|
def request_auto_redraw
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-libui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -64,14 +64,14 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.0.
|
67
|
+
version: 0.0.13
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.0.
|
74
|
+
version: 0.0.13
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: chunky_png
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -244,6 +244,7 @@ files:
|
|
244
244
|
- examples/basic_transform2.rb
|
245
245
|
- examples/basic_window.rb
|
246
246
|
- examples/basic_window2.rb
|
247
|
+
- examples/button_counter.rb
|
247
248
|
- examples/color_button.rb
|
248
249
|
- examples/color_the_circles.rb
|
249
250
|
- examples/control_gallery.rb
|
@@ -283,14 +284,18 @@ files:
|
|
283
284
|
- glimmer-dsl-libui.gemspec
|
284
285
|
- icons/glimmer.png
|
285
286
|
- lib/glimmer-dsl-libui.rb
|
287
|
+
- lib/glimmer/dsl/libui/bind_expression.rb
|
286
288
|
- lib/glimmer/dsl/libui/control_expression.rb
|
289
|
+
- lib/glimmer/dsl/libui/data_binding_expression.rb
|
287
290
|
- lib/glimmer/dsl/libui/dsl.rb
|
288
291
|
- lib/glimmer/dsl/libui/file_expression.rb
|
289
292
|
- lib/glimmer/dsl/libui/listener_expression.rb
|
293
|
+
- lib/glimmer/dsl/libui/observe_expression.rb
|
290
294
|
- lib/glimmer/dsl/libui/open_file_expression.rb
|
291
295
|
- lib/glimmer/dsl/libui/property_expression.rb
|
292
296
|
- lib/glimmer/dsl/libui/save_file_expression.rb
|
293
297
|
- lib/glimmer/dsl/libui/shape_expression.rb
|
298
|
+
- lib/glimmer/dsl/libui/shine_data_binding_expression.rb
|
294
299
|
- lib/glimmer/dsl/libui/string_expression.rb
|
295
300
|
- lib/glimmer/dsl/libui/tab_item_expression.rb
|
296
301
|
- lib/glimmer/fiddle_consumer.rb
|