glimmer-dsl-libui 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4aa989bad8bba6c9e59285e38a699b7842eb7f089a976782ac75363debfd829e
4
- data.tar.gz: '081812a749e0ab795dfafcac60b58ab639f50933580f5ed3e404354691dd3d94'
3
+ metadata.gz: 709fb51692fedecbca6438b288711c2fb7f3a71cb5ce5f5f16e1a5c9629bc5fb
4
+ data.tar.gz: 2706858ead6f7bf47f042be22cc40b0546706de8c4c7cfbfdf7457aeb007fa3a
5
5
  SHA512:
6
- metadata.gz: 2e189f2db6399f9f718a06ca68b82665c7d9b54031dc62a76af1a4bb056f1299f40fe9993940163594157bdfcd649635cc27967aaadb7b709286d0b630d9b584
7
- data.tar.gz: 5289461f384cf3237add39dba3fba83448c117d63ca53ac8e5dcc0af33cb4683179e077a712e927615825fc226bf94b234b4088e45b3f8de6c7b97a0d480c3a4
6
+ metadata.gz: 8b501a86cf85fb6b1c488580b76336765cf1d2fbdf864edf16e3587bba80710a900a05186e0c9e3f67a667ab64fbaf3ebcf1ec54c4ebbfb8e41ddd7b77f93555
7
+ data.tar.gz: 5e1f94ad2479f71d54a163d69d6c266eac9f361909e3c305e04afc073c882178ac1dba80fbc9927a7037a93593000eb469e0c7a9e0342003ced8cf349ddfd6ae
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.10
4
+
5
+ - Support examples/font_button.rb
6
+ - Support `font_button` control
7
+ - Add File -> Quit menu item to examples/meta_example.rb
8
+ - Glimmer Style Guide added to README.md
9
+
3
10
  ## 0.0.9
4
11
 
5
12
  - Build a meta-example (example of examples)
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.9
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.10
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)
@@ -6,17 +6,17 @@
6
6
 
7
7
  [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [LibUI](https://github.com/kojix2/LibUI) is a prerequisite-free Ruby desktop development GUI library. No need to pre-install any prerequisites. Just install the gem and have platform-independent native GUI that just works!
8
8
 
9
- [LibUI](https://github.com/kojix2/LibUI) is a thin [Ruby](https://www.ruby-lang.org/en/) wrapper around [libui](https://github.com/andlabs/libui), a relatively new C GUI library that renders native widgets on every platform (similar to [SWT](https://www.eclipse.org/swt/), but without the heavy weight of the [Java Virtual Machine](https://www.java.com/en/)).
9
+ [LibUI](https://github.com/kojix2/LibUI) is a thin [Ruby](https://www.ruby-lang.org/en/) wrapper around [libui](https://github.com/andlabs/libui), a relatively new C GUI library that renders native controls on every platform (similar to [SWT](https://www.eclipse.org/swt/), but without the heavy weight of the [Java Virtual Machine](https://www.java.com/en/)).
10
10
 
11
11
  The main trade-off in using [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) as opposed to [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) or [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk) is the fact that [SWT](https://www.eclipse.org/swt/) and [Tk](https://www.tcl.tk/) are more mature than mid-alpha [libui](https://github.com/andlabs/libui) as GUI toolkits. Still, if there is only a need to build a small simple application, [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) could be a good convenient choice due to having zero prerequisites beyond the dependencies included in the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui). Also, just like [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk), its apps start instantly and have a small memory footprint. [LibUI](https://github.com/kojix2/LibUI) is a promising new GUI toolkit that might prove quite worthy in the future.
12
12
 
13
13
  [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) aims to provide a DSL similar to the [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) to enable more productive desktop development in Ruby with:
14
- - Declarative DSL syntax that visually maps to the GUI widget hierarchy
14
+ - Declarative DSL syntax that visually maps to the GUI control hierarchy
15
15
  - Convention over configuration via smart defaults and automation of low-level details
16
16
  - Requiring the least amount of syntax possible to build GUI
17
17
  - Bidirectional Data-Binding to declaratively wire and automatically synchronize GUI with Business Models
18
- - Custom Widget support
19
- - Scaffolding for new custom widgets, apps, and gems
18
+ - Custom Control support
19
+ - Scaffolding for new custom controls, apps, and gems
20
20
  - Native-Executable packaging on Mac, Windows, and Linux.
21
21
 
22
22
  Example:
@@ -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.9](#-glimmer-dsl-for-libui-009)
46
+ - [Glimmer DSL for LibUI 0.0.10](#-glimmer-dsl-for-libui-0010)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
@@ -54,6 +54,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
54
54
  - [Extra Operations](#extra-operations)
55
55
  - [Smart Defaults and Conventions](#smart-defaults-and-conventions)
56
56
  - [Original API](#original-api)
57
+ - [Glimmer Style Guide](#glimmer-style-guide)
57
58
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
58
59
  - [Examples](#examples)
59
60
  - [Basic Window](#basic-window)
@@ -62,6 +63,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
62
63
  - [Simple Notepad](#simple-notepad)
63
64
  - [Midi Player](#midi-player)
64
65
  - [Control Gallery](#control-gallery)
66
+ - [Font Button](#font-button)
65
67
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
66
68
  - [Help](#help)
67
69
  - [Issues](#issues)
@@ -76,9 +78,9 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
76
78
 
77
79
  The Glimmer GUI DSL provides object-oriented declarative hierarchical syntax for [LibUI](https://github.com/kojix2/LibUI) that:
78
80
  - Supports smart defaults (e.g. automatic `on_closing` listener that quits `window`)
79
- - Automates wiring of widgets (e.g. `button` is automatically set as child of `window`)
81
+ - Automates wiring of controls (e.g. `button` is automatically set as child of `window`)
80
82
  - Hides lower-level details (e.g. `LibUI.main` loop is started automatically when triggering `show` on `window`)
81
- - Nests widgets according to their visual hierarchy
83
+ - Nests controls according to their visual hierarchy
82
84
  - Requires the minimum amount of syntax needed to describe an app's GUI
83
85
 
84
86
  The Glimmer GUI DSL follows these simple concepts in mapping from [LibUI](https://github.com/kojix2/LibUI) syntax:
@@ -149,7 +151,7 @@ gem install glimmer-dsl-libui
149
151
  Or install via Bundler `Gemfile`:
150
152
 
151
153
  ```ruby
152
- gem 'glimmer-dsl-libui', '~> 0.0.9'
154
+ gem 'glimmer-dsl-libui', '~> 0.0.10'
153
155
  ```
154
156
 
155
157
  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.
@@ -213,7 +215,7 @@ Control(Args) | Properties | Listeners
213
215
  `date_time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
214
216
  `editable_combobox` | `items` (`Array` of `String`), `text` (`String`) | `on_changed`
215
217
  `entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
216
- `font_button` | `font` (`LibUI::FFI::FontDescriptor`) | `on_changed`
218
+ `font_button` | `font` [read-only] (`Hash` of keys: `:family`, `:size`, `:weight`, `:italic`, `:stretch`) | `on_changed`
217
219
  `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
218
220
  `horizontal_box` | `padded` (Boolean) | None
219
221
  `horizontal_separator` | None | None
@@ -276,12 +278,22 @@ Control(Args) | Properties | Listeners
276
278
  - All boolean property readers return `true` or `false` in Ruby instead of the [libui](https://github.com/andlabs/libui) original `0` or `1` in C.
277
279
  - All boolean property writers accept `true`/`false` in addition to `1`/`0` in Ruby
278
280
  - All string property readers return a `String` object in Ruby instead of the [libui](https://github.com/andlabs/libui) Fiddle pointer object.
281
+ - Automatically allocate font descriptors upon instantiating `font_button` controls and free font descriptors when destorying `font_button` controls
279
282
 
280
283
  ### Original API
281
284
 
282
285
  To learn more about the [LibUI](https://github.com/kojix2/LibUI) API exposed through [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui),
283
286
  check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.h)
284
287
 
288
+ ## Glimmer Style Guide
289
+
290
+ - Control arguments are always wrapped inside parentheses
291
+ - Control blocks are always declared with curly braces to clearly visualize hierarchical view code and separate from logic code
292
+ - Control property declarations always have arguments and never take a block
293
+ - Control property arguments are never wrapped inside parentheses
294
+ - 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.
295
+ - 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.
296
+
285
297
  ## Girb (Glimmer IRB)
286
298
 
287
299
  You can run the `girb` command (`bin/girb` if you cloned the project locally):
@@ -346,6 +358,10 @@ class MetaExample
346
358
  end
347
359
 
348
360
  def launch
361
+ menu('File') {
362
+ quit_menu_item
363
+ }
364
+
349
365
  window('Meta-Example', 700, 500) { |w|
350
366
  margined true
351
367
 
@@ -1324,6 +1340,91 @@ MAIN_WINDOW = window('Control Gallery', 600, 500) {
1324
1340
  MAIN_WINDOW.show
1325
1341
  ```
1326
1342
 
1343
+ ### Font Button
1344
+
1345
+ [examples/font_button.rb](examples/font_button.rb)
1346
+
1347
+ Run with this command from the root of the project if you cloned the project:
1348
+
1349
+ ```
1350
+ ruby -r './lib/glimmer-dsl-libui' examples/font_button.rb
1351
+ ```
1352
+
1353
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1354
+
1355
+ ```
1356
+ ruby -r glimmer-dsl-libui -e "require 'examples/font_button'"
1357
+ ```
1358
+
1359
+ Mac
1360
+
1361
+ ![glimmer-dsl-libui-mac-font-button.png](images/glimmer-dsl-libui-mac-font-button.png)
1362
+ ![glimmer-dsl-libui-mac-font-button-selection.png](images/glimmer-dsl-libui-mac-font-button-selection.png)
1363
+
1364
+ Linux
1365
+
1366
+ ![glimmer-dsl-libui-linux-font-button.png](images/glimmer-dsl-libui-linux-font-button.png)
1367
+ ![glimmer-dsl-libui-linux-font-button-selection.png](images/glimmer-dsl-libui-linux-font-button-selection.png)
1368
+
1369
+ [LibUI](https://github.com/kojix2/LibUI) Original Version:
1370
+
1371
+ ```ruby
1372
+ require 'libui'
1373
+
1374
+ UI = LibUI
1375
+
1376
+ UI.init
1377
+
1378
+ main_window = UI.new_window('hello world', 300, 200, 1)
1379
+
1380
+ font_button = UI.new_font_button
1381
+ font_descriptor = UI::FFI::FontDescriptor.malloc
1382
+ UI.font_button_on_changed(font_button) do
1383
+ UI.font_button_font(font_button, font_descriptor)
1384
+ p family: font_descriptor.Family.to_s,
1385
+ size: font_descriptor.Size,
1386
+ weight: font_descriptor.Weight,
1387
+ italic: font_descriptor.Italic,
1388
+ stretch: font_descriptor.Stretch
1389
+ end
1390
+
1391
+ UI.window_on_closing(main_window) do
1392
+ puts 'Bye Bye'
1393
+ UI.control_destroy(main_window)
1394
+ UI.quit
1395
+ 0
1396
+ end
1397
+
1398
+ UI.window_set_child(main_window, font_button)
1399
+ UI.control_show(main_window)
1400
+
1401
+ UI.main
1402
+ UI.quit
1403
+
1404
+ ```
1405
+
1406
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1407
+
1408
+ ```ruby
1409
+ require 'glimmer-dsl-libui'
1410
+
1411
+ include Glimmer
1412
+
1413
+ window('hello world', 300, 200) {
1414
+ font_button { |fb|
1415
+ on_changed do
1416
+ font_descriptor = fb.font
1417
+ p font_descriptor
1418
+ end
1419
+ }
1420
+
1421
+ on_closing do
1422
+ puts 'Bye Bye'
1423
+ end
1424
+ }.show
1425
+
1426
+ ```
1427
+
1327
1428
  ## Contributing to glimmer-dsl-libui
1328
1429
 
1329
1430
  - Check out the latest master to make sure the feature hasn't been
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ window('hello world', 300, 200) {
8
+ font_button { |fb|
9
+ on_changed do
10
+ font_descriptor = fb.font
11
+ p font_descriptor
12
+ end
13
+ }
14
+
15
+ on_closing do
16
+ puts 'Bye Bye'
17
+ end
18
+ }.show
@@ -21,6 +21,10 @@ class MetaExample
21
21
  end
22
22
 
23
23
  def launch
24
+ menu('File') {
25
+ quit_menu_item
26
+ }
27
+
24
28
  window('Meta-Example', 700, 500) { |w|
25
29
  margined true
26
30
 
Binary file
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI font button objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class FontButtonProxy < ControlProxy
30
+ def font
31
+ @font_descriptor ||= ::LibUI::FFI::FontDescriptor.malloc
32
+ ::LibUI.font_button_font(@libui, @font_descriptor)
33
+ {
34
+ family: @font_descriptor.Family.to_s,
35
+ size: @font_descriptor.Size,
36
+ weight: @font_descriptor.Weight,
37
+ italic: @font_descriptor.Italic,
38
+ stretch: @font_descriptor.Stretch
39
+ }
40
+ end
41
+
42
+ def destroy
43
+ ::LibUI.free_font_button_font(@font_descriptor) unless @font_descriptor.nil?
44
+ super
45
+ end
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -165,6 +165,7 @@ files:
165
165
  - examples/basic_window.rb
166
166
  - examples/basic_window2.rb
167
167
  - examples/control_gallery.rb
168
+ - examples/font_button.rb
168
169
  - examples/meta_example.rb
169
170
  - examples/midi_player.rb
170
171
  - examples/simple_notepad.rb
@@ -186,6 +187,7 @@ files:
186
187
  - lib/glimmer/libui/date_picker_proxy.rb
187
188
  - lib/glimmer/libui/date_time_picker_proxy.rb
188
189
  - lib/glimmer/libui/editable_combobox_proxy.rb
190
+ - lib/glimmer/libui/font_button_proxy.rb
189
191
  - lib/glimmer/libui/group_proxy.rb
190
192
  - lib/glimmer/libui/horizontal_box_proxy.rb
191
193
  - lib/glimmer/libui/menu_item_proxy.rb