glimmer-dsl-libui 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 588ece65aa562fd337018de00f5e60156926cb6d9ee6144f5f89e2e8dfaa2d74
4
- data.tar.gz: f50f57a58f6b7915f5e9fc123eecf9e982be5f18ff93833a8d0603ce3955063d
3
+ metadata.gz: fcb53c296d806a067e4397ba0b51d6449672846fc126285f9b3ecdaf93b204a9
4
+ data.tar.gz: 97dd865c4b0b45e2ba88e6c16b47196f0c6aa2151697ba33c6a9dd391873507e
5
5
  SHA512:
6
- metadata.gz: 6b0d02fde1567c4be008e81b91fc67df319fd2c46bf44466da6e4ff2e8a49f31bd239a78ed69be43f1338fa51dd4fcd648d6c5ecbe2aafe41fb345911df327bf
7
- data.tar.gz: cfe32a98fddb52c1cf320e4e8d7651d0b083172ada4dd4b43441f0fdb839cde207841c96e39d9e47c7cffeb536a7d6620aed3abe869c790ce595c4361ac2988c
6
+ metadata.gz: daaff4633ae70ad0691cb4828fc1678ca2fda631d1ce23dce3ebbff889fef60f25569e84492ce121a2ff518af94b796a44c0ac54095f9b843e9ec7ce9e104902
7
+ data.tar.gz: 6a633312a198a65ff053d1ad28112716e2d8a2468c3336a471786dcb2cf6cdc9b31b12af1881da98864d2ab953a38d92e39278631c92cd9d1d995c4a6ad71360
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.1.3
4
+
5
+ - New examples/area_gallery.rb
6
+ - Support `figure(x = nil, y = nil) {}` (`draw_path_new_figure`)
7
+ - Support `closed true` property inside nested figure (`draw_path_close_figure`)
8
+ - Support `line`
9
+ - Support `bezier`
10
+ - Support `arc` (`draw_path_arc_to` if `draw_path_new_figure` was called already or `draw_path_new_figure_with_arc` if parent is a figure without x,y)
11
+ - Support `square` with `x`, `y`, and `length` properties
12
+
3
13
  ## 0.1.2
4
14
 
5
15
  - Support re-opening a control by using `#content {...}`
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.1.2
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.3
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)
@@ -19,7 +19,7 @@ The main trade-off in using [Glimmer DSL for LibUI](https://rubygems.org/gems/gl
19
19
  - Scaffolding for new custom controls, apps, and gems
20
20
  - Native-Executable packaging on Mac, Windows, and Linux.
21
21
 
22
- Example:
22
+ Hello, World!
23
23
 
24
24
  ```ruby
25
25
  require 'glimmer-dsl-libui'
@@ -32,6 +32,98 @@ window('hello world').show
32
32
  ![glimmer-dsl-libui-mac-basic-window.png](images/glimmer-dsl-libui-mac-basic-window.png)
33
33
  ![glimmer-dsl-libui-linux-basic-window.png](images/glimmer-dsl-libui-linux-basic-window.png)
34
34
 
35
+ Basic Table Progress Bar
36
+
37
+ ```ruby
38
+ require 'glimmer-dsl-libui'
39
+
40
+ include Glimmer
41
+
42
+ data = [
43
+ ['task 1', 0],
44
+ ['task 2', 15],
45
+ ['task 3', 100],
46
+ ['task 4', 75],
47
+ ['task 5', -1],
48
+ ]
49
+
50
+ window('Task progress', 300, 200) {
51
+ horizontal_box {
52
+ table {
53
+ text_column('Task')
54
+ progress_bar_column('Progress')
55
+
56
+ cell_rows data
57
+ }
58
+ }
59
+ }.show
60
+ ```
61
+
62
+ ![glimmer-dsl-libui-mac-basic-table-progress-bar.png](images/glimmer-dsl-libui-mac-basic-table-progress-bar.png)
63
+ ![glimmer-dsl-libui-linux-basic-table-progress-bar.png](images/glimmer-dsl-libui-linux-basic-table-progress-bar.png)
64
+
65
+ Area Gallery
66
+
67
+ ```ruby
68
+ require 'glimmer-dsl-libui'
69
+
70
+ include Glimmer
71
+
72
+ window('Area Gallery', 400, 400) {
73
+ vertical_box {
74
+ area {
75
+ path { # declarative stable path
76
+ square(0, 0, 100)
77
+ square(100, 100, 400)
78
+
79
+ fill r: 102, g: 102, b: 204
80
+ }
81
+ path { # declarative stable path
82
+ rectangle(0, 100, 100, 400)
83
+ rectangle(100, 0, 400, 100)
84
+
85
+ fill r: 204, g: 102, b: 204
86
+ }
87
+ path { # declarative stable path
88
+ figure(100, 100) {
89
+ line(100, 400)
90
+ line(400, 100)
91
+ line(400, 400)
92
+
93
+ closed true
94
+ }
95
+
96
+ fill r: 202, g: 102, b: 104, a: 0.5
97
+ stroke thickness: 1, r: 0, g: 0, b: 0
98
+ }
99
+ path { # declarative stable path
100
+ figure(0, 0) {
101
+ bezier(200, 100, 100, 200, 400, 100)
102
+ bezier(300, 100, 100, 300, 100, 400)
103
+ bezier(100, 300, 300, 100, 400, 400)
104
+
105
+ closed true
106
+ }
107
+
108
+ fill r: 202, g: 102, b: 204, a: 0.5
109
+ stroke thickness: 2, r: 0, g: 0, b: 0
110
+ }
111
+ path { # declarative stable path
112
+ arc(200, 200, 90, 0, 360, false)
113
+
114
+ fill r: 202, g: 102, b: 204, a: 0.5
115
+ stroke thickness: 2, r: 0, g: 0, b: 0
116
+ }
117
+ }
118
+ }
119
+ }.show
120
+ ```
121
+
122
+ ![glimmer-dsl-libui-mac-area-gallery.png](images/glimmer-dsl-libui-mac-area-gallery.png)
123
+ ![glimmer-dsl-libui-linux-area-gallery.png](images/glimmer-dsl-libui-linux-area-gallery.png)
124
+
125
+ [Check Out Many More Examples Over Here!](#examples)
126
+
35
127
  NOTE: [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is in early alpha mode (only supports included [examples](#examples)). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
36
128
 
37
129
  Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interested in:
@@ -43,9 +135,10 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
43
135
 
44
136
  ## Table of Contents
45
137
 
46
- - [Glimmer DSL for LibUI 0.1.2](#-glimmer-dsl-for-libui-012)
138
+ - [Glimmer DSL for LibUI 0.1.3](#-glimmer-dsl-for-libui-013)
47
139
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
140
  - [Usage](#usage)
141
+ - [Girb (Glimmer IRB)](#girb-glimmer-irb)
49
142
  - [API](#api)
50
143
  - [Supported Controls](#supported-controls)
51
144
  - [Common Control Properties](#common-control-properties)
@@ -58,7 +151,6 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
58
151
  - [API Gotchas](#api-gotchas)
59
152
  - [Original API](#original-api)
60
153
  - [Glimmer Style Guide](#glimmer-style-guide)
61
- - [Girb (Glimmer IRB)](#girb-glimmer-irb)
62
154
  - [Examples](#examples)
63
155
  - [Basic Window](#basic-window)
64
156
  - [Basic Button](#basic-button)
@@ -83,6 +175,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
83
175
  - [Form Table](#form-table)
84
176
  - [Basic Area](#basic-area)
85
177
  - [Dynamic Area](#dynamic-area)
178
+ - [Area Gallery](#area-gallery)
86
179
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
87
180
  - [Help](#help)
88
181
  - [Issues](#issues)
@@ -170,7 +263,7 @@ gem install glimmer-dsl-libui
170
263
  Or install via Bundler `Gemfile`:
171
264
 
172
265
  ```ruby
173
- gem 'glimmer-dsl-libui', '~> 0.1.2'
266
+ gem 'glimmer-dsl-libui', '~> 0.1.3'
174
267
  ```
175
268
 
176
269
  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.
@@ -197,6 +290,24 @@ end
197
290
  Application.new.launch
198
291
  ```
199
292
 
293
+ If you are new to [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui), check out [Girb](#girb-glimmer-irb) and [Examples](#examples) to quickly learn through copy/paste. You may refer to the [API](#api) later on once you have gotten your feet wet with [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) and need more detailed reference information.
294
+
295
+ ## Girb (Glimmer IRB)
296
+
297
+ You can run the `girb` command (`bin/girb` if you cloned the project locally) to do some quick and dirty experimentation and learning:
298
+
299
+ ```
300
+ girb
301
+ ```
302
+
303
+ 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.
304
+
305
+ ![glimmer-dsl-libui-girb.png](images/glimmer-dsl-libui-girb.png)
306
+
307
+ For a more advanced code editing tool, check out the [Meta-Example (The Example of Examples)](#examples).
308
+
309
+ Gotcha: On the Mac, when you close a window opened in `girb`, it remains open until you enter `exit` or open another GUI window.
310
+
200
311
  ## API
201
312
 
202
313
  Any control returned by a [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) keyword declaration can be introspected for its properties and updated via object-oriented attributes (standard Ruby `attr`/`attr=` or `set_attr`).
@@ -227,6 +338,8 @@ Control(Args) | Properties | Listeners
227
338
  ------------- | ---------- | ---------
228
339
  `about_menu_item` | None | `on_clicked`
229
340
  `area` | None | `on_draw`
341
+ `arc(x_center as Numeric, y_center as Numeric, radius as Numeric, start_angle as Numeric, sweep as Numeric, is_negative as Boolean)` | `x_center` (`Numeric`), `y_center` (`Numeric`), `radius` (`Numeric`), `start_angle` (`Numeric`), `sweep` (`Numeric`), `is_negative` (Boolean) | None
342
+ `bezier(c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)` | `c1_x` (`Numeric`), `c1_y` (`Numeric`), `c2_x` (`Numeric`), `c2_y` (`Numeric`), `end_x` (`Numeric`), `end_y` (`Numeric`) | None
230
343
  `button(text as String)` | `text` (`String`) | `on_clicked`
231
344
  `button_column(name as String)` | `enabled` (Boolean) | None
232
345
  `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
@@ -238,6 +351,7 @@ Control(Args) | Properties | Listeners
238
351
  `date_time_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`
239
352
  `editable_combobox` | `items` (`Array` of `String`), `text` (`String`) | `on_changed`
240
353
  `entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
354
+ `figure(x as Numeric, y as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `closed` (Boolean) | None
241
355
  `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`
242
356
  `form` | `padded` (Boolean) | None
243
357
  `grid` | `padded` (Boolean) | None
@@ -249,6 +363,7 @@ Control(Args) | Properties | Listeners
249
363
  `image_column(name as String)` | None | None
250
364
  `image_text_column(name as String)` | None | None
251
365
  `label(text as String)` | `text` (`String`) | None
366
+ `line(x as Numeric, y as Numeric)` | `x` (`Numeric`), `y` (`Numeric`) | None
252
367
  `menu(text as String)` | None | None
253
368
  `menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
254
369
  `multiline_entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
@@ -261,9 +376,10 @@ Control(Args) | Properties | Listeners
261
376
  `progress_bar_column(name as String)` | None | None
262
377
  `quit_menu_item` | None | `on_clicked`
263
378
  `radio_buttons` | `selected` (`Integer`) | `on_selected`
264
- `rectangle(x as Numeric, y as Numeric, width as Numeric, height as Numeric)` | None | None
379
+ `rectangle(x as Numeric, y as Numeric, width as Numeric, height as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `width` (`Numeric`), `height` (`Numeric`) | None
265
380
  `slider(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
266
381
  `spinbox(min as Numeric, max as Numeric)` | `value` (`Numeric`) | `on_changed`
382
+ `square(x as Numeric, y as Numeric, length as Numeric)` | `x` (`Numeric`), `y` (`Numeric`), `length` (`Numeric`) | None
267
383
  `tab` | `margined` (Boolean), `num_pages` (`Integer`) | None
268
384
  `tab_item(name as String)` | `index` [read-only] (`Integer`), `margined` (Boolean), `name` [read-only] (`String`) | None
269
385
  `table` | `cell_rows` (`Array` (rows) of `Arrays` (row columns) of cell values (e.g. `String` values for `text_column` cells or `Array` of `image`/`String` for `image_text_column`)), `editable` as Boolean | None
@@ -328,6 +444,80 @@ Note that the `cell_rows` property declaration results in "implicit data-binding
328
444
  - Inserting cell rows: Calling `Array#<<`, `Array#push`, `Array#prepend`, or any insertion/addition `Array` method automatically inserts rows in actual `table` control
329
445
  - Changing cell rows: Calling `Array#[]=`, `Array#map!`, or any update `Array` method automatically updates rows in actual `table` control
330
446
 
447
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
448
+
449
+ ```ruby
450
+ require 'glimmer-dsl-libui'
451
+
452
+ include Glimmer
453
+
454
+ data = [
455
+ ['Lisa Sky', 'lisa@sky.com', '720-523-4329', 'Denver', 'CO', '80014'],
456
+ ['Jordan Biggins', 'jordan@biggins.com', '617-528-5399', 'Boston', 'MA', '02101'],
457
+ ['Mary Glass', 'mary@glass.com', '847-589-8788', 'Elk Grove Village', 'IL', '60007'],
458
+ ['Darren McGrath', 'darren@mcgrath.com', '206-539-9283', 'Seattle', 'WA', '98101'],
459
+ ['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA', '90001'],
460
+ ]
461
+
462
+ window('Contacts', 600, 600) { |w|
463
+ margined true
464
+
465
+ vertical_box {
466
+ form {
467
+ stretchy false
468
+
469
+ @name_entry = entry {
470
+ label 'Name'
471
+ }
472
+ @email_entry = entry {
473
+ label 'Email'
474
+ }
475
+ @phone_entry = entry {
476
+ label 'Phone'
477
+ }
478
+ @city_entry = entry {
479
+ label 'City'
480
+ }
481
+ @state_entry = entry {
482
+ label 'State'
483
+ }
484
+ }
485
+
486
+ button('Save Contact') {
487
+ stretchy false
488
+
489
+ on_clicked do
490
+ new_row = [@name_entry.text, @email_entry.text, @phone_entry.text, @city_entry.text, @state_entry.text]
491
+ if new_row.include?('')
492
+ msg_box_error(w, 'Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
493
+ else
494
+ data << new_row # automatically inserts a row into the table due to implicit data-binding
495
+ @name_entry.text = ''
496
+ @email_entry.text = ''
497
+ @phone_entry.text = ''
498
+ @city_entry.text = ''
499
+ @state_entry.text = ''
500
+ end
501
+ end
502
+ }
503
+
504
+ table {
505
+ text_column('Name')
506
+ text_column('Email')
507
+ text_column('Phone')
508
+ text_column('City')
509
+ text_column('State')
510
+
511
+ cell_rows data # implicit data-binding
512
+ }
513
+ }
514
+ }.show
515
+ ```
516
+
517
+ ![glimmer-dsl-libui-linux-form-table.png](images/glimmer-dsl-libui-linux-form-table.png)
518
+
519
+ Learn more by checking out [examples](#examples).
520
+
331
521
  ### Area API
332
522
 
333
523
  The `area` control can be used in one of two ways:
@@ -384,6 +574,14 @@ window('Basic Area', 400, 400) {
384
574
 
385
575
  Check [examples/dynamic_area.rb](#dynamic-area) for a more detailed semi-declarative example.
386
576
 
577
+ Available nested `path` shapes:
578
+ - `rectangle(x as Numeric, y as Numeric, width as Numeric, height as Numeric)`
579
+ - `square(x as Numeric, y as Numeric, length as Numeric)`
580
+ - `arc(x_center as Numeric, y_center as Numeric, radius as Numeric, start_angle as Numeric, sweep as Numeric, is_negative as Boolean)`
581
+ - `line(x as Numeric, y as Numeric)`
582
+ - `bezier(c1_x as Numeric, c1_y as Numeric, c2_x as Numeric, c2_y as Numeric, end_x as Numeric, end_y as Numeric)`
583
+ - `figure(x as Numeric, y as Numeric)` (composite that can contain other shapes) (can set `closed true` to connect last point to first point automatically)
584
+
387
585
  In general, it is recommended to use declarative stable paths whenever feasible since they require less code and simpler maintenance. But, in more advanced cases, semi-declarative dynamic paths could be used instead, especially if there are thousands of paths.
388
586
 
389
587
  To redraw an `area`, you may call `#queue_redraw_all` method.
@@ -439,21 +637,9 @@ check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.
439
637
  - 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.
440
638
  - 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.
441
639
 
442
- ## Girb (Glimmer IRB)
443
-
444
- You can run the `girb` command (`bin/girb` if you cloned the project locally):
445
-
446
- ```
447
- girb
448
- ```
449
-
450
- 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.
451
-
452
- Gotcha: On the Mac, when you close a window opened in `girb`, it remains open until you enter `exit` or open another GUI window.
453
-
454
640
  ## Examples
455
641
 
456
- 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.
642
+ The following 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.
457
643
 
458
644
  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.
459
645
 
@@ -3005,6 +3191,87 @@ window('Dynamic Area', 240, 600) {
3005
3191
  }.show
3006
3192
  ```
3007
3193
 
3194
+ ### Area Gallery
3195
+
3196
+ [examples/area_gallery.rb](examples/area_gallery.rb)
3197
+
3198
+ Run with this command from the root of the project if you cloned the project:
3199
+
3200
+ ```
3201
+ ruby -r './lib/glimmer-dsl-libui' examples/area_gallery.rb
3202
+ ```
3203
+
3204
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
3205
+
3206
+ ```
3207
+ ruby -r glimmer-dsl-libui -e "require 'examples/area_gallery'"
3208
+ ```
3209
+
3210
+ Mac
3211
+
3212
+ ![glimmer-dsl-libui-mac-area-gallery.png](images/glimmer-dsl-libui-mac-area-gallery.png)
3213
+
3214
+ Linux
3215
+
3216
+ ![glimmer-dsl-libui-linux-area-gallery.png](images/glimmer-dsl-libui-linux-area-gallery.png)
3217
+
3218
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
3219
+
3220
+ ```ruby
3221
+ require 'glimmer-dsl-libui'
3222
+
3223
+ include Glimmer
3224
+
3225
+ window('Area Gallery', 400, 400) {
3226
+ vertical_box {
3227
+ area {
3228
+ path { # declarative stable path
3229
+ square(0, 0, 100)
3230
+ square(100, 100, 400)
3231
+
3232
+ fill r: 102, g: 102, b: 204
3233
+ }
3234
+ path { # declarative stable path
3235
+ rectangle(0, 100, 100, 400)
3236
+ rectangle(100, 0, 400, 100)
3237
+
3238
+ fill r: 204, g: 102, b: 204
3239
+ }
3240
+ path { # declarative stable path
3241
+ figure(100, 100) {
3242
+ line(100, 400)
3243
+ line(400, 100)
3244
+ line(400, 400)
3245
+
3246
+ closed true
3247
+ }
3248
+
3249
+ fill r: 202, g: 102, b: 104, a: 0.5
3250
+ stroke thickness: 1, r: 0, g: 0, b: 0
3251
+ }
3252
+ path { # declarative stable path
3253
+ figure(0, 0) {
3254
+ bezier(200, 100, 100, 200, 400, 100)
3255
+ bezier(300, 100, 100, 300, 100, 400)
3256
+ bezier(100, 300, 300, 100, 400, 400)
3257
+
3258
+ closed true
3259
+ }
3260
+
3261
+ fill r: 202, g: 102, b: 204, a: 0.5
3262
+ stroke thickness: 2, r: 0, g: 0, b: 0
3263
+ }
3264
+ path { # declarative stable path
3265
+ arc(200, 200, 90, 0, 360, false)
3266
+
3267
+ fill r: 202, g: 102, b: 204, a: 0.5
3268
+ stroke thickness: 2, r: 0, g: 0, b: 0
3269
+ }
3270
+ }
3271
+ }
3272
+ }.show
3273
+ ```
3274
+
3008
3275
  ## Contributing to glimmer-dsl-libui
3009
3276
 
3010
3277
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -0,0 +1,52 @@
1
+ require 'glimmer-dsl-libui'
2
+
3
+ include Glimmer
4
+
5
+ window('Area Gallery', 400, 400) {
6
+ vertical_box {
7
+ area {
8
+ path { # declarative stable path
9
+ square(0, 0, 100)
10
+ square(100, 100, 400)
11
+
12
+ fill r: 102, g: 102, b: 204
13
+ }
14
+ path { # declarative stable path
15
+ rectangle(0, 100, 100, 400)
16
+ rectangle(100, 0, 400, 100)
17
+
18
+ fill r: 204, g: 102, b: 204
19
+ }
20
+ path { # declarative stable path
21
+ figure(100, 100) {
22
+ line(100, 400)
23
+ line(400, 100)
24
+ line(400, 400)
25
+
26
+ closed true
27
+ }
28
+
29
+ fill r: 202, g: 102, b: 104, a: 0.5
30
+ stroke thickness: 1, r: 0, g: 0, b: 0
31
+ }
32
+ path { # declarative stable path
33
+ figure(0, 0) {
34
+ bezier(200, 100, 100, 200, 400, 100)
35
+ bezier(300, 100, 100, 300, 100, 400)
36
+ bezier(100, 300, 300, 100, 400, 400)
37
+
38
+ closed true
39
+ }
40
+
41
+ fill r: 202, g: 102, b: 204, a: 0.5
42
+ stroke thickness: 2, r: 0, g: 0, b: 0
43
+ }
44
+ path { # declarative stable path
45
+ arc(200, 200, 90, 0, 360, false)
46
+
47
+ fill r: 202, g: 102, b: 204, a: 0.5
48
+ stroke thickness: 2, r: 0, g: 0, b: 0
49
+ }
50
+ }
51
+ }
52
+ }.show
Binary file
@@ -29,7 +29,7 @@ module Glimmer
29
29
  include ParentExpression
30
30
 
31
31
  def can_interpret?(parent, keyword, *args, &block)
32
- Glimmer::LibUI::ControlProxy.control_exists?(keyword)
32
+ Glimmer::LibUI::ControlProxy.exists?(keyword)
33
33
  end
34
34
 
35
35
  def interpret(parent, keyword, *args, &block)
@@ -39,6 +39,7 @@ module Glimmer
39
39
  listener
40
40
  property
41
41
  control
42
+ shape
42
43
  ]
43
44
  )
44
45
  end
@@ -21,13 +21,17 @@
21
21
 
22
22
  require 'glimmer/dsl/expression'
23
23
  require 'glimmer/libui/control_proxy'
24
+ require 'glimmer/libui/shape'
24
25
 
25
26
  module Glimmer
26
27
  module DSL
27
28
  module Libui
28
29
  class PropertyExpression < Expression
29
30
  def can_interpret?(parent, keyword, *args, &block)
30
- parent.is_a?(Glimmer::LibUI::ControlProxy) and
31
+ (
32
+ parent.is_a?(Glimmer::LibUI::ControlProxy) or
33
+ parent.is_a?(Glimmer::LibUI::Shape)
34
+ ) and
31
35
  block.nil? and
32
36
  parent.respond_to?(keyword, *args)
33
37
  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/dsl/expression'
23
+ require 'glimmer/dsl/parent_expression'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Libui
28
+ class ShapeExpression < Expression
29
+ include ParentExpression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ Glimmer::LibUI::Shape.exists?(keyword) and
33
+ (
34
+ parent.is_a?(Glimmer::LibUI::PathProxy) or
35
+ parent.is_a?(Glimmer::LibUI::Shape)
36
+ )
37
+ end
38
+
39
+ def interpret(parent, keyword, *args, &block)
40
+ Glimmer::LibUI::Shape.create(keyword, parent, args, &block)
41
+ end
42
+
43
+ def add_content(parent, keyword, *args, &block)
44
+ super
45
+ parent.post_add_content
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ # TODO Consider moving all shapes underneath Shape namespace
54
+ require 'glimmer/libui/path_proxy'
55
+ require 'glimmer/libui/shape'
56
+ Dir[File.expand_path('../../libui/*.rb', __dir__)].each {|f| require f}
@@ -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/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Arc < Shape
27
+ parameters :x_center, :y_center, :radius, :start_angle, :sweep, :is_negative
28
+
29
+ def draw(area_draw_params)
30
+ @args[5] ||= ControlProxy.boolean_to_integer(@args[5], allow_nil: false)
31
+ if parent.is_a?(Figure) && parent.x.nil? && parent.y.nil?
32
+ ::LibUI.draw_path_new_figure_with_arc(path_proxy.libui, *@args)
33
+ else
34
+ ::LibUI.draw_path_arc_to(path_proxy.libui, *@args)
35
+ end
36
+ super
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Bezier < Shape
27
+ parameters :c1_x, :c1_y, :c2_x, :c2_y, :end_x, :end_y
28
+
29
+ def draw(area_draw_params)
30
+ ::LibUI.draw_path_bezier_to(path_proxy.libui, *@args)
31
+ super
32
+ end
33
+ end
34
+ end
35
+ end
@@ -26,7 +26,7 @@ module Glimmer
26
26
  # Follows the Proxy Design Pattern
27
27
  class ControlProxy
28
28
  class << self
29
- def control_exists?(keyword)
29
+ def exists?(keyword)
30
30
  ::LibUI.respond_to?("new_#{keyword}") ||
31
31
  ::LibUI.respond_to?(keyword) ||
32
32
  Glimmer::LibUI.constants.include?("#{keyword.camelcase(:upper)}Proxy".to_sym)
@@ -55,12 +55,12 @@ module Glimmer
55
55
  control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
56
56
  end
57
57
 
58
- def integer_to_boolean(int)
59
- int.nil? ? nil : int == 1
58
+ def integer_to_boolean(int, allow_nil: true)
59
+ int.nil? ? (allow_nil ? nil : false) : int == 1
60
60
  end
61
61
 
62
- def boolean_to_integer(bool)
63
- bool.nil? ? nil : (bool ? 1 : 0)
62
+ def boolean_to_integer(bool, allow_nil: true)
63
+ bool.nil? ? (allow_nil ? nil : 0) : (bool ? 1 : 0)
64
64
  end
65
65
 
66
66
  def menu_proxies
@@ -92,7 +92,7 @@ module Glimmer
92
92
  ]
93
93
 
94
94
  # libui returns the contained LibUI object
95
- attr_reader :parent_proxy, :libui, :args, :keyword
95
+ attr_reader :parent_proxy, :libui, :args, :keyword, :block
96
96
 
97
97
  def initialize(keyword, parent, args, &block)
98
98
  @keyword = keyword
@@ -0,0 +1,51 @@
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/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Represents a figure consisting of shapes (nested under path)
27
+ # Can optionally have `closed true` property (connecting last point to first point automatically)
28
+ class Figure < Shape
29
+ parameters :x, :y
30
+
31
+ def draw(area_draw_params)
32
+ ::LibUI.draw_path_new_figure(path_proxy.libui, *@args) unless @args.empty? # TODO if args empty then wait till there is an arc child and it starts the figure
33
+ children.each {|child| child.draw(area_draw_params)}
34
+ ::LibUI.draw_path_close_figure(path_proxy.libui) if closed?
35
+ super
36
+ end
37
+
38
+ def closed(value = nil)
39
+ if value.nil?
40
+ @closed
41
+ else
42
+ @closed = value
43
+ area_proxy&.queue_redraw_all
44
+ end
45
+ end
46
+ alias closed= closed
47
+ alias set_closed closed
48
+ alias closed? closed
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Line < Shape
27
+ parameters :x, :y
28
+
29
+ def draw(area_draw_params)
30
+ ::LibUI.draw_path_line_to(path_proxy.libui, *@args)
31
+ super
32
+ end
33
+ end
34
+ end
35
+ end
@@ -72,6 +72,7 @@ module Glimmer
72
72
  @fill ||= {}
73
73
  else
74
74
  @fill = args
75
+ @fill[:a] = 1.0 if @fill[:a].nil?
75
76
  @parent_proxy&.queue_redraw_all
76
77
  end
77
78
  @fill.tap do
@@ -95,6 +96,7 @@ module Glimmer
95
96
  @stroke ||= {}
96
97
  else
97
98
  @stroke = args
99
+ @stroke[:a] = 1.0 if @stroke[:a].nil?
98
100
  @parent_proxy&.queue_redraw_all
99
101
  end
100
102
  @stroke.tap do
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Rectangle < Shape
27
+ parameters :x, :y, :width, :height
28
+
29
+ def draw(area_draw_params)
30
+ ::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args)
31
+ super
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,129 @@
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
+ # Represents LibUI lightweight shape objects nested under path (e.g. line, rectangle, arc, bezier)
25
+ class Shape
26
+ class << self
27
+ def exists?(keyword)
28
+ Glimmer::LibUI.constants.include?(constant_symbol(keyword)) and
29
+ shape_class(keyword).respond_to?(:ancestors) and
30
+ shape_class(keyword).ancestors.include?(Shape)
31
+ end
32
+
33
+ def create(keyword, parent, args, &block)
34
+ shape_class(keyword).new(keyword, parent, args, &block)
35
+ end
36
+
37
+ def shape_class(keyword)
38
+ Glimmer::LibUI.const_get(constant_symbol(keyword))
39
+ end
40
+
41
+ def parameters(*params)
42
+ if params.empty?
43
+ @parameters
44
+ else
45
+ @parameters = params
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def constant_symbol(keyword)
52
+ "#{keyword.camelcase(:upper)}".to_sym
53
+ end
54
+ end
55
+
56
+ attr_reader :parent, :args, :keyword, :block
57
+
58
+ def initialize(keyword, parent, args, &block)
59
+ @keyword = keyword
60
+ @parent = parent
61
+ @args = args
62
+ @block = block
63
+ post_add_content if @block.nil?
64
+ end
65
+
66
+ # Subclasses may override to perform post add_content work (normally must call super)
67
+ def post_add_content
68
+ @parent&.post_initialize_child(self)
69
+ end
70
+
71
+ # Subclasses may override to perform post initialization work on an added child (normally must call super)
72
+ def post_initialize_child(child)
73
+ children << child
74
+ end
75
+
76
+ def children
77
+ @children ||= []
78
+ end
79
+
80
+ # Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method
81
+ def draw(area_draw_params)
82
+ destroy if area_proxy.nil?
83
+ end
84
+
85
+ def destroy
86
+ @parent.children.delete(self)
87
+ end
88
+
89
+ def area_proxy
90
+ find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(AreaProxy) }
91
+ end
92
+
93
+ def path_proxy
94
+ find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(PathProxy) }
95
+ end
96
+
97
+ def respond_to?(method_name, *args, &block)
98
+ self.class.parameters.include?(method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym) or
99
+ super(method_name, true)
100
+ end
101
+
102
+ def method_missing(method_name, *args, &block)
103
+ method_name_parameter = method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym
104
+ if self.class.parameters.include?(method_name_parameter)
105
+ method_name = method_name.to_s
106
+ parameter_index = self.class.parameters.index(method_name_parameter)
107
+ if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
108
+ @args[parameter_index] = args.first
109
+ area_proxy&.queue_redraw_all
110
+ else
111
+ @args[parameter_index]
112
+ end
113
+ else
114
+ super
115
+ end
116
+ end
117
+
118
+ private
119
+
120
+ def find_parent_in_ancestors(&condition)
121
+ found = self
122
+ until condition.call(found)
123
+ found = found.respond_to?(:parent_proxy) ? found.parent_proxy : found.parent
124
+ end
125
+ found
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Square < Shape
27
+ parameters :x, :y, :length
28
+
29
+ def draw(area_draw_params)
30
+ ::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args, length)
31
+ super
32
+ end
33
+ end
34
+ end
35
+ end
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.1.2
4
+ version: 0.1.3
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-28 00:00:00.000000000 Z
11
+ date: 2021-09-29 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/area_gallery.rb
197
198
  - examples/basic_area.rb
198
199
  - examples/basic_area2.rb
199
200
  - examples/basic_button.rb
@@ -230,10 +231,13 @@ files:
230
231
  - lib/glimmer/dsl/libui/open_file_expression.rb
231
232
  - lib/glimmer/dsl/libui/property_expression.rb
232
233
  - lib/glimmer/dsl/libui/save_file_expression.rb
234
+ - lib/glimmer/dsl/libui/shape_expression.rb
233
235
  - lib/glimmer/dsl/libui/tab_item_expression.rb
234
236
  - lib/glimmer/fiddle_consumer.rb
235
237
  - lib/glimmer/libui/about_menu_item_proxy.rb
238
+ - lib/glimmer/libui/arc.rb
236
239
  - lib/glimmer/libui/area_proxy.rb
240
+ - lib/glimmer/libui/bezier.rb
237
241
  - lib/glimmer/libui/box.rb
238
242
  - lib/glimmer/libui/button_column_proxy.rb
239
243
  - lib/glimmer/libui/button_proxy.rb
@@ -251,6 +255,7 @@ files:
251
255
  - lib/glimmer/libui/editable_column.rb
252
256
  - lib/glimmer/libui/editable_combobox_proxy.rb
253
257
  - lib/glimmer/libui/enableable_column.rb
258
+ - lib/glimmer/libui/figure.rb
254
259
  - lib/glimmer/libui/font_button_proxy.rb
255
260
  - lib/glimmer/libui/form_proxy.rb
256
261
  - lib/glimmer/libui/grid_proxy.rb
@@ -261,6 +266,7 @@ files:
261
266
  - lib/glimmer/libui/image_proxy.rb
262
267
  - lib/glimmer/libui/image_text_column_proxy.rb
263
268
  - lib/glimmer/libui/label_proxy.rb
269
+ - lib/glimmer/libui/line.rb
264
270
  - lib/glimmer/libui/menu_item_proxy.rb
265
271
  - lib/glimmer/libui/menu_proxy.rb
266
272
  - lib/glimmer/libui/multiline_entry_proxy.rb
@@ -270,8 +276,10 @@ files:
270
276
  - lib/glimmer/libui/progress_bar_column_proxy.rb
271
277
  - lib/glimmer/libui/quit_menu_item_proxy.rb
272
278
  - lib/glimmer/libui/radio_buttons_proxy.rb
273
- - lib/glimmer/libui/rectangle_proxy.rb
279
+ - lib/glimmer/libui/rectangle.rb
274
280
  - lib/glimmer/libui/separator_menu_item_proxy.rb
281
+ - lib/glimmer/libui/shape.rb
282
+ - lib/glimmer/libui/square.rb
275
283
  - lib/glimmer/libui/tab_item_proxy.rb
276
284
  - lib/glimmer/libui/table_proxy.rb
277
285
  - lib/glimmer/libui/text_column_proxy.rb
@@ -1,100 +0,0 @@
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
- destroy if @parent_proxy.parent_proxy.nil?
42
- end
43
-
44
- def destroy
45
- @parent_proxy.children.delete(self) unless @parent_proxy.nil?
46
- ControlProxy.control_proxies.delete(self)
47
- end
48
-
49
- def x(value = nil)
50
- if value.nil?
51
- @args[0]
52
- else
53
- @args[0] = value
54
- @parent_proxy.parent_proxy&.queue_redraw_all
55
- end
56
- end
57
- alias x= x
58
- alias set_x x
59
-
60
- def y(value = nil)
61
- if value.nil?
62
- @args[1]
63
- else
64
- @args[1] = value
65
- @parent_proxy.parent_proxy&.queue_redraw_all
66
- end
67
- end
68
- alias y= y
69
- alias set_y y
70
-
71
- def width(value = nil)
72
- if value.nil?
73
- @args[2]
74
- else
75
- @args[2] = value
76
- @parent_proxy.parent_proxy&.queue_redraw_all
77
- end
78
- end
79
- alias width= width
80
- alias set_width width
81
-
82
- def height(value = nil)
83
- if value.nil?
84
- @args[3]
85
- else
86
- @args[3] = value
87
- @parent_proxy.parent_proxy&.queue_redraw_all
88
- end
89
- end
90
- alias height= height
91
- alias set_height height
92
-
93
- private
94
-
95
- def build_control
96
- # No Op
97
- end
98
- end
99
- end
100
- end