glimmer-dsl-libui 0.0.25 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +285 -7
- data/VERSION +1 -1
- data/examples/basic_area.rb +17 -0
- data/examples/basic_table_progress_bar.rb +24 -0
- data/examples/form_table.rb +67 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/fiddle_consumer.rb +33 -0
- data/lib/glimmer/libui/area_proxy.rb +68 -0
- data/lib/glimmer/libui/checkbox_column_proxy.rb +2 -2
- data/lib/glimmer/libui/checkbox_text_column_proxy.rb +34 -2
- data/lib/glimmer/libui/path_proxy.rb +141 -0
- data/lib/glimmer/libui/progress_bar_column_proxy.rb +40 -0
- data/lib/glimmer/libui/rectangle_proxy.rb +56 -0
- data/lib/glimmer/libui/table_proxy.rb +21 -20
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0e5255370f70684a7f60de75fe52399f604761996059b23370ce53c4e11cdd1
|
4
|
+
data.tar.gz: 00fe32154a83c206843d2386406cde3841da5296cb432585d8aedf421578c47c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92ef8efbe6d9563dcf20affce754ea4f8fd6ee3eceec014f7499a8ea15631e0127877526ca313513129aee506dc9b363651dde235e2e965a456ddcb2df29c7ae
|
7
|
+
data.tar.gz: 9ceec5135f065862bfc7590883346dc0930380da5e12f6b575a5c4a6c1c6d45e7d575392daf0b003cf78889a5c90cc4033cd48783e1a6c2cd5f4e53d4814b009
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.1.0
|
4
|
+
|
5
|
+
- Support examples/basic_area.rb
|
6
|
+
- Support `area` control
|
7
|
+
- Support `path(fill_mode)` control
|
8
|
+
- Support `rectangle(x, y, width, height)` figure
|
9
|
+
- Support `path` `fill` property
|
10
|
+
- Support `path` `stroke` property
|
11
|
+
|
12
|
+
## 0.0.28
|
13
|
+
|
14
|
+
- Support automatic table row change when updating a row in `cell_rows` (e.g. `data[3] = ['new', 'row', 'cell', 'values']`)
|
15
|
+
- Support `editable` property for `checkbox_column` (checkbox editing only works in Windows due to a [libui](https://github.com/andlabs/libui) limitation)
|
16
|
+
- Support `editable`, `editable_checkbox`, and `editable_text` properties for `checkbox_text_column` (checkbox editing only works in Windows due to a [libui](https://github.com/andlabs/libui) limitation)
|
17
|
+
- Fix examples/basic_table_checkbox_text.rb by removing `editable` property
|
18
|
+
|
19
|
+
## 0.0.27
|
20
|
+
|
21
|
+
- New examples/form_table.rb
|
22
|
+
- Support automatic table row insertion upon inserting data rows into `cell_rows`
|
23
|
+
|
24
|
+
## 0.0.26
|
25
|
+
|
26
|
+
- New examples/basic_table_progress_bar.rb
|
27
|
+
- Support table `progress_bar_column`
|
28
|
+
|
3
29
|
## 0.0.25
|
4
30
|
|
5
31
|
- New examples/basic_table_checkbox_text.rb
|
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.1.0
|
2
2
|
## Prerequisite-Free Ruby Desktop Development GUI Library
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/ce2853efdbecf6ebdc73/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-libui/maintainability)
|
@@ -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.1.0](#-glimmer-dsl-for-libui-010)
|
47
47
|
- [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
|
48
48
|
- [Usage](#usage)
|
49
49
|
- [API](#api)
|
@@ -52,6 +52,8 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
|
|
52
52
|
- [Common Control Operations](#common-control-operations)
|
53
53
|
- [Extra Dialogs](#extra-dialogs)
|
54
54
|
- [Extra Operations](#extra-operations)
|
55
|
+
- [Table API](#table-api)
|
56
|
+
- [Area API](#area-api)
|
55
57
|
- [Smart Defaults and Conventions](#smart-defaults-and-conventions)
|
56
58
|
- [API Gotchas](#api-gotchas)
|
57
59
|
- [Original API](#original-api)
|
@@ -77,6 +79,9 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
|
|
77
79
|
- [Basic Table Button](#basic-table-button)
|
78
80
|
- [Basic Table Checkbox](#basic-table-checkbox)
|
79
81
|
- [Basic Table Checkbox Text](#basic-table-checkbox-text)
|
82
|
+
- [Basic Table Progress Bar](#basic-table-progress-bar)
|
83
|
+
- [Form Table](#form-table)
|
84
|
+
- [Basic Area](#basic-area)
|
80
85
|
- [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
|
81
86
|
- [Help](#help)
|
82
87
|
- [Issues](#issues)
|
@@ -164,7 +169,7 @@ gem install glimmer-dsl-libui
|
|
164
169
|
Or install via Bundler `Gemfile`:
|
165
170
|
|
166
171
|
```ruby
|
167
|
-
gem 'glimmer-dsl-libui', '~> 0.0
|
172
|
+
gem 'glimmer-dsl-libui', '~> 0.1.0'
|
168
173
|
```
|
169
174
|
|
170
175
|
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.
|
@@ -220,11 +225,12 @@ w.libui # => #<Fiddle::Pointer:0x00007fde53997980 ptr=0x00007fde51352a60 size=0
|
|
220
225
|
Control(Args) | Properties | Listeners
|
221
226
|
------------- | ---------- | ---------
|
222
227
|
`about_menu_item` | None | `on_clicked`
|
228
|
+
`area` | None | None
|
223
229
|
`button(text as String)` | `text` (`String`) | `on_clicked`
|
224
230
|
`button_column(name as String)` | `enabled` (Boolean) | None
|
225
231
|
`checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
|
226
|
-
`checkbox_column(name as String)` |
|
227
|
-
`checkbox_text_column(name as String)` | `editable` (Boolean) | None
|
232
|
+
`checkbox_column(name as String)` | `editable` (Boolean) | None
|
233
|
+
`checkbox_text_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
|
228
234
|
`combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
|
229
235
|
`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`
|
230
236
|
`date_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`, `mday` as `Integer`, `mon` as `Integer`, `year` as `Integer`, `wday` as `Integer`, `yday` as `Integer`, `dst` as Boolean) | `on_changed`
|
@@ -248,10 +254,13 @@ Control(Args) | Properties | Listeners
|
|
248
254
|
`msg_box(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
|
249
255
|
`msg_box_error(window as Glimmer::LibUI::WindowProxy, title as String, description as String)` | None | None
|
250
256
|
`non_wrapping_multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
|
257
|
+
`path` | `fill` (`Hash` of `:r` as `0`-`255`, `:g` as `0`-`255`, `:b` as `0`-`255`, `:a` as `0.0`-`1.0`), `stroke` (`Hash` of `:r` as `0`-`255`, `:g` as `0`-`255`, `:b` as `0`-`255`, `:a` as `0.0`-`1.0`, `:cap` as `Numeric`, `:join` as `Numeric`, `:thickness` as `Numeric`, `:miter_limit` as `Numeric` ) | None
|
251
258
|
`preferences_menu_item` | None | `on_clicked`
|
252
259
|
`progress_bar` | `value` (`Numeric`) | None
|
260
|
+
`progress_bar_column(name as String)` | None | None
|
253
261
|
`quit_menu_item` | None | `on_clicked`
|
254
262
|
`radio_buttons` | `selected` (`Integer`) | `on_selected`
|
263
|
+
`rectangle(x as Numeric, y as Numeric, width as Numeric, height as Numeric)` | None | None
|
255
264
|
`slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
|
256
265
|
`spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
|
257
266
|
`tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
|
@@ -299,6 +308,28 @@ Control(Args) | Properties | Listeners
|
|
299
308
|
- `ControlProxy::main_window_proxy`: returns the first window proxy instantiated in the application
|
300
309
|
- `ControlProxy#window_proxy`: returns the window proxy parent for a control
|
301
310
|
|
311
|
+
### Table API
|
312
|
+
|
313
|
+
The `table` control must first declare its columns via one of these column keywords (mentioned in [Supported Controls](#supported-controls)):
|
314
|
+
- `button_column`: expects `String` cell values
|
315
|
+
- `checkbox_column`: expects Boolean cell values
|
316
|
+
- `checkbox_text_column`: expects dual-element `Array` of Boolean and `String` cell values
|
317
|
+
- `image_column`: expects `image` cell values (produced by `image` and `image_part` keywords as per [Supported Controls](#supported-controls))
|
318
|
+
- `image_text_column`: expects dual-element `Array` of `image` and `String` cell values
|
319
|
+
- `text_column`: expects `String` cell values
|
320
|
+
- `progress_bar_column`: expects `Integer` cell values
|
321
|
+
|
322
|
+
Afterwards, it must declare its `cell_rows` array (`Array` of `Array`s of column cell values) and whether it is `editable` (Boolean) for all its columns.
|
323
|
+
|
324
|
+
Note that the `cell_rows` property declaration results in "implicit data-binding" between the `table` control and `Array` of `Arrays` (a new innovation) to provide convenience automatic support for:
|
325
|
+
- Deleting cell rows: Calling `Array#delete`, `Array#delete_at`, `Array#delete_if`, or any filtering/deletion `Array` method automatically deletes rows in actual `table` control
|
326
|
+
- Inserting cell rows: Calling `Array#<<`, `Array#push`, `Array#prepend`, or any insertion/addition `Array` method automatically inserts rows in actual `table` control
|
327
|
+
- Changing cell rows: Calling `Array#[]=`, `Array#map!`, or any update `Array` method automatically updates rows in actual `table` control
|
328
|
+
|
329
|
+
### Area API
|
330
|
+
|
331
|
+
The `area` control can have a `path` nested underneath declaratively, containing figures like `rectangle`, and all the drawing logic is generated automatically from that.
|
332
|
+
|
302
333
|
### Smart Defaults and Conventions
|
303
334
|
|
304
335
|
- `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
|
@@ -324,13 +355,15 @@ Control(Args) | Properties | Listeners
|
|
324
355
|
- Smart defaults for `grid` child attributes are `left` (`0`), `top` (`0`), `xspan` (`1`), `yspan` (`1`), `hexpand` (`false`), `halign` (`0`), `vexpand` (`false`), and `valign` (`0`)
|
325
356
|
- The `table` control automatically constructs required `TableModelHandler`, `TableModel`, and `TableParams`, calculating all their arguments from `cell_rows` and `editable` properties (e.g. `NumRows`) as well as nested columns (e.g. `text_column`)
|
326
357
|
- Table model instances are automatically freed from memory after `window` is destroyed.
|
327
|
-
- Table `cell_rows` data has implicit data-binding to table cell values. When deleting data from `cell_rows` array, then actual rows from the `table` are automatically deleted.
|
358
|
+
- Table `cell_rows` data has implicit data-binding to table cell values for deletion, insertion, and change (done by diffing `cell_rows` value before and after change and auto-informing `table` of deletions [`LibUI.table_model_row_deleted`], insertions [`LibUI.table_model_row_deleted`], and changes [`LibUI.table_model_row_changed`]). When deleting data rows from `cell_rows` array, then actual rows from the `table` are automatically deleted. When inserting data rows into `cell_rows` array, then actual `table` rows are automatically inserted. When updating data rows in `cell_rows` array, then actual `table` rows are automatically updated.
|
328
359
|
- `image` instances are automatically freed from memory after `window` is destroyed.
|
329
360
|
- `image` `width` and `height` can be left off if it has one `image_part` only as they default to the same `width` and `height` of the `image_part`
|
361
|
+
- `area` paths are specified declaratively with figures underneath (e.g. `rectangle`) and `area` draw listener is automatically generated
|
330
362
|
|
331
363
|
### API Gotchas
|
332
364
|
|
333
|
-
There is no proper way to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`)
|
365
|
+
- There is no proper way to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`).
|
366
|
+
- `table` `checkbox_column` and `checkbox_text_column` checkbox editing only works on Windows and Linux (not Mac) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
|
334
367
|
|
335
368
|
### Original API
|
336
369
|
|
@@ -2411,6 +2444,251 @@ window('Animal sounds', 400, 200) {
|
|
2411
2444
|
}.show
|
2412
2445
|
```
|
2413
2446
|
|
2447
|
+
### Basic Table Progress Bar
|
2448
|
+
|
2449
|
+
[examples/basic_table_progress_bar.rb](examples/basic_table_progress_bar.rb)
|
2450
|
+
|
2451
|
+
Run with this command from the root of the project if you cloned the project:
|
2452
|
+
|
2453
|
+
```
|
2454
|
+
ruby -r './lib/glimmer-dsl-libui' examples/basic_table_progress_bar.rb
|
2455
|
+
```
|
2456
|
+
|
2457
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
2458
|
+
|
2459
|
+
```
|
2460
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/basic_table_progress_bar'"
|
2461
|
+
```
|
2462
|
+
|
2463
|
+
Mac
|
2464
|
+
|
2465
|
+
![glimmer-dsl-libui-mac-basic-table-progress-bar.png](images/glimmer-dsl-libui-mac-basic-table-progress-bar.png)
|
2466
|
+
|
2467
|
+
Linux
|
2468
|
+
|
2469
|
+
![glimmer-dsl-libui-linux-basic-table-progress-bar.png](images/glimmer-dsl-libui-linux-basic-table-progress-bar.png)
|
2470
|
+
|
2471
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
2472
|
+
|
2473
|
+
```ruby
|
2474
|
+
require 'glimmer-dsl-libui'
|
2475
|
+
|
2476
|
+
include Glimmer
|
2477
|
+
|
2478
|
+
data = [
|
2479
|
+
['task 1', 0],
|
2480
|
+
['task 2', 15],
|
2481
|
+
['task 3', 100],
|
2482
|
+
['task 4', 75],
|
2483
|
+
['task 5', -1],
|
2484
|
+
]
|
2485
|
+
|
2486
|
+
window('Task progress', 300, 200) {
|
2487
|
+
horizontal_box {
|
2488
|
+
table {
|
2489
|
+
text_column('Task')
|
2490
|
+
progress_bar_column('Progress')
|
2491
|
+
|
2492
|
+
cell_rows data
|
2493
|
+
}
|
2494
|
+
}
|
2495
|
+
}.show
|
2496
|
+
```
|
2497
|
+
|
2498
|
+
### Form Table
|
2499
|
+
|
2500
|
+
[examples/form_table.rb](examples/form_table.rb)
|
2501
|
+
|
2502
|
+
Run with this command from the root of the project if you cloned the project:
|
2503
|
+
|
2504
|
+
```
|
2505
|
+
ruby -r './lib/glimmer-dsl-libui' examples/form_table.rb
|
2506
|
+
```
|
2507
|
+
|
2508
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
2509
|
+
|
2510
|
+
```
|
2511
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/form_table'"
|
2512
|
+
```
|
2513
|
+
|
2514
|
+
Mac
|
2515
|
+
|
2516
|
+
![glimmer-dsl-libui-mac-form-table.png](images/glimmer-dsl-libui-mac-form-table.png)
|
2517
|
+
![glimmer-dsl-libui-mac-form-table-contact-entered.png](images/glimmer-dsl-libui-mac-form-table-contact-entered.png)
|
2518
|
+
|
2519
|
+
Linux
|
2520
|
+
|
2521
|
+
![glimmer-dsl-libui-linux-form-table.png](images/glimmer-dsl-libui-linux-form-table.png)
|
2522
|
+
![glimmer-dsl-libui-linux-form-table-contact-entered.png](images/glimmer-dsl-libui-linux-form-table-contact-entered.png)
|
2523
|
+
|
2524
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
2525
|
+
|
2526
|
+
```ruby
|
2527
|
+
require 'glimmer-dsl-libui'
|
2528
|
+
|
2529
|
+
include Glimmer
|
2530
|
+
|
2531
|
+
data = [
|
2532
|
+
['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO', '80014'],
|
2533
|
+
['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA', '02101'],
|
2534
|
+
['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL', '60007'],
|
2535
|
+
['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA', '98101'],
|
2536
|
+
['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA', '90001'],
|
2537
|
+
]
|
2538
|
+
|
2539
|
+
window('Contacts', 600, 600) { |w|
|
2540
|
+
margined true
|
2541
|
+
|
2542
|
+
vertical_box {
|
2543
|
+
form {
|
2544
|
+
stretchy false
|
2545
|
+
|
2546
|
+
@name_entry = entry {
|
2547
|
+
label 'Name'
|
2548
|
+
}
|
2549
|
+
@email_entry = entry {
|
2550
|
+
label 'Email'
|
2551
|
+
}
|
2552
|
+
@phone_entry = entry {
|
2553
|
+
label 'Phone'
|
2554
|
+
}
|
2555
|
+
@city_entry = entry {
|
2556
|
+
label 'City'
|
2557
|
+
}
|
2558
|
+
@state_entry = entry {
|
2559
|
+
label 'State'
|
2560
|
+
}
|
2561
|
+
}
|
2562
|
+
|
2563
|
+
button('Save Contact') {
|
2564
|
+
stretchy false
|
2565
|
+
|
2566
|
+
on_clicked do
|
2567
|
+
new_row = [@name_entry.text, @email_entry.text, @phone_entry.text, @city_entry.text, @state_entry.text]
|
2568
|
+
if new_row.include?('')
|
2569
|
+
msg_box_error(w, 'Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
|
2570
|
+
else
|
2571
|
+
data << new_row # automatically inserts a row into the table due to implicit data-binding
|
2572
|
+
@name_entry.text = ''
|
2573
|
+
@email_entry.text = ''
|
2574
|
+
@phone_entry.text = ''
|
2575
|
+
@city_entry.text = ''
|
2576
|
+
@state_entry.text = ''
|
2577
|
+
end
|
2578
|
+
end
|
2579
|
+
}
|
2580
|
+
|
2581
|
+
table {
|
2582
|
+
text_column('Name')
|
2583
|
+
text_column('Email')
|
2584
|
+
text_column('Phone')
|
2585
|
+
text_column('City')
|
2586
|
+
text_column('State')
|
2587
|
+
|
2588
|
+
cell_rows data # implicit data-binding
|
2589
|
+
}
|
2590
|
+
}
|
2591
|
+
}.show
|
2592
|
+
```
|
2593
|
+
|
2594
|
+
### Basic Area
|
2595
|
+
|
2596
|
+
[examples/basic_area.rb](examples/basic_area.rb)
|
2597
|
+
|
2598
|
+
Run with this command from the root of the project if you cloned the project:
|
2599
|
+
|
2600
|
+
```
|
2601
|
+
ruby -r './lib/glimmer-dsl-libui' examples/basic_area.rb
|
2602
|
+
```
|
2603
|
+
|
2604
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
2605
|
+
|
2606
|
+
```
|
2607
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/basic_area'"
|
2608
|
+
```
|
2609
|
+
|
2610
|
+
Mac
|
2611
|
+
|
2612
|
+
![glimmer-dsl-libui-mac-basic-area.png](images/glimmer-dsl-libui-mac-basic-area.png)
|
2613
|
+
|
2614
|
+
Linux
|
2615
|
+
|
2616
|
+
![glimmer-dsl-libui-linux-basic-area.png](images/glimmer-dsl-libui-linux-basic-area.png)
|
2617
|
+
|
2618
|
+
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
2619
|
+
|
2620
|
+
```ruby
|
2621
|
+
require 'libui'
|
2622
|
+
|
2623
|
+
UI = LibUI
|
2624
|
+
|
2625
|
+
UI.init
|
2626
|
+
|
2627
|
+
handler = UI::FFI::AreaHandler.malloc
|
2628
|
+
area = UI.new_area(handler)
|
2629
|
+
brush = UI::FFI::DrawBrush.malloc
|
2630
|
+
|
2631
|
+
handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, area_draw_params|
|
2632
|
+
path = UI.draw_new_path(0)
|
2633
|
+
UI.draw_path_add_rectangle(path, 0, 0, 400, 400)
|
2634
|
+
UI.draw_path_end(path)
|
2635
|
+
brush.Type = 0
|
2636
|
+
brush.R = 0.4
|
2637
|
+
brush.G = 0.4
|
2638
|
+
brush.B = 0.8
|
2639
|
+
brush.A = 1.0
|
2640
|
+
area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params)
|
2641
|
+
UI.draw_fill(area_draw_params.Context, path, brush.to_ptr)
|
2642
|
+
UI.draw_free_path(path)
|
2643
|
+
end
|
2644
|
+
|
2645
|
+
handler.Draw = handler_draw_event
|
2646
|
+
handler.MouseEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
|
2647
|
+
handler.MouseCrossed = Fiddle::Closure::BlockCaller.new(0, [0]) {}
|
2648
|
+
handler.DragBroken = Fiddle::Closure::BlockCaller.new(0, [0]) {}
|
2649
|
+
handler.KeyEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
|
2650
|
+
|
2651
|
+
box = UI.new_vertical_box
|
2652
|
+
UI.box_set_padded(box, 1)
|
2653
|
+
UI.box_append(box, area, 1)
|
2654
|
+
|
2655
|
+
main_window = UI.new_window('Basic Area', 400, 400, 1)
|
2656
|
+
UI.window_set_margined(main_window, 1)
|
2657
|
+
UI.window_set_child(main_window, box)
|
2658
|
+
|
2659
|
+
UI.window_on_closing(main_window) do
|
2660
|
+
UI.control_destroy(main_window)
|
2661
|
+
UI.quit
|
2662
|
+
0
|
2663
|
+
end
|
2664
|
+
UI.control_show(main_window)
|
2665
|
+
|
2666
|
+
UI.main
|
2667
|
+
UI.quit
|
2668
|
+
```
|
2669
|
+
|
2670
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
2671
|
+
|
2672
|
+
```ruby
|
2673
|
+
require 'glimmer-dsl-libui'
|
2674
|
+
|
2675
|
+
include Glimmer
|
2676
|
+
|
2677
|
+
window('Basic Area', 400, 400) {
|
2678
|
+
margined true
|
2679
|
+
|
2680
|
+
vertical_box {
|
2681
|
+
area {
|
2682
|
+
path { # a stable path is added declaratively
|
2683
|
+
rectangle(0, 0, 400, 400)
|
2684
|
+
|
2685
|
+
fill r: 102, g: 102, b: 204, a: 1.0
|
2686
|
+
}
|
2687
|
+
}
|
2688
|
+
}
|
2689
|
+
}.show
|
2690
|
+
```
|
2691
|
+
|
2414
2692
|
## Contributing to glimmer-dsl-libui
|
2415
2693
|
|
2416
2694
|
- Check out the latest master to make sure the feature hasn't been
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Basic Area', 400, 400) {
|
6
|
+
margined true
|
7
|
+
|
8
|
+
vertical_box {
|
9
|
+
area {
|
10
|
+
path { # a stable path is added declaratively
|
11
|
+
rectangle(0, 0, 400, 400)
|
12
|
+
|
13
|
+
fill r: 102, g: 102, b: 204, a: 1.0
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}.show
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
data = [
|
8
|
+
['task 1', 0],
|
9
|
+
['task 2', 15],
|
10
|
+
['task 3', 100],
|
11
|
+
['task 4', 75],
|
12
|
+
['task 5', -1],
|
13
|
+
]
|
14
|
+
|
15
|
+
window('Task progress', 300, 200) {
|
16
|
+
horizontal_box {
|
17
|
+
table {
|
18
|
+
text_column('Task')
|
19
|
+
progress_bar_column('Progress')
|
20
|
+
|
21
|
+
cell_rows data
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}.show
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
data = [
|
8
|
+
['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO', '80014'],
|
9
|
+
['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA', '02101'],
|
10
|
+
['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL', '60007'],
|
11
|
+
['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA', '98101'],
|
12
|
+
['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA', '90001'],
|
13
|
+
]
|
14
|
+
|
15
|
+
window('Contacts', 600, 600) { |w|
|
16
|
+
margined true
|
17
|
+
|
18
|
+
vertical_box {
|
19
|
+
form {
|
20
|
+
stretchy false
|
21
|
+
|
22
|
+
@name_entry = entry {
|
23
|
+
label 'Name'
|
24
|
+
}
|
25
|
+
@email_entry = entry {
|
26
|
+
label 'Email'
|
27
|
+
}
|
28
|
+
@phone_entry = entry {
|
29
|
+
label 'Phone'
|
30
|
+
}
|
31
|
+
@city_entry = entry {
|
32
|
+
label 'City'
|
33
|
+
}
|
34
|
+
@state_entry = entry {
|
35
|
+
label 'State'
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
button('Save Contact') {
|
40
|
+
stretchy false
|
41
|
+
|
42
|
+
on_clicked do
|
43
|
+
new_row = [@name_entry.text, @email_entry.text, @phone_entry.text, @city_entry.text, @state_entry.text]
|
44
|
+
if new_row.include?('')
|
45
|
+
msg_box_error(w, 'Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
|
46
|
+
else
|
47
|
+
data << new_row # automatically inserts a row into the table due to implicit data-binding
|
48
|
+
@name_entry.text = ''
|
49
|
+
@email_entry.text = ''
|
50
|
+
@phone_entry.text = ''
|
51
|
+
@city_entry.text = ''
|
52
|
+
@state_entry.text = ''
|
53
|
+
end
|
54
|
+
end
|
55
|
+
}
|
56
|
+
|
57
|
+
table {
|
58
|
+
text_column('Name')
|
59
|
+
text_column('Email')
|
60
|
+
text_column('Phone')
|
61
|
+
text_column('City')
|
62
|
+
text_column('State')
|
63
|
+
|
64
|
+
cell_rows data # implicit data-binding
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}.show
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -0,0 +1,33 @@
|
|
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 FiddleConsumer
|
24
|
+
# Protects Fiddle::Closure::BlockCaller objects from garbage collection.
|
25
|
+
def fiddle_closure_block_caller(*args, &block)
|
26
|
+
@blockcaller ||= []
|
27
|
+
args << [0] if args.size == 1 # Argument types are ommited
|
28
|
+
blockcaller = ::Fiddle::Closure::BlockCaller.new(*args, &block)
|
29
|
+
@blockcaller << blockcaller
|
30
|
+
blockcaller
|
31
|
+
end
|
32
|
+
end
|
33
|
+
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
|
+
require 'glimmer/fiddle_consumer'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module LibUI
|
27
|
+
# Proxy for LibUI area objects
|
28
|
+
#
|
29
|
+
# Follows the Proxy Design Pattern
|
30
|
+
class AreaProxy < ControlProxy
|
31
|
+
include Glimmer::FiddleConsumer
|
32
|
+
|
33
|
+
attr_reader :area_handler
|
34
|
+
|
35
|
+
def post_initialize_child(child)
|
36
|
+
super
|
37
|
+
children << child
|
38
|
+
end
|
39
|
+
|
40
|
+
def post_add_content
|
41
|
+
super
|
42
|
+
install_listeners
|
43
|
+
end
|
44
|
+
|
45
|
+
def children
|
46
|
+
@children ||= []
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_control
|
52
|
+
@area_handler = ::LibUI::FFI::AreaHandler.malloc
|
53
|
+
@libui = ::LibUI.new_area(@area_handler)
|
54
|
+
end
|
55
|
+
|
56
|
+
def install_listeners
|
57
|
+
@area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params|
|
58
|
+
area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params)
|
59
|
+
children.each {|child| child.draw(area_draw_params)}
|
60
|
+
end
|
61
|
+
@area_handler.MouseEvent = fiddle_closure_block_caller(0, [0]) {}
|
62
|
+
@area_handler.MouseCrossed = fiddle_closure_block_caller(0, [0]) {}
|
63
|
+
@area_handler.DragBroken = fiddle_closure_block_caller(0, [0]) {}
|
64
|
+
@area_handler.KeyEvent = fiddle_closure_block_caller(0, [0]) {}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -30,12 +30,12 @@ module Glimmer
|
|
30
30
|
# Follows the Proxy Design Pattern
|
31
31
|
class CheckboxColumnProxy < ControlProxy
|
32
32
|
include Column
|
33
|
-
|
33
|
+
include EditableColumn
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def build_control
|
38
|
-
@parent_proxy.append_checkbox_column(name, column_index,
|
38
|
+
@parent_proxy.append_checkbox_column(name, column_index, editable_value)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -32,12 +32,44 @@ module Glimmer
|
|
32
32
|
class CheckboxTextColumnProxy < ControlProxy
|
33
33
|
include Column
|
34
34
|
include DualColumn
|
35
|
-
include EditableColumn
|
35
|
+
include EditableColumn
|
36
36
|
|
37
|
+
def editable_checkbox(value = nil)
|
38
|
+
if value.nil?
|
39
|
+
@editable_checkbox = false if @editable_checkbox.nil?
|
40
|
+
@editable_checkbox
|
41
|
+
else
|
42
|
+
@editable_checkbox = !!value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
alias editable_checkbox= editable_checkbox
|
46
|
+
alias set_editable_checkbox editable_checkbox
|
47
|
+
alias editable_checkbox? editable_checkbox
|
48
|
+
|
49
|
+
def editable_text(value = nil)
|
50
|
+
if value.nil?
|
51
|
+
@editable_text = false if @editable_text.nil?
|
52
|
+
@editable_text
|
53
|
+
else
|
54
|
+
@editable_text = !!value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
alias editable_text= editable_text
|
58
|
+
alias set_editable_text editable_text
|
59
|
+
alias editable_text? editable_text
|
60
|
+
|
37
61
|
private
|
38
62
|
|
39
63
|
def build_control
|
40
|
-
@parent_proxy.append_checkbox_text_column(name, column_index,
|
64
|
+
@parent_proxy.append_checkbox_text_column(name, column_index, editable_checkbox_value, second_column_index, editable_text_value)
|
65
|
+
end
|
66
|
+
|
67
|
+
def editable_checkbox_value
|
68
|
+
(@parent_proxy.editable? || editable? || editable_checkbox?) ? -2 : -1
|
69
|
+
end
|
70
|
+
|
71
|
+
def editable_text_value
|
72
|
+
(@parent_proxy.editable? || editable? || editable_text?) ? -2 : -1
|
41
73
|
end
|
42
74
|
end
|
43
75
|
end
|
@@ -0,0 +1,141 @@
|
|
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 path objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class PathProxy < ControlProxy
|
30
|
+
# TODO support mode without parent proxy
|
31
|
+
def initialize(keyword, parent, args, &block)
|
32
|
+
@keyword = keyword
|
33
|
+
@parent_proxy = parent
|
34
|
+
@args = args
|
35
|
+
@block = block
|
36
|
+
@enabled = true
|
37
|
+
post_add_content if @block.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def post_initialize_child(child)
|
41
|
+
super
|
42
|
+
children << child
|
43
|
+
end
|
44
|
+
|
45
|
+
def children
|
46
|
+
@children ||= []
|
47
|
+
end
|
48
|
+
|
49
|
+
def draw(area_draw_params)
|
50
|
+
build_control
|
51
|
+
children.each {|child| child.draw(area_draw_params)}
|
52
|
+
::LibUI.draw_path_end(@libui)
|
53
|
+
::LibUI.draw_fill(area_draw_params.Context, @libui, fill_draw_brush.to_ptr) unless fill.empty?
|
54
|
+
::LibUI.draw_stroke(area_draw_params.Context, @libui, stroke_draw_brush, draw_stroke_params) unless stroke.empty?
|
55
|
+
::LibUI.draw_free_path(@libui)
|
56
|
+
end
|
57
|
+
|
58
|
+
def draw_fill_mode
|
59
|
+
@args[0].is_a?(Integer) ? @args[0] : @args[0].to_s == 'alternate' ? 1 : 0
|
60
|
+
end
|
61
|
+
|
62
|
+
def fill(args = nil)
|
63
|
+
if args.nil?
|
64
|
+
@fill ||= {}
|
65
|
+
else
|
66
|
+
@fill = args
|
67
|
+
end
|
68
|
+
end
|
69
|
+
alias fill= fill
|
70
|
+
alias set_fill fill
|
71
|
+
|
72
|
+
def fill_draw_brush
|
73
|
+
@fill_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
|
74
|
+
init_draw_brush(@fill_draw_brush, @fill)
|
75
|
+
@fill_draw_brush
|
76
|
+
end
|
77
|
+
|
78
|
+
def stroke(args = nil)
|
79
|
+
if args.nil?
|
80
|
+
@stroke ||= {}
|
81
|
+
else
|
82
|
+
@stroke = args
|
83
|
+
end
|
84
|
+
end
|
85
|
+
alias stroke= stroke
|
86
|
+
alias set_stroke stroke
|
87
|
+
|
88
|
+
def stroke_draw_brush
|
89
|
+
@stroke_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
|
90
|
+
init_draw_brush(@stroke_draw_brush, @stroke)
|
91
|
+
@stroke_draw_brush
|
92
|
+
end
|
93
|
+
|
94
|
+
def draw_stroke_params
|
95
|
+
@draw_stroke_params ||= ::LibUI::FFI::DrawStrokeParams.malloc
|
96
|
+
@draw_stroke_params.Cap = @stroke[:cap] || 0 # flat
|
97
|
+
@draw_stroke_params.Join = @stroke[:join] || 0 # miter
|
98
|
+
@draw_stroke_params.Thickness = @stroke[:thickness] || 1
|
99
|
+
@draw_stroke_params.MiterLimit = @stroke[:miter_limit] || 10 # DEFAULT_MITER_LIMIT
|
100
|
+
@draw_stroke_params_dashes ||= Fiddle::Pointer.malloc(8)
|
101
|
+
@draw_stroke_params.Dashes = @draw_stroke_params_dashes
|
102
|
+
@draw_stroke_params.NumDashes = @stroke[:num_dashes] || 0 # TODO reimplement this line correctly (perhaps no need to pass num dashes, yet dashes themselves and use their count here)
|
103
|
+
@draw_stroke_params.DashPhase = @stroke[:dash_phase] || 0
|
104
|
+
@draw_stroke_params
|
105
|
+
end
|
106
|
+
|
107
|
+
def destroy
|
108
|
+
if @parent_proxy
|
109
|
+
@parent_proxy.children.delete(self)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def build_control
|
116
|
+
@libui = ::LibUI.draw_new_path(draw_fill_mode)
|
117
|
+
end
|
118
|
+
|
119
|
+
def init_draw_brush(draw_brush, draw_brush_args)
|
120
|
+
case draw_brush_args[:type]
|
121
|
+
when Integer
|
122
|
+
draw_brush.Type = draw_brush_args[:type]
|
123
|
+
when :solid, 'solid'
|
124
|
+
draw_brush.Type = 0
|
125
|
+
when :linear_gradient, 'linear_gradient'
|
126
|
+
draw_brush.Type = 1
|
127
|
+
when :radial_gradient, 'radial_gradient'
|
128
|
+
draw_brush.Type = 2
|
129
|
+
when :image, 'image'
|
130
|
+
draw_brush.Type = 3
|
131
|
+
else
|
132
|
+
draw_brush.Type = 0
|
133
|
+
end
|
134
|
+
draw_brush.R = (draw_brush_args[:r] || draw_brush_args[:red]).to_f / 255.0
|
135
|
+
draw_brush.G = (draw_brush_args[:g] || draw_brush_args[:green]).to_f / 255.0
|
136
|
+
draw_brush.B = (draw_brush_args[:b] || draw_brush_args[:blue]).to_f / 255.0
|
137
|
+
draw_brush.A = (draw_brush_args[:a] || draw_brush_args[:alpha])
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
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
|
+
require 'glimmer/libui/control_proxy'
|
23
|
+
require 'glimmer/libui/column'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module LibUI
|
27
|
+
# Proxy for LibUI progress bar column objects
|
28
|
+
#
|
29
|
+
# Follows the Proxy Design Pattern
|
30
|
+
class ProgressBarColumnProxy < ControlProxy
|
31
|
+
include Column
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def build_control
|
36
|
+
@parent_proxy.append_progress_bar_column(name, column_index)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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 rectangle objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class RectangleProxy < ControlProxy
|
30
|
+
def initialize(keyword, parent, args, &block)
|
31
|
+
@keyword = keyword
|
32
|
+
@parent_proxy = parent
|
33
|
+
@args = args
|
34
|
+
@block = block
|
35
|
+
@enabled = true
|
36
|
+
post_add_content if @block.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw(area_draw_params)
|
40
|
+
::LibUI.draw_path_add_rectangle(@parent_proxy.libui, *@args)
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy
|
44
|
+
if @parent_proxy
|
45
|
+
@parent_proxy.children.delete(self)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_control
|
52
|
+
# No Op
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -21,6 +21,7 @@
|
|
21
21
|
|
22
22
|
require 'glimmer/libui/control_proxy'
|
23
23
|
require 'glimmer/data_binding/observer'
|
24
|
+
require 'glimmer/fiddle_consumer'
|
24
25
|
|
25
26
|
using ArrayIncludeMethods
|
26
27
|
|
@@ -30,6 +31,8 @@ module Glimmer
|
|
30
31
|
#
|
31
32
|
# Follows the Proxy Design Pattern
|
32
33
|
class TableProxy < ControlProxy
|
34
|
+
include Glimmer::FiddleConsumer
|
35
|
+
|
33
36
|
attr_reader :model_handler, :model, :table_params, :columns
|
34
37
|
|
35
38
|
def initialize(keyword, parent, args, &block)
|
@@ -71,8 +74,16 @@ module Glimmer
|
|
71
74
|
@last_cell_rows = @cell_rows.clone
|
72
75
|
Glimmer::DataBinding::Observer.proc do
|
73
76
|
if @cell_rows.size < @last_cell_rows.size && @last_cell_rows.include_all?(*@cell_rows)
|
74
|
-
@last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |
|
75
|
-
::LibUI.table_model_row_deleted(model,
|
77
|
+
@last_cell_rows.array_diff_indexes(@cell_rows).reverse.each do |row|
|
78
|
+
::LibUI.table_model_row_deleted(model, row)
|
79
|
+
end
|
80
|
+
elsif @cell_rows.size > @last_cell_rows.size && @cell_rows.include_all?(*@last_cell_rows)
|
81
|
+
@cell_rows.array_diff_indexes(@last_cell_rows).each do |row|
|
82
|
+
::LibUI.table_model_row_inserted(model, row)
|
83
|
+
end
|
84
|
+
else
|
85
|
+
@cell_rows.each_with_index do |new_row_data, row|
|
86
|
+
::LibUI.table_model_row_changed(model, row) if new_row_data != @last_cell_rows[row]
|
76
87
|
end
|
77
88
|
end
|
78
89
|
@last_cell_rows = @cell_rows.clone
|
@@ -104,21 +115,19 @@ module Glimmer
|
|
104
115
|
|
105
116
|
def build_control
|
106
117
|
@model_handler = ::LibUI::FFI::TableModelHandler.malloc
|
107
|
-
@model_handler.NumColumns =
|
108
|
-
@model_handler.ColumnType =
|
118
|
+
@model_handler.NumColumns = fiddle_closure_block_caller(4) { @columns.map {|c| c.is_a?(DualColumn) ? 2 : 1}.sum }
|
119
|
+
@model_handler.ColumnType = fiddle_closure_block_caller(4, [1, 1, 4]) do |_, _, column|
|
109
120
|
case @columns[column]
|
110
121
|
when TextColumnProxy, ButtonColumnProxy, NilClass
|
111
122
|
0
|
112
123
|
when ImageColumnProxy, ImageTextColumnProxy
|
113
124
|
1
|
114
|
-
when CheckboxColumnProxy, CheckboxTextColumnProxy
|
125
|
+
when CheckboxColumnProxy, CheckboxTextColumnProxy, ProgressBarColumnProxy
|
115
126
|
2
|
116
|
-
# when ProgressBarColumnProxy
|
117
|
-
# 2
|
118
127
|
end
|
119
128
|
end
|
120
|
-
@model_handler.NumRows =
|
121
|
-
@model_handler.CellValue =
|
129
|
+
@model_handler.NumRows = fiddle_closure_block_caller(4) { cell_rows.count }
|
130
|
+
@model_handler.CellValue = fiddle_closure_block_caller(1, [1, 1, 4, 4]) do |_, _, row, column|
|
122
131
|
the_cell_rows = expanded_cell_rows
|
123
132
|
case @columns[column]
|
124
133
|
when TextColumnProxy, ButtonColumnProxy, NilClass
|
@@ -127,9 +136,11 @@ module Glimmer
|
|
127
136
|
::LibUI.new_table_value_image((expanded_cell_rows[row] && (expanded_cell_rows[row][column].respond_to?(:libui) ? expanded_cell_rows[row][column].libui : expanded_cell_rows[row][column])))
|
128
137
|
when CheckboxColumnProxy, CheckboxTextColumnProxy
|
129
138
|
::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column] == 1 || expanded_cell_rows[row][column].to_s.strip.downcase == 'true' ? 1 : 0)))
|
139
|
+
when ProgressBarColumnProxy
|
140
|
+
::LibUI.new_table_value_int((expanded_cell_rows[row] && (expanded_cell_rows[row][column].to_i)))
|
130
141
|
end
|
131
142
|
end
|
132
|
-
@model_handler.SetCellValue =
|
143
|
+
@model_handler.SetCellValue = fiddle_closure_block_caller(0, [1, 1, 4, 4, 1]) do |_, _, row, column, val|
|
133
144
|
case @columns[column]
|
134
145
|
when TextColumnProxy
|
135
146
|
column = @columns[column].index
|
@@ -159,16 +170,6 @@ module Glimmer
|
|
159
170
|
end
|
160
171
|
end
|
161
172
|
|
162
|
-
def rbcallback(*args, &block)
|
163
|
-
# TODO consider moving to a more general reusable location in the future (e.g. when used with `AreaProxy`)
|
164
|
-
# Protects BlockCaller objects from garbage collection.
|
165
|
-
@blockcaller ||= []
|
166
|
-
args << [0] if args.size == 1 # Argument types are ommited
|
167
|
-
blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
|
168
|
-
@blockcaller << blockcaller
|
169
|
-
blockcaller
|
170
|
-
end
|
171
|
-
|
172
173
|
def next_column_index
|
173
174
|
@next_column_index ||= -1
|
174
175
|
@next_column_index += 1
|
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.1.0
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -194,6 +194,7 @@ files:
|
|
194
194
|
- VERSION
|
195
195
|
- bin/girb
|
196
196
|
- bin/girb_runner.rb
|
197
|
+
- examples/basic_area.rb
|
197
198
|
- examples/basic_button.rb
|
198
199
|
- examples/basic_entry.rb
|
199
200
|
- examples/basic_table.rb
|
@@ -202,6 +203,7 @@ files:
|
|
202
203
|
- examples/basic_table_checkbox_text.rb
|
203
204
|
- examples/basic_table_image.rb
|
204
205
|
- examples/basic_table_image_text.rb
|
206
|
+
- examples/basic_table_progress_bar.rb
|
205
207
|
- examples/basic_window.rb
|
206
208
|
- examples/basic_window2.rb
|
207
209
|
- examples/color_button.rb
|
@@ -211,6 +213,7 @@ files:
|
|
211
213
|
- examples/editable_table.rb
|
212
214
|
- examples/font_button.rb
|
213
215
|
- examples/form.rb
|
216
|
+
- examples/form_table.rb
|
214
217
|
- examples/grid.rb
|
215
218
|
- examples/meta_example.rb
|
216
219
|
- examples/midi_player.rb
|
@@ -225,7 +228,9 @@ files:
|
|
225
228
|
- lib/glimmer/dsl/libui/property_expression.rb
|
226
229
|
- lib/glimmer/dsl/libui/save_file_expression.rb
|
227
230
|
- lib/glimmer/dsl/libui/tab_item_expression.rb
|
231
|
+
- lib/glimmer/fiddle_consumer.rb
|
228
232
|
- lib/glimmer/libui/about_menu_item_proxy.rb
|
233
|
+
- lib/glimmer/libui/area_proxy.rb
|
229
234
|
- lib/glimmer/libui/box.rb
|
230
235
|
- lib/glimmer/libui/button_column_proxy.rb
|
231
236
|
- lib/glimmer/libui/button_proxy.rb
|
@@ -257,9 +262,12 @@ files:
|
|
257
262
|
- lib/glimmer/libui/menu_proxy.rb
|
258
263
|
- lib/glimmer/libui/multiline_entry_proxy.rb
|
259
264
|
- lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb
|
265
|
+
- lib/glimmer/libui/path_proxy.rb
|
260
266
|
- lib/glimmer/libui/preferences_menu_item_proxy.rb
|
267
|
+
- lib/glimmer/libui/progress_bar_column_proxy.rb
|
261
268
|
- lib/glimmer/libui/quit_menu_item_proxy.rb
|
262
269
|
- lib/glimmer/libui/radio_buttons_proxy.rb
|
270
|
+
- lib/glimmer/libui/rectangle_proxy.rb
|
263
271
|
- lib/glimmer/libui/separator_menu_item_proxy.rb
|
264
272
|
- lib/glimmer/libui/tab_item_proxy.rb
|
265
273
|
- lib/glimmer/libui/table_proxy.rb
|