glimmer-dsl-wx 0.0.7 → 0.1.0

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +309 -35
  5. data/VERSION +1 -1
  6. data/bin/girb +1 -1
  7. data/bin/girb_runner.rb +1 -1
  8. data/glimmer-dsl-wx.gemspec +0 -0
  9. data/lib/glimmer/dsl/wx/about_box_expression.rb +1 -1
  10. data/lib/glimmer/dsl/wx/bind_expression.rb +16 -16
  11. data/lib/glimmer/dsl/wx/control_expression.rb +1 -1
  12. data/lib/glimmer/dsl/wx/data_binding_expression.rb +25 -25
  13. data/lib/glimmer/dsl/wx/dsl.rb +4 -7
  14. data/lib/glimmer/dsl/wx/listener_expression.rb +1 -1
  15. data/lib/glimmer/dsl/wx/observe_expression.rb +1 -1
  16. data/lib/glimmer/dsl/wx/operation_expression.rb +23 -27
  17. data/lib/glimmer/dsl/wx/property_expression.rb +10 -3
  18. data/lib/glimmer/dsl/wx/shine_data_binding_expression.rb +23 -22
  19. data/lib/glimmer/dsl/wx/sizer_addable_expression.rb +1 -1
  20. data/lib/glimmer/dsl/wx/sizer_args_expression.rb +1 -1
  21. data/lib/glimmer/dsl/wx/sizer_expression.rb +1 -1
  22. data/lib/glimmer/wx/control_proxy/frame_proxy.rb +1 -1
  23. data/lib/glimmer/wx/control_proxy/slider_proxy.rb +55 -0
  24. data/lib/glimmer/wx/control_proxy/spin_ctrl_double_proxy.rb +41 -0
  25. data/lib/glimmer/wx/control_proxy/spin_ctrl_proxy.rb +41 -0
  26. data/lib/glimmer/wx/control_proxy/text_ctrl_proxy.rb +39 -0
  27. data/lib/glimmer/wx/control_proxy.rb +3 -3
  28. data/lib/glimmer/wx/data_bindable.rb +1 -1
  29. data/lib/glimmer/wx/parent.rb +1 -1
  30. data/lib/glimmer/wx/sizer_proxy.rb +1 -1
  31. data/lib/glimmer-dsl-wx.rb +1 -1
  32. data/samples/hello/hello_button.rb +1 -1
  33. data/samples/hello/hello_button2.rb +1 -1
  34. data/samples/hello/hello_data_binding.rb +126 -0
  35. data/samples/hello/hello_sizer.rb +7 -7
  36. data/samples/hello/hello_world.rb +1 -1
  37. data/samples/hello/hello_world2.rb +1 -1
  38. data/samples/minimal/nothing.rb +1 -1
  39. metadata +19 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d67fb5f483b55ca655215bf87926ae501dd680b4ffeebbfe02756b257398d4f3
4
- data.tar.gz: fffd53b54fba50092ea146df9bb90b268f333cc903a29b6178e9cc80217b9d3a
3
+ metadata.gz: 29fe9921216dd94b4784192eebb73db6125697148b8c617f05f41dc919b55f59
4
+ data.tar.gz: 1b1299da11273e591436920f6c3dd3d495f6b9941602144f5968ba79ffc1623a
5
5
  SHA512:
6
- metadata.gz: 9e1544b9b4dedfc9f99b31833982642bba382e69b857957a6647aecc8e93ae8d7a7d60af5a6c7f0cdff858ef555c3d7a5b12536a61ce3ba49322051f39ed17fe
7
- data.tar.gz: 402553fc0c1462d0f7e20d9931d894347739f9d9229bb1616731ec42897ba45a5e2a37f7ca54f8c06514a726e48cc4f1e4a1e9e2cd641aa810b5b0d793e12046
6
+ metadata.gz: 94a29ba03eb985c4ef98abc95e60734d711f2282322d0b4b0bed0bf9e78f947f91c2c45636ae21fcd73bfbc5b7ca89e3b5477c562312166193562c6a3f15ef76
7
+ data.tar.gz: 4c6b627cc677c733d921d860d1e8b466ff21d8eaac654f3e7f530067939a5fb0bb7d7bf095a35d6b15da26f93402a2d55d46fbfa3219d71868c45b2f8dde2fd3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.1.0
4
+
5
+ - Upgrade to wxruby3 1.0.0
6
+ - Upgrade to glimmer 2.7.7
7
+ - Support control operations (methods) in the DSL
8
+ - Improve detection of property setter methods on controls when invoking from DSL
9
+ - Support property unidirectional data-binding for all controls
10
+ - Support property bidirectional data-binding for text_ctrl
11
+ - Support property bidirectional data-binding for spin_ctrl
12
+ - Support property bidirectional data-binding for spin_ctrl_double
13
+ - Support property bidirectional data-binding for slider
14
+ - Hello, Data-Binding! Sample
15
+
3
16
  ## 0.0.7
4
17
 
5
18
  - Sizer addable support (e.g. supporting `growable_col(1, 1)`, using `add_growable_col(1, 1)` method in wxruby3 API)
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 Andy Maleh
1
+ Copyright (c) 2023-2024 Andy Maleh
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,10 +1,12 @@
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
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.1.0
2
2
  ## wxWidgets Ruby Desktop Development GUI Library
3
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.
7
7
 
8
+ ![Hello, Data-Binding!](/screenshots/glimmer-dsl-wx-sample-hello-data-binding.gif?raw=true)
9
+
8
10
  [Glimmer DSL for WX](https://rubygems.org/gems/glimmer-dsl-wx) 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:
9
11
  - [Declarative DSL syntax](#glimmer-gui-dsl-concepts) that visually maps to the GUI control hierarchy
10
12
  - [Convention over configuration](#smart-defaults-and-conventions) via smart defaults and automation of low-level details
@@ -24,7 +26,7 @@ include Glimmer
24
26
  frame(title: 'Hello, World!')
25
27
  ```
26
28
 
27
- ![Hello, World!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-world.png?raw=true)
29
+ ![Hello, World!](/screenshots/glimmer-dsl-wx-sample-hello-world.png?raw=true)
28
30
 
29
31
  **Hello Button!**
30
32
 
@@ -54,35 +56,25 @@ frame { |main_frame|
54
56
  }
55
57
  ```
56
58
 
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
-
61
- **[Glimmer](https://rubygems.org/gems/glimmer) DSL Comparison Table:**
62
- DSL | Platforms | Native? | Vector Graphics? | Pros | Cons | Prereqs
63
- ----|-----------|---------|------------------|------|------|--------
64
- [Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)](https://github.com/AndyObtiva/glimmer-dsl-swt) | Mac / Windows / Linux | Yes | Yes (Canvas Shape DSL) | Very Mature / Scaffolding / Native Executable Packaging / Custom Widgets | Slow JRuby Startup Time / Heavy Memory Footprint | Java / JRuby
65
- [Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)](https://github.com/AndyObtiva/glimmer-dsl-opal) | All Web Browsers | No | Yes (Canvas Shape DSL) | Simpler than All JavaScript Technologies / Auto-Webify Desktop Apps | Setup Process / Only Rails 5 Support for Now | Rails
66
- [Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-libui) | Mac / Windows / Linux | Yes | Yes (Area API) | Fast Startup Time / Light Memory Footprint | LibUI is an Incomplete Mid-Alpha Only | None Other Than MRI Ruby
67
- [Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-tk) | Mac / Windows / Linux | Some Native-Themed Widgets (Not Truly Native) | Yes (Canvas) | Fast Startup Time / Light Memory Footprint | Complicated Setup / Widgets Do Not Look Truly Native, Espcially on Linux | ActiveTcl / MRI Ruby
68
- [Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-gtk) | Mac / Windows / Linux | Only on Linux | Yes (Cairo) | Complete Access to GNOME Features on Linux (Forte) | Not Native on Mac and Windows | None Other Than MRI Ruby on Linux / Brew Packages on Mac / MSYS & MING Toolchains on Windows / MRI Ruby
69
- [Glimmer DSL for FX (FOX Toolkit Ruby Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-fx) | Mac (requires XQuartz) / Windows / Linux | No | Yes (Canvas) | No Prerequisites on Windows (Forte Since Binaries Are Included Out of The Box) | Widgets Do Not Look Native / Mac Usage Obtrusively Starts XQuartz | None Other Than MRI Ruby on Windows / XQuarts on Mac / MRI Ruby
70
- [Glimmer DSL for WX (wxWidgets Ruby Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-wx) | Mac / Windows / Linux | Yes | Yes | Fast Startup Time / Light Memory Footprint | wxruby3 is still beta and does not support Mac yet | wxWidgets library, Doxygen, and other prereqs
71
- [Glimmer DSL for JFX (JRuby JavaFX Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-jfx) | Mac / Windows / Linux | No | Yes (javafx.scene.shape and javafx.scene.canvas) | Rich in Custom Widgets | Slow JRuby Startup Time / Heavy Memory Footprint / Widgets Do Not Look Native | Java / JRuby / JavaFX SDK
72
- [Glimmer DSL for Swing (JRuby Swing Desktop Development GUI Library)](https://github.com/AndyObtiva/glimmer-dsl-swing) | Mac / Windows / Linux | No | Yes (Java2D) | Very Mature | Slow JRuby Startup Time / Heavy Memory Footprint / Widgets Do Not Look Native | Java / JRuby
73
- [Glimmer DSL for XML (& HTML)](https://github.com/AndyObtiva/glimmer-dsl-xml) | All Web Browsers | No | Yes (SVG) | Programmable / Lighter-weight Than Actual XML | XML Elements Are Sometimes Not Well-Named (Many Types of Input) | None
74
- [Glimmer DSL for CSS](https://github.com/AndyObtiva/glimmer-dsl-css) | All Web Browsers | No | Yes | Programmable | CSS Is Over-Engineered / Too Many Features To Learn | None
59
+ ![Hello, Button!](/screenshots/glimmer-dsl-wx-sample-hello-button.png?raw=true)
60
+
61
+ ![Hello, Button! Clicked](/screenshots/glimmer-dsl-wx-sample-hello-button-clicked.png?raw=true)
62
+
63
+ Learn more about the differences between various [Glimmer](https://github.com/AndyObtiva/glimmer) DSLs by looking at the **[Glimmer DSL Comparison Table](https://github.com/AndyObtiva/glimmer#glimmer-dsl-comparison-table)**.
75
64
 
76
65
  ## Table of Contents
77
66
 
78
67
  - [Glimmer DSL for WX](#)
79
68
  - [Setup](#setup)
69
+ - [Usage](#usage)
80
70
  - [GIRB (Glimmer IRB)](#girb-glimmer-irb)
81
71
  - [Smart Defaults and Conventions](#smart-defaults-and-conventions)
82
72
  - [Samples](#samples)
83
73
  - [Hello, World!](#hello-world)
84
74
  - [Hello, Button!](#hello-button)
85
75
  - [Hello, Sizer!](#hello-sizer)
76
+ - [Hello, Data-Binding!](#hello-data-binding)
77
+ - [Coming From wxruby3](#coming-from-wxruby3)
86
78
  - [Process](#process)
87
79
  - [Resources](#resources)
88
80
  - [Help](#help)
@@ -108,7 +100,7 @@ gem install glimmer-dsl-wx
108
100
  Or install via Bundler `Gemfile`:
109
101
 
110
102
  ```ruby
111
- gem 'glimmer-dsl-wx', '~> 0.0.7'
103
+ gem 'glimmer-dsl-wx', '~> 0.1.0'
112
104
  ```
113
105
 
114
106
  Test that installation worked by running a sample:
@@ -123,6 +115,127 @@ If you cloned project, test by running a sample locally:
123
115
  ruby -r ./lib/glimmer-dsl-wx.rb samples/hello/hello_world.rb
124
116
  ```
125
117
 
118
+ ## Usage
119
+
120
+ To use [glimmer-dsl-wx](https://rubygems.org/gems/glimmer-dsl-wx):
121
+ 1. Add `require 'glimmer-dsl-wx'` at the top of the Ruby file (this will automatically `require 'wxruby3'` too)
122
+ 2. Add `include Glimmer` into the top-level main object for testing or into an actual class for serious application usage.
123
+ 3. Write GUI DSL code beginning with `frame` to build a window first and then nest other controls/sizers within it.
124
+
125
+ Example:
126
+
127
+ ```ruby
128
+ require 'glimmer-dsl-wx'
129
+
130
+ include Glimmer
131
+
132
+ frame { |main_frame|
133
+ title 'Hello, Button!'
134
+
135
+ h_box_sizer {
136
+ button {
137
+ sizer_args 0, Wx::RIGHT, 10
138
+ label 'Click To Find Who Built This!'
139
+
140
+ on_button do
141
+ message_dialog(
142
+ "The Glimmer DSL for WX Team",
143
+ "Greeting",
144
+ Wx::OK | Wx::ICON_INFORMATION
145
+ ).show_modal
146
+ end
147
+ }
148
+ }
149
+ }
150
+ ```
151
+
152
+ ![Hello, Button!](/screenshots/glimmer-dsl-wx-sample-hello-button.png?raw=true)
153
+
154
+ Glimmer DSL for WX follows these simple concepts in mapping from wxruby3 syntax to Glimmer GUI DSL syntax:
155
+
156
+ **Keyword(args)**: wxruby3 controls/sizers may be declared by lower-case underscored name. For example, `Frame` becomes `frame`. `HBoxSizer` becomes `h_box_sizer`. And, they receive the same arguments as the wxruby3 class constructor. For example, `Frame.new(title: 'Hello')` becomes `frame(title: 'Hello')`.
157
+
158
+ **Content Block** (Properties/Listeners/Controls): Any keyword may be optionally followed by a declarative Ruby curly-brace multi-line content block containing properties (attributes), listeners, and/or nested controls/sizers.
159
+
160
+ Example:
161
+
162
+ ```ruby
163
+ frame(title: 'Hello, Button') {
164
+ h_box_sizer {
165
+ button(label: 'Click To Find Who Built This!')
166
+ }
167
+ }
168
+ ```
169
+
170
+ Content block optionally receives one arg representing the control or sizer it represents.
171
+
172
+ Example:
173
+
174
+ ```ruby
175
+ frame(title: 'Hello, Button!') { |main_frame|
176
+ h_box_sizer {
177
+ button {
178
+ sizer_args 0, Wx::RIGHT, 10
179
+ label 'Click To Find Who Built This!'
180
+
181
+ on_button do
182
+ about_box(
183
+ name: main_frame.title,
184
+ version: Wx::WXRUBY_VERSION,
185
+ description: "This is the Hello, Button! sample",
186
+ developers: ['The Glimmer DSL for WX Development Team']
187
+ )
188
+ end
189
+ }
190
+ }
191
+ }
192
+ ```
193
+
194
+ **Property**: Control properties may be declared inside keyword blocks with lower-case underscored name followed by property value args (e.g. `title "Hello"` inside `frame`). Behind the scenes, properties correspond to `control.property=` methods like `frame.title=`.
195
+
196
+ Controls and sizers (objects that organize controls within certain layouts) could accept a special `sizer_args` property, which takes the arguments normally passed to the `sizer.add` method. For example, `sizer_args 0, Wx::RIGHT, 10` translates to `sizer.add(control, 0, Wx::Right, 10)` behind the scenes.
197
+
198
+ **Listener**: Control listeners may be declared inside keyword blocks with listener lower-case underscored name beginning with `on_` followed by event name (translates to `frame.evt_#{event_name}` like `frame.evt_button` for the click of a button) and receiving required block handler (always followed by a `do; end` style block to signify imperative Model logic vs declarative View control/sizer nesting).
199
+
200
+ Example:
201
+
202
+ ```ruby
203
+ button('click') {
204
+ on_clicked do
205
+ puts 'clicked'
206
+ end
207
+ }
208
+ ```
209
+
210
+ Optionally, the listener block can receive an arg representing the control.
211
+
212
+ ```ruby
213
+ ...
214
+ button {
215
+ sizer_args 0, Wx::RIGHT, 10
216
+ label 'Click To Find Who Built This!'
217
+
218
+ on_button do
219
+ # Do work!
220
+ end
221
+ }
222
+ ...
223
+ ```
224
+
225
+ Behind the scenes, listeners correspond to `frame.evt_#{event_name}` methods. So, for `on_button`, the event name is `button`, and that translates to `frame.evt_button(button, &listener)` behind the scenes.
226
+
227
+ **Operation**: Controls have methods that invoke certain operations on them. For example, `message_dialog` has a `#show_modal` method that shows the message dialog GUI.
228
+
229
+ ```ruby
230
+ ...
231
+ message_dialog(
232
+ "The Glimmer DSL for WX Team",
233
+ "Greeting",
234
+ Wx::OK | Wx::ICON_INFORMATION
235
+ ).show_modal
236
+ ...
237
+ ```
238
+
126
239
  ## GIRB (Glimmer IRB)
127
240
 
128
241
  You can run the `girb` command (`bin/girb` if you cloned the project locally) to do some quick and dirty experimentation and learning:
@@ -142,7 +255,7 @@ This gives you `irb` with the `glimmer-dsl-wx` gem loaded and the `Glimmer` modu
142
255
 
143
256
  ### Hello, World!
144
257
 
145
- ![Hello, World!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-world.png?raw=true)
258
+ ![Hello, World!](/screenshots/glimmer-dsl-wx-sample-hello-world.png?raw=true)
146
259
 
147
260
  ```ruby
148
261
  require 'glimmer-dsl-wx'
@@ -166,9 +279,9 @@ frame {
166
279
 
167
280
  ### Hello Button!
168
281
 
169
- ![Hello, Button!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-button.png?raw=true)
282
+ ![Hello, Button!](/screenshots/glimmer-dsl-wx-sample-hello-button.png?raw=true)
170
283
 
171
- ![Hello, Button! Clicked](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-button-clicked.png?raw=true)
284
+ ![Hello, Button! Clicked](/screenshots/glimmer-dsl-wx-sample-hello-button-clicked.png?raw=true)
172
285
 
173
286
  ```ruby
174
287
  require 'glimmer-dsl-wx'
@@ -223,9 +336,9 @@ frame { |main_frame|
223
336
 
224
337
  ### Hello Sizer!
225
338
 
226
- ![Hello, Sizer!](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-sizer-button.png?raw=true)
339
+ ![Hello, Sizer!](/screenshots/glimmer-dsl-wx-sample-hello-sizer.png?raw=true)
227
340
 
228
- ![Hello, Sizer! Clicked](https://github.com/AndyObtiva/glimmer-dsl-wx/blob/master/screenshots/glimmer-dsl-wx-sample-hello-sizer-clicked.png?raw=true)
341
+ ![Hello, Sizer! Clicked](/screenshots/glimmer-dsl-wx-sample-hello-sizer-clicked.png?raw=true)
229
342
 
230
343
  ```ruby
231
344
  require 'glimmer-dsl-wx'
@@ -246,7 +359,7 @@ frame { |main_frame|
246
359
  on_button do
247
360
  message_dialog(
248
361
  "Hello",
249
- "Greeting",
362
+ "Greeting 1",
250
363
  Wx::OK | Wx::ICON_INFORMATION
251
364
  ).show_modal
252
365
  end
@@ -261,7 +374,7 @@ frame { |main_frame|
261
374
  on_button do
262
375
  message_dialog(
263
376
  "Howdy",
264
- "Greeting",
377
+ "Greeting 2",
265
378
  Wx::OK | Wx::ICON_INFORMATION
266
379
  ).show_modal
267
380
  end
@@ -276,7 +389,7 @@ frame { |main_frame|
276
389
  on_button do
277
390
  message_dialog(
278
391
  "Hi",
279
- "Greeting",
392
+ "Greeting 3",
280
393
  Wx::OK | Wx::ICON_INFORMATION
281
394
  ).show_modal
282
395
  end
@@ -293,7 +406,7 @@ frame { |main_frame|
293
406
  on_button do
294
407
  message_dialog(
295
408
  "Ciao",
296
- "Greeting",
409
+ "Greeting 4",
297
410
  Wx::OK | Wx::ICON_INFORMATION
298
411
  ).show_modal
299
412
  end
@@ -308,7 +421,7 @@ frame { |main_frame|
308
421
  on_button do
309
422
  message_dialog(
310
423
  "Aloha",
311
- "Greeting",
424
+ "Greeting 5",
312
425
  Wx::OK | Wx::ICON_INFORMATION
313
426
  ).show_modal
314
427
  end
@@ -323,7 +436,7 @@ frame { |main_frame|
323
436
  on_button do
324
437
  message_dialog(
325
438
  "Salut",
326
- "Greeting",
439
+ "Greeting 6",
327
440
  Wx::OK | Wx::ICON_INFORMATION
328
441
  ).show_modal
329
442
  end
@@ -333,6 +446,165 @@ frame { |main_frame|
333
446
  }
334
447
  ```
335
448
 
449
+ ### Hello Data-Binding!
450
+
451
+ Glimmer DSL for WX supports data-binding via `<=` for unidirectional data-binding and `<=>` for bidirectional data-binding.
452
+
453
+ ![Hello, Data-Binding!](/screenshots/glimmer-dsl-wx-sample-hello-data-binding.gif?raw=true)
454
+
455
+ ```ruby
456
+ require 'glimmer-dsl-wx'
457
+
458
+ class Donor
459
+ DONATION_AMOUNT_MIN = 0
460
+ DONATION_AMOUNT_MAX = 100
461
+ DONATION_AMOUNT_DEFAULT = 50
462
+
463
+ attr_accessor :first_name, :last_name, :donation_amount
464
+
465
+ def initialize
466
+ @last_name = @first_name = ''
467
+ @donation_amount = DONATION_AMOUNT_DEFAULT
468
+ end
469
+
470
+ def full_name
471
+ full_name_parts = [first_name, last_name]
472
+ full_name_string = full_name_parts.join(' ').strip
473
+ if full_name_string.empty?
474
+ 'Anonymous'
475
+ else
476
+ full_name_string
477
+ end
478
+ end
479
+
480
+ def summary
481
+ "#{full_name} donated $#{donation_amount}"
482
+ end
483
+ end
484
+
485
+ donor = Donor.new
486
+
487
+ include Glimmer
488
+
489
+ frame(title: 'Hello, Data-Binding!') { |window|
490
+ panel {
491
+ v_box_sizer {
492
+ h_box_sizer {
493
+ sizer_args 0, Wx::DOWN, 10
494
+
495
+ static_text(label: 'First Name:') {
496
+ sizer_args 0, Wx::RIGHT, 10
497
+ }
498
+ text_ctrl {
499
+ sizer_args 0, Wx::RIGHT, 10
500
+ # data-bind donor.first_name to text_ctrl.value bidirectionally,
501
+ # ensuring changes to either attribute update the other attribute
502
+ value <=> [donor, :first_name]
503
+ }
504
+ }
505
+
506
+ h_box_sizer {
507
+ sizer_args 0, Wx::DOWN, 10
508
+
509
+ static_text(label: 'Last Name:') {
510
+ sizer_args 0, Wx::RIGHT, 10
511
+ }
512
+ text_ctrl {
513
+ sizer_args 0, Wx::RIGHT, 10
514
+ # data-bind donor.last_name to text_ctrl.value bidirectionally,
515
+ # ensuring changes to either attribute update the other attribute
516
+ value <=> [donor, :last_name]
517
+ }
518
+ }
519
+
520
+ h_box_sizer {
521
+ sizer_args 0, Wx::DOWN, 10
522
+
523
+ static_text(label: 'Donation Amount: $') {
524
+ sizer_args 0, Wx::RIGHT, 1
525
+ }
526
+ spin_ctrl {
527
+ sizer_args 0, Wx::RIGHT, 10
528
+ range Donor::DONATION_AMOUNT_MIN, Donor::DONATION_AMOUNT_MAX
529
+ # data-bind donor.donation_amount to spin_ctrl.value bidirectionally,
530
+ # ensuring changes to either attribute update the other attribute
531
+ value <=> [donor, :donation_amount]
532
+ }
533
+ }
534
+
535
+ h_box_sizer {
536
+ sizer_args 0, Wx::DOWN, 10
537
+
538
+ slider {
539
+ sizer_args 0, Wx::RIGHT, 10
540
+ range Donor::DONATION_AMOUNT_MIN, Donor::DONATION_AMOUNT_MAX
541
+ # data-bind donor.first_name to spinner.value bidirectionally,
542
+ # ensuring changes to either attribute update the other attribute
543
+ value <=> [donor, :donation_amount]
544
+ }
545
+ }
546
+
547
+ h_box_sizer {
548
+ sizer_args 0, Wx::DOWN, 10
549
+
550
+ static_text(label: '') {
551
+ sizer_args 0, Wx::RIGHT, 10
552
+ # data-bind donor.summary to static_text.label unidirectionally,
553
+ # with computed data-binding from donor summary dependencies: first_name, last_name, and donation_amount
554
+ # ensuring changes to donor.summary or any of its dependencies update static_text.label
555
+ label <= [donor, :summary, computed_by: [:first_name, :last_name, :donation_amount]]
556
+ }
557
+ }
558
+ }
559
+ }
560
+ }
561
+ ```
562
+
563
+ ## Coming From wxruby3
564
+
565
+ If you would like to translate wxruby3 code into Glimmer DSL for WX code, read the [Usage](#usage) section to understand how Glimmer GUI DSL syntax works, and then check out the example below, which is written in both wxruby3 and Glimmer DSL for WX.
566
+
567
+ Example written in wxruby3:
568
+
569
+ ```ruby
570
+ require 'wx'
571
+
572
+ class TheFrame < Wx::Frame
573
+ def initialize(title)
574
+ super(nil, title: title)
575
+ panel = Wx::Panel.new(self)
576
+ button = Wx::Button.new(panel, label: 'Click me')
577
+ button.evt_button(Wx::ID_ANY) { Wx.message_box('Hello. Thanks for clicking me!', 'Hello Button sample') }
578
+ end
579
+ end
580
+
581
+ Wx::App.run { TheFrame.new('Hello world!').show }
582
+ ```
583
+
584
+ ![Hello_Button](https://raw.githubusercontent.com/mcorino/wxRuby3/master/assets/hello_button.png)
585
+ ![Hello_Button_Clicked](https://raw.githubusercontent.com/mcorino/wxRuby3/master/assets/hello_button_clicked.png)
586
+
587
+ Example re-written in Glimmer DSL for WX:
588
+
589
+ ```ruby
590
+ require 'glimmer-dsl-wx'
591
+
592
+ include Glimmer
593
+
594
+ frame(title: 'Hello world!') {
595
+ panel {
596
+ button(label: 'Click me') {
597
+ on_button do
598
+ Wx.message_box('Hello. Thanks for clicking me!', 'Hello Button sample')
599
+ end
600
+ }
601
+ }
602
+ }
603
+ ```
604
+
605
+ ![Hello_Button](https://raw.githubusercontent.com/mcorino/wxRuby3/master/assets/hello_button.png)
606
+ ![Hello_Button_Clicked](https://raw.githubusercontent.com/mcorino/wxRuby3/master/assets/hello_button_clicked.png)
607
+
336
608
  ## Process
337
609
 
338
610
  [Glimmer Process](https://github.com/AndyObtiva/glimmer/blob/master/PROCESS.md)
@@ -340,8 +612,10 @@ frame { |main_frame|
340
612
  ## Resources
341
613
 
342
614
  - [Code Master Blog](https://andymaleh.blogspot.com)
343
- - [wxruby3 Bindings](https://github.com/mcorino/wxRuby3)
344
- - [wxWidgets GUI Toolkit](https://www.wxwidgets.org/)
615
+ - [wxruby3 Bindings](https://github.com/mcorino/wxRuby3) (used by Glimmer DSL for WX)
616
+ - [wxWidgets GUI Toolkit](https://www.wxwidgets.org/) (used by Glimmer DSL for WX)
617
+ - [wxWidgets Controls](https://docs.wxwidgets.org/3.0/group__group__class__ctrl.html)
618
+ - [wxWidgets Sizers](https://docs.wxwidgets.org/3.0/overview_sizer.html)
345
619
 
346
620
  ## Help
347
621
 
@@ -393,7 +667,7 @@ Note that the latest development sometimes takes place in the [development](http
393
667
 
394
668
  [MIT](LICENSE.txt)
395
669
 
396
- Copyright (c) 2023 Andy Maleh
670
+ Copyright (c) 2023-2024 Andy Maleh
397
671
 
398
672
  --
399
673
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.1.0
data/bin/girb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # Copyright (c) 2023 Andy Maleh
3
+ # Copyright (c) 2023-2024 Andy Maleh
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining
6
6
  # a copy of this software and associated documentation files (the
data/bin/girb_runner.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
Binary file
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -19,18 +19,18 @@
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/dsl/static_expression'
23
- # require 'glimmer/dsl/bind_expression'
24
- #
25
- # module Glimmer
26
- # module DSL
27
- # module Libui
28
- ### Responsible for setting up the return value of the bind keyword (command symbol)
29
- ### as a ModelBinding. It is then used by another command handler like
30
- ### DataBindingExpression
31
- # class BindExpression < StaticExpression
32
- # include Glimmer::DSL::BindExpression
33
- # end
34
- # end
35
- # end
36
- # end
22
+ require 'glimmer/dsl/static_expression'
23
+ require 'glimmer/dsl/bind_expression'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Wx
28
+ # Responsible for setting up the return value of the bind keyword (command symbol)
29
+ # as a ModelBinding. It is then used by another command handler like
30
+ # DataBindingExpression
31
+ class BindExpression < StaticExpression
32
+ include Glimmer::DSL::BindExpression
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -19,27 +19,27 @@
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/dsl/expression'
23
- # require 'glimmer/data_binding/model_binding'
24
- #
25
- # module Glimmer
26
- # module DSL
27
- # module Libui
28
- ### Responsible for wiring data-binding
29
- ### Depends on BindExpression
30
- # class DataBindingExpression < Expression
31
- # def can_interpret?(parent, keyword, *args, &block)
32
- # args.size == 1 and
33
- # args[0].is_a?(DataBinding::ModelBinding) and
34
- # parent.respond_to?(:data_bind)
35
- # end
36
- #
37
- # def interpret(parent, keyword, *args, &block)
38
- # property = keyword
39
- # model_binding = args[0]
40
- # parent.data_bind(property, model_binding)
41
- # end
42
- # end
43
- # end
44
- # end
45
- # end
22
+ require 'glimmer/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Wx
28
+ # Responsible for wiring data-binding
29
+ # Depends on BindExpression
30
+ class DataBindingExpression < Expression
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ args.size == 1 and
33
+ args[0].is_a?(DataBinding::ModelBinding) and
34
+ parent.respond_to?(:data_bind)
35
+ end
36
+
37
+ def interpret(parent, keyword, *args, &block)
38
+ property = keyword
39
+ model_binding = args[0]
40
+ parent.data_bind(property, model_binding)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2023 Andy Maleh
1
+ # Copyright (c) 2023-2024 Andy Maleh
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
@@ -35,18 +35,15 @@ module Glimmer
35
35
  module Wx
36
36
  Engine.add_dynamic_expressions(
37
37
  Wx,
38
- # listener
39
- # data_binding
40
- # shine_data_binding
41
- # property
42
- # operation
43
- # control
44
38
  %w[
45
39
  listener
40
+ data_binding
41
+ shine_data_binding
46
42
  sizer_args
47
43
  sizer_addable
48
44
  sizer
49
45
  property
46
+ operation
50
47
  control
51
48
  ]
52
49
  )