glimmer-dsl-libui 0.0.8 → 0.0.12
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 +23 -0
- data/README.md +261 -19
- data/VERSION +1 -1
- data/examples/basic_window2.rb +1 -1
- data/examples/color_button.rb +14 -0
- data/examples/font_button.rb +18 -0
- data/examples/meta_example.rb +68 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/box.rb +10 -0
- data/lib/glimmer/libui/color_button_proxy.rb +64 -0
- data/lib/glimmer/libui/control_proxy.rb +23 -7
- data/lib/glimmer/libui/font_button_proxy.rb +68 -0
- data/lib/glimmer/libui/group_proxy.rb +5 -0
- data/lib/glimmer/libui/window_proxy.rb +10 -1
- data/lib/glimmer-dsl-libui.rb +1 -0
- metadata +27 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8be478e9d224fabeac6b2d42b7ccae6f7063491c88b1ea14e90cf1665e379bdf
|
4
|
+
data.tar.gz: b8b9b58fe072ec1973263ae20dbbe5407d7dceb30290420dd6734397cd850918
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 534bf3ffa94019746c5a1291af5d8a676766221ea299e627cbb38dd1e3814f941688b8cf0182f243b942e73180f2f642c93598ca4d03a3a2df36cc249459316a
|
7
|
+
data.tar.gz: 3d6a77dcaffdedc6149d2efdb05df1e01f6499114054d5d43f83d576abeed0791d7cc6138335087fbfbd4d29bd481b1c016e71fe4c40af963218fd6e5227b3be
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.12
|
4
|
+
|
5
|
+
- Have examples/meta_example.rb allow code editing to enable experimentation and learning
|
6
|
+
- Fix issue with examples/meta_example using puts_debuggerer (a development gem)
|
7
|
+
|
8
|
+
## 0.0.11
|
9
|
+
|
10
|
+
- New examples/basic_color.rb
|
11
|
+
- Support `color_button` `color` property
|
12
|
+
- Proper destroy of controls (deleting from parent `box`, `window`, or `group` first)
|
13
|
+
- On the Mac only, if no menu is specified, add a Quit menu item automatically to allow quitting with CMD+Q
|
14
|
+
|
15
|
+
## 0.0.10
|
16
|
+
|
17
|
+
- Support examples/font_button.rb
|
18
|
+
- Support `font_button` control
|
19
|
+
- Add File -> Quit menu item to examples/meta_example.rb
|
20
|
+
- Glimmer Style Guide added to README.md
|
21
|
+
|
22
|
+
## 0.0.9
|
23
|
+
|
24
|
+
- Build a meta-example (example of examples)
|
25
|
+
|
3
26
|
## 0.0.8
|
4
27
|
|
5
28
|
- Add `?` suffixed aliases to all boolean property methods
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
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
|
+
# [<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.12
|
2
2
|
## Prerequisite-Free Ruby Desktop Development GUI Library
|
3
3
|
[](http://badge.fury.io/rb/glimmer-dsl-libui)
|
4
4
|
[](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-libui/maintainability)
|
@@ -6,18 +6,18 @@
|
|
6
6
|
|
7
7
|
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [LibUI](https://github.com/kojix2/LibUI) is a prerequisite-free Ruby desktop development GUI library. No need to pre-install any prerequisites. Just install the gem and have platform-independent native GUI that just works!
|
8
8
|
|
9
|
-
[LibUI](https://github.com/kojix2/LibUI) is a thin [Ruby](https://www.ruby-lang.org/en/) wrapper around [libui](https://github.com/andlabs/libui), a relatively new C GUI library that renders native
|
9
|
+
[LibUI](https://github.com/kojix2/LibUI) is a thin [Ruby](https://www.ruby-lang.org/en/) wrapper around [libui](https://github.com/andlabs/libui), a relatively new C GUI library that renders native controls on every platform (similar to [SWT](https://www.eclipse.org/swt/), but without the heavy weight of the [Java Virtual Machine](https://www.java.com/en/)).
|
10
10
|
|
11
11
|
The main trade-off in using [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) as opposed to [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) or [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk) is the fact that [SWT](https://www.eclipse.org/swt/) and [Tk](https://www.tcl.tk/) are more mature than mid-alpha [libui](https://github.com/andlabs/libui) as GUI toolkits. Still, if there is only a need to build a small simple application, [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) could be a good convenient choice due to having zero prerequisites beyond the dependencies included in the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui). Also, just like [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk), its apps start instantly and have a small memory footprint. [LibUI](https://github.com/kojix2/LibUI) is a promising new GUI toolkit that might prove quite worthy in the future.
|
12
12
|
|
13
13
|
[Glimmer DSL for LibUI](https://rubygems.org/gems/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:
|
14
|
-
- Declarative DSL syntax that visually maps to the GUI
|
14
|
+
- Declarative DSL syntax that visually maps to the GUI control hierarchy
|
15
15
|
- Convention over configuration via smart defaults and automation of low-level details
|
16
16
|
- Requiring the least amount of syntax possible to build GUI
|
17
17
|
- Bidirectional Data-Binding to declaratively wire and automatically synchronize GUI with Business Models
|
18
|
-
- Custom
|
19
|
-
- Scaffolding for new custom
|
20
|
-
- Native-Executable packaging on Mac, Windows, and Linux
|
18
|
+
- Custom Control support
|
19
|
+
- Scaffolding for new custom controls, apps, and gems
|
20
|
+
- Native-Executable packaging on Mac, Windows, and Linux.
|
21
21
|
|
22
22
|
Example:
|
23
23
|
|
@@ -43,7 +43,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
|
|
43
43
|
|
44
44
|
## Table of Contents
|
45
45
|
|
46
|
-
- [Glimmer DSL for LibUI 0.0.
|
46
|
+
- [Glimmer DSL for LibUI 0.0.12](#-glimmer-dsl-for-libui-0012)
|
47
47
|
- [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
|
48
48
|
- [Usage](#usage)
|
49
49
|
- [API](#api)
|
@@ -54,6 +54,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
|
|
54
54
|
- [Extra Operations](#extra-operations)
|
55
55
|
- [Smart Defaults and Conventions](#smart-defaults-and-conventions)
|
56
56
|
- [Original API](#original-api)
|
57
|
+
- [Glimmer Style Guide](#glimmer-style-guide)
|
57
58
|
- [Girb (Glimmer IRB)](#girb-glimmer-irb)
|
58
59
|
- [Examples](#examples)
|
59
60
|
- [Basic Window](#basic-window)
|
@@ -62,6 +63,8 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
|
|
62
63
|
- [Simple Notepad](#simple-notepad)
|
63
64
|
- [Midi Player](#midi-player)
|
64
65
|
- [Control Gallery](#control-gallery)
|
66
|
+
- [Font Button](#font-button)
|
67
|
+
- [Color Button](#color-button)
|
65
68
|
- [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
|
66
69
|
- [Help](#help)
|
67
70
|
- [Issues](#issues)
|
@@ -76,9 +79,9 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
|
|
76
79
|
|
77
80
|
The Glimmer GUI DSL provides object-oriented declarative hierarchical syntax for [LibUI](https://github.com/kojix2/LibUI) that:
|
78
81
|
- Supports smart defaults (e.g. automatic `on_closing` listener that quits `window`)
|
79
|
-
- Automates wiring of
|
82
|
+
- Automates wiring of controls (e.g. `button` is automatically set as child of `window`)
|
80
83
|
- Hides lower-level details (e.g. `LibUI.main` loop is started automatically when triggering `show` on `window`)
|
81
|
-
- Nests
|
84
|
+
- Nests controls according to their visual hierarchy
|
82
85
|
- Requires the minimum amount of syntax needed to describe an app's GUI
|
83
86
|
|
84
87
|
The Glimmer GUI DSL follows these simple concepts in mapping from [LibUI](https://github.com/kojix2/LibUI) syntax:
|
@@ -149,7 +152,7 @@ gem install glimmer-dsl-libui
|
|
149
152
|
Or install via Bundler `Gemfile`:
|
150
153
|
|
151
154
|
```ruby
|
152
|
-
gem 'glimmer-dsl-libui', '~> 0.0.
|
155
|
+
gem 'glimmer-dsl-libui', '~> 0.0.12'
|
153
156
|
```
|
154
157
|
|
155
158
|
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.
|
@@ -208,12 +211,12 @@ Control(Args) | Properties | Listeners
|
|
208
211
|
`button(text as String)` | `text` (`String`) | `on_clicked`
|
209
212
|
`checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
|
210
213
|
`combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
|
211
|
-
`color_button` | `color` (
|
214
|
+
`color_button` | `color` (Array of `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float`), `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float` | `on_changed`
|
212
215
|
`date_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
|
213
216
|
`date_time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
|
214
217
|
`editable_combobox` | `items` (`Array` of `String`), `text` (`String`) | `on_changed`
|
215
218
|
`entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
|
216
|
-
`font_button` | `font` (`
|
219
|
+
`font_button` | `font` [read-only] (`Hash` of keys: `:family`, `:size`, `:weight`, `:italic`, `:stretch`), `family` as `String`, `size` as `Float`, `weight` as `Integer`, `italic` as `Integer`, `stretch` as `Integer` | `on_changed`
|
217
220
|
`group(text as String)` | `margined` (Boolean), `title` (`String`) | None
|
218
221
|
`horizontal_box` | `padded` (Boolean) | None
|
219
222
|
`horizontal_separator` | None | None
|
@@ -265,9 +268,9 @@ Control(Args) | Properties | Listeners
|
|
265
268
|
|
266
269
|
### Smart Defaults and Conventions
|
267
270
|
|
268
|
-
- `horizontal_box` and `vertical_box` controls have `padded` as `
|
269
|
-
- `group` controls have `margined` as `
|
270
|
-
- All controls nested under a `horizontal_box` or `vertical_box` have `stretchy` property (passed to `box_append` method) as `
|
271
|
+
- `horizontal_box` and `vertical_box` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
|
272
|
+
- `group` controls have `margined` as `true` upon instantiation to ensure more user-friendly GUI by default
|
273
|
+
- All controls nested under a `horizontal_box` or `vertical_box` have `stretchy` property (passed to `box_append` method) as `true` by default (filling maximum space)
|
271
274
|
- `window` constructor args can be left off and have the following defaults when unspecified: `title` as `'Glimmer'`, `width` as `150`, `height` as `150`, and `has_menubar` as `true`)
|
272
275
|
- `window` has an `on_closing` listener by default that quits application upon hitting the close button (can be overridden with a manual `on_closing` implementation that returns integer `0` for success)
|
273
276
|
- `quit_menu_item` has an `on_clicked` listener by default that quits application upon selecting the quit menu item (can be overridden with a manual `on_clicked` implementation that returns integer `0` for success)
|
@@ -276,12 +279,26 @@ Control(Args) | Properties | Listeners
|
|
276
279
|
- All boolean property readers return `true` or `false` in Ruby instead of the [libui](https://github.com/andlabs/libui) original `0` or `1` in C.
|
277
280
|
- All boolean property writers accept `true`/`false` in addition to `1`/`0` in Ruby
|
278
281
|
- All string property readers return a `String` object in Ruby instead of the [libui](https://github.com/andlabs/libui) Fiddle pointer object.
|
282
|
+
- Automatically allocate font descriptors upon instantiating `font_button` controls and free them when destorying `font_button` controls
|
283
|
+
- Automatically allocate color value pointers upon instantiating `color_button` controls and free them when destorying `color_button` controls
|
284
|
+
- On the Mac, if no `menu` items were added, an automatic `quit_menu_item` is added to enable quitting with CTRL+Q
|
285
|
+
- When destroying a control nested under a `horizontal_box` or `vertical_box`, it is automatically deleted from the box's children
|
286
|
+
- When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
|
279
287
|
|
280
288
|
### Original API
|
281
289
|
|
282
290
|
To learn more about the [LibUI](https://github.com/kojix2/LibUI) API exposed through [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui),
|
283
291
|
check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.h)
|
284
292
|
|
293
|
+
## Glimmer Style Guide
|
294
|
+
|
295
|
+
- Control arguments are always wrapped by parentheses
|
296
|
+
- Control blocks are always declared with curly braces to clearly visualize hierarchical view code and separate from logic code
|
297
|
+
- Control property declarations always have arguments and never take a block
|
298
|
+
- Control property arguments are never wrapped inside parentheses
|
299
|
+
- Control listeners are always declared starting with on_ prefix and affixing listener event method name afterwards in underscored lowercase form. Their multi-line blocks have a `do; end` style.
|
300
|
+
- Pure logic multi-line blocks that do not constitute GUI DSL view elements have `do; end` style to clearly separate logic code from view code.
|
301
|
+
|
285
302
|
## Girb (Glimmer IRB)
|
286
303
|
|
287
304
|
You can run the `girb` command (`bin/girb` if you cloned the project locally):
|
@@ -296,7 +313,103 @@ Gotcha: On the Mac, when you close a window opened in `girb`, it remains open un
|
|
296
313
|
|
297
314
|
## Examples
|
298
315
|
|
299
|
-
These examples
|
316
|
+
These examples include reimplementions of the examples in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) as well as brand new examples.
|
317
|
+
|
318
|
+
To browse all examples, simply launch the [Meta-Example](examples/meta_example.rb), which lists all examples and displays each example's code when selected. It also enables code editing to facilitate experimentation and learning.
|
319
|
+
|
320
|
+
[examples/meta_example.rb](examples/meta_example.rb)
|
321
|
+
|
322
|
+
Run with this command from the root of the project if you cloned the project:
|
323
|
+
|
324
|
+
```
|
325
|
+
ruby -r './lib/glimmer-dsl-libui' examples/meta_example.rb
|
326
|
+
```
|
327
|
+
|
328
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
329
|
+
|
330
|
+
```
|
331
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/meta_example'"
|
332
|
+
```
|
333
|
+
|
334
|
+
Mac
|
335
|
+
|
336
|
+

|
337
|
+
|
338
|
+
Linux
|
339
|
+
|
340
|
+

|
341
|
+
|
342
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
343
|
+
|
344
|
+
```ruby
|
345
|
+
require 'glimmer-dsl-libui'
|
346
|
+
require 'facets'
|
347
|
+
|
348
|
+
class MetaExample
|
349
|
+
include Glimmer
|
350
|
+
|
351
|
+
def examples
|
352
|
+
if @examples.nil?
|
353
|
+
example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '**', '*.rb'))
|
354
|
+
example_file_names = example_files.map { |f| File.basename(f, '.rb') }
|
355
|
+
example_file_names = example_file_names.reject { |f| f == 'meta_example' }
|
356
|
+
@examples = example_file_names.map { |f| f.underscore.titlecase }
|
357
|
+
end
|
358
|
+
@examples
|
359
|
+
end
|
360
|
+
|
361
|
+
def file_path_for(example)
|
362
|
+
File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
|
363
|
+
end
|
364
|
+
|
365
|
+
def glimmer_dsl_libui_file
|
366
|
+
File.expand_path('../lib/glimmer-dsl-libui', __dir__)
|
367
|
+
end
|
368
|
+
|
369
|
+
def launch
|
370
|
+
window('Meta-Example', 700, 500) { |w|
|
371
|
+
margined true
|
372
|
+
|
373
|
+
horizontal_box {
|
374
|
+
vertical_box {
|
375
|
+
@rbs = radio_buttons {
|
376
|
+
stretchy false
|
377
|
+
items examples
|
378
|
+
selected 0
|
379
|
+
|
380
|
+
on_selected do
|
381
|
+
@nwme.text = File.read(file_path_for(@examples[@rbs.selected]))
|
382
|
+
end
|
383
|
+
}
|
384
|
+
button('Launch') {
|
385
|
+
stretchy false
|
386
|
+
|
387
|
+
on_clicked do
|
388
|
+
begin
|
389
|
+
meta_example_file = File.join(Dir.home, '.meta_example.rb')
|
390
|
+
File.write(meta_example_file, @nwme.text)
|
391
|
+
result = `ruby -r #{glimmer_dsl_libui_file} #{meta_example_file} 2>&1`
|
392
|
+
msg_box(w, 'Error Running Example', result) if result.include?('error')
|
393
|
+
rescue => e
|
394
|
+
puts 'Unable to write code changes! Running original example...'
|
395
|
+
system "ruby -r #{glimmer_dsl_libui_file} #{file_path_for(@examples[@rbs.selected])}"
|
396
|
+
end
|
397
|
+
end
|
398
|
+
}
|
399
|
+
}
|
400
|
+
vertical_box {
|
401
|
+
@nwme = non_wrapping_multiline_entry {
|
402
|
+
text File.read(file_path_for(@examples[@rbs.selected]))
|
403
|
+
}
|
404
|
+
}
|
405
|
+
}
|
406
|
+
}.show
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
MetaExample.new.launch
|
411
|
+
```
|
412
|
+
|
300
413
|
|
301
414
|
### Basic Window
|
302
415
|
|
@@ -379,7 +492,7 @@ ruby -r glimmer-dsl-libui -e "require 'examples/basic_button'"
|
|
379
492
|
Mac
|
380
493
|
|
381
494
|

|
382
|
-

|
495
|
+

|
383
496
|
|
384
497
|
Linux
|
385
498
|
|
@@ -424,7 +537,7 @@ require 'glimmer-dsl-libui'
|
|
424
537
|
|
425
538
|
include Glimmer
|
426
539
|
|
427
|
-
window('hello world', 300, 200) { |w|
|
540
|
+
window('hello world', 300, 200, true) { |w|
|
428
541
|
button('Button') {
|
429
542
|
on_clicked do
|
430
543
|
msg_box(w, 'Information', 'You clicked the button')
|
@@ -444,7 +557,7 @@ require 'glimmer-dsl-libui'
|
|
444
557
|
|
445
558
|
include Glimmer
|
446
559
|
|
447
|
-
window { # args can
|
560
|
+
window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
|
448
561
|
title 'hello world'
|
449
562
|
content_size 300, 200
|
450
563
|
|
@@ -1239,6 +1352,135 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
|
|
1239
1352
|
MAIN_WINDOW.show
|
1240
1353
|
```
|
1241
1354
|
|
1355
|
+
### Font Button
|
1356
|
+
|
1357
|
+
[examples/font_button.rb](examples/font_button.rb)
|
1358
|
+
|
1359
|
+
Run with this command from the root of the project if you cloned the project:
|
1360
|
+
|
1361
|
+
```
|
1362
|
+
ruby -r './lib/glimmer-dsl-libui' examples/font_button.rb
|
1363
|
+
```
|
1364
|
+
|
1365
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
1366
|
+
|
1367
|
+
```
|
1368
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/font_button'"
|
1369
|
+
```
|
1370
|
+
|
1371
|
+
Mac
|
1372
|
+
|
1373
|
+

|
1374
|
+

|
1375
|
+
|
1376
|
+
Linux
|
1377
|
+
|
1378
|
+

|
1379
|
+

|
1380
|
+
|
1381
|
+
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
1382
|
+
|
1383
|
+
```ruby
|
1384
|
+
require 'libui'
|
1385
|
+
|
1386
|
+
UI = LibUI
|
1387
|
+
|
1388
|
+
UI.init
|
1389
|
+
|
1390
|
+
main_window = UI.new_window('hello world', 300, 200, 1)
|
1391
|
+
|
1392
|
+
font_button = UI.new_font_button
|
1393
|
+
font_descriptor = UI::FFI::FontDescriptor.malloc
|
1394
|
+
UI.font_button_on_changed(font_button) do
|
1395
|
+
UI.font_button_font(font_button, font_descriptor)
|
1396
|
+
p family: font_descriptor.Family.to_s,
|
1397
|
+
size: font_descriptor.Size,
|
1398
|
+
weight: font_descriptor.Weight,
|
1399
|
+
italic: font_descriptor.Italic,
|
1400
|
+
stretch: font_descriptor.Stretch
|
1401
|
+
end
|
1402
|
+
|
1403
|
+
UI.window_on_closing(main_window) do
|
1404
|
+
puts 'Bye Bye'
|
1405
|
+
UI.control_destroy(main_window)
|
1406
|
+
UI.quit
|
1407
|
+
0
|
1408
|
+
end
|
1409
|
+
|
1410
|
+
UI.window_set_child(main_window, font_button)
|
1411
|
+
UI.control_show(main_window)
|
1412
|
+
|
1413
|
+
UI.main
|
1414
|
+
UI.quit
|
1415
|
+
|
1416
|
+
```
|
1417
|
+
|
1418
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
1419
|
+
|
1420
|
+
```ruby
|
1421
|
+
require 'glimmer-dsl-libui'
|
1422
|
+
|
1423
|
+
include Glimmer
|
1424
|
+
|
1425
|
+
window('hello world', 300, 200) {
|
1426
|
+
font_button { |fb|
|
1427
|
+
on_changed do
|
1428
|
+
font_descriptor = fb.font
|
1429
|
+
p font_descriptor
|
1430
|
+
end
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
on_closing do
|
1434
|
+
puts 'Bye Bye'
|
1435
|
+
end
|
1436
|
+
}.show
|
1437
|
+
```
|
1438
|
+
|
1439
|
+
### Color Button
|
1440
|
+
|
1441
|
+
[examples/color_button.rb](examples/color_button.rb)
|
1442
|
+
|
1443
|
+
Run with this command from the root of the project if you cloned the project:
|
1444
|
+
|
1445
|
+
```
|
1446
|
+
ruby -r './lib/glimmer-dsl-libui' examples/color_button.rb
|
1447
|
+
```
|
1448
|
+
|
1449
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
1450
|
+
|
1451
|
+
```
|
1452
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/color_button'"
|
1453
|
+
```
|
1454
|
+
|
1455
|
+
Mac
|
1456
|
+
|
1457
|
+

|
1458
|
+

|
1459
|
+
|
1460
|
+
Linux
|
1461
|
+
|
1462
|
+

|
1463
|
+

|
1464
|
+
|
1465
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
1466
|
+
|
1467
|
+
```ruby
|
1468
|
+
# frozen_string_literal: true
|
1469
|
+
|
1470
|
+
require 'glimmer-dsl-libui'
|
1471
|
+
|
1472
|
+
include Glimmer
|
1473
|
+
|
1474
|
+
window('color button', 230) {
|
1475
|
+
color_button { |cb|
|
1476
|
+
on_changed do
|
1477
|
+
rgba = cb.color
|
1478
|
+
p rgba
|
1479
|
+
end
|
1480
|
+
}
|
1481
|
+
}.show
|
1482
|
+
```
|
1483
|
+
|
1242
1484
|
## Contributing to glimmer-dsl-libui
|
1243
1485
|
|
1244
1486
|
- Check out the latest master to make sure the feature hasn't been
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
data/examples/basic_window2.rb
CHANGED
@@ -4,7 +4,7 @@ require 'glimmer-dsl-libui'
|
|
4
4
|
|
5
5
|
include Glimmer
|
6
6
|
|
7
|
-
window { # args can
|
7
|
+
window { # first 3 args can be set via properties with 4th arg has_menubar=true by default
|
8
8
|
title 'hello world'
|
9
9
|
content_size 300, 200
|
10
10
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
window('hello world', 300, 200) {
|
8
|
+
font_button { |fb|
|
9
|
+
on_changed do
|
10
|
+
font_descriptor = fb.font
|
11
|
+
p font_descriptor
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
on_closing do
|
16
|
+
puts 'Bye Bye'
|
17
|
+
end
|
18
|
+
}.show
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
require 'facets'
|
5
|
+
|
6
|
+
class MetaExample
|
7
|
+
include Glimmer
|
8
|
+
|
9
|
+
def examples
|
10
|
+
if @examples.nil?
|
11
|
+
example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '**', '*.rb'))
|
12
|
+
example_file_names = example_files.map { |f| File.basename(f, '.rb') }
|
13
|
+
example_file_names = example_file_names.reject { |f| f == 'meta_example' }
|
14
|
+
@examples = example_file_names.map { |f| f.underscore.titlecase }
|
15
|
+
end
|
16
|
+
@examples
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_path_for(example)
|
20
|
+
File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
|
21
|
+
end
|
22
|
+
|
23
|
+
def glimmer_dsl_libui_file
|
24
|
+
File.expand_path('../lib/glimmer-dsl-libui', __dir__)
|
25
|
+
end
|
26
|
+
|
27
|
+
def launch
|
28
|
+
window('Meta-Example', 700, 500) { |w|
|
29
|
+
margined true
|
30
|
+
|
31
|
+
horizontal_box {
|
32
|
+
vertical_box {
|
33
|
+
@rbs = radio_buttons {
|
34
|
+
stretchy false
|
35
|
+
items examples
|
36
|
+
selected 0
|
37
|
+
|
38
|
+
on_selected do
|
39
|
+
@nwme.text = File.read(file_path_for(@examples[@rbs.selected]))
|
40
|
+
end
|
41
|
+
}
|
42
|
+
button('Launch') {
|
43
|
+
stretchy false
|
44
|
+
|
45
|
+
on_clicked do
|
46
|
+
begin
|
47
|
+
meta_example_file = File.join(Dir.home, '.meta_example.rb')
|
48
|
+
File.write(meta_example_file, @nwme.text)
|
49
|
+
result = `ruby -r #{glimmer_dsl_libui_file} #{meta_example_file} 2>&1`
|
50
|
+
msg_box(w, 'Error Running Example', result) if result.include?('error')
|
51
|
+
rescue => e
|
52
|
+
puts 'Unable to write code changes! Running original example...'
|
53
|
+
system "ruby -r #{glimmer_dsl_libui_file} #{file_path_for(@examples[@rbs.selected])}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
}
|
57
|
+
}
|
58
|
+
vertical_box {
|
59
|
+
@nwme = non_wrapping_multiline_entry {
|
60
|
+
text File.read(file_path_for(@examples[@rbs.selected]))
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}.show
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
MetaExample.new.launch
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
data/lib/glimmer/libui/box.rb
CHANGED
@@ -29,12 +29,22 @@ module Glimmer
|
|
29
29
|
def post_initialize_child(child)
|
30
30
|
child.stretchy = true if child.stretchy.nil?
|
31
31
|
::LibUI.box_append(@libui, child.libui, ControlProxy.boolean_to_integer(child.stretchy))
|
32
|
+
children << child
|
32
33
|
end
|
33
34
|
|
34
35
|
def libui_api_keyword
|
35
36
|
'box'
|
36
37
|
end
|
37
38
|
|
39
|
+
def children
|
40
|
+
@children ||= []
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy_child(child)
|
44
|
+
::LibUI.send("box_delete", @libui, children.index(child))
|
45
|
+
ControlProxy.all_control_proxies.delete(child)
|
46
|
+
end
|
47
|
+
|
38
48
|
private
|
39
49
|
|
40
50
|
def build_control
|
@@ -0,0 +1,64 @@
|
|
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 color button objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class ColorButtonProxy < ControlProxy
|
30
|
+
def color
|
31
|
+
@red ||= Fiddle::Pointer.malloc(8) # double
|
32
|
+
@green ||= Fiddle::Pointer.malloc(8) # double
|
33
|
+
@blue ||= Fiddle::Pointer.malloc(8) # double
|
34
|
+
@alpha ||= Fiddle::Pointer.malloc(8) # double
|
35
|
+
::LibUI.color_button_color(@libui, @red, @green, @blue, @alpha)
|
36
|
+
[@red[0, 8].unpack1('d') * 255.0, @green[0, 8].unpack1('d') * 255.0, @blue[0, 8].unpack1('d') * 255.0, @alpha[0, 8].unpack1('d')]
|
37
|
+
end
|
38
|
+
|
39
|
+
def red
|
40
|
+
color[0]
|
41
|
+
end
|
42
|
+
|
43
|
+
def green
|
44
|
+
color[1]
|
45
|
+
end
|
46
|
+
|
47
|
+
def blue
|
48
|
+
color[2]
|
49
|
+
end
|
50
|
+
|
51
|
+
def alpha
|
52
|
+
color[3]
|
53
|
+
end
|
54
|
+
|
55
|
+
def destroy
|
56
|
+
Fiddle.free @red unless @red.nil?
|
57
|
+
Fiddle.free @green unless @green.nil?
|
58
|
+
Fiddle.free @blue unless @blue.nil?
|
59
|
+
Fiddle.free @alpha unless @alpha.nil?
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -52,7 +52,7 @@ module Glimmer
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def main_window_proxy
|
55
|
-
all_control_proxies.find {|c| c.is_a?(WindowProxy)}
|
55
|
+
all_control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
|
56
56
|
end
|
57
57
|
|
58
58
|
def integer_to_boolean(int)
|
@@ -62,6 +62,10 @@ module Glimmer
|
|
62
62
|
def boolean_to_integer(bool)
|
63
63
|
bool.nil? ? nil : (bool ? 1 : 0)
|
64
64
|
end
|
65
|
+
|
66
|
+
def menu_proxies
|
67
|
+
all_control_proxies.select {|c| c.keyword == 'menu' }
|
68
|
+
end
|
65
69
|
end
|
66
70
|
|
67
71
|
BOOLEAN_PROPERTIES = %w[
|
@@ -167,7 +171,7 @@ module Glimmer
|
|
167
171
|
::LibUI.send("#{libui_api_keyword}_#{method_name}", @libui, *args)
|
168
172
|
elsif ::LibUI.respond_to?("control_#{method_name.to_s.sub(/\?$/, '')}") && args.empty?
|
169
173
|
property = method_name.to_s.sub(/\?$/, '')
|
170
|
-
value = ::LibUI.send("control_#{
|
174
|
+
value = ::LibUI.send("control_#{property}", @libui, *args)
|
171
175
|
handle_string_property(property, handle_boolean_property(property, value))
|
172
176
|
elsif ::LibUI.respond_to?("control_set_#{method_name.to_s.sub(/=$/, '')}")
|
173
177
|
property = method_name.to_s.sub(/=$/, '')
|
@@ -198,6 +202,23 @@ module Glimmer
|
|
198
202
|
@keyword
|
199
203
|
end
|
200
204
|
|
205
|
+
def destroy
|
206
|
+
if parent_proxy.nil?
|
207
|
+
default_destroy
|
208
|
+
else
|
209
|
+
parent_proxy.destroy_child(self)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def destroy_child(child)
|
214
|
+
child.default_destroy
|
215
|
+
end
|
216
|
+
|
217
|
+
def default_destroy
|
218
|
+
send_to_libui('destroy')
|
219
|
+
ControlProxy.all_control_proxies.delete(self)
|
220
|
+
end
|
221
|
+
|
201
222
|
def enabled(value = nil)
|
202
223
|
if value.nil?
|
203
224
|
@enabled
|
@@ -229,11 +250,6 @@ module Glimmer
|
|
229
250
|
alias set_visible visible
|
230
251
|
alias visible= visible
|
231
252
|
|
232
|
-
def destroy
|
233
|
-
send_to_libui('destroy')
|
234
|
-
self.class.all_control_proxies.delete(self)
|
235
|
-
end
|
236
|
-
|
237
253
|
private
|
238
254
|
|
239
255
|
def build_control
|
@@ -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 font button objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class FontButtonProxy < ControlProxy
|
30
|
+
def font
|
31
|
+
@font_descriptor ||= ::LibUI::FFI::FontDescriptor.malloc
|
32
|
+
::LibUI.font_button_font(@libui, @font_descriptor)
|
33
|
+
{
|
34
|
+
family: @font_descriptor.Family.to_s,
|
35
|
+
size: @font_descriptor.Size,
|
36
|
+
weight: @font_descriptor.Weight,
|
37
|
+
italic: @font_descriptor.Italic,
|
38
|
+
stretch: @font_descriptor.Stretch
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def family
|
43
|
+
font[:family]
|
44
|
+
end
|
45
|
+
|
46
|
+
def size
|
47
|
+
font[:size]
|
48
|
+
end
|
49
|
+
|
50
|
+
def weight
|
51
|
+
font[:weight]
|
52
|
+
end
|
53
|
+
|
54
|
+
def italic
|
55
|
+
font[:italic]
|
56
|
+
end
|
57
|
+
|
58
|
+
def stretch
|
59
|
+
font[:stretch]
|
60
|
+
end
|
61
|
+
|
62
|
+
def destroy
|
63
|
+
::LibUI.free_font_button_font(@font_descriptor) unless @font_descriptor.nil?
|
64
|
+
super
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -35,9 +35,14 @@ module Glimmer
|
|
35
35
|
def post_initialize_child(child)
|
36
36
|
::LibUI.window_set_child(@libui, child.libui)
|
37
37
|
end
|
38
|
+
|
39
|
+
def destroy_child(child)
|
40
|
+
::LibUI.send("window_set_child", @libui, nil)
|
41
|
+
super
|
42
|
+
end
|
38
43
|
|
39
44
|
def show
|
40
|
-
|
45
|
+
super
|
41
46
|
unless @shown_at_least_once
|
42
47
|
@shown_at_least_once = true
|
43
48
|
::LibUI.main
|
@@ -64,6 +69,10 @@ module Glimmer
|
|
64
69
|
private
|
65
70
|
|
66
71
|
def build_control
|
72
|
+
if OS.mac? && ControlProxy.menu_proxies.empty?
|
73
|
+
menu_proxy = ControlProxy.create('menu', nil, [''])
|
74
|
+
quit_menu_item_proxy = ControlProxy.create('quit_menu_item', menu_proxy, [])
|
75
|
+
end
|
67
76
|
construction_args = @args.dup
|
68
77
|
construction_args[0] = DEFAULT_TITLE if construction_args.size == 0
|
69
78
|
construction_args[1] = DEFAULT_WIDTH if construction_args.size == 1
|
data/lib/glimmer-dsl-libui.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.12
|
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-09-
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -24,6 +24,26 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.1.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: os
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.0.0
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.0.0
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: libui
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,7 +184,10 @@ files:
|
|
164
184
|
- examples/basic_entry.rb
|
165
185
|
- examples/basic_window.rb
|
166
186
|
- examples/basic_window2.rb
|
187
|
+
- examples/color_button.rb
|
167
188
|
- examples/control_gallery.rb
|
189
|
+
- examples/font_button.rb
|
190
|
+
- examples/meta_example.rb
|
168
191
|
- examples/midi_player.rb
|
169
192
|
- examples/simple_notepad.rb
|
170
193
|
- glimmer-dsl-libui.gemspec
|
@@ -180,11 +203,13 @@ files:
|
|
180
203
|
- lib/glimmer/libui/about_menu_item_proxy.rb
|
181
204
|
- lib/glimmer/libui/box.rb
|
182
205
|
- lib/glimmer/libui/check_menu_item_proxy.rb
|
206
|
+
- lib/glimmer/libui/color_button_proxy.rb
|
183
207
|
- lib/glimmer/libui/combobox_proxy.rb
|
184
208
|
- lib/glimmer/libui/control_proxy.rb
|
185
209
|
- lib/glimmer/libui/date_picker_proxy.rb
|
186
210
|
- lib/glimmer/libui/date_time_picker_proxy.rb
|
187
211
|
- lib/glimmer/libui/editable_combobox_proxy.rb
|
212
|
+
- lib/glimmer/libui/font_button_proxy.rb
|
188
213
|
- lib/glimmer/libui/group_proxy.rb
|
189
214
|
- lib/glimmer/libui/horizontal_box_proxy.rb
|
190
215
|
- lib/glimmer/libui/menu_item_proxy.rb
|