glimmer-dsl-libui 0.7.5 → 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec43caceca7a5693e9a98278af76787a03cdfa7e259b4eafc221456f2388f1cf
4
- data.tar.gz: 72e7b5b20c6d07ab1160d1e83c7564dea41181b538b71d73d54acb41e839f503
3
+ metadata.gz: cc2c8178ea922168b2df15740230c175155c96313d847dd117137ba18eba0991
4
+ data.tar.gz: 49cbaff89df8bb0d1099b6adf9f0dcdaefe05010c4ee7b295160b0f7fbe8bd66
5
5
  SHA512:
6
- metadata.gz: b829f991b9fa34fb2ba186a022a950e45e65d13e81019ad53829b2c57b13aa7a16c10304207c6cc734015a4a5a3b44885070da15832f92f655603e925623396e
7
- data.tar.gz: c00a6b5c543039dc64c68f5e2e3cccfad74f7b511ba6fb40aa3482e9468ea49de995dc0edb8cc924082c2cce456923a47e5d9bc406b2866be8999f6309b31925
6
+ metadata.gz: 30c0cbe41224d6c18e32c204a9f8fab80330ce27d8174f3293399ea9aeb73474f2083145d361d708f062d7035762a4417a135be886dacc09785034ed2b8f0887
7
+ data.tar.gz: 3f5adf2374b390a21f4e6e7c28003c0446d5fd2a1c810beaebedb820530f56f7415c4a44f91887056be8e7745bc6cc6cd9728c9833cbd7688886f1b3a293d355
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.7.7
4
+
5
+ - Support ability for `area` `on_key_event`/`on_key_down`/`on_key_up` listeners to return a boolean value indicating whether they handled a key event or not in case some key events need to be left to other operating system key handlers like COMMAND+Q for the Mac quit menu item
6
+ - Update `examples/tetris.rb` to return `false` in its `on_key_down` listener for unhandled events
7
+ - Update `examples/area_gallery.rb` to return `false` in its `on_key_event`/`on_key_down`/`on_key_up` listeners for unhandled events
8
+
9
+ ## 0.7.6
10
+
11
+ - Fix issue with hearing "fonk" sound on every key press when handling `on_key_event`/`on_key_down`/`on_key_up` listeners (by returning expected `1` value if the listeners are handled properly or otherwise allowing the "fonk" sound to ring when the listeners are not handled)
12
+ - Update examples/tetris.rb with COMMAND+Q shortcut for quitting on the Mac and ALT+F4 shortcut for quitting on Windows/Linux
13
+
3
14
  ## 0.7.5
4
15
 
5
16
  - Fix [issue 46](https://github.com/AndyObtiva/glimmer-dsl-libui/issues/46) (GTK Error rendering table with zero initial elements), which happens when explicitly data-binding table cell_rows to an empty array
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.7.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 LibUI 0.7.7
2
2
  ## Prerequisite-Free Ruby Desktop Development GUI Library
3
3
  ### The Quickest Way From Zero To GUI
4
4
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
@@ -544,7 +544,7 @@ gem install glimmer-dsl-libui
544
544
  Or install via Bundler `Gemfile`:
545
545
 
546
546
  ```ruby
547
- gem 'glimmer-dsl-libui', '~> 0.7.5'
547
+ gem 'glimmer-dsl-libui', '~> 0.7.7'
548
548
  ```
549
549
 
550
550
  Test that installation worked by running the [Meta-Example](#examples):
@@ -763,7 +763,7 @@ Keyword(Args) | Properties | Listeners
763
763
  - `valign` [dsl-only] (`:fill`, `:start`, `:center`, or `:end`) [default=`:fill`]: available in [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) when nested under `grid`
764
764
 
765
765
  ### Common Control Operations
766
- - `destroy`
766
+ - `destroy` (note that for closing a `window`, in addition to calling `somewindow.destroy`, you also have to call `::LibUI.quit`)
767
767
  - `disable`
768
768
  - `enable`
769
769
  - `hide`
@@ -1947,7 +1947,7 @@ The [Observer Design Pattern](https://en.wikipedia.org/wiki/Observer_pattern) (a
1947
1947
 
1948
1948
  ![MVC - Model View Controller](https://developer.mozilla.org/en-US/docs/Glossary/MVC/model-view-controller-light-blue.png)
1949
1949
 
1950
- [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) supports the [Observer Design Pattern](https://en.wikipedia.org/wiki/Observer_pattern) via the `observe(model, attribute_or_key=nil)` keyword, which can observe `Object` models with attributes, `Hash`es with keys, and `Array`s. It automatically enhances objects as needed to support automatically notifying observers of changes via `observable#notify_observers(attribute_or_key = nil)` method:
1950
+ [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) supports the [Observer Design Pattern](https://en.wikipedia.org/wiki/Observer_pattern) via control listeners in the View layer (e.g. `on_clicked` or `on_closing`) and via the `observe(model, attribute_or_key=nil)` keyword in the Model layer, which can observe `Object` models with attributes, `Hash`es with keys, and `Array`s. It automatically enhances objects as needed to support automatically notifying observers of changes via `observable#notify_observers(attribute_or_key = nil)` method:
1951
1951
  - `Object` becomes `Glimmer::DataBinding::ObservableModel`, which supports observing specified `Object` model attributes.
1952
1952
  - `Hash` becomes `Glimmer::DataBinding::ObservableHash`, which supports observing all `Hash` keys or a specific `Hash` key
1953
1953
  - `Array` becomes `Glimmer::DataBinding::ObservableArray`, which supports observing `Array` changes like those done with `push`, `<<`, `delete`, and `map!` methods (all mutation methods).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.5
1
+ 0.7.7
@@ -92,14 +92,50 @@ window('Area Gallery', 400, 400) {
92
92
 
93
93
  on_key_event do |area_key_event|
94
94
  p area_key_event
95
+ # As a smart default, key events are assumed to be handled if you add a key event listener,
96
+ # but you can return false to indicate a key event is not handled to allow it
97
+ # to propagate to other operating system key handlers, like the Mac quit menu item,
98
+ # which expects a COMMAND+Q shortcut usually.
99
+ # Otherwise, if you return false in all key event handlers for a specific key combo,
100
+ # the Mac beeps (makes a "fonk" sound), which is normal behavior on the Mac.
101
+ case area_key_event
102
+ in modifiers: [:command], key: 'q'
103
+ false if OS.mac? # allow to propagate to Mac quit menu item
104
+ else
105
+ # true # no return value (nil) or any return value other than false or 0 means true (event handled)
106
+ end
95
107
  end
96
108
 
97
109
  on_key_up do |area_key_event|
98
110
  puts 'key up'
111
+ # As a smart default, key events are assumed to be handled if you add a key event listener,
112
+ # but you can return false to indicate a key event is not handled to allow it
113
+ # to propagate to other operating system key handlers, like the Mac quit menu item,
114
+ # which expects a COMMAND+Q shortcut usually.
115
+ # Otherwise, if you return false in all key event handlers for a specific key combo,
116
+ # the Mac beeps (makes a "fonk" sound), which is normal behavior on the Mac.
117
+ case area_key_event
118
+ in modifiers: [:command], key: 'q'
119
+ false if OS.mac? # allow to propagate to Mac quit menu item
120
+ else
121
+ # true # no return value (nil) or any return value other than false or 0 means true (event handled)
122
+ end
99
123
  end
100
124
 
101
125
  on_key_down do |area_key_event|
102
126
  puts 'key down'
127
+ # As a smart default, key events are assumed to be handled if you add a key event listener,
128
+ # but you can return false to indicate a key event is not handled to allow it
129
+ # to propagate to other operating system key handlers, like the Mac quit menu item,
130
+ # which expects a COMMAND+Q shortcut usually.
131
+ # Otherwise, if you return false in all key event handlers for a specific key combo,
132
+ # the Mac beeps (makes a "fonk" sound), which is normal behavior on the Mac.
133
+ case area_key_event
134
+ in modifiers: [:command], key: 'q'
135
+ false if OS.mac? # allow to propagate to Mac quit menu item
136
+ else
137
+ # true # no return value (nil) or any return value other than false or 0 means true (event handled)
138
+ end
103
139
  end
104
140
  }
105
141
  }.show
data/examples/tetris.rb CHANGED
@@ -258,6 +258,7 @@ class Tetris
258
258
  }
259
259
 
260
260
  on_key_down do |key_event|
261
+ handled = true # assume it is handled for all cases except the else clause below
261
262
  case key_event
262
263
  in ext_key: :down
263
264
  if OS.windows?
@@ -293,8 +294,12 @@ class Tetris
293
294
  in modifier: :control
294
295
  @game.rotate!(:left)
295
296
  else
296
- # Do Nothing
297
+ # returning false explicitly means the key event was not handled, which
298
+ # propagates the event to other handlers, like the quit menu item, which
299
+ # can handle COMMAND+Q on the Mac to quit an application
300
+ handled = false
297
301
  end
302
+ handled
298
303
  end
299
304
 
300
305
  extra_content&.call
Binary file
@@ -179,14 +179,32 @@ module Glimmer
179
179
  @area_handler.DragBroken = fiddle_closure_block_caller(0, [1, 1]) do |_, _|
180
180
  notify_custom_listeners('on_drag_broken')
181
181
  end
182
- @area_handler.KeyEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_key_event|
182
+ @area_handler.KeyEvent = fiddle_closure_block_caller(1, [1, 1, 1]) do |_, _, area_key_event|
183
183
  area_key_event = ::LibUI::FFI::AreaKeyEvent.new(area_key_event)
184
184
  area_key_event = area_key_event_hash(area_key_event)
185
- notify_custom_listeners('on_key_event', area_key_event)
185
+ on_key_up_results = on_key_down_results = []
186
+ on_key_event_results = notify_custom_listeners('on_key_event', area_key_event)
186
187
  if area_key_event[:up]
187
- notify_custom_listeners('on_key_up', area_key_event)
188
+ on_key_up_results = notify_custom_listeners('on_key_up', area_key_event)
188
189
  else
189
- notify_custom_listeners('on_key_down', area_key_event)
190
+ on_key_down_results = notify_custom_listeners('on_key_down', area_key_event)
191
+ end
192
+ if ((
193
+ handle_custom_listener('on_key_event').empty? ||
194
+ (handle_custom_listener('on_key_event').any? && on_key_event_results.all? {|result| LibUI.boolean_to_integer(result) == 0})
195
+ ) &&
196
+ (
197
+ handle_custom_listener('on_key_up').empty? ||
198
+ (handle_custom_listener('on_key_up').any? && on_key_up_results.all? {|result| LibUI.boolean_to_integer(result) == 0})
199
+ ) &&
200
+ (
201
+ handle_custom_listener('on_key_down').empty? ||
202
+ (handle_custom_listener('on_key_down').any? && on_key_down_results.all? {|result| LibUI.boolean_to_integer(result) == 0})
203
+ )
204
+ )
205
+ 0
206
+ else
207
+ 1
190
208
  end
191
209
  end
192
210
  @listeners_installed = true
@@ -221,13 +239,14 @@ module Glimmer
221
239
 
222
240
  def area_key_event_hash(area_key_event)
223
241
  modifiers = modifiers_to_symbols(area_key_event.Modifiers)
242
+ modifier = modifiers_to_symbols(area_key_event.Modifier).first
224
243
  {
225
244
  key: key_to_char(area_key_event.Key, modifiers),
226
245
  key_value: area_key_event.Key,
227
246
  key_code: area_key_event.Key,
228
247
  ext_key: ext_key_to_symbol(area_key_event.ExtKey),
229
248
  ext_key_value: area_key_event.ExtKey,
230
- modifier: modifiers_to_symbols(area_key_event.Modifier).first,
249
+ modifier: modifier,
231
250
  modifiers: modifiers,
232
251
  up: Glimmer::LibUI.integer_to_boolean(area_key_event.Up),
233
252
  }
@@ -223,7 +223,7 @@ module Glimmer
223
223
  end
224
224
 
225
225
  def notify_custom_listeners(listener_name, *args)
226
- handle_custom_listener(listener_name).each do |listener|
226
+ handle_custom_listener(listener_name).map do |listener|
227
227
  listener.call(*args)
228
228
  end
229
229
  end
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.7.5
4
+ version: 0.7.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-04-30 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -567,7 +567,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
567
567
  - !ruby/object:Gem::Version
568
568
  version: '0'
569
569
  requirements: []
570
- rubygems_version: 3.3.16
570
+ rubygems_version: 3.3.1
571
571
  signing_key:
572
572
  specification_version: 4
573
573
  summary: Glimmer DSL for LibUI