glimmer-dsl-libui 0.0.10 → 0.0.11

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: 709fb51692fedecbca6438b288711c2fb7f3a71cb5ce5f5f16e1a5c9629bc5fb
4
- data.tar.gz: 2706858ead6f7bf47f042be22cc40b0546706de8c4c7cfbfdf7457aeb007fa3a
3
+ metadata.gz: 22947befdd94073071547600efd1434fe98babc87c1fb35a169c9133e7979653
4
+ data.tar.gz: c7733269d49a56c24c13c3df6df4efc680882f12e62926a9169f5114a412af0a
5
5
  SHA512:
6
- metadata.gz: 8b501a86cf85fb6b1c488580b76336765cf1d2fbdf864edf16e3587bba80710a900a05186e0c9e3f67a667ab64fbaf3ebcf1ec54c4ebbfb8e41ddd7b77f93555
7
- data.tar.gz: 5e1f94ad2479f71d54a163d69d6c266eac9f361909e3c305e04afc073c882178ac1dba80fbc9927a7037a93593000eb469e0c7a9e0342003ced8cf349ddfd6ae
6
+ metadata.gz: d0c881484a837ddc71738e8e91f75881da6de87773703d88172f6d2a13626382d7eaee749ba6ef09f175e90f937a91d248462268780783d34b1a6e65584097da
7
+ data.tar.gz: f484ecb4e1b16c21899b3263d18d736925752519e6271c611c8ac2ef4639884e8cc057661a7440824cc1df1dacb595226563b9a1343f2b25586358c0340c92cd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.11
4
+
5
+ - New examples/basic_color.rb
6
+ - Support `color_button` `color` property
7
+ - Proper destroy of controls (deleting from parent `box`, `window`, or `group` first)
8
+ - On the Mac only, if no menu is specified, add a Quit menu item automatically to allow quitting with CMD+Q
9
+
3
10
  ## 0.0.10
4
11
 
5
12
  - Support examples/font_button.rb
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.0.10
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.0.11
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
  [![Maintainability](https://api.codeclimate.com/v1/badges/ce2853efdbecf6ebdc73/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-libui/maintainability)
@@ -43,7 +43,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
43
43
 
44
44
  ## Table of Contents
45
45
 
46
- - [Glimmer DSL for LibUI 0.0.10](#-glimmer-dsl-for-libui-0010)
46
+ - [Glimmer DSL for LibUI 0.0.11](#-glimmer-dsl-for-libui-0011)
47
47
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
48
48
  - [Usage](#usage)
49
49
  - [API](#api)
@@ -64,6 +64,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
64
64
  - [Midi Player](#midi-player)
65
65
  - [Control Gallery](#control-gallery)
66
66
  - [Font Button](#font-button)
67
+ - [Color Button](#color-button)
67
68
  - [Contributing to glimmer-dsl-libui](#contributing-to-glimmer-dsl-libui)
68
69
  - [Help](#help)
69
70
  - [Issues](#issues)
@@ -151,7 +152,7 @@ gem install glimmer-dsl-libui
151
152
  Or install via Bundler `Gemfile`:
152
153
 
153
154
  ```ruby
154
- gem 'glimmer-dsl-libui', '~> 0.0.10'
155
+ gem 'glimmer-dsl-libui', '~> 0.0.11'
155
156
  ```
156
157
 
157
158
  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.
@@ -210,12 +211,12 @@ Control(Args) | Properties | Listeners
210
211
  `button(text as String)` | `text` (`String`) | `on_clicked`
211
212
  `checkbox(text as String)` | `checked` (Boolean), `text` (`String`) | `on_toggled`
212
213
  `combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
213
- `color_button` | `color` (r `Numeric`, g `Numeric`, b `Numeric`, a `Numeric`) | `on_changed`
214
+ `color_button` | `color` (Array of `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float`), `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float` | `on_changed`
214
215
  `date_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
215
216
  `date_time_picker` | `time` (`LibUI::FFI::TM`) | `on_changed`
216
217
  `editable_combobox` | `items` (`Array` of `String`), `text` (`String`) | `on_changed`
217
218
  `entry` | `read_only` (Boolean), `text` (`String`) | `on_changed`
218
- `font_button` | `font` [read-only] (`Hash` of keys: `:family`, `:size`, `:weight`, `:italic`, `:stretch`) | `on_changed`
219
+ `font_button` | `font` [read-only] (`Hash` of keys: `:family`, `:size`, `:weight`, `:italic`, `:stretch`), `family` as `String`, `size` as `Float`, `weight` as `Integer`, `italic` as `Integer`, `stretch` as `Integer` | `on_changed`
219
220
  `group(text as String)` | `margined` (Boolean), `title` (`String`) | None
220
221
  `horizontal_box` | `padded` (Boolean) | None
221
222
  `horizontal_separator` | None | None
@@ -278,7 +279,11 @@ Control(Args) | Properties | Listeners
278
279
  - All boolean property readers return `true` or `false` in Ruby instead of the [libui](https://github.com/andlabs/libui) original `0` or `1` in C.
279
280
  - All boolean property writers accept `true`/`false` in addition to `1`/`0` in Ruby
280
281
  - All string property readers return a `String` object in Ruby instead of the [libui](https://github.com/andlabs/libui) Fiddle pointer object.
281
- - Automatically allocate font descriptors upon instantiating `font_button` controls and free font descriptors when destorying `font_button` controls
282
+ - Automatically allocate font descriptors upon instantiating `font_button` controls and free them when destorying `font_button` controls
283
+ - Automatically allocate color value pointers upon instantiating `color_button` controls and free them when destorying `color_button` controls
284
+ - On the Mac, if no `menu` items were added, an automatic `quit_menu_item` is added to enable quitting with CTRL+Q
285
+ - When destroying a control nested under a `horizontal_box` or `vertical_box`, it is automatically deleted from the box's children
286
+ - When destroying a control nested under a `window` or `group`, it is automatically unset as their child to allow successful destruction
282
287
 
283
288
  ### Original API
284
289
 
@@ -287,7 +292,7 @@ check out the [libui C headers](https://github.com/andlabs/libui/blob/master/ui.
287
292
 
288
293
  ## Glimmer Style Guide
289
294
 
290
- - Control arguments are always wrapped inside parentheses
295
+ - Control arguments are always wrapped by parentheses
291
296
  - Control blocks are always declared with curly braces to clearly visualize hierarchical view code and separate from logic code
292
297
  - Control property declarations always have arguments and never take a block
293
298
  - Control property arguments are never wrapped inside parentheses
@@ -308,7 +313,7 @@ Gotcha: On the Mac, when you close a window opened in `girb`, it remains open un
308
313
 
309
314
  ## Examples
310
315
 
311
- These examples include reimplementions of the examples in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the [Glimmer GUI DSL](#glimmer-gui-dsl-concepts).
316
+ These examples include reimplementions of the examples in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) as well as brand new examples.
312
317
 
313
318
  To browse all examples, simply launch the [Meta-Example](examples/meta_example.rb), which lists all examples and displays each example's code when selected.
314
319
 
@@ -334,7 +339,7 @@ Linux
334
339
 
335
340
  ![glimmer-dsl-libui-linux-meta-example.png](images/glimmer-dsl-libui-linux-meta-example.png)
336
341
 
337
- [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
342
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
338
343
 
339
344
  ```ruby
340
345
  require 'glimmer-dsl-libui'
@@ -480,7 +485,7 @@ ruby -r glimmer-dsl-libui -e "require 'examples/basic_button'"
480
485
  Mac
481
486
 
482
487
  ![glimmer-dsl-libui-mac-basic-button.png](images/glimmer-dsl-libui-mac-basic-button.png)
483
- ![glimmer-dsl-libui-mac-basic-button-msg-box.png](images/glimmer-dsl-libui-basic-button-msg-box.png)
488
+ ![glimmer-dsl-libui-mac-basic-button-msg-box.png](images/glimmer-dsl-libui-mac-basic-button-msg-box.png)
484
489
 
485
490
  Linux
486
491
 
@@ -1422,7 +1427,51 @@ window('hello world', 300, 200) {
1422
1427
  puts 'Bye Bye'
1423
1428
  end
1424
1429
  }.show
1430
+ ```
1431
+
1432
+ ### Color Button
1433
+
1434
+ [examples/color_button.rb](examples/color_button.rb)
1435
+
1436
+ Run with this command from the root of the project if you cloned the project:
1437
+
1438
+ ```
1439
+ ruby -r './lib/glimmer-dsl-libui' examples/color_button.rb
1440
+ ```
1441
+
1442
+ Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
1443
+
1444
+ ```
1445
+ ruby -r glimmer-dsl-libui -e "require 'examples/color_button'"
1446
+ ```
1447
+
1448
+ Mac
1425
1449
 
1450
+ ![glimmer-dsl-libui-mac-color-button.png](images/glimmer-dsl-libui-mac-color-button.png)
1451
+ ![glimmer-dsl-libui-mac-color-button-selection.png](images/glimmer-dsl-libui-mac-color-button-selection.png)
1452
+
1453
+ Linux
1454
+
1455
+ ![glimmer-dsl-libui-linux-color-button.png](images/glimmer-dsl-libui-linux-color-button.png)
1456
+ ![glimmer-dsl-libui-linux-color-button-selection.png](images/glimmer-dsl-libui-linux-color-button-selection.png)
1457
+
1458
+ New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
1459
+
1460
+ ```ruby
1461
+ # frozen_string_literal: true
1462
+
1463
+ require 'glimmer-dsl-libui'
1464
+
1465
+ include Glimmer
1466
+
1467
+ window('color button', 230) {
1468
+ color_button { |cb|
1469
+ on_changed do
1470
+ rgba = cb.color
1471
+ p rgba
1472
+ end
1473
+ }
1474
+ }.show
1426
1475
  ```
1427
1476
 
1428
1477
  ## Contributing to glimmer-dsl-libui
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+
5
+ include Glimmer
6
+
7
+ window('color button', 230) {
8
+ color_button { |cb|
9
+ on_changed do
10
+ rgba = cb.color
11
+ p rgba
12
+ end
13
+ }
14
+ }.show
@@ -21,10 +21,6 @@ class MetaExample
21
21
  end
22
22
 
23
23
  def launch
24
- menu('File') {
25
- quit_menu_item
26
- }
27
-
28
24
  window('Meta-Example', 700, 500) { |w|
29
25
  margined true
30
26
 
Binary file
@@ -29,12 +29,22 @@ module Glimmer
29
29
  def post_initialize_child(child)
30
30
  child.stretchy = true if child.stretchy.nil?
31
31
  ::LibUI.box_append(@libui, child.libui, ControlProxy.boolean_to_integer(child.stretchy))
32
+ children << child
32
33
  end
33
34
 
34
35
  def libui_api_keyword
35
36
  'box'
36
37
  end
37
38
 
39
+ def children
40
+ @children ||= []
41
+ end
42
+
43
+ def destroy_child(child)
44
+ ::LibUI.send("box_delete", @libui, children.index(child))
45
+ ControlProxy.all_control_proxies.delete(child)
46
+ end
47
+
38
48
  private
39
49
 
40
50
  def build_control
@@ -0,0 +1,64 @@
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
+ require 'glimmer/libui/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ # Proxy for LibUI color button objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ColorButtonProxy < ControlProxy
30
+ def color
31
+ @red ||= Fiddle::Pointer.malloc(8) # double
32
+ @green ||= Fiddle::Pointer.malloc(8) # double
33
+ @blue ||= Fiddle::Pointer.malloc(8) # double
34
+ @alpha ||= Fiddle::Pointer.malloc(8) # double
35
+ ::LibUI.color_button_color(@libui, @red, @green, @blue, @alpha)
36
+ [@red[0, 8].unpack1('d') * 255.0, @green[0, 8].unpack1('d') * 255.0, @blue[0, 8].unpack1('d') * 255.0, @alpha[0, 8].unpack1('d')]
37
+ end
38
+
39
+ def red
40
+ color[0]
41
+ end
42
+
43
+ def green
44
+ color[1]
45
+ end
46
+
47
+ def blue
48
+ color[2]
49
+ end
50
+
51
+ def alpha
52
+ color[3]
53
+ end
54
+
55
+ def destroy
56
+ Fiddle.free @red unless @red.nil?
57
+ Fiddle.free @green unless @green.nil?
58
+ Fiddle.free @blue unless @blue.nil?
59
+ Fiddle.free @alpha unless @alpha.nil?
60
+ super
61
+ end
62
+ end
63
+ end
64
+ end
@@ -52,7 +52,7 @@ module Glimmer
52
52
  end
53
53
 
54
54
  def main_window_proxy
55
- all_control_proxies.find {|c| c.is_a?(WindowProxy)}
55
+ all_control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
56
56
  end
57
57
 
58
58
  def integer_to_boolean(int)
@@ -62,6 +62,10 @@ module Glimmer
62
62
  def boolean_to_integer(bool)
63
63
  bool.nil? ? nil : (bool ? 1 : 0)
64
64
  end
65
+
66
+ def menu_proxies
67
+ all_control_proxies.select {|c| c.keyword == 'menu' }
68
+ end
65
69
  end
66
70
 
67
71
  BOOLEAN_PROPERTIES = %w[
@@ -167,7 +171,7 @@ module Glimmer
167
171
  ::LibUI.send("#{libui_api_keyword}_#{method_name}", @libui, *args)
168
172
  elsif ::LibUI.respond_to?("control_#{method_name.to_s.sub(/\?$/, '')}") && args.empty?
169
173
  property = method_name.to_s.sub(/\?$/, '')
170
- value = ::LibUI.send("control_#{method_name.to_s.sub(/\?$/, '')}", @libui, *args)
174
+ value = ::LibUI.send("control_#{property}", @libui, *args)
171
175
  handle_string_property(property, handle_boolean_property(property, value))
172
176
  elsif ::LibUI.respond_to?("control_set_#{method_name.to_s.sub(/=$/, '')}")
173
177
  property = method_name.to_s.sub(/=$/, '')
@@ -198,6 +202,23 @@ module Glimmer
198
202
  @keyword
199
203
  end
200
204
 
205
+ def destroy
206
+ if parent_proxy.nil?
207
+ default_destroy
208
+ else
209
+ parent_proxy.destroy_child(self)
210
+ end
211
+ end
212
+
213
+ def destroy_child(child)
214
+ child.default_destroy
215
+ end
216
+
217
+ def default_destroy
218
+ send_to_libui('destroy')
219
+ ControlProxy.all_control_proxies.delete(self)
220
+ end
221
+
201
222
  def enabled(value = nil)
202
223
  if value.nil?
203
224
  @enabled
@@ -229,11 +250,6 @@ module Glimmer
229
250
  alias set_visible visible
230
251
  alias visible= visible
231
252
 
232
- def destroy
233
- send_to_libui('destroy')
234
- self.class.all_control_proxies.delete(self)
235
- end
236
-
237
253
  private
238
254
 
239
255
  def build_control
@@ -39,6 +39,26 @@ module Glimmer
39
39
  }
40
40
  end
41
41
 
42
+ def family
43
+ font[:family]
44
+ end
45
+
46
+ def size
47
+ font[:size]
48
+ end
49
+
50
+ def weight
51
+ font[:weight]
52
+ end
53
+
54
+ def italic
55
+ font[:italic]
56
+ end
57
+
58
+ def stretch
59
+ font[:stretch]
60
+ end
61
+
42
62
  def destroy
43
63
  ::LibUI.free_font_button_font(@font_descriptor) unless @font_descriptor.nil?
44
64
  super
@@ -31,6 +31,11 @@ module Glimmer
31
31
  ::LibUI.group_set_child(@libui, child.libui)
32
32
  end
33
33
 
34
+ def destroy_child(child)
35
+ ::LibUI.send("group_set_child", @libui, nil)
36
+ super
37
+ end
38
+
34
39
  private
35
40
 
36
41
  def build_control
@@ -35,9 +35,14 @@ module Glimmer
35
35
  def post_initialize_child(child)
36
36
  ::LibUI.window_set_child(@libui, child.libui)
37
37
  end
38
+
39
+ def destroy_child(child)
40
+ ::LibUI.send("window_set_child", @libui, nil)
41
+ super
42
+ end
38
43
 
39
44
  def show
40
- send_to_libui('show')
45
+ super
41
46
  unless @shown_at_least_once
42
47
  @shown_at_least_once = true
43
48
  ::LibUI.main
@@ -64,6 +69,10 @@ module Glimmer
64
69
  private
65
70
 
66
71
  def build_control
72
+ if OS.mac? && ControlProxy.menu_proxies.empty?
73
+ menu_proxy = ControlProxy.create('menu', nil, [''])
74
+ quit_menu_item_proxy = ControlProxy.create('quit_menu_item', menu_proxy, [])
75
+ end
67
76
  construction_args = @args.dup
68
77
  construction_args[0] = DEFAULT_TITLE if construction_args.size == 0
69
78
  construction_args[1] = DEFAULT_WIDTH if construction_args.size == 1
@@ -26,6 +26,7 @@ require 'glimmer'
26
26
  # require 'logging'
27
27
  # require 'puts_debuggerer' if ENV['pd'].to_s.downcase == 'true'
28
28
  # require 'super_module'
29
+ require 'os'
29
30
  require 'libui'
30
31
 
31
32
  # Internal requires
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.0.10
4
+ version: 0.0.11
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-09-20 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: os
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 2.0.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.0
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: libui
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +184,7 @@ files:
164
184
  - examples/basic_entry.rb
165
185
  - examples/basic_window.rb
166
186
  - examples/basic_window2.rb
187
+ - examples/color_button.rb
167
188
  - examples/control_gallery.rb
168
189
  - examples/font_button.rb
169
190
  - examples/meta_example.rb
@@ -182,6 +203,7 @@ files:
182
203
  - lib/glimmer/libui/about_menu_item_proxy.rb
183
204
  - lib/glimmer/libui/box.rb
184
205
  - lib/glimmer/libui/check_menu_item_proxy.rb
206
+ - lib/glimmer/libui/color_button_proxy.rb
185
207
  - lib/glimmer/libui/combobox_proxy.rb
186
208
  - lib/glimmer/libui/control_proxy.rb
187
209
  - lib/glimmer/libui/date_picker_proxy.rb