glimmer-dsl-libui 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +22 -19
- data/VERSION +1 -1
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/attributed_string.rb +3 -0
- data/lib/glimmer/libui/control_proxy.rb +4 -12
- data/lib/glimmer/libui/data_bindable.rb +39 -0
- data/lib/glimmer/libui/shape.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e66ca998dc3b30b4a9ef856b9d23f4359d9b24a4f1a1805760b5912c675310f
|
4
|
+
data.tar.gz: 1e464fd9986e1516709e919c3aba9307b90dc0498c1f478050f5cfc54b3ca377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab5d10582f486b129c531aa7472f05e342c5d823d81bec4531dea8996328b916d8eb4e12c49763f28c720e76a9d64feda23b607bca6a748ba0506d4f974e6c1c
|
7
|
+
data.tar.gz: 910c1fd367831c3cb91c3a1a1a37c040ae0cac00cf259a08007625d3bbd8adc39cab8809bc5a8820d700ef925d525372370fc035d1c5c5461b9aae21f759bd4e
|
data/CHANGELOG.md
CHANGED
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.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.4.4
|
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
|
[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
@@ -373,7 +373,7 @@ gem install glimmer-dsl-libui
|
|
373
373
|
Or install via Bundler `Gemfile`:
|
374
374
|
|
375
375
|
```ruby
|
376
|
-
gem 'glimmer-dsl-libui', '~> 0.4.
|
376
|
+
gem 'glimmer-dsl-libui', '~> 0.4.4'
|
377
377
|
```
|
378
378
|
|
379
379
|
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.
|
@@ -877,7 +877,7 @@ Given that it is very new and is not a [libui](https://github.com/andlabs/libui)
|
|
877
877
|
- Including an `image` inside an `area` `on_draw` listener improves performance due to not retaining pixel/line data in memory.
|
878
878
|
- Supplying `width` and `height` (2nd and 3rd arguments) greatly improves performance when shrinking image.
|
879
879
|
|
880
|
-
Currently, it is recommended to use `image` with very small `width` and `height` values only.
|
880
|
+
Currently, it is recommended to use `image` with very small `width` and `height` values only (e.g. 24x24).
|
881
881
|
|
882
882
|
Setting a [`transform` `matrix`](#area-transform-matrix) is supported under `image` just like it is under `path` and `text` inside `area`.
|
883
883
|
|
@@ -1033,6 +1033,8 @@ window('Basic Image', 96, 96) {
|
|
1033
1033
|
|
1034
1034
|
One final note is that in Linux, table images grow and shrink with the image size unlike on the Mac where table row heights are constant regardless of image sizes. As such, you may be able to repurpose a table with a single image column and a single row as an image control with more native libui rendering if you are only targeting Linux with your app.
|
1035
1035
|
|
1036
|
+
![linux table image](images/glimmer-dsl-libui-linux-basic-table-image.png)
|
1037
|
+
|
1036
1038
|
Check out [examples/basic_image.rb](#basic-image) (all versions) for examples of using `image` Glimmer custom control.
|
1037
1039
|
|
1038
1040
|
#### Colors
|
@@ -1352,6 +1354,14 @@ See examples of the `observe` keyword at [Color The Circles](#color-the-circles)
|
|
1352
1354
|
|
1353
1355
|
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) supports both bidirectional (two-way) data-binding and unidirectional (one-way) data-binding.
|
1354
1356
|
|
1357
|
+
Data-binding enables writing very expressive, terse, and declarative code to synchronize View properties with Model attributes without writing many lines or pages of imperative code doing the same thing, increasing productivity immensely.
|
1358
|
+
|
1359
|
+
Data-binding automatically takes advantage of the [Observer Pattern](#observer-pattern) behind the scenes and is very well suited to declaring View property data sources piecemeal. On the other hand, explicit use of the [Observer Pattern](#observer-pattern) is sometimes more suitable when needing to make multiple View updates upon a single Model attribute change.
|
1360
|
+
|
1361
|
+
Data-binding supports utilizing the [MVP (Model View Presenter)](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter) flavor of [MVC](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) by observing both the View and a Presenter for changes and updating the opposite side upon encountering them. This enables writing more decoupled cleaner code that keeps View code and Model code disentangled and highly maintainable. For example, check out the Snake game presenters for [Grid](/examples/snake/presenter/grid.rb) and [Cell](/examples/snake/presenter/cell.rb), which act as proxies for the actual Snake game models [Snake](/examples/snake/model/snake.rb) and [Apple](/examples/snake/model/apple.rb), mediating synchronization of data between them and the [Snake View GUI](/examples/snake.rb).
|
1362
|
+
|
1363
|
+
![MVP](https://www.researchgate.net/profile/Gilles-Perrouin/publication/320249584/figure/fig8/AS:668260987068418@1536337243385/Model-view-presenter-architecture.png)
|
1364
|
+
|
1355
1365
|
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) supports bidirectional (two-way) data-binding of the following controls/properties via the `<=>` operator (indicating data is moving in both directions between View and Model):
|
1356
1366
|
- `entry` `text` property
|
1357
1367
|
- `multiline_entry` `text` property
|
@@ -1372,11 +1382,11 @@ Another example of bidirectional data-binding with an option:
|
|
1372
1382
|
|
1373
1383
|
```ruby
|
1374
1384
|
entry {
|
1375
|
-
text <=> [self, :
|
1385
|
+
text <=> [self, :entered_text, after_write: ->(text) {puts text}]
|
1376
1386
|
}
|
1377
1387
|
```
|
1378
1388
|
|
1379
|
-
That is data-binding `
|
1389
|
+
That is data-binding `entered_text` attribute on `self` to `entry` `text` property and printing text after write to the model.
|
1380
1390
|
|
1381
1391
|
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) supports unidirectional (one-way) data-binding of any control/shape/attributed-string property via the `<=` operator (indicating data is moving from the right side, which is the Model, to the left side, which is the GUI View object).
|
1382
1392
|
|
@@ -1400,20 +1410,12 @@ window {
|
|
1400
1410
|
|
1401
1411
|
That is data-binding the `window` `title` property to the `score` attribute of a `@game`, but converting on read from the Model to a `String`.
|
1402
1412
|
|
1403
|
-
|
1404
|
-
- Bidirectional (two-way) data-binding to
|
1405
|
-
- Unidirectional (one-way) data-binding to
|
1413
|
+
To summarize the data-binding API:
|
1414
|
+
- `view_property <=> [model, attribute, *read_or_write_options]`: Bidirectional (two-way) data-binding to Model attribute accessor
|
1415
|
+
- `view_property <= [model, attribute, *read_only_options]`: Unidirectional (one-way) data-binding to Model attribute reader
|
1406
1416
|
|
1407
1417
|
This is also known as the [Glimmer Shine](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax for data-binding, a [Glimmer](https://github.com/AndyObtiva/glimmer)-only unique innovation that takes advantage of [Ruby](https://www.ruby-lang.org/en/)'s highly expressive syntax and malleable DSL support.
|
1408
1418
|
|
1409
|
-
Data-binding enables writing very expressive, terse, and declarative code to synchronize View properties with Model attributes without writing many lines or pages of imperative code doing the same thing.
|
1410
|
-
|
1411
|
-
Data-binding automatically takes advantage of the [Observer Pattern](#observer-pattern) behind the scenes and is very well suited to declaring View property data sources piecemeal. On the other hand, explicit use of the [Observer Pattern](#observer-pattern) is sometimes more suitable when needing to make multiple View updates upon a single Model attribute change.
|
1412
|
-
|
1413
|
-
Data-binding supports utilizing the [MVP (Model View Presenter)](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter) flavor of [MVC](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) by observing both the View and a Presenter for changes and updating the opposite side upon encountering them. This enables writing more decoupled cleaner code that keeps View code and Model code disentangled and highly maintainable. For example, check out the Snake game presenters for [Grid](/examples/snake/presenter/grid.rb) and [Cell](/examples/snake/presenter/cell.rb), which act as proxies for the actual Snake game models [Snake](/examples/snake/model/snake.rb) and [Apple](/examples/snake/model/apple.rb), mediating synchronization of data between them and the [Snake View GUI](/examples/snake.rb).
|
1414
|
-
|
1415
|
-
![MVP](https://www.researchgate.net/profile/Gilles-Perrouin/publication/320249584/figure/fig8/AS:668260987068418@1536337243385/Model-view-presenter-architecture.png)
|
1416
|
-
|
1417
1419
|
Data-binding options include:
|
1418
1420
|
- `before_read {|value| ...}`: performs an operation before reading data from Model to update the View.
|
1419
1421
|
- `on_read {|value| ...}`: converts value read from Model to update the View.
|
@@ -1421,6 +1423,7 @@ Data-binding options include:
|
|
1421
1423
|
- `before_write {|value| ...}`: performs an operation before writing data to Model from View.
|
1422
1424
|
- `on_write {|value| ...}`: converts value read from View to update the Model.
|
1423
1425
|
- `after_write {|converted_value| ...}`: performs an operation after writing to Model from View.
|
1426
|
+
- `computed_by attribute` or `computed_by [attribute1, attribute2, ...]`: indicates model attribute is computed from specified attribute(s), thus updated when they are updated (see in [Login example version 2](/examples/login2.rb))
|
1424
1427
|
|
1425
1428
|
Note that with both `on_read` and `on_write` converters, you could pass a `Symbol` representing the name of a method on the value object to invoke.
|
1426
1429
|
|
@@ -1434,7 +1437,7 @@ entry {
|
|
1434
1437
|
|
1435
1438
|
Gotcha: never data-bind a control property to an attribute on the same view object with the same exact name (e.g. binding `entry` `text` property to `self` `text` attribute) as it would conflict with it. Instead, data-bind view property to an attribute with a different name on the view object or with the same name, but on a presenter or model object (e.g. data-bind `entry` `text` to `self` `legal_text` attribute or to `contract` model `text` attribute)
|
1436
1439
|
|
1437
|
-
Learn more from data-binding usage in [Basic Entry](#basic-entry), [Form](#form), [Form Table](#form-table), [
|
1440
|
+
Learn more from data-binding usage in [Login](#login) (4 data-binding versions), [Basic Entry](#basic-entry), [Form](#form), [Form Table](#form-table), [Method-Based Custom Keyword](#method-based-custom-keyword), [Snake](#snake) and [Tic Tac Toe](#tic_tac_toe) examples.
|
1438
1441
|
|
1439
1442
|
### API Gotchas
|
1440
1443
|
|
@@ -6892,7 +6895,7 @@ end
|
|
6892
6895
|
Login.new.launch
|
6893
6896
|
```
|
6894
6897
|
|
6895
|
-
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version (with [data-binding](#data-binding)):
|
6898
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 3 (with [data-binding](#data-binding)):
|
6896
6899
|
|
6897
6900
|
```ruby
|
6898
6901
|
require 'glimmer-dsl-libui'
|
@@ -6962,7 +6965,7 @@ end
|
|
6962
6965
|
Login.new.launch
|
6963
6966
|
```
|
6964
6967
|
|
6965
|
-
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version (with [data-binding](#data-binding)):
|
6968
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 4 (with [data-binding](#data-binding)):
|
6966
6969
|
|
6967
6970
|
```ruby
|
6968
6971
|
require 'glimmer-dsl-libui'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -23,10 +23,13 @@ require 'glimmer/libui/control_proxy'
|
|
23
23
|
require 'glimmer/libui/control_proxy/area_proxy'
|
24
24
|
require 'glimmer/libui/parent'
|
25
25
|
require 'glimmer/libui/control_proxy/transformable'
|
26
|
+
require 'glimmer/libui/data_bindable'
|
26
27
|
|
27
28
|
module Glimmer
|
28
29
|
module LibUI
|
29
30
|
class AttributedString
|
31
|
+
include DataBindable
|
32
|
+
|
30
33
|
attr_reader :keyword, :parent_proxy, :args
|
31
34
|
attr_accessor :block
|
32
35
|
|
@@ -19,6 +19,8 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
+
require 'glimmer/libui/data_bindable'
|
23
|
+
|
22
24
|
module Glimmer
|
23
25
|
module LibUI
|
24
26
|
# Proxy for LibUI control objects
|
@@ -101,6 +103,8 @@ module Glimmer
|
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
106
|
+
include DataBindable
|
107
|
+
|
104
108
|
KEYWORD_ALIASES = {
|
105
109
|
'msg_box' => 'message_box',
|
106
110
|
'msg_box_error' => 'message_box_error',
|
@@ -332,18 +336,6 @@ module Glimmer
|
|
332
336
|
alias set_visible visible
|
333
337
|
alias visible= visible
|
334
338
|
|
335
|
-
# Data-binds model to update view.
|
336
|
-
# Subclasses can override to do inverse data-binding by observing view control for property changes and updating model binding accordingly
|
337
|
-
def data_bind(property, model_binding)
|
338
|
-
model_attribute_observer = Glimmer::DataBinding::Observer.proc do
|
339
|
-
new_value = model_binding.evaluate_property
|
340
|
-
send("#{property}=", new_value) unless send(property) == new_value
|
341
|
-
end
|
342
|
-
model_attribute_observer.observe(model_binding)
|
343
|
-
model_attribute_observer.call # initial update
|
344
|
-
model_attribute_observer
|
345
|
-
end
|
346
|
-
|
347
339
|
def content(&block)
|
348
340
|
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ControlExpression.new, @keyword, &block)
|
349
341
|
end
|
@@ -0,0 +1,39 @@
|
|
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
|
+
# Parent controls and shapes who have children and add child post_initialize_child
|
25
|
+
module DataBindable
|
26
|
+
# Data-binds model to update view.
|
27
|
+
# Subclasses can override to do inverse data-binding by observing view control for property changes and updating model binding accordingly
|
28
|
+
def data_bind(property, model_binding)
|
29
|
+
model_attribute_observer = Glimmer::DataBinding::Observer.proc do
|
30
|
+
new_value = model_binding.evaluate_property
|
31
|
+
send("#{property}=", new_value) unless send(property) == new_value
|
32
|
+
end
|
33
|
+
model_attribute_observer.observe(model_binding)
|
34
|
+
model_attribute_observer.call # initial update
|
35
|
+
model_attribute_observer
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/glimmer/libui/shape.rb
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
require 'glimmer/libui/parent'
|
23
23
|
require 'glimmer/libui/control_proxy/area_proxy'
|
24
24
|
require 'glimmer/libui/control_proxy/path_proxy'
|
25
|
+
require 'glimmer/libui/data_bindable'
|
25
26
|
|
26
27
|
module Glimmer
|
27
28
|
module LibUI
|
@@ -64,6 +65,7 @@ module Glimmer
|
|
64
65
|
end
|
65
66
|
|
66
67
|
include Parent
|
68
|
+
include DataBindable
|
67
69
|
|
68
70
|
attr_reader :parent, :args, :keyword, :block
|
69
71
|
|
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.4.
|
4
|
+
version: 0.4.4
|
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-11-
|
11
|
+
date: 2021-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -372,6 +372,7 @@ files:
|
|
372
372
|
- lib/glimmer/libui/control_proxy/transformable.rb
|
373
373
|
- lib/glimmer/libui/control_proxy/triple_column.rb
|
374
374
|
- lib/glimmer/libui/control_proxy/window_proxy.rb
|
375
|
+
- lib/glimmer/libui/data_bindable.rb
|
375
376
|
- lib/glimmer/libui/image_path_renderer.rb
|
376
377
|
- lib/glimmer/libui/parent.rb
|
377
378
|
- lib/glimmer/libui/shape.rb
|