glimmer-dsl-libui 0.2.5 → 0.2.6

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: b691a0eeec6e7d571ac6815c272e0dd5ae48c0f0302fc11876ae373cb92cba1e
4
- data.tar.gz: 576d6840f47182d0dc0bd3ccccdb301b5a9efb2f7b7038efa3e5fa8d8ea30537
3
+ metadata.gz: c673025a7a4676538178064f6fb3db7c98eb35f2c2b8c0bf7eb75627d4810309
4
+ data.tar.gz: b3c7a7c67edc0566e542cbdad854a5340cba70c61ac36611a5279095b7710248
5
5
  SHA512:
6
- metadata.gz: d00b9ecc527e56e144d1baead2910e62a29f9f429af9fc57a1da05a4d590d9286f47c2fe8d840062c1a989f42183f9dfc717a0800db2ec6467acc434201d3707
7
- data.tar.gz: 53dbe182b9b9607111915412af9d418571511af560dc5af83d792214139c62f91358aa5555147d962a040802852d74f581413b99d287827454ea2ca865ec110b
6
+ metadata.gz: 49254ae087358b968b0479dd4ccc1909e03e532e8ad3671432dedd96079d7487f9fb7bdfd3f3f20edd53475389e0553b4676f7fceacd04b130444914254afcd9
7
+ data.tar.gz: f40187fed7f069bf214c16b287b87848e9815a79c72ddb78dd47f9df567d40ceef432dc800ba74ee7247d6f1a0a32e81b65d863e860f2ccec7ea6c20d11a97eb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.6
4
+
5
+ - Support `string` control property: `open_type_features`
6
+ - Auto-free attributed string objects from memory
7
+
3
8
  ## 0.2.5
4
9
 
5
10
  - Support attributed `string` `underline_color` property (built-in enum symbols and custom color)
@@ -8,9 +13,9 @@
8
13
 
9
14
  - Support examples/custom_draw_text.rb
10
15
  - Support stable `text` control nestable under `area`
11
- - Support `string` control property `background`
12
- - Support `string` control property `font`
13
- - Support `string` control property `underline`
16
+ - Support `string` control property: `background`
17
+ - Support `string` control property: `font`
18
+ - Support `string` control property: `underline`
14
19
  - Enhance `combobox` to accept `String` value for `selected` item instead of just `Integer` index
15
20
  - Add `selected_item` read-only property to `combobox` to return selected item `String` value
16
21
  - Fix `color` property support for `string` to accept 255-based rgb values
@@ -23,7 +28,7 @@
23
28
  - Support dynamic `text` control to be called in `area` `on_draw` listener
24
29
  - Support `text` control `default_font` property
25
30
  - Support `string` control nestable under `text` to represent an attributed/unattributed string (depending on nestable properties)
26
- - Support `string` control property `color`
31
+ - Support `string` control property: `color`
27
32
  - Support enum symbols for `align` property of `text` control
28
33
  - Support enum symbols for `:italic` font descriptor key (in addition to numbers)
29
34
  - Support enum symbols for `:stretch` font descriptor key (in addition to numbers)
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.2.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.2.6
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)
@@ -197,7 +197,7 @@ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interes
197
197
 
198
198
  ## Table of Contents
199
199
 
200
- - [Glimmer DSL for LibUI 0.2.5](#-glimmer-dsl-for-libui-025)
200
+ - [Glimmer DSL for LibUI 0.2.6](#-glimmer-dsl-for-libui-026)
201
201
  - [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
202
202
  - [Usage](#usage)
203
203
  - [Girb (Glimmer IRB)](#girb-glimmer-irb)
@@ -333,7 +333,7 @@ gem install glimmer-dsl-libui
333
333
  Or install via Bundler `Gemfile`:
334
334
 
335
335
  ```ruby
336
- gem 'glimmer-dsl-libui', '~> 0.2.5'
336
+ gem 'glimmer-dsl-libui', '~> 0.2.6'
337
337
  ```
338
338
 
339
339
  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.
@@ -790,6 +790,50 @@ Check [Basic Transform](#basic-transform) example for use of [X11](https://en.wi
790
790
 
791
791
  Check [Histogram](#histogram) example for use of hex colors.
792
792
 
793
+ To draw `text` in an `area`, you simply nest a `text(x, y, width)` control directly under `area` or inside a `on_draw` listener, and then nest attributed `string {string_value}` controls underneath it returning an actual `String` (think of them as the `<span>` element in html, which contains a string of text).
794
+
795
+ `text` control can have the following properties:
796
+ - `default_font`:
797
+ - `align`: `:left` (default), `:center`, or `:right` (`align` currently seems not to work on the Mac)
798
+
799
+ `string` can have the following properties:
800
+ - `font`: font descriptor hash consisting of `:family`, `:size`, `:weight` (`[:minimum, :thin, :ultra_light, :light, :book, :normal, :medium, :semi_bold, :bold, :ultra_bold, :heavy, :ultra_heavy, :maximum]`), `:italic` (`[:normal, :oblique, :italic]`), and `:stretch` (`[:ultra_condensed, :extra_condensed, :condensed, :semi_condensed, :normal, :semi_expanded, :expanded, :extra_expanded, :ultra_expanded]`) key values
801
+ - `color`: rgba, hex, or x11 color
802
+ - `background`: rgba, hex, or x11 color
803
+ - `underline`: one of `:none`, `:single`, `:double`, `:suggestion`, `:color_custom`, `:color_spelling`, `:color_grammar`, `:color_auxiliary`
804
+ - `underline_color`: one of `:spelling`, `:grammar`, `:auxiliary`, rgba, hex, or x11 color
805
+ - `open_type_features`: it must have a block containing `open_type_tag` occurrances, which take the a, b, c, d arguments plus a number at the end.
806
+
807
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
808
+
809
+ ```ruby
810
+ window('area text drawing') {
811
+ area {
812
+ text {
813
+ default_font family: 'Helvetica', size: 12, weight: :normal, italic: :normal, stretch: :normal
814
+
815
+ string {
816
+ font family: 'Georgia', size: 13, weight: :medium, italic: :normal, stretch: :normal
817
+ color r: 230, g: 100, b: 50, a: 0.5
818
+ background r: 230, g: 200, b: 250, a: 0.8
819
+ underline :single
820
+ underline_color :spelling
821
+ open_type_features {
822
+ open_type_tag 'l', 'i', 'g', 'a', 0
823
+ open_type_tag 'l', 'i', 'g', 'a', 1
824
+ }
825
+
826
+ "This is a test\n\n"
827
+ }
828
+
829
+ string {
830
+ 'This is another test'
831
+ }
832
+ }
833
+ }
834
+ }.show
835
+ ```
836
+
793
837
  ### Smart Defaults and Conventions
794
838
 
795
839
  - `horizontal_box`, `vertical_box`, `grid`, and `form` controls have `padded` as `true` upon instantiation to ensure more user-friendly GUI by default
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -71,7 +71,7 @@ class CustomDrawText
71
71
  area {
72
72
  text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
73
73
  # align :left # default alignment
74
-
74
+
75
75
  @string = string {
76
76
  ' At last Ygramul sensed that something was coming toward ' \
77
77
  'her. With the speed of lightning, she turned about, confronting ' \
@@ -79,7 +79,7 @@ class CustomDrawText
79
79
  text { # default arguments for x, y, and width are (0, 0, area_draw_params[:area_width])
80
80
  # align :left # default alignment
81
81
 
82
- @string = string {
82
+ string {
83
83
  font @font
84
84
  color @color
85
85
  background @background
Binary file
@@ -94,12 +94,27 @@ module Glimmer
94
94
  alias underline_color= underline_color
95
95
  alias set_underline_color underline_color
96
96
 
97
+ def open_type_features(value = nil)
98
+ if value.nil?
99
+ @open_type_features
100
+ else
101
+ @open_type_features = value
102
+ redraw
103
+ end
104
+ end
105
+ alias open_type_features= open_type_features
106
+ alias set_open_type_features open_type_features
107
+
97
108
  def post_add_content
98
109
  block_result = block&.call
99
110
  @string = block_result if block_result.is_a?(String)
100
111
  @parent_proxy&.post_initialize_child(self)
101
112
  end
102
113
 
114
+ def post_initialize_child(child)
115
+ self.open_type_features = child if child.is_a?(Glimmer::LibUI::ControlProxy::OpenTypeFeaturesProxy)
116
+ end
117
+
103
118
  def draw(area_draw_params)
104
119
  @start = ::LibUI.attributed_string_len(@parent_proxy.attributed_string)
105
120
  ::LibUI.attributed_string_append_unattributed(@parent_proxy.attributed_string, @string)
@@ -137,10 +152,15 @@ module Glimmer
137
152
  stretch_attribute = ::LibUI.new_stretch_attribute(Glimmer::LibUI.enum_symbol_to_value(:text_stretch, font[:stretch]))
138
153
  ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, stretch_attribute, @start, @start + @string.size)
139
154
  end
155
+ unless open_type_features.nil?
156
+ open_type_features_attribute = ::LibUI.new_features_attribute(open_type_features.libui)
157
+ ::LibUI.attributed_string_set_attribute(@parent_proxy.attributed_string, open_type_features_attribute, @start, @start + @string.size)
158
+ end
140
159
  destroy if area_proxy.nil?
141
160
  end
142
161
 
143
162
  def destroy
163
+ open_type_features.destroy unless open_type_features.nil?
144
164
  @parent_proxy&.children&.delete(self)
145
165
  end
146
166
 
@@ -0,0 +1,53 @@
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
+ require 'glimmer/libui/control_proxy/area_proxy'
24
+ require 'glimmer/libui/parent'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ class ControlProxy
29
+ # Proxy for LibUI open type features objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class OpenTypeFeaturesProxy < ControlProxy
33
+ include Parent
34
+
35
+ def destroy
36
+ ::LibUI.free_open_type_features(@libui)
37
+ @parent_proxy&.children&.delete(self)
38
+ ControlProxy.control_proxies.delete(self)
39
+ end
40
+
41
+ def redraw
42
+ @parent_proxy.redraw
43
+ end
44
+
45
+ private
46
+
47
+ def build_control
48
+ @libui = ::LibUI.new_open_type_features
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,59 @@
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
+ require 'glimmer/libui/control_proxy/area_proxy'
24
+ require 'glimmer/libui/parent'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ class ControlProxy
29
+ # Proxy for LibUI open type tag objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class OpenTypeTagProxy < ControlProxy
33
+ def destroy
34
+ @parent_proxy&.children&.delete(self)
35
+ ControlProxy.control_proxies.delete(self)
36
+ end
37
+
38
+ def redraw
39
+ @parent_proxy.redraw
40
+ end
41
+
42
+ private
43
+
44
+ def build_control
45
+ tag_args = @args.dup
46
+ tag_args[0] = ordinalize(tag_args[0])
47
+ tag_args[1] = ordinalize(tag_args[1])
48
+ tag_args[2] = ordinalize(tag_args[2])
49
+ tag_args[3] = ordinalize(tag_args[3])
50
+ ::LibUI.open_type_features_add(@parent_proxy.libui, *tag_args)
51
+ end
52
+
53
+ def ordinalize(arg)
54
+ arg.is_a?(String) ? arg.ord : arg
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -56,6 +56,7 @@ module Glimmer
56
56
  build_control
57
57
  ::LibUI.draw_text(area_draw_params[:context], @libui, x, y)
58
58
  ::LibUI.draw_free_text_layout(@libui)
59
+ ::LibUI.free_attributed_string(@attributed_string)
59
60
  end
60
61
 
61
62
  def destroy
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.2.5
4
+ version: 0.2.6
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-10-06 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -312,6 +312,8 @@ files:
312
312
  - lib/glimmer/libui/control_proxy/message_box/msg_box_proxy.rb
313
313
  - lib/glimmer/libui/control_proxy/multiline_entry_proxy.rb
314
314
  - lib/glimmer/libui/control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb
315
+ - lib/glimmer/libui/control_proxy/open_type_features_proxy.rb
316
+ - lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb
315
317
  - lib/glimmer/libui/control_proxy/path_proxy.rb
316
318
  - lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb
317
319
  - lib/glimmer/libui/control_proxy/tab_item_proxy.rb