glimmer-dsl-wx 0.0.5 → 0.0.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: 9d5a658d9129e3c8ebf9c27f75d090d8d3f987a56866d1072d8ee17c757a7845
4
- data.tar.gz: 31fc334221373c19a3461742fac4c201caf513b79413fa3738e09b4aa7a7b752
3
+ metadata.gz: d67fb5f483b55ca655215bf87926ae501dd680b4ffeebbfe02756b257398d4f3
4
+ data.tar.gz: fffd53b54fba50092ea146df9bb90b268f333cc903a29b6178e9cc80217b9d3a
5
5
  SHA512:
6
- metadata.gz: 1516d96c79fdcd492d647092af6eed155b36091b7c2499c60384c24666a16e2cb5d2f397d92dd4c5f408d5d9cb947d24b50f7797ca70c644831ceafd89b6225a
7
- data.tar.gz: e55a50420ee69b41e8406367151320aa29dd9d1d4ba57481475877e6e1624b2fcd1e157c00705ae9f43fb0b417ec4214079a8fa0377f32095c75c06300995368
6
+ metadata.gz: 9e1544b9b4dedfc9f99b31833982642bba382e69b857957a6647aecc8e93ae8d7a7d60af5a6c7f0cdff858ef555c3d7a5b12536a61ce3ba49322051f39ed17fe
7
+ data.tar.gz: 402553fc0c1462d0f7e20d9931d894347739f9d9229bb1616731ec42897ba45a5e2a37f7ca54f8c06514a726e48cc4f1e4a1e9e2cd641aa810b5b0d793e12046
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.7
4
+
5
+ - Sizer addable support (e.g. supporting `growable_col(1, 1)`, using `add_growable_col(1, 1)` method in wxruby3 API)
6
+ - Ability to nest sizers within sizers
7
+ - Update samples/hello/hello_sizer.rb to use a `spacer` addable and nest `v_box_sizer` under `h_box_sizer`
8
+
9
+ ## 0.0.6
10
+
11
+ - Sizer (layout) support
12
+ - samples/hello/hello_sizer.rb
13
+ - Refactor/move `glimmer_new` samples to `hello` directory
14
+ - Fix `ControlProxy#frame_proxy` method, which grabs the parent frame (going all the way to the top of the hierarchy)
15
+
3
16
  ## 0.0.5
4
17
 
5
18
  - Nested child control support
data/README.md CHANGED
@@ -1,6 +1,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 WX 0.0.5
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 WX 0.0.7
2
2
  ## wxWidgets Ruby Desktop Development GUI Library
3
- [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-wx.svg)](http://badge.fury.io/rb/glimmer-dsl-wx)
3
+ [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-wx.svg)](https://badge.fury.io/rb/glimmer-dsl-wx)
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)
5
5
 
6
6
  [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [WX](https://www.wxwidgets.org/) is an [MRI Ruby](https://www.ruby-lang.org) desktop development GUI (Graphical User Interface) library for the cross-platform native widget [wxWidgets](https://www.wxwidgets.org/) GUI toolkit. It provides a Glimmer GUI DSL on top of the [wxruby3](https://github.com/mcorino/wxRuby3) binding.
@@ -16,8 +16,6 @@
16
16
 
17
17
  **Hello, World!**
18
18
 
19
- ![Hello, World!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-world.png?raw=true)
20
-
21
19
  ```ruby
22
20
  require 'glimmer-dsl-wx'
23
21
 
@@ -26,70 +24,40 @@ include Glimmer
26
24
  frame(title: 'Hello, World!')
27
25
  ```
28
26
 
29
- Alternate Syntax:
30
-
31
- ```ruby
32
- require 'glimmer-dsl-wx'
33
-
34
- include Glimmer
35
-
36
- frame {
37
- title 'Hello, World!'
38
- }
39
- ```
27
+ ![Hello, World!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-world.png?raw=true)
40
28
 
41
29
  **Hello Button!**
42
30
 
43
-
44
- ![Hello, Button!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-button.png?raw=true)
45
-
46
- ![Hello, Button! Clicked](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-button-clicked.png?raw=true)
47
-
48
-
49
31
  ```ruby
50
32
  require 'glimmer-dsl-wx'
51
33
 
52
34
  include Glimmer
53
35
 
54
- frame(title: 'Hello, Button!') { |f|
55
- button(label: 'Click To Find Who Built This!') {
56
- on_button do
57
- about_box(
58
- name: f.title,
59
- version: Wx::WXRUBY_VERSION,
60
- description: "This is the Hello, Button! sample",
61
- developers: ['The Glimmer DSL for WX Development Team']
62
- )
63
- end
64
- }
65
- }
66
- ```
67
-
68
- Alternate Syntax:
69
-
70
- ```ruby
71
- require 'glimmer-dsl-wx'
72
-
73
- include Glimmer
74
-
75
- frame { |f|
36
+ frame { |main_frame|
76
37
  title 'Hello, Button!'
77
38
 
78
- button {
79
- label 'Click To Find Who Built This!'
80
-
81
- on_button do
82
- about_box(
83
- name: f.title,
84
- version: Wx::WXRUBY_VERSION,
85
- description: "This is the Hello, Button! sample",
86
- developers: ['The Glimmer DSL for WX Development Team']
87
- )
88
- end
39
+ h_box_sizer {
40
+ button {
41
+ sizer_args 0, Wx::RIGHT, 10
42
+ label 'Click To Find Who Built This!'
43
+
44
+ on_button do
45
+ about_box(
46
+ name: main_frame.title,
47
+ version: Wx::WXRUBY_VERSION,
48
+ description: "This is the Hello, Button! sample",
49
+ developers: ['The Glimmer DSL for WX Development Team']
50
+ )
51
+ end
52
+ }
89
53
  }
90
54
  }
91
55
  ```
92
56
 
57
+ ![Hello, Button!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-button.png?raw=true)
58
+
59
+ ![Hello, Button! Clicked](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-button-clicked.png?raw=true)
60
+
93
61
  **[Glimmer](https://rubygems.org/gems/glimmer) DSL Comparison Table:**
94
62
  DSL | Platforms | Native? | Vector Graphics? | Pros | Cons | Prereqs
95
63
  ----|-----------|---------|------------------|------|------|--------
@@ -108,7 +76,13 @@ DSL | Platforms | Native? | Vector Graphics? | Pros | Cons | Prereqs
108
76
  ## Table of Contents
109
77
 
110
78
  - [Glimmer DSL for WX](#)
111
- - [Usage](#usage)
79
+ - [Setup](#setup)
80
+ - [GIRB (Glimmer IRB)](#girb-glimmer-irb)
81
+ - [Smart Defaults and Conventions](#smart-defaults-and-conventions)
82
+ - [Samples](#samples)
83
+ - [Hello, World!](#hello-world)
84
+ - [Hello, Button!](#hello-button)
85
+ - [Hello, Sizer!](#hello-sizer)
112
86
  - [Process](#process)
113
87
  - [Resources](#resources)
114
88
  - [Help](#help)
@@ -120,7 +94,7 @@ DSL | Platforms | Native? | Vector Graphics? | Pros | Cons | Prereqs
120
94
  - [Contributors](#contributors)
121
95
  - [License](#license)
122
96
 
123
- ## Usage
97
+ ## Setup
124
98
 
125
99
  Follow instructions for installing [wxruby3](https://github.com/mcorino/wxRuby3) on a supported platform (Linux or Windows):
126
100
  https://github.com/mcorino/wxRuby3/blob/master/INSTALL.md
@@ -134,19 +108,229 @@ gem install glimmer-dsl-wx
134
108
  Or install via Bundler `Gemfile`:
135
109
 
136
110
  ```ruby
137
- gem 'glimmer-dsl-wx', '~> 0.0.5'
111
+ gem 'glimmer-dsl-wx', '~> 0.0.7'
138
112
  ```
139
113
 
140
114
  Test that installation worked by running a sample:
141
115
 
142
116
  ```
143
- ruby -r glimmer-dsl-wx -e "require 'samples/glimmer_new/hello_world'"
117
+ ruby -r glimmer-dsl-wx -e "require 'samples/hello/hello_world'"
144
118
  ```
145
119
 
146
120
  If you cloned project, test by running a sample locally:
147
121
 
148
122
  ```
149
- ruby -r ./lib/glimmer-dsl-wx.rb samples/glimmer_new/hello_world.rb
123
+ ruby -r ./lib/glimmer-dsl-wx.rb samples/hello/hello_world.rb
124
+ ```
125
+
126
+ ## GIRB (Glimmer IRB)
127
+
128
+ You can run the `girb` command (`bin/girb` if you cloned the project locally) to do some quick and dirty experimentation and learning:
129
+
130
+ ```
131
+ girb
132
+ ```
133
+
134
+ This gives you `irb` with the `glimmer-dsl-wx` gem loaded and the `Glimmer` module mixed into the main object for easy experimentation with GUI.
135
+
136
+ ## Smart Defaults and Conventions
137
+
138
+ - Instantiate any wxWidgets control or sizer by using its underscored name (e.g. `Button` becomes `button`)
139
+ - `frame` will automatically execute within a `Wx::App.run` block and `show` the Frame
140
+
141
+ ## Samples
142
+
143
+ ### Hello, World!
144
+
145
+ ![Hello, World!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-world.png?raw=true)
146
+
147
+ ```ruby
148
+ require 'glimmer-dsl-wx'
149
+
150
+ include Glimmer
151
+
152
+ frame(title: 'Hello, World!')
153
+ ```
154
+
155
+ Alternate Syntax:
156
+
157
+ ```ruby
158
+ require 'glimmer-dsl-wx'
159
+
160
+ include Glimmer
161
+
162
+ frame {
163
+ title 'Hello, World!'
164
+ }
165
+ ```
166
+
167
+ ### Hello Button!
168
+
169
+ ![Hello, Button!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-button.png?raw=true)
170
+
171
+ ![Hello, Button! Clicked](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-button-clicked.png?raw=true)
172
+
173
+ ```ruby
174
+ require 'glimmer-dsl-wx'
175
+
176
+ include Glimmer
177
+
178
+ frame(title: 'Hello, Button!') { |main_frame|
179
+ h_box_sizer {
180
+ button(label: 'Click To Find Who Built This!') {
181
+ sizer_args 0, Wx::RIGHT, 10
182
+
183
+ on_button do
184
+ about_box(
185
+ name: main_frame.title,
186
+ version: Wx::WXRUBY_VERSION,
187
+ description: "This is the Hello, Button! sample",
188
+ developers: ['The Glimmer DSL for WX Development Team']
189
+ )
190
+ end
191
+ }
192
+ }
193
+ }
194
+ ```
195
+
196
+ Alternate Syntax:
197
+
198
+ ```ruby
199
+ require 'glimmer-dsl-wx'
200
+
201
+ include Glimmer
202
+
203
+ frame { |main_frame|
204
+ title 'Hello, Button!'
205
+
206
+ h_box_sizer {
207
+ button {
208
+ sizer_args 0, Wx::RIGHT, 10
209
+ label 'Click To Find Who Built This!'
210
+
211
+ on_button do
212
+ about_box(
213
+ name: main_frame.title,
214
+ version: Wx::WXRUBY_VERSION,
215
+ description: "This is the Hello, Button! sample",
216
+ developers: ['The Glimmer DSL for WX Development Team']
217
+ )
218
+ end
219
+ }
220
+ }
221
+ }
222
+ ```
223
+
224
+ ### Hello Sizer!
225
+
226
+ ![Hello, Sizer!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-sizer-button.png?raw=true)
227
+
228
+ ![Hello, Sizer! Clicked](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-sizer-clicked.png?raw=true)
229
+
230
+ ```ruby
231
+ require 'glimmer-dsl-wx'
232
+
233
+ include Glimmer
234
+
235
+ frame { |main_frame|
236
+ title 'Hello, Sizer!'
237
+
238
+ h_box_sizer {
239
+ v_box_sizer {
240
+ sizer_args 0, Wx::RIGHT, 10
241
+
242
+ button {
243
+ sizer_args 0, Wx::DOWN, 10
244
+ label 'Greeting 1'
245
+
246
+ on_button do
247
+ message_dialog(
248
+ "Hello",
249
+ "Greeting",
250
+ Wx::OK | Wx::ICON_INFORMATION
251
+ ).show_modal
252
+ end
253
+ }
254
+
255
+ spacer(10)
256
+
257
+ button {
258
+ sizer_args 0, Wx::DOWN, 10
259
+ label 'Greeting 2'
260
+
261
+ on_button do
262
+ message_dialog(
263
+ "Howdy",
264
+ "Greeting",
265
+ Wx::OK | Wx::ICON_INFORMATION
266
+ ).show_modal
267
+ end
268
+ }
269
+
270
+ spacer(10)
271
+
272
+ button {
273
+ sizer_args 0, Wx::DOWN, 10
274
+ label 'Greeting 3'
275
+
276
+ on_button do
277
+ message_dialog(
278
+ "Hi",
279
+ "Greeting",
280
+ Wx::OK | Wx::ICON_INFORMATION
281
+ ).show_modal
282
+ end
283
+ }
284
+ }
285
+
286
+ v_box_sizer {
287
+ sizer_args 0, Wx::RIGHT, 10
288
+
289
+ button {
290
+ sizer_args 0, Wx::DOWN, 10
291
+ label 'Greeting 4'
292
+
293
+ on_button do
294
+ message_dialog(
295
+ "Ciao",
296
+ "Greeting",
297
+ Wx::OK | Wx::ICON_INFORMATION
298
+ ).show_modal
299
+ end
300
+ }
301
+
302
+ spacer(10)
303
+
304
+ button {
305
+ sizer_args 0, Wx::DOWN, 10
306
+ label 'Greeting 5'
307
+
308
+ on_button do
309
+ message_dialog(
310
+ "Aloha",
311
+ "Greeting",
312
+ Wx::OK | Wx::ICON_INFORMATION
313
+ ).show_modal
314
+ end
315
+ }
316
+
317
+ spacer(10)
318
+
319
+ button {
320
+ sizer_args 0, Wx::DOWN, 10
321
+ label 'Greeting 6'
322
+
323
+ on_button do
324
+ message_dialog(
325
+ "Salut",
326
+ "Greeting",
327
+ Wx::OK | Wx::ICON_INFORMATION
328
+ ).show_modal
329
+ end
330
+ }
331
+ }
332
+ }
333
+ }
150
334
  ```
151
335
 
152
336
  ## Process
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.7
Binary file
@@ -37,6 +37,7 @@ module Glimmer
37
37
  end
38
38
 
39
39
  def around(parent, keyword, args, block, &interpret_and_add_content)
40
+ # TODO refactor/extract this logic to a FrameExpression
40
41
  if keyword == 'frame'
41
42
  ::Wx::App.run do
42
43
  frame_proxy = interpret_and_add_content.call
@@ -43,6 +43,9 @@ module Glimmer
43
43
  # control
44
44
  %w[
45
45
  listener
46
+ sizer_args
47
+ sizer_addable
48
+ sizer
46
49
  property
47
50
  control
48
51
  ]
@@ -0,0 +1,42 @@
1
+ # Copyright (c) 2023 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/wx/control_proxy'
24
+ require 'glimmer/wx/sizer_proxy'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Wx
29
+ class SizerAddableExpression < Expression
30
+ def can_interpret?(parent, keyword, *args, &block)
31
+ parent.is_a?(Glimmer::Wx::SizerProxy) and
32
+ block.nil? and
33
+ parent.can_add_sizer_addable?(keyword)
34
+ end
35
+
36
+ def interpret(parent, keyword, *args, &block)
37
+ parent.add_sizer_addable(keyword, *args)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2023 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/static_expression'
23
+ require 'glimmer/wx/control_proxy'
24
+ require 'glimmer/wx/sizer_proxy'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Wx
29
+ class SizerArgsExpression < StaticExpression
30
+ def can_interpret?(parent, keyword, *args, &block)
31
+ keyword == 'sizer_args' and
32
+ (
33
+ parent.is_a?(Glimmer::Wx::ControlProxy) or
34
+ parent.is_a?(Glimmer::Wx::SizerProxy)
35
+ ) and
36
+ parent&.parent_proxy&.is_a?(Glimmer::Wx::SizerProxy)
37
+ end
38
+
39
+ def interpret(parent, keyword, *args, &block)
40
+ parent.parent_proxy.add(parent, *args, &block)
41
+ end
42
+ end
43
+ SizerArgumentsExpression = SizerArgsExpression
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ # Copyright (c) 2023 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/wx/control_proxy'
24
+ require 'glimmer/wx/sizer_proxy'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Wx
29
+ class SizerExpression < Expression
30
+ include ParentExpression
31
+
32
+ def can_interpret?(parent, keyword, *args, &block)
33
+ (
34
+ parent.is_a?(Glimmer::Wx::ControlProxy) or
35
+ parent.is_a?(Glimmer::Wx::SizerProxy)
36
+ ) and
37
+ Glimmer::Wx::SizerProxy.exists?(keyword)
38
+ end
39
+
40
+ def interpret(parent, keyword, *args, &block)
41
+ Glimmer::Wx::SizerProxy.create(keyword, parent, args, &block)
42
+ end
43
+
44
+ def add_content(parent, keyword, *args, &block)
45
+ options = args.last.is_a?(Hash) ? args.last : {post_add_content: true}
46
+ options[:post_add_content] = true if options[:post_add_content].nil?
47
+ super
48
+ parent&.post_add_content if options[:post_add_content]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -116,9 +116,19 @@ module Glimmer
116
116
  # No Op by default
117
117
  end
118
118
 
119
+ # Returns closest frame ancestor or self if it is a frame
119
120
  def frame_proxy
120
121
  found_proxy = self
121
- until found_proxy.nil? || found_proxy.is_a?(WindowProxy)
122
+ until found_proxy.nil? || found_proxy.is_a?(FrameProxy)
123
+ found_proxy = found_proxy.parent_proxy
124
+ end
125
+ found_proxy
126
+ end
127
+
128
+ # Returns closest control ancestor
129
+ def control_proxy
130
+ found_proxy = parent_proxy
131
+ until found_proxy.nil? || found_proxy.is_a?(ControlProxy)
122
132
  found_proxy = found_proxy.parent_proxy
123
133
  end
124
134
  found_proxy
@@ -132,7 +142,7 @@ module Glimmer
132
142
 
133
143
  def handle_listener(listener_name, &listener)
134
144
  event = listener_name.to_s.sub('on_', '')
135
- @parent_proxy.wx.send("evt_#{event}", @wx, &listener)
145
+ frame_proxy.wx.send("evt_#{event}", @wx, &listener)
136
146
  # elsif has_custom_listener?(listener_name)
137
147
  # handle_custom_listener(listener_name, &listener)
138
148
  # end
@@ -210,15 +220,8 @@ module Glimmer
210
220
  private
211
221
 
212
222
  def build_control
213
- if is_a?(Parent)
214
- @wx = ControlProxy.new_control(@keyword, @parent_proxy&.wx, @args)
215
- else
216
- sizer = ::Wx::HBoxSizer.new
217
- @parent_proxy.sizer = sizer
218
- @wx = ControlProxy.new_control(@keyword, @parent_proxy&.wx, @args)
219
- sizer.add @wx, 0, ::Wx::RIGHT, 8
220
- end
221
- @wx
223
+ # must pass control_proxy.wx as parent because the direct parent might be a sizer
224
+ @wx = ControlProxy.new_control(@keyword, control_proxy&.wx, @args)
222
225
  end
223
226
  end
224
227
  end
@@ -0,0 +1,166 @@
1
+ # Copyright (c) 2023 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/wx/data_bindable'
23
+ require 'glimmer/wx/parent'
24
+
25
+ module Glimmer
26
+ module Wx
27
+ # Proxy for Wx sizer objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class SizerProxy
31
+ class << self
32
+ def exists?(keyword)
33
+ keyword.end_with?('_sizer') and
34
+ (
35
+ ::Wx.constants.include?(wx_constant_symbol(keyword)) or
36
+ descendant_keyword_constant_map.keys.include?(keyword)
37
+ )
38
+ end
39
+
40
+ def create(keyword, parent, args, &block)
41
+ sizer_proxy_class(keyword).new(keyword, parent, args, &block)
42
+ end
43
+
44
+ def sizer_proxy_class(keyword)
45
+ descendant_keyword_constant_map[keyword] || SizerProxy
46
+ end
47
+
48
+ def new_sizer(keyword, parent, args)
49
+ args = args.clone || []
50
+ if args.last.is_a?(Hash)
51
+ args[-1] = args[-1].clone
52
+ end
53
+ ::Wx.const_get(wx_constant_symbol(keyword)).new(*args)
54
+ end
55
+
56
+ def wx_constant_symbol(keyword)
57
+ keyword.to_s.camelcase(:upper).to_sym
58
+ end
59
+
60
+ def constant_symbol(keyword)
61
+ "#{keyword.to_s.camelcase(:upper)}Proxy".to_sym
62
+ end
63
+
64
+ def sizer_addable_method(keyword)
65
+ "add_#{keyword}"
66
+ end
67
+
68
+ def keyword(constant_symbol)
69
+ constant_symbol.to_s.underscore.sub(/_proxy$/, '')
70
+ end
71
+
72
+ def descendant_keyword_constant_map
73
+ @descendant_keyword_constant_map ||= map_descendant_keyword_constants_for(self)
74
+ end
75
+
76
+ def reset_descendant_keyword_constant_map
77
+ @descendant_keyword_constant_map = nil
78
+ descendant_keyword_constant_map
79
+ end
80
+
81
+ def map_descendant_keyword_constants_for(klass, accumulator: {})
82
+ klass.constants.map do |constant_symbol|
83
+ [constant_symbol, klass.const_get(constant_symbol)]
84
+ end.select do |constant_symbol, constant|
85
+ constant.is_a?(Module) && !accumulator.values.include?(constant)
86
+ end.each do |constant_symbol, constant|
87
+ accumulator[keyword(constant_symbol)] = constant
88
+ map_descendant_keyword_constants_for(constant, accumulator: accumulator)
89
+ end
90
+ accumulator
91
+ end
92
+ end
93
+
94
+ include DataBindable
95
+
96
+ # wx returns the contained LibUI object
97
+ attr_reader :parent_proxy, :wx, :args, :keyword, :block, :content_added
98
+ alias content_added? content_added
99
+
100
+ def initialize(keyword, parent, args, &block)
101
+ @keyword = keyword
102
+ @parent_proxy = parent
103
+ @args = args
104
+ @block = block
105
+ build_sizer
106
+ post_add_content if @block.nil?
107
+ end
108
+
109
+ # Subclasses may override to perform post add_content work (normally must call super)
110
+ def post_add_content
111
+ unless @content_added
112
+ @parent_proxy&.post_initialize_child(self)
113
+ @content_added = true
114
+ end
115
+ end
116
+
117
+ # Subclasses may override to perform post initialization work on an added child
118
+ def post_initialize_child(child)
119
+ # No Op by default
120
+ end
121
+
122
+ def respond_to?(method_name, *args, &block)
123
+ @wx.respond_to?(method_name, true) ||
124
+ super(method_name, true)
125
+ end
126
+
127
+ def method_missing(method_name, *args, &block)
128
+ if @wx.respond_to?(method_name, true)
129
+ @wx.send(method_name, *args, &block)
130
+ else
131
+ super
132
+ end
133
+ end
134
+
135
+ def content(&block)
136
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::SizerExpression.new, @keyword, {post_add_content: @content_added}, &block)
137
+ end
138
+
139
+ def add(control_proxy, *args, &block)
140
+ @wx.add(control_proxy.wx, *args)
141
+ end
142
+
143
+ # Checks if it can add a sizer addable (visual things other than controls)
144
+ # Example: for keyword `growable_col`, sizer addable method is `add_growable_col`
145
+ def can_add_sizer_addable?(keyword)
146
+ @wx.respond_to?(SizerProxy.sizer_addable_method(keyword))
147
+ end
148
+
149
+ # Adds a sizer addable (visual things other than controls)
150
+ # Example: for keyword `growable_col`, sizer addable method is `add_growable_col`
151
+ def add_sizer_addable(keyword, *args)
152
+ @wx.send(SizerProxy.sizer_addable_method(keyword), *args)
153
+ end
154
+
155
+ private
156
+
157
+ def build_sizer
158
+ @wx = SizerProxy.new_sizer(@keyword, @parent_proxy.wx, @args)
159
+ parent_proxy.sizer = @wx if parent_proxy.is_a?(Glimmer::Wx::ControlProxy)
160
+ @wx
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -23,15 +23,19 @@ require 'glimmer-dsl-wx'
23
23
 
24
24
  include Glimmer
25
25
 
26
- frame(title: 'Hello, Button!') { |f|
27
- button(label: 'Click To Find Who Built This!') {
28
- on_button do
29
- about_box(
30
- name: f.title,
31
- version: Wx::WXRUBY_VERSION,
32
- description: "This is the Hello, Button! sample",
33
- developers: ['The Glimmer DSL for WX Development Team']
34
- )
35
- end
26
+ frame(title: 'Hello, Button!') { |main_frame|
27
+ h_box_sizer {
28
+ button(label: 'Click To Find Who Built This!') {
29
+ sizer_args 0, Wx::RIGHT, 10
30
+
31
+ on_button do
32
+ about_box(
33
+ name: main_frame.title,
34
+ version: Wx::WXRUBY_VERSION,
35
+ description: "This is the Hello, Button! sample",
36
+ developers: ['The Glimmer DSL for WX Development Team']
37
+ )
38
+ end
39
+ }
36
40
  }
37
41
  }
@@ -23,19 +23,22 @@ require 'glimmer-dsl-wx'
23
23
 
24
24
  include Glimmer
25
25
 
26
- frame { |f|
26
+ frame { |main_frame|
27
27
  title 'Hello, Button!'
28
28
 
29
- button {
30
- label 'Click To Find Who Built This!'
31
-
32
- on_button do
33
- about_box(
34
- name: f.title,
35
- version: Wx::WXRUBY_VERSION,
36
- description: "This is the Hello, Button! sample",
37
- developers: ['The Glimmer DSL for WX Development Team']
38
- )
39
- end
29
+ h_box_sizer {
30
+ button {
31
+ sizer_args 0, Wx::RIGHT, 10
32
+ label 'Click To Find Who Built This!'
33
+
34
+ on_button do
35
+ about_box(
36
+ name: main_frame.title,
37
+ version: Wx::WXRUBY_VERSION,
38
+ description: "This is the Hello, Button! sample",
39
+ developers: ['The Glimmer DSL for WX Development Team']
40
+ )
41
+ end
42
+ }
40
43
  }
41
44
  }
@@ -0,0 +1,124 @@
1
+ # Copyright (c) 2023 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-wx'
23
+
24
+ include Glimmer
25
+
26
+ frame { |main_frame|
27
+ title 'Hello, Sizer!'
28
+
29
+ h_box_sizer {
30
+ v_box_sizer {
31
+ sizer_args 0, Wx::RIGHT, 10
32
+
33
+ button {
34
+ sizer_args 0, Wx::DOWN, 10
35
+ label 'Greeting 1'
36
+
37
+ on_button do
38
+ message_dialog(
39
+ "Hello",
40
+ "Greeting",
41
+ Wx::OK | Wx::ICON_INFORMATION
42
+ ).show_modal
43
+ end
44
+ }
45
+
46
+ spacer(10)
47
+
48
+ button {
49
+ sizer_args 0, Wx::DOWN, 10
50
+ label 'Greeting 2'
51
+
52
+ on_button do
53
+ message_dialog(
54
+ "Howdy",
55
+ "Greeting",
56
+ Wx::OK | Wx::ICON_INFORMATION
57
+ ).show_modal
58
+ end
59
+ }
60
+
61
+ spacer(10)
62
+
63
+ button {
64
+ sizer_args 0, Wx::DOWN, 10
65
+ label 'Greeting 3'
66
+
67
+ on_button do
68
+ message_dialog(
69
+ "Hi",
70
+ "Greeting",
71
+ Wx::OK | Wx::ICON_INFORMATION
72
+ ).show_modal
73
+ end
74
+ }
75
+ }
76
+
77
+ v_box_sizer {
78
+ sizer_args 0, Wx::RIGHT, 10
79
+
80
+ button {
81
+ sizer_args 0, Wx::DOWN, 10
82
+ label 'Greeting 4'
83
+
84
+ on_button do
85
+ message_dialog(
86
+ "Ciao",
87
+ "Greeting",
88
+ Wx::OK | Wx::ICON_INFORMATION
89
+ ).show_modal
90
+ end
91
+ }
92
+
93
+ spacer(10)
94
+
95
+ button {
96
+ sizer_args 0, Wx::DOWN, 10
97
+ label 'Greeting 5'
98
+
99
+ on_button do
100
+ message_dialog(
101
+ "Aloha",
102
+ "Greeting",
103
+ Wx::OK | Wx::ICON_INFORMATION
104
+ ).show_modal
105
+ end
106
+ }
107
+
108
+ spacer(10)
109
+
110
+ button {
111
+ sizer_args 0, Wx::DOWN, 10
112
+ label 'Greeting 6'
113
+
114
+ on_button do
115
+ message_dialog(
116
+ "Salut",
117
+ "Greeting",
118
+ Wx::OK | Wx::ICON_INFORMATION
119
+ ).show_modal
120
+ end
121
+ }
122
+ }
123
+ }
124
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-wx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.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: 2023-06-24 00:00:00.000000000 Z
11
+ date: 2023-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -240,20 +240,25 @@ files:
240
240
  - lib/glimmer/dsl/wx/operation_expression.rb
241
241
  - lib/glimmer/dsl/wx/property_expression.rb
242
242
  - lib/glimmer/dsl/wx/shine_data_binding_expression.rb
243
+ - lib/glimmer/dsl/wx/sizer_addable_expression.rb
244
+ - lib/glimmer/dsl/wx/sizer_args_expression.rb
245
+ - lib/glimmer/dsl/wx/sizer_expression.rb
243
246
  - lib/glimmer/proc_tracker.rb
244
247
  - lib/glimmer/wx/control_proxy.rb
245
248
  - lib/glimmer/wx/control_proxy/frame_proxy.rb
246
249
  - lib/glimmer/wx/data_bindable.rb
247
250
  - lib/glimmer/wx/parent.rb
251
+ - lib/glimmer/wx/sizer_proxy.rb
248
252
  - samples/art/wxruby-128x128.png
249
253
  - samples/art/wxruby-256x256.png
250
254
  - samples/art/wxruby-64x64.png
251
255
  - samples/art/wxruby.ico
252
256
  - samples/art/wxruby.png
253
- - samples/glimmer_new/hello_button.rb
254
- - samples/glimmer_new/hello_button2.rb
255
- - samples/glimmer_new/hello_world.rb
256
- - samples/glimmer_new/hello_world2.rb
257
+ - samples/hello/hello_button.rb
258
+ - samples/hello/hello_button2.rb
259
+ - samples/hello/hello_sizer.rb
260
+ - samples/hello/hello_world.rb
261
+ - samples/hello/hello_world2.rb
257
262
  - samples/minimal/mondrian.ico
258
263
  - samples/minimal/mondrian.png
259
264
  - samples/minimal/nothing.rb
File without changes
File without changes