glimmer-dsl-libui 0.5.6 → 0.5.7

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: 48926d5aab22eec664c80bc9ebe5a94a841e4b6173cca343ad9876fb33924b03
4
- data.tar.gz: 890dba3f171225448aad354ec767819faaf3cb59e48764adc63b0f35bcbc0fe3
3
+ metadata.gz: a5ccd1c22e43fbb8401dff62f07008895ad88522452f079112998d0e10f58d72
4
+ data.tar.gz: 9820c416164d39189ca3d6cfc90076b566b68b3c5e50b293e85d97edd2d4d04b
5
5
  SHA512:
6
- metadata.gz: 94650e60ccb1ed496dd682f937e4a91a3cffad37cfc3da17c462fd2db7349e06af9572c425f1b90d8a3a522c09eddd2b7eed6b4982c31a77fff97322aff6bbed
7
- data.tar.gz: fc41c1e9882b42155729547ee2d83e43a40a64ae56c2523ff880cd2f818357fb42328a72b79810ccfb75fc7356ac70910e1d4202249488cb4f8aef9d3a8034fe
6
+ metadata.gz: 545d81430224a9e197ddc4cd15168af5a3cd5f0d24c20f405bb5db3bbe499e38fa0339697e254dd100d7a76aa733fc98f7c3d3f9a8f824dc45a0fc13c4651b24
7
+ data.tar.gz: 41f91f675dab3a0ecc4004ddc6670db3770127e03dce01143c5be0996894abe9960ee7c6c2ef89166f88faaa6529e24a437821f6b59ce4f764a6c3f7407313cd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.5.7
4
+
5
+ - Support Custom Window keywords (aka Applications) using `Glimmer::LibUI::CustomWindow` or alias of `Glimmer::LibUI::Application`
6
+ - Refactor examples/class_based_custom_controls.rb to use `Glimmer::LibUI::Application` (alias: `Glimmer::LibUI::CustomWindow`)
7
+
3
8
  ## 0.5.6
4
9
 
5
10
  - Upgrade to glimmer 2.7.1 and document its support for keyed data-binding
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.5.6
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.5.7
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)
@@ -577,7 +577,7 @@ gem install glimmer-dsl-libui
577
577
  Or install via Bundler `Gemfile`:
578
578
 
579
579
  ```ruby
580
- gem 'glimmer-dsl-libui', '~> 0.5.6'
580
+ gem 'glimmer-dsl-libui', '~> 0.5.7'
581
581
  ```
582
582
 
583
583
  Test that installation worked by running the [Meta-Example](#examples):
@@ -1704,6 +1704,136 @@ window('Method-Based Custom Keyword') {
1704
1704
 
1705
1705
  ![glimmer-dsl-libui-mac-method-based-custom-keyword.png](images/glimmer-dsl-libui-mac-method-based-custom-keyword.png)
1706
1706
 
1707
+ You can also define Custom Window keywords, that is custom controls with `window` being the body root. These are also known as Applications. To define a Custom Window, you `include Glimmer::LibUI::CustomWindow` or `include Glimmer:LibUI::Application` and then you can invoke the `::launch` method on the class.
1708
+
1709
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
1710
+
1711
+ ```ruby
1712
+ require 'glimmer-dsl-libui'
1713
+ require 'facets'
1714
+
1715
+ Address = Struct.new(:street, :p_o_box, :city, :state, :zip_code)
1716
+
1717
+ class FormField
1718
+ include Glimmer::LibUI::CustomControl
1719
+
1720
+ options :model, :attribute
1721
+
1722
+ body {
1723
+ entry { |e|
1724
+ label attribute.to_s.underscore.split('_').map(&:capitalize).join(' ')
1725
+ text <=> [model, attribute]
1726
+ }
1727
+ }
1728
+ end
1729
+
1730
+ class AddressForm
1731
+ include Glimmer::LibUI::CustomControl
1732
+
1733
+ options :address
1734
+
1735
+ body {
1736
+ form {
1737
+ form_field(model: address, attribute: :street)
1738
+ form_field(model: address, attribute: :p_o_box)
1739
+ form_field(model: address, attribute: :city)
1740
+ form_field(model: address, attribute: :state)
1741
+ form_field(model: address, attribute: :zip_code)
1742
+ }
1743
+ }
1744
+ end
1745
+
1746
+ class LabelPair
1747
+ include Glimmer::LibUI::CustomControl
1748
+
1749
+ options :model, :attribute, :value
1750
+
1751
+ body {
1752
+ horizontal_box {
1753
+ label(attribute.to_s.underscore.split('_').map(&:capitalize).join(' '))
1754
+ label(value.to_s) {
1755
+ text <= [model, attribute]
1756
+ }
1757
+ }
1758
+ }
1759
+ end
1760
+
1761
+ class AddressView
1762
+ include Glimmer::LibUI::CustomControl
1763
+
1764
+ options :address
1765
+
1766
+ body {
1767
+ vertical_box {
1768
+ address.each_pair do |attribute, value|
1769
+ label_pair(model: address, attribute: attribute, value: value)
1770
+ end
1771
+ }
1772
+ }
1773
+ end
1774
+
1775
+ class ClassBasedCustomControls
1776
+ include Glimmer::LibUI::Application # alias: Glimmer::LibUI::CustomWindow
1777
+
1778
+ before_body do
1779
+ @address1 = Address.new('123 Main St', '23923', 'Denver', 'Colorado', '80014')
1780
+ @address2 = Address.new('2038 Park Ave', '83272', 'Boston', 'Massachusetts', '02101')
1781
+ end
1782
+
1783
+ body {
1784
+ window('Class-Based Custom Keyword') {
1785
+ margined true
1786
+
1787
+ horizontal_box {
1788
+ vertical_box {
1789
+ label('Address 1') {
1790
+ stretchy false
1791
+ }
1792
+
1793
+ address_form(address: @address1)
1794
+
1795
+ horizontal_separator {
1796
+ stretchy false
1797
+ }
1798
+
1799
+ label('Address 1 (Saved)') {
1800
+ stretchy false
1801
+ }
1802
+
1803
+ address_view(address: @address1)
1804
+ }
1805
+
1806
+ vertical_separator {
1807
+ stretchy false
1808
+ }
1809
+
1810
+ vertical_box {
1811
+ label('Address 2') {
1812
+ stretchy false
1813
+ }
1814
+
1815
+ address_form(address: @address2)
1816
+
1817
+ horizontal_separator {
1818
+ stretchy false
1819
+ }
1820
+
1821
+ label('Address 2 (Saved)') {
1822
+ stretchy false
1823
+ }
1824
+
1825
+ address_view(address: @address2)
1826
+ }
1827
+ }
1828
+ }
1829
+ }
1830
+ end
1831
+
1832
+ ClassBasedCustomControls.launch
1833
+ ```
1834
+
1835
+ ![glimmer-dsl-libui-mac-method-based-custom-keyword.png](images/glimmer-dsl-libui-mac-method-based-custom-keyword.png)
1836
+
1707
1837
  The [`area`](#area-api) control can be utilized to build non-native custom controls from scratch by leveraging vector graphics, formattable text, keyboard events, and mouse events. This is demonstrated in the [Area-Based Custom Controls](#area-based-custom-controls) example.
1708
1838
 
1709
1839
  Defining custom keywords enables unlimited extension of the [Glimmer GUI DSL](#glimmer-gui-dsl). The sky is the limit on what can be done with custom keywords as a result. You can compose new visual vocabulary to build applications in any domain from higher concepts rather than [mere standard controls](#supported-keywords). For example, in a traffic signaling app, you could define `street`, `light_signal`, `traffic_sign`, and `car` as custom keywords and build your application from these concepts directly, saving enormous time and achieving much higher productivity.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.6
1
+ 0.5.7
@@ -1,8 +1,6 @@
1
1
  require 'glimmer-dsl-libui'
2
2
  require 'facets'
3
3
 
4
- include Glimmer
5
-
6
4
  Address = Struct.new(:street, :p_o_box, :city, :state, :zip_code)
7
5
 
8
6
  class FormField
@@ -63,51 +61,61 @@ class AddressView
63
61
  }
64
62
  end
65
63
 
66
- address1 = Address.new('123 Main St', '23923', 'Denver', 'Colorado', '80014')
67
- address2 = Address.new('2038 Park Ave', '83272', 'Boston', 'Massachusetts', '02101')
68
-
69
- window('Class-Based Custom Keyword') {
70
- margined true
64
+ class ClassBasedCustomControls
65
+ include Glimmer::LibUI::Application # alias: Glimmer::LibUI::CustomWindow
71
66
 
72
- horizontal_box {
73
- vertical_box {
74
- label('Address 1') {
75
- stretchy false
76
- }
77
-
78
- address_form(address: address1)
79
-
80
- horizontal_separator {
81
- stretchy false
82
- }
83
-
84
- label('Address 1 (Saved)') {
85
- stretchy false
86
- }
87
-
88
- address_view(address: address1)
89
- }
90
-
91
- vertical_separator {
92
- stretchy false
93
- }
94
-
95
- vertical_box {
96
- label('Address 2') {
97
- stretchy false
98
- }
99
-
100
- address_form(address: address2)
101
-
102
- horizontal_separator {
103
- stretchy false
104
- }
67
+ before_body do
68
+ @address1 = Address.new('123 Main St', '23923', 'Denver', 'Colorado', '80014')
69
+ @address2 = Address.new('2038 Park Ave', '83272', 'Boston', 'Massachusetts', '02101')
70
+ end
71
+
72
+ body {
73
+ window('Class-Based Custom Keyword') {
74
+ margined true
105
75
 
106
- label('Address 2 (Saved)') {
107
- stretchy false
76
+ horizontal_box {
77
+ vertical_box {
78
+ label('Address 1') {
79
+ stretchy false
80
+ }
81
+
82
+ address_form(address: @address1)
83
+
84
+ horizontal_separator {
85
+ stretchy false
86
+ }
87
+
88
+ label('Address 1 (Saved)') {
89
+ stretchy false
90
+ }
91
+
92
+ address_view(address: @address1)
93
+ }
94
+
95
+ vertical_separator {
96
+ stretchy false
97
+ }
98
+
99
+ vertical_box {
100
+ label('Address 2') {
101
+ stretchy false
102
+ }
103
+
104
+ address_form(address: @address2)
105
+
106
+ horizontal_separator {
107
+ stretchy false
108
+ }
109
+
110
+ label('Address 2 (Saved)') {
111
+ stretchy false
112
+ }
113
+
114
+ address_view(address: @address2)
115
+ }
108
116
  }
109
-
110
- address_view(address: address2)
111
117
  }
112
118
  }
113
- }.show
119
+ end
120
+
121
+ ClassBasedCustomControls.launch
Binary file
@@ -24,6 +24,7 @@ require 'glimmer/dsl/expression'
24
24
  require 'glimmer/dsl/parent_expression'
25
25
  require 'glimmer/dsl/top_level_expression'
26
26
  require 'glimmer/libui/custom_control'
27
+ require 'glimmer/libui/custom_window'
27
28
 
28
29
  module Glimmer
29
30
  module DSL
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'super_module'
23
23
  require 'glimmer'
24
+ require 'glimmer/error'
24
25
  require 'glimmer/proc_tracker'
25
26
  require 'glimmer/data_binding/observer'
26
27
  require 'glimmer/data_binding/observable_model'
@@ -33,8 +34,10 @@ module Glimmer
33
34
 
34
35
  super_module_included do |klass|
35
36
  # TODO clear memoization of WidgetProxy.libui_class_for for a keyword if a custom control was defined with that keyword
36
- klass.include(Glimmer)
37
- Glimmer::LibUI::CustomControl.add_custom_control_namespaces_for(klass)
37
+ unless klass.name.include?('Glimmer::LibUI::CustomWindow')
38
+ klass.include(Glimmer)
39
+ Glimmer::LibUI::CustomControl.add_custom_control_namespaces_for(klass)
40
+ end
38
41
  end
39
42
 
40
43
  class << self
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2021-2022 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 'super_module'
23
+ require 'glimmer/libui/custom_control'
24
+ require 'glimmer/error'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ module CustomWindow
29
+ include SuperModule
30
+ include Glimmer::LibUI::CustomControl
31
+
32
+ class << self
33
+ def launch(*args, &content)
34
+ launched_custom_shell = send(keyword, *args, &content)
35
+ launched_custom_shell.show
36
+ end
37
+ end
38
+
39
+ def initialize(parent, *swt_constants, options, &content)
40
+ super
41
+ raise Glimmer::Error, 'Invalid custom window body root! Must be a window, another custom window, or a custom control with window as its body root!' unless body_root.is_a?(Glimmer::LibUI::ControlProxy::WindowProxy) || body_root.is_a?(Glimmer::LibUI::CustomWindow) || (body_root.is_a?(Glimmer::LibUI::CustomControl) && body_root.body_root.is_a?(Glimmer::LibUI::ControlProxy::WindowProxy))
42
+ end
43
+
44
+ # Classes may override
45
+ def show
46
+ body_root.show
47
+ end
48
+
49
+ # TODO consider using Forwardable instead
50
+ def destroy
51
+ body_root.destroy
52
+ end
53
+
54
+ def destroying?
55
+ body_root.destroying?
56
+ end
57
+ end
58
+
59
+ Application = CustomWindow
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ module Glimmer
2
+ class << self
3
+ def included(klass)
4
+ klass.extend(Glimmer)
5
+ end
6
+ end
7
+ end
@@ -37,7 +37,7 @@ require 'libui'
37
37
 
38
38
  # Internal requires
39
39
  # require 'ext/glimmer/config'
40
- # require 'ext/glimmer'
40
+ require 'glimmer-dsl-libui/ext/glimmer'
41
41
  require 'glimmer/dsl/libui/dsl'
42
42
  require 'glimmer/libui'
43
43
  Glimmer::Config.loop_max_count = -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.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2022-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -358,6 +358,7 @@ files:
358
358
  - icons/blank.png
359
359
  - icons/glimmer.png
360
360
  - lib/glimmer-dsl-libui.rb
361
+ - lib/glimmer-dsl-libui/ext/glimmer.rb
361
362
  - lib/glimmer/dsl/libui/bind_expression.rb
362
363
  - lib/glimmer/dsl/libui/control_expression.rb
363
364
  - lib/glimmer/dsl/libui/custom_control_expression.rb
@@ -443,6 +444,7 @@ files:
443
444
  - lib/glimmer/libui/control_proxy/triple_column.rb
444
445
  - lib/glimmer/libui/control_proxy/window_proxy.rb
445
446
  - lib/glimmer/libui/custom_control.rb
447
+ - lib/glimmer/libui/custom_window.rb
446
448
  - lib/glimmer/libui/data_bindable.rb
447
449
  - lib/glimmer/libui/image_path_renderer.rb
448
450
  - lib/glimmer/libui/parent.rb