glimmer-dsl-libui 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 68aa91e5f6012112c0ad1ad21492b650e63335ea60f3e2b0a9b7040e94b92030
4
+ data.tar.gz: ac76c9b9683c69422139b6957f0d966b7a870236408f096c89059b32ee1fa8b9
5
+ SHA512:
6
+ metadata.gz: 58115e4fba45bffea3cc5645285742e6a5d4d7b8a0e4515365cd722001b5c386e16ff126f9c3800caedfc95508402633af8be0c1644303eb5cae7499bdbc0bac
7
+ data.tar.gz: b656e89bf37d3e2743dfb5752cdb5e1f482f128b1c078346f8a70f1fdbf97ad38a708956f694a2171c83f3c83a20fe673b50508925a5f5da0540032d9bb5076b
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ ## 0.0.1
4
+
5
+ - LibUI general control and window support
6
+ - LibUI listener support
7
+ - LibUI property support
8
+ - girb (Glimmer IRB)
9
+ - Support examples/basic_window.rb
10
+ - Support examples/basic_button.rb
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
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.
data/README.md ADDED
@@ -0,0 +1,303 @@
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.0.1
2
+ ## Dependency-Free Ruby Desktop Development GUI Library
3
+ [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/ce2853efdbecf6ebdc73/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-libui/maintainability)
5
+ [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
+
7
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is a dependency-free Ruby desktop development GUI library. No need to pre-install any pre-requisites. Just install the gem and have platform-independent GUI that just works!
8
+
9
+ [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui) aims to provide a DSL similar to the [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) to enable more productive desktop development in Ruby with:
10
+ - Declarative DSL syntax that visually maps to the GUI widget hierarchy
11
+ - Convention over configuration via smart defaults and automation of low-level details
12
+ - Requiring the least amount of syntax possible to build GUI
13
+ - Bidirectional Data-Binding to declaratively wire and automatically synchronize GUI with Business Models
14
+ - Custom Widget support
15
+ - Scaffolding for new custom widgets, apps, and gems
16
+ - Native-Executable packaging on Mac, Windows, and Linux
17
+
18
+ ## Glimmer GUI DSL Concepts
19
+
20
+ The Glimmer GUI DSL provides a declarative syntax for [LibUI](https://github.com/kojix2/LibUI) that:
21
+ - Supports smart defaults (e.g. automatic `on_closing` listener that quits `window`)
22
+ - Automates wiring of widgets (e.g. `button` is automatically set as child of `window`)
23
+ - Hides lower-level details (e.g. `LibUI.main` loop is started automatically when triggering `show` on `window`)
24
+ - Nests widgets according to their visual hierarchy
25
+ - Requires the minimum amount of syntax needed to describe an app's GUI
26
+
27
+ The Glimmer GUI DSL follows these simple concepts in mapping from [LibUI](https://github.com/kojix2/LibUI) syntax:
28
+ - **Control**: [LibUI](https://github.com/kojix2/LibUI) controls may be declared by lower-case underscored name (aka keyword) (e.g. `window` or `button`). Behind the scenes, they are represented by keyword methods that map to corresponding `LibUI.new_keyword` methods receiving args (e.g. `window('hello world', 300, 200, 1)`).
29
+ - **Content/Properties/Listeners Block**: Any keyword may be optionally followed by a Ruby curly-brace multi-line-block containing nested controls (content) and/or properties (attributes) (e.g. `window('hello world', 300, 200, 1) {button('greet')}`). It optionally recives one arg representing the control (e.g. `button('greet') {|b| on_clicked { puts b.text}}`)
30
+ - **Property**: Control properties may be declared inside keyword blocks with lower-case underscored name followed by property value args (e.g. `title "hello world"` inside `group`). Behind the scenes, they properties correspond to `control_set_property` methods.
31
+ - **Listener**: Control listeners may be declared inside keyword blocks with listener lower-case underscored name beginning with `on_` and receiving required block handler (e.g. `on_clicked {puts 'clicked'}` inside `button`). Behind the scenes, they listeners correspond to `control_on_event` methods.
32
+
33
+ Example of an app written in [LibUI](https://github.com/kojix2/LibUI)'s procedural imperative syntax:
34
+
35
+ ```ruby
36
+ require 'libui'
37
+
38
+ UI = LibUI
39
+
40
+ UI.init
41
+
42
+ main_window = UI.new_window('hello world', 300, 200, 1)
43
+
44
+ UI.control_show(main_window)
45
+
46
+ UI.window_on_closing(main_window) do
47
+ puts 'Bye Bye'
48
+ UI.control_destroy(main_window)
49
+ UI.quit
50
+ 0
51
+ end
52
+
53
+ UI.main
54
+ UI.quit
55
+ ```
56
+
57
+ Example of the same app written in [Glimmer](https://github.com/AndyObtiva/glimmer) object-oriented declarative hierarchical syntax:
58
+
59
+ ```ruby
60
+ require 'glimmer-dsl-libui'
61
+
62
+ include Glimmer
63
+
64
+ window('hello world', 300, 200, 1) {
65
+ on_closing do
66
+ puts 'Bye Bye'
67
+ end
68
+ }.show
69
+ ```
70
+
71
+ ## Usage
72
+
73
+ Add `require 'glimmer-dsl-libui'` at the top, and then `include Glimmer` into the top-level main object for testing or into an actual class for serious usage.
74
+
75
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
76
+
77
+ ```ruby
78
+ require 'glimmer-dsl-libui'
79
+
80
+ class Application
81
+ include Glimmer
82
+
83
+ def launch
84
+ window('hello world', 300, 200, 1) {
85
+ button('Button') {
86
+ on_clicked do
87
+ puts 'Button Clicked'
88
+ end
89
+ }
90
+
91
+ on_closing do
92
+ puts 'Bye Bye'
93
+ end
94
+ }.show
95
+ end
96
+ end
97
+
98
+ Application.new.launch
99
+ ```
100
+
101
+ ## API
102
+
103
+ Any control returned by a Glimmer GUI DSL keyword declaration can be introspected for its properties and updated via object-oriented attributes (standard Ruby `attr`/`attr=` or `set_attr`).
104
+
105
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
106
+
107
+ ```ruby
108
+ w = window('hello world', 300, 200, 1)
109
+ puts w.title # => hello world
110
+ w.title = 'howdy'
111
+ puts w.title # => howdy
112
+ w.set_title 'aloha'
113
+ puts w.title # => aloha
114
+ ```
115
+
116
+ ## Girb (Glimmer IRB)
117
+
118
+ You can run the `girb` command (`bin/girb` if you cloned the project locally):
119
+
120
+ ```
121
+ girb
122
+ ```
123
+
124
+ This gives you `irb` with the `glimmer-dsl-libui` gem loaded and the `Glimmer` module mixed into the main object for easy experimentation with GUI.
125
+
126
+ Gotcha: On the Mac, when you close a window opened in `girb`, it remains open until you enter `exit` or open another GUI window.
127
+
128
+ ## Examples
129
+
130
+ These examples reimplement the ones in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the shorter Glimmer GUI DSL syntax.
131
+
132
+ ### Basic Window
133
+
134
+ [examples/basic_window.rb](examples/basic_window.rb)
135
+
136
+ Mac
137
+
138
+ ![glimmer-dsl-libui-basic-window-mac.png](images/glimmer-dsl-libui-basic-window-mac.png)
139
+
140
+ Linux
141
+
142
+ ![glimmer-dsl-libui-basic-window-linux.png](images/glimmer-dsl-libui-basic-window-linux.png)
143
+
144
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
145
+
146
+ ```ruby
147
+ require 'libui'
148
+
149
+ UI = LibUI
150
+
151
+ UI.init
152
+
153
+ main_window = UI.new_window('hello world', 300, 200, 1)
154
+
155
+ UI.control_show(main_window)
156
+
157
+ UI.window_on_closing(main_window) do
158
+ puts 'Bye Bye'
159
+ UI.control_destroy(main_window)
160
+ UI.quit
161
+ 0
162
+ end
163
+
164
+ UI.main
165
+ UI.quit
166
+ ```
167
+
168
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
169
+
170
+ ```ruby
171
+ require 'glimmer-dsl-libui'
172
+
173
+ include Glimmer
174
+
175
+ window('hello world', 300, 200, 1) {
176
+ on_closing do
177
+ puts 'Bye Bye'
178
+ end
179
+ }.show
180
+ ```
181
+
182
+ ### Basic Button
183
+
184
+ [examples/basic_button.rb](examples/basic_button.rb)
185
+
186
+ Mac
187
+
188
+ ![glimmer-dsl-libui-basic-button-mac.png](images/glimmer-dsl-libui-basic-button-mac.png)
189
+ ![glimmer-dsl-libui-basic-button-msg-box-mac.png](images/glimmer-dsl-libui-basic-button-msg-box-mac.png)
190
+
191
+ Linux
192
+
193
+ ![glimmer-dsl-libui-basic-button-linux.png](images/glimmer-dsl-libui-basic-button-linux.png)
194
+ ![glimmer-dsl-libui-basic-button-msg-box-linux.png](images/glimmer-dsl-libui-basic-button-msg-box-linux.png)
195
+
196
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
197
+
198
+ ```ruby
199
+ require 'libui'
200
+
201
+ UI = LibUI
202
+
203
+ UI.init
204
+
205
+ main_window = UI.new_window('hello world', 300, 200, 1)
206
+
207
+ button = UI.new_button('Button')
208
+
209
+ UI.button_on_clicked(button) do
210
+ UI.msg_box(main_window, 'Information', 'You clicked the button')
211
+ end
212
+
213
+ UI.window_on_closing(main_window) do
214
+ puts 'Bye Bye'
215
+ UI.control_destroy(main_window)
216
+ UI.quit
217
+ 0
218
+ end
219
+
220
+ UI.window_set_child(main_window, button)
221
+ UI.control_show(main_window)
222
+
223
+ UI.main
224
+ UI.quit
225
+ ```
226
+
227
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
228
+
229
+ ```ruby
230
+ require 'glimmer-dsl-libui'
231
+
232
+ include Glimmer
233
+
234
+ window('hello world', 300, 200, 1) { |w|
235
+ button('Button') {
236
+ on_clicked do
237
+ msg_box(w, 'Information', 'You clicked the button')
238
+ end
239
+ }
240
+
241
+ on_closing do
242
+ puts 'Bye Bye'
243
+ end
244
+ }.show
245
+ ```
246
+
247
+ ## Contributing to glimmer-dsl-libui
248
+
249
+ - Check out the latest master to make sure the feature hasn't been
250
+ implemented or the bug hasn't been fixed yet.
251
+ - Check out the issue tracker to make sure someone already hasn't
252
+ requested it and/or contributed it.
253
+ - Fork the project.
254
+ - Start a feature/bugfix branch.
255
+ - Commit and push until you are happy with your contribution.
256
+ - Make sure to add tests for it. This is important so I don't break it
257
+ in a future version unintentionally.
258
+ - Please try not to mess with the Rakefile, version, or history. If
259
+ you want to have your own version, or is otherwise necessary, that
260
+ is fine, but please isolate to its own commit so I can cherry-pick
261
+ around it.
262
+
263
+ ## Help
264
+
265
+ ### Issues
266
+
267
+ You may submit [issues](https://github.com/AndyObtiva/glimmer/issues) on [GitHub](https://github.com/AndyObtiva/glimmer/issues).
268
+
269
+ [Click here to submit an issue.](https://github.com/AndyObtiva/glimmer/issues)
270
+
271
+ ### Chat
272
+
273
+ If you need live help, try to [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
274
+
275
+ ## Process
276
+
277
+ [Glimmer Process](https://github.com/AndyObtiva/glimmer/blob/master/PROCESS.md)
278
+
279
+ ## Planned Features and Feature Suggestions
280
+
281
+ These features have been planned or suggested. You might see them in a future version of [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui). You are welcome to contribute more feature suggestions.
282
+
283
+ [TODO.md](TODO.md)
284
+
285
+ ## Change Log
286
+
287
+ [CHANGELOG.md](CHANGELOG.md)
288
+
289
+ ## Contributors
290
+
291
+ * [Andy Maleh](https://github.com/AndyObtiva) (Founder)
292
+
293
+ [Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer-dsl-libui/graphs/contributors)
294
+
295
+ ## License
296
+
297
+ [MIT](LICENSE.txt)
298
+
299
+ Copyright (c) 2021 Andy Maleh
300
+
301
+ --
302
+
303
+ [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 />](https://github.com/AndyObtiva/glimmer) Built for [Glimmer](https://github.com/AndyObtiva/glimmer) (DSL Framework).
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/girb ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2020-2021 Andy Maleh
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ # This script was written for Windows and Linux only
25
+
26
+ require_relative 'girb_runner'
27
+
28
+ require 'irb'
29
+
30
+ IRB.start('.')
@@ -0,0 +1,47 @@
1
+ # Copyright (c) 2020-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 'puts_debuggerer'
23
+ require 'fileutils'
24
+ require 'etc'
25
+
26
+ require_relative '../lib/glimmer-dsl-libui'
27
+
28
+ include Glimmer
29
+
30
+ GIRB_RUNNER_EXIT_FILE = "#{Etc.getpwuid.dir}/.girb_runner_exit"
31
+ FileUtils.rm_rf GIRB_RUNNER_EXIT_FILE
32
+
33
+ @exit_method = method(:exit)
34
+
35
+ @exit_girb_block = lambda do
36
+ FileUtils.touch GIRB_RUNNER_EXIT_FILE
37
+ end
38
+
39
+ def self.exit(*args)
40
+ @exit_girb_block.call
41
+ @exit_method.call(*args)
42
+ end
43
+
44
+ def self.quit(*args)
45
+ @exit_girb_block.call
46
+ @exit_method.call(*args)
47
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ window('hello world', 300, 200, 1) { |w|
8
+ button('Button') {
9
+ on_clicked do
10
+ msg_box(w, 'Information', 'You clicked the button')
11
+ end
12
+ }
13
+
14
+ on_closing do
15
+ puts 'Bye Bye'
16
+ end
17
+ }.show
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ window('hello world', 300, 200, 1) {
8
+ on_closing do
9
+ puts 'Bye Bye'
10
+ end
11
+ }.show
Binary file
@@ -0,0 +1,50 @@
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/dsl/parent_expression'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Libui
28
+ class ControlExpression < Expression
29
+ include ParentExpression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ Glimmer::LibUI::ControlProxy.control_exists?(keyword)
33
+ end
34
+
35
+ def interpret(parent, keyword, *args, &block)
36
+ Glimmer::LibUI::ControlProxy.create(keyword, parent, args, &block)
37
+ end
38
+
39
+ def add_content(parent, keyword, *args, &block)
40
+ super
41
+ parent.post_add_content
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ require 'glimmer/libui/control_proxy'
50
+ require 'glimmer/libui/window_proxy'
@@ -0,0 +1,50 @@
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/engine'
23
+ Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f}
24
+
25
+ # Glimmer DSL expression configuration module
26
+ #
27
+ # When DSL engine interprets an expression, it attempts to handle
28
+ # with expressions listed here in the order specified.
29
+
30
+ # Every expression has a corresponding Expression subclass
31
+ # in glimmer/dsl
32
+
33
+ module Glimmer
34
+ module DSL
35
+ module Libui
36
+ Engine.add_dynamic_expressions(
37
+ Libui,
38
+ # list_selection_data_binding
39
+ # data_binding
40
+ # block_attribute
41
+ # attribute
42
+ %w[
43
+ listener
44
+ property
45
+ control
46
+ ]
47
+ )
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
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/libui/control_proxy'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Libui
28
+ class ListenerExpression < Expression
29
+ def can_interpret?(parent, keyword, *args, &block)
30
+ parent.is_a?(Glimmer::LibUI::ControlProxy) and
31
+ block_given? and
32
+ parent.can_handle_listener?(keyword)
33
+ end
34
+
35
+ def interpret(parent, keyword, *args, &block)
36
+ parent.handle_listener(keyword, &block)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
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/libui/control_proxy'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Libui
28
+ class PropertyExpression < Expression
29
+ def can_interpret?(parent, keyword, *args, &block)
30
+ parent.is_a?(Glimmer::LibUI::ControlProxy) and
31
+ block.nil? and
32
+ parent.respond_to?(keyword, *args)
33
+ end
34
+
35
+ def interpret(parent, keyword, *args, &block)
36
+ parent.send(keyword, *args)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,121 @@
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
+ module Glimmer
23
+ module LibUI
24
+ # Proxy for LibUI Control objects
25
+ #
26
+ # Follows the Proxy Design Pattern
27
+ class ControlProxy
28
+ class << self
29
+ def control_exists?(keyword)
30
+ ::LibUI.respond_to?("new_#{keyword}") || ::LibUI.respond_to?(keyword)
31
+ end
32
+
33
+ def create(keyword, parent, args)
34
+ widget_proxy_class(keyword).new(keyword, parent, args)
35
+ end
36
+
37
+ def widget_proxy_class(keyword)
38
+ begin
39
+ class_name = "#{keyword.camelcase(:upper)}Proxy".to_sym
40
+ Glimmer::LibUI.const_get(class_name)
41
+ rescue
42
+ Glimmer::LibUI::ControlProxy
43
+ end
44
+ end
45
+ end
46
+
47
+ # libui returns the contained LibUI object
48
+ attr_reader :parent_proxy, :libui, :args, :keyword
49
+
50
+ def initialize(keyword, parent, args, &block)
51
+ @keyword = keyword
52
+ @parent_proxy = parent
53
+ @args = args
54
+ build_control
55
+ if @parent_proxy.is_a?(WindowProxy)
56
+ ::LibUI.window_set_child(@parent_proxy.libui, @libui)
57
+ end
58
+ end
59
+
60
+ def post_add_content
61
+ # No Op by default
62
+ end
63
+
64
+ def can_handle_listener?(listener_name)
65
+ ::LibUI.respond_to?("control_#{listener_name}") || ::LibUI.respond_to?("#{@keyword}_#{listener_name}")
66
+ end
67
+
68
+ def handle_listener(listener_name, &listener)
69
+ if ::LibUI.respond_to?("control_#{listener_name}")
70
+ ::LibUI.send("control_#{listener_name}", @libui, &listener)
71
+ elsif ::LibUI.respond_to?("#{@keyword}_#{listener_name}")
72
+ ::LibUI.send("#{@keyword}_#{listener_name}", @libui, &listener)
73
+ end
74
+ end
75
+
76
+ def respond_to?(method_name, *args, &block)
77
+ respond_to_libui?(method_name, *args, &block) || super
78
+ end
79
+
80
+ def respond_to_libui?(method_name, *args, &block)
81
+ ::LibUI.respond_to?("control_#{method_name}") ||
82
+ ::LibUI.respond_to?("#{@keyword}_#{method_name}") ||
83
+ ::LibUI.respond_to?("#{@keyword}_set_#{method_name}") ||
84
+ ::LibUI.respond_to?("#{@keyword}_set_#{method_name.to_s.sub(/=$/, '')}")
85
+ end
86
+
87
+ def method_missing(method_name, *args, &block)
88
+ if respond_to_libui?(method_name, *args, &block)
89
+ send_to_libui(method_name, *args, &block)
90
+ else
91
+ super
92
+ end
93
+ end
94
+
95
+ def send_to_libui(method_name, *args, &block)
96
+ if ::LibUI.respond_to?("control_#{method_name}")
97
+ ::LibUI.send("control_#{method_name}", @libui, *args)
98
+ elsif ::LibUI.respond_to?("#{@keyword}_#{method_name}") && args.empty?
99
+ ::LibUI.send("#{@keyword}_#{method_name}", @libui, *args)
100
+ elsif ::LibUI.respond_to?("#{@keyword}_set_#{method_name}") && !args.empty?
101
+ ::LibUI.send("#{@keyword}_set_#{method_name}", @libui, *args)
102
+ elsif ::LibUI.respond_to?("#{@keyword}_set_#{method_name.to_s.sub(/=$/, '')}") && !args.empty?
103
+ ::LibUI.send("#{@keyword}_set_#{method_name.to_s.sub(/=$/, '')}", @libui, *args)
104
+ elsif ::LibUI.respond_to?("#{@keyword}_#{method_name}") && method_name.start_with?('set_') && !args.empty?
105
+ ::LibUI.send("#{@keyword}_#{method_name}", @libui, *args)
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ def build_control
112
+ @libui ||= if ::LibUI.respond_to?("new_#{keyword}")
113
+ ::LibUI.send("new_#{@keyword}", *@args)
114
+ elsif ::LibUI.respond_to?(keyword)
115
+ @args[0] = @args.first.libui if @args.first.is_a?(ControlProxy)
116
+ ::LibUI.send(@keyword, *@args)
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,68 @@
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/libui/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI Window objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class WindowProxy < ControlProxy
30
+ def show
31
+ send_to_libui('show')
32
+ unless @shown_at_least_once
33
+ @shown_at_least_once = true
34
+ ::LibUI.main
35
+ end
36
+ end
37
+
38
+ def handle_listener(listener_name, &listener)
39
+ if listener_name == 'on_closing'
40
+ default_behavior_listener = Proc.new do
41
+ return_value = listener.call
42
+ if return_value.is_a?(Numeric)
43
+ return_value
44
+ else
45
+ destroy
46
+ ::LibUI.quit
47
+ 0
48
+ end
49
+ end
50
+ end
51
+ super(listener_name, &default_behavior_listener)
52
+ end
53
+
54
+ private
55
+
56
+ def build_control
57
+ ::LibUI.init
58
+ super.tap do
59
+ handle_listener('on_closing') do
60
+ destroy
61
+ ::LibUI.quit
62
+ 0
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,40 @@
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
+ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
23
+
24
+ # External requires
25
+ require 'glimmer'
26
+ # require 'logging'
27
+ # require 'puts_debuggerer' if ENV['pd'].to_s.downcase == 'true'
28
+ # require 'super_module'
29
+ require 'libui'
30
+
31
+ # Internal requires
32
+ # require 'ext/glimmer/config'
33
+ # require 'ext/glimmer'
34
+ require 'glimmer/dsl/libui/dsl'
35
+ Glimmer::Config.loop_max_count = -1
36
+ Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
37
+ method = method_symbol.to_s
38
+ result = false
39
+ result ||= method == 'load_iseq'
40
+ end
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glimmer-dsl-libui
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andy Maleh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: glimmer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: libui
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.9
41
+ - !ruby/object:Gem::Dependency
42
+ name: juwelier
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.4.9
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 3.0.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.4.9
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 3.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake-tui
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 0.2.1
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 0.2.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: puts_debuggerer
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.13.1
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.13.1
103
+ - !ruby/object:Gem::Dependency
104
+ name: coveralls
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.8.23
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '='
115
+ - !ruby/object:Gem::Version
116
+ version: 0.8.23
117
+ - !ruby/object:Gem::Dependency
118
+ name: simplecov
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.16.1
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.16.1
131
+ - !ruby/object:Gem::Dependency
132
+ name: simplecov-lcov
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 0.7.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 0.7.0
145
+ description: Dependency-Free Ruby Desktop Development GUI Library (no need to pre-install
146
+ any pre-requisites. Just install the gem and have platform-independent GUI that
147
+ just works)
148
+ email: andy.am@gmail.com
149
+ executables:
150
+ - girb
151
+ extensions: []
152
+ extra_rdoc_files:
153
+ - CHANGELOG.md
154
+ - LICENSE.txt
155
+ - README.md
156
+ files:
157
+ - CHANGELOG.md
158
+ - LICENSE.txt
159
+ - README.md
160
+ - VERSION
161
+ - bin/girb
162
+ - bin/girb_runner.rb
163
+ - examples/basic_button.rb
164
+ - examples/basic_window.rb
165
+ - glimmer-dsl-libui.gemspec
166
+ - lib/glimmer-dsl-libui.rb
167
+ - lib/glimmer/dsl/libui/control_expression.rb
168
+ - lib/glimmer/dsl/libui/dsl.rb
169
+ - lib/glimmer/dsl/libui/listener_expression.rb
170
+ - lib/glimmer/dsl/libui/property_expression.rb
171
+ - lib/glimmer/libui/control_proxy.rb
172
+ - lib/glimmer/libui/window_proxy.rb
173
+ homepage: http://github.com/AndyObtiva/glimmer-dsl-libui
174
+ licenses:
175
+ - MIT
176
+ metadata: {}
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ - "."
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubygems_version: 3.2.22
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: Glimmer DSL for LibUI
197
+ test_files: []