glimmer-dsl-libui 0.4.13 → 0.4.14
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +23 -17
- data/VERSION +1 -1
- data/examples/basic_image.rb +5 -3
- data/examples/basic_image2.rb +1 -3
- data/examples/basic_image3.rb +3 -3
- data/examples/basic_image4.rb +0 -3
- data/examples/basic_image5.rb +0 -2
- data/examples/form_table.rb +1 -1
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/control_proxy/image_proxy.rb +74 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d51961908ec1315a42fe183bc79cbe86bc8d86e2dea9ac9a35d2dfaefaf3912d
|
4
|
+
data.tar.gz: af6c03eb6d451816d32242c7f7d99ce3ed28755f363f3620faea2a590c3e0ea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb828f87dfbc9c56fd15123ecb29a3c499f22c315ef6582d47c629353e444f16c2b0755b958abe8d77f0506ee25c1cffbafa0a682ea2bfb1e9d649fa49cb7e9f
|
7
|
+
data.tar.gz: ff5f76d4c7868c28d223a95bff04a5a3b9cf01879eec9231a709afd2e67a6ce6bb2a4df8a8ccf41406a1cf69aaf7250a40c7c726952f8e8b8cc280b0e8e77175
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.4.14
|
4
|
+
|
5
|
+
- Support passing width or height alone to `image` keyword, calculating the other dimension automatically while preserving original aspect ratio
|
6
|
+
- Support passing x and y coordinates to `image` keyword as 2nd and 3rd arguments of 5 arguments (file, x, y, width, height)
|
7
|
+
- Support passing x, y, width, height to `image` keyword as options kwargs
|
8
|
+
|
3
9
|
## 0.4.13
|
4
10
|
|
5
11
|
- Shorten height of examples/cpu_percentage.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.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.4.14
|
2
2
|
## Prerequisite-Free Ruby Desktop Development GUI Library
|
3
3
|
[](http://badge.fury.io/rb/glimmer-dsl-libui)
|
4
4
|
[](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
@@ -180,7 +180,7 @@ class FormTable
|
|
180
180
|
text_column('State')
|
181
181
|
|
182
182
|
editable true
|
183
|
-
cell_rows <=> [self, :contacts] # explicit data-binding to
|
183
|
+
cell_rows <=> [self, :contacts] # explicit data-binding to self.contacts Modal Array, auto-inferring model attribute names from underscored table column names by convention
|
184
184
|
|
185
185
|
on_changed do |row, type, row_data|
|
186
186
|
puts "Row #{row} #{type}: #{row_data}"
|
@@ -500,7 +500,7 @@ gem install glimmer-dsl-libui
|
|
500
500
|
Or install via Bundler `Gemfile`:
|
501
501
|
|
502
502
|
```ruby
|
503
|
-
gem 'glimmer-dsl-libui', '~> 0.4.
|
503
|
+
gem 'glimmer-dsl-libui', '~> 0.4.14'
|
504
504
|
```
|
505
505
|
|
506
506
|
Test that installation worked by running the [Meta-Example](#examples):
|
@@ -1027,7 +1027,8 @@ Given that it is very new and is not a [libui](https://github.com/andlabs/libui)
|
|
1027
1027
|
- It only supports the `.png` file format.
|
1028
1028
|
- [libui](https://github.com/andlabs/libui) pixel-by-pixel rendering performance is slow.
|
1029
1029
|
- Including an `image` inside an `area` `on_draw` listener improves performance due to not retaining pixel/line data in memory.
|
1030
|
-
- Supplying `width` and `height`
|
1030
|
+
- Supplying `width` and `height` options greatly improves performance when shrinking image (e.g. `image('somefile.png', width: 24, height: 24)`). You can also supply one of the two dimensions, and the other one gets calculated automatically while preserving original aspect ratio (e.g. `image('somefile.png', height: 24)`)
|
1031
|
+
- [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) lets you optionally specify `x` and `y` in addition to `file`, `width` and `height` (5 arguments total) to offset image location.
|
1031
1032
|
|
1032
1033
|
Currently, it is recommended to use `image` with very small `width` and `height` values only (e.g. 24x24).
|
1033
1034
|
|
@@ -1046,7 +1047,11 @@ include Glimmer
|
|
1046
1047
|
|
1047
1048
|
window('Basic Image', 96, 96) {
|
1048
1049
|
area {
|
1049
|
-
image(File.expand_path('icons/glimmer.png', __dir__),
|
1050
|
+
image(File.expand_path('icons/glimmer.png', __dir__), height: 96) # width is automatically calculated from height while preserving original aspect ratio
|
1051
|
+
# image(File.expand_path('icons/glimmer.png', __dir__), width: 96, height: 96) # you can specify both width and height options
|
1052
|
+
# image(File.expand_path('icons/glimmer.png', __dir__), 96, 96) # you can specify width, height as args
|
1053
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), 0, 0, 96, 96) # you can specify x, y, width, height args as alternative
|
1054
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), x: 0, y: 0, width: 96, height: 96) # you can specify x, y, width, height options as alternative
|
1050
1055
|
}
|
1051
1056
|
}.show
|
1052
1057
|
```
|
@@ -1078,6 +1083,8 @@ window('Basic Image', 96, 96) {
|
|
1078
1083
|
area {
|
1079
1084
|
image {
|
1080
1085
|
file File.expand_path('icons/glimmer.png', __dir__)
|
1086
|
+
# x 0 # default
|
1087
|
+
# y 0 # default
|
1081
1088
|
width 96
|
1082
1089
|
height 96
|
1083
1090
|
}
|
@@ -1623,7 +1630,7 @@ class SomeTable
|
|
1623
1630
|
text_column('City')
|
1624
1631
|
text_column('State')
|
1625
1632
|
|
1626
|
-
cell_rows <=> [self, :contacts] # explicit data-binding to Model Array auto-inferring model attribute names from underscored table column names by convention
|
1633
|
+
cell_rows <=> [self, :contacts] # explicit data-binding to self.contacts Model Array, auto-inferring model attribute names from underscored table column names by convention
|
1627
1634
|
}
|
1628
1635
|
}.show
|
1629
1636
|
end
|
@@ -4098,7 +4105,11 @@ window('Basic Image', 96, 96) {
|
|
4098
4105
|
# image pixel rendered. Check basic_image2.rb for a faster alternative using on_draw manually.
|
4099
4106
|
#
|
4100
4107
|
# It is recommended to pass width/height args to shrink image and achieve faster performance.
|
4101
|
-
image(File.expand_path('../icons/glimmer.png', __dir__),
|
4108
|
+
image(File.expand_path('../icons/glimmer.png', __dir__), height: 96) # width is automatically calculated from height while preserving original aspect ratio
|
4109
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), width: 96, height: 96) # you can specify both width, height options as alternative
|
4110
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), 96, 96) # you can specify width, height args as alternative
|
4111
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), 0, 0, 96, 96) # you can specify x, y, width, height args as alternative
|
4112
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), x: 0, y: 0, width: 96, height: 96) # you can specify x, y, width, height options as alternative
|
4102
4113
|
}
|
4103
4114
|
}.show
|
4104
4115
|
```
|
@@ -4106,8 +4117,6 @@ window('Basic Image', 96, 96) {
|
|
4106
4117
|
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2 (better performance via `on_draw`):
|
4107
4118
|
|
4108
4119
|
```ruby
|
4109
|
-
# frozen_string_literal: true
|
4110
|
-
|
4111
4120
|
require 'glimmer-dsl-libui'
|
4112
4121
|
|
4113
4122
|
include Glimmer
|
@@ -4115,7 +4124,7 @@ include Glimmer
|
|
4115
4124
|
window('Basic Image', 96, 96) {
|
4116
4125
|
area {
|
4117
4126
|
on_draw do |area_draw_params|
|
4118
|
-
image(File.expand_path('../icons/glimmer.png', __dir__),
|
4127
|
+
image(File.expand_path('../icons/glimmer.png', __dir__), height: 96)
|
4119
4128
|
end
|
4120
4129
|
}
|
4121
4130
|
}.show
|
@@ -4124,8 +4133,6 @@ window('Basic Image', 96, 96) {
|
|
4124
4133
|
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 3 (explicit properties):
|
4125
4134
|
|
4126
4135
|
```ruby
|
4127
|
-
# frozen_string_literal: true
|
4128
|
-
|
4129
4136
|
require 'glimmer-dsl-libui'
|
4130
4137
|
|
4131
4138
|
include Glimmer
|
@@ -4142,7 +4149,9 @@ window('Basic Image', 96, 96) {
|
|
4142
4149
|
# It is recommended to pass width/height args to shrink image and achieve faster performance.
|
4143
4150
|
image {
|
4144
4151
|
file File.expand_path('../icons/glimmer.png', __dir__)
|
4145
|
-
|
4152
|
+
# x 0 # default
|
4153
|
+
# y 0 # default
|
4154
|
+
# width 96 # gets calculated from height while preserving original aspect ratio of 512x512
|
4146
4155
|
height 96
|
4147
4156
|
}
|
4148
4157
|
}
|
@@ -4152,8 +4161,6 @@ window('Basic Image', 96, 96) {
|
|
4152
4161
|
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 4 (better performance with `on_draw` when setting explicit properties):
|
4153
4162
|
|
4154
4163
|
```ruby
|
4155
|
-
# frozen_string_literal: true
|
4156
|
-
|
4157
4164
|
require 'glimmer-dsl-libui'
|
4158
4165
|
|
4159
4166
|
include Glimmer
|
@@ -4163,7 +4170,6 @@ window('Basic Image', 96, 96) {
|
|
4163
4170
|
on_draw do |area_draw_params|
|
4164
4171
|
image {
|
4165
4172
|
file File.expand_path('../icons/glimmer.png', __dir__)
|
4166
|
-
width 96
|
4167
4173
|
height 96
|
4168
4174
|
}
|
4169
4175
|
end
|
@@ -6896,7 +6902,7 @@ class FormTable
|
|
6896
6902
|
text_column('State')
|
6897
6903
|
|
6898
6904
|
editable true
|
6899
|
-
cell_rows <=> [self, :contacts] # explicit data-binding to Model Array auto-inferring model attribute names from underscored table column names by convention
|
6905
|
+
cell_rows <=> [self, :contacts] # explicit data-binding to self.contacts Model Array, auto-inferring model attribute names from underscored table column names by convention
|
6900
6906
|
|
6901
6907
|
on_changed do |row, type, row_data|
|
6902
6908
|
puts "Row #{row} #{type}: #{row_data}"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.14
|
data/examples/basic_image.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'glimmer-dsl-libui'
|
4
2
|
|
5
3
|
include Glimmer
|
@@ -14,6 +12,10 @@ window('Basic Image', 96, 96) {
|
|
14
12
|
# image pixel rendered. Check basic_image2.rb for a faster alternative using on_draw manually.
|
15
13
|
#
|
16
14
|
# It is recommended to pass width/height args to shrink image and achieve faster performance.
|
17
|
-
image(File.expand_path('../icons/glimmer.png', __dir__),
|
15
|
+
image(File.expand_path('../icons/glimmer.png', __dir__), height: 96) # width is automatically calculated from height while preserving original aspect ratio
|
16
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), width: 96, height: 96) # you can specify both width, height options as alternative
|
17
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), 96, 96) # you can specify width, height args as alternative
|
18
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), 0, 0, 96, 96) # you can specify x, y, width, height args as alternative
|
19
|
+
# image(File.expand_path('../icons/glimmer.png', __dir__), x: 0, y: 0, width: 96, height: 96) # you can specify x, y, width, height options as alternative
|
18
20
|
}
|
19
21
|
}.show
|
data/examples/basic_image2.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'glimmer-dsl-libui'
|
4
2
|
|
5
3
|
include Glimmer
|
@@ -7,7 +5,7 @@ include Glimmer
|
|
7
5
|
window('Basic Image', 96, 96) {
|
8
6
|
area {
|
9
7
|
on_draw do |area_draw_params|
|
10
|
-
image(File.expand_path('../icons/glimmer.png', __dir__),
|
8
|
+
image(File.expand_path('../icons/glimmer.png', __dir__), height: 96)
|
11
9
|
end
|
12
10
|
}
|
13
11
|
}.show
|
data/examples/basic_image3.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'glimmer-dsl-libui'
|
4
2
|
|
5
3
|
include Glimmer
|
@@ -16,7 +14,9 @@ window('Basic Image', 96, 96) {
|
|
16
14
|
# It is recommended to pass width/height args to shrink image and achieve faster performance.
|
17
15
|
image {
|
18
16
|
file File.expand_path('../icons/glimmer.png', __dir__)
|
19
|
-
|
17
|
+
# x 0 # default
|
18
|
+
# y 0 # default
|
19
|
+
# width 96 # gets calculated from height while preserving original aspect ratio of 512x512
|
20
20
|
height 96
|
21
21
|
}
|
22
22
|
}
|
data/examples/basic_image4.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'glimmer-dsl-libui'
|
4
2
|
|
5
3
|
include Glimmer
|
@@ -9,7 +7,6 @@ window('Basic Image', 96, 96) {
|
|
9
7
|
on_draw do |area_draw_params|
|
10
8
|
image {
|
11
9
|
file File.expand_path('../icons/glimmer.png', __dir__)
|
12
|
-
width 96
|
13
10
|
height 96
|
14
11
|
}
|
15
12
|
end
|
data/examples/basic_image5.rb
CHANGED
data/examples/form_table.rb
CHANGED
@@ -98,7 +98,7 @@ class FormTable
|
|
98
98
|
text_column('State')
|
99
99
|
|
100
100
|
editable true
|
101
|
-
cell_rows <=> [self, :contacts] # explicit data-binding to Model Array
|
101
|
+
cell_rows <=> [self, :contacts] # explicit data-binding to self.contacts Model Array, auto-inferring model attribute names from underscored table column names by convention
|
102
102
|
|
103
103
|
on_changed do |row, type, row_data|
|
104
104
|
puts "Row #{row} #{type}: #{row_data}"
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -53,11 +53,12 @@ module Glimmer
|
|
53
53
|
include Parent
|
54
54
|
prepend Transformable
|
55
55
|
|
56
|
-
attr_reader :data, :pixels, :shapes
|
56
|
+
attr_reader :data, :pixels, :shapes, :options
|
57
57
|
|
58
58
|
def initialize(keyword, parent, args, &block)
|
59
59
|
@keyword = keyword
|
60
60
|
@parent_proxy = parent
|
61
|
+
@options = args.last.is_a?(Hash) ? args.pop : {}
|
61
62
|
@args = args
|
62
63
|
@block = block
|
63
64
|
@enabled = true
|
@@ -92,11 +93,47 @@ module Glimmer
|
|
92
93
|
alias file= file
|
93
94
|
alias set_file file
|
94
95
|
|
96
|
+
def x(value = nil)
|
97
|
+
if value.nil?
|
98
|
+
@args.size > 3 ? @args[1] : (@options[:x] || 0)
|
99
|
+
else
|
100
|
+
if @args.size > 3
|
101
|
+
@args[1] = value
|
102
|
+
else
|
103
|
+
@options[:x] = value
|
104
|
+
end
|
105
|
+
if area_image? && @content_added
|
106
|
+
post_add_content
|
107
|
+
request_auto_redraw
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
alias x= x
|
112
|
+
alias set_x x
|
113
|
+
|
114
|
+
def y(value = nil)
|
115
|
+
if value.nil?
|
116
|
+
@args.size > 3 ? @args[2] : (@options[:y] || 0)
|
117
|
+
else
|
118
|
+
if @args.size > 3
|
119
|
+
@args[2] = value
|
120
|
+
else
|
121
|
+
@options[:y] = value
|
122
|
+
end
|
123
|
+
if area_image? && @content_added
|
124
|
+
post_add_content
|
125
|
+
request_auto_redraw
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
alias y= y
|
130
|
+
alias set_y y
|
131
|
+
|
95
132
|
def width(value = nil)
|
96
133
|
if value.nil?
|
97
|
-
@args[1]
|
134
|
+
@args.size > 3 ? @args[3] : (@options[:width] || @args[1])
|
98
135
|
else
|
99
|
-
|
136
|
+
set_width_variable(value)
|
100
137
|
if area_image? && @content_added
|
101
138
|
post_add_content
|
102
139
|
request_auto_redraw
|
@@ -108,9 +145,9 @@ module Glimmer
|
|
108
145
|
|
109
146
|
def height(value = nil)
|
110
147
|
if value.nil?
|
111
|
-
@args[2]
|
148
|
+
@args.size > 3 ? @args[4] : (@options[:height] || @args[2])
|
112
149
|
else
|
113
|
-
|
150
|
+
set_height_variable(value)
|
114
151
|
if area_image? && @content_added
|
115
152
|
post_add_content
|
116
153
|
request_auto_redraw
|
@@ -148,6 +185,26 @@ module Glimmer
|
|
148
185
|
|
149
186
|
private
|
150
187
|
|
188
|
+
def set_width_variable(value)
|
189
|
+
if @args.size > 3
|
190
|
+
@args[3] = value
|
191
|
+
elsif @options[:width]
|
192
|
+
@options[:width] = value
|
193
|
+
else
|
194
|
+
@args[1] = value
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def set_height_variable(value)
|
199
|
+
if @args.size > 3
|
200
|
+
@args[4] = value
|
201
|
+
elsif @options[:height]
|
202
|
+
@options[:height] = value
|
203
|
+
else
|
204
|
+
@args[2] = value
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
151
208
|
def build_control
|
152
209
|
unless area_image? # image object
|
153
210
|
if file
|
@@ -180,10 +237,15 @@ module Glimmer
|
|
180
237
|
canvas = ChunkyPNG::Canvas.from_io(f)
|
181
238
|
f.close
|
182
239
|
end
|
183
|
-
canvas.
|
240
|
+
original_width = canvas.width
|
241
|
+
original_height = canvas.height
|
242
|
+
require 'bigdecimal'
|
243
|
+
calculated_width = ((BigDecimal(height)/BigDecimal(original_height))*original_width).to_i if height && !width
|
244
|
+
calculated_height = ((BigDecimal(width)/BigDecimal(original_width))*original_height).to_i if width && !height
|
245
|
+
canvas.resample_nearest_neighbor!(calculated_width || width, calculated_height || height) if width || height
|
184
246
|
@data = canvas.to_rgba_stream
|
185
|
-
|
186
|
-
|
247
|
+
set_width_variable(canvas.width) unless width
|
248
|
+
set_height_variable(canvas.height) unless height
|
187
249
|
[@data, width, height]
|
188
250
|
end
|
189
251
|
|
@@ -203,6 +265,8 @@ module Glimmer
|
|
203
265
|
@shapes = []
|
204
266
|
original_pixels = @pixels.dup
|
205
267
|
indexed_original_pixels = Hash[original_pixels.each_with_index.to_a]
|
268
|
+
x_offset = x
|
269
|
+
y_offset = y
|
206
270
|
@pixels.each do |pixel|
|
207
271
|
index = indexed_original_pixels[pixel]
|
208
272
|
@rectangle_start_x ||= pixel[:x]
|
@@ -211,9 +275,9 @@ module Glimmer
|
|
211
275
|
@rectangle_width += 1
|
212
276
|
else
|
213
277
|
if pixel[:x] > 0 && pixel[:color] == original_pixels[index - 1][:color]
|
214
|
-
@shapes << {x: @rectangle_start_x, y: pixel[:y], width: @rectangle_width, height: 1, color: pixel[:color]}
|
278
|
+
@shapes << {x: x_offset + @rectangle_start_x, y: y_offset + pixel[:y], width: @rectangle_width, height: 1, color: pixel[:color]}
|
215
279
|
else
|
216
|
-
@shapes << {x: pixel[:x], y: pixel[:y], width: 1, height: 1, color: pixel[:color]}
|
280
|
+
@shapes << {x: x_offset + pixel[:x], y: y_offset + pixel[:y], width: 1, height: 1, color: pixel[:color]}
|
217
281
|
end
|
218
282
|
@rectangle_width = 1
|
219
283
|
@rectangle_start_x = pixel[:x] == width - 1 ? 0 : pixel[:x] + 1
|
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.4.
|
4
|
+
version: 0.4.14
|
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-12-
|
11
|
+
date: 2021-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|