libui 0.1.3.pre-x64-mingw-ucrt → 0.2.0-x64-mingw-ucrt

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.
data/lib/libui.rb CHANGED
@@ -1,258 +1,274 @@
1
- require_relative 'libui/version'
2
- require_relative 'libui/utils'
3
- require 'rbconfig'
4
-
5
- module LibUI
6
- class Error < StandardError; end
7
-
8
- class << self
9
- attr_accessor :ffi_lib
10
- end
11
-
12
- lib_name = [
13
- "libui.#{RbConfig::CONFIG['host_cpu']}.#{RbConfig::CONFIG['SOEXT']}",
14
- "libui.#{RbConfig::CONFIG['SOEXT']}"
15
- ]
16
-
17
- self.ffi_lib = \
18
- if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
19
- lib_name.lazy
20
- .map { |name| File.expand_path(name, ENV['LIBUIDIR']) }
21
- .find { |path| File.exist?(path) }
22
- else
23
- lib_name.lazy
24
- .map { |name| File.expand_path("../vendor/#{name}", __dir__) }
25
- .find { |path| File.exist?(path) }
26
- end
27
-
28
- require_relative 'libui/ffi'
29
- require_relative 'libui/libui_base'
30
-
31
- extend LibUIBase
32
-
33
- class << self
34
- def init(opt = nil)
35
- unless opt
36
- opt = FFI::InitOptions.malloc
37
- opt.to_ptr.free = Fiddle::RUBY_FREE
38
- end
39
- i = super(opt)
40
- return if i.size.zero?
41
-
42
- warn 'error'
43
- warn UI.free_init_error(init)
44
- end
45
-
46
- # Gets the window position.
47
- # Coordinates are measured from the top left corner of the screen.
48
- # @param w [Fiddle::Pointer] Pointer of uiWindow instance.
49
- # @return [Array] position of the window. [x, y]
50
- # @note This method may return inaccurate or dummy values on Unix platforms.
51
-
52
- def window_position(w)
53
- x_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
54
- y_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
55
- super(w, x_ptr, y_ptr)
56
- x = x_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
57
- y = y_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
58
- [x, y]
59
- end
60
-
61
- # FIXME: This is a workaround for a old version of Fiddle.
62
- # Fiddle 1.1.2 and above should be able to handle one character string.
63
- # See https://github.com/ruby/fiddle/issues/96
64
-
65
- def open_type_features_add(otf, a, b, c, d, value)
66
- a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
67
- super(otf, a, b, c, d, value)
68
- end
69
-
70
- def open_type_features_remove(otf, a, b, c, d)
71
- a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
72
- super(otf, a, b, c, d)
73
- end
74
-
75
- def open_type_features_get(otf, a, b, c, d, value)
76
- a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
77
- super(otf, a, b, c, d, value)
78
- end
79
- end
80
-
81
- ## UI_ENUM https://github.com/libui-ng/libui-ng/blob/master/ui.h
82
-
83
- # ForEach
84
- ForEachContinue = 0
85
- ForEachStop = 1
86
-
87
- # WindowResizeEdge
88
- WindowResizeEdgeLeft = 0
89
- WindowResizeEdgeTop = 1
90
- WindowResizeEdgeRight = 2
91
- WindowResizeEdgeBottom = 3
92
- WindowResizeEdgeTopLeft = 4
93
- WindowResizeEdgeTopRight = 5
94
- WindowResizeEdgeBottomLeft = 6
95
- WindowResizeEdgeBottomRight = 7
96
-
97
- # DrawBrushType
98
- DrawBrushTypeSolid = 0
99
- DrawBrushTypeLinearGradient = 1
100
- DrawBrushTypeRadialGradient = 2
101
- DrawBrushTypeImage = 3
102
-
103
- # DrawLineCap
104
- DrawLineCapFlat = 0
105
- DrawLineCapRound = 1
106
- DrawLineCapSquare = 2
107
-
108
- # DrawLineJoin
109
- DrawLineJoinMiter = 0
110
- DrawLineJoinRound = 1
111
- DrawLineJoinBevel = 2
112
-
113
- DrawDefaultMiterLimit = 10.0
114
-
115
- # DrawFillMode
116
- DrawFillModeWinding = 0
117
- DrawFillModeAlternate = 1
118
-
119
- # AttributeType
120
- AttributeTypeFamily = 0
121
- AttributeTypeSize = 1
122
- AttributeTypeWeight = 2
123
- AttributeTypeItalic = 3
124
- AttributeTypeStretch = 4
125
- AttributeTypeColor = 5
126
- AttributeTypeBackground = 6
127
- AttributeTypeUnderline = 7
128
- AttributeTypeUnderlineColor = 8
129
- AttributeTypeFeatures = 9
130
-
131
- # TextWeight
132
- TextWeightMinimum = 0
133
- TextWeightThin = 100
134
- TextWeightUltraLight = 200
135
- TextWeightLight = 300
136
- TextWeightBook = 350
137
- TextWeightNormal = 400
138
- TextWeightMedium = 500
139
- TextWeightSemiBold = 600
140
- TextWeightBold = 700
141
- TextWeightUltraBold = 800
142
- TextWeightHeavy = 900
143
- TextWeightUltraHeavy = 950
144
- TextWeightMaximum = 1000
145
-
146
- # TextItalic
147
- TextItalicNormal = 0
148
- TextItalicOblique = 1
149
- TextItalicItalic = 2
150
-
151
- # TextStretch
152
- TextStretchUltraCondensed = 0
153
- TextStretchExtraCondensed = 1
154
- TextStretchCondensed = 2
155
- TextStretchSemiCondensed = 3
156
- TextStretchNormal = 4
157
- TextStretchSemiExpanded = 5
158
- TextStretchExpanded = 6
159
- TextStretchExtraExpanded = 7
160
- TextStretchUltraExpanded = 8
161
-
162
- # Underline
163
- UnderlineNone = 0
164
- UnderlineSingle = 1
165
- UnderlineDouble = 2
166
- UnderlineSuggestion = 3
167
-
168
- # UnderlineColor
169
- UnderlineColorCustom = 0
170
- UnderlineColorSpelling = 1
171
- UnderlineColorGrammar = 2
172
- UnderlineColorAuxiliary = 3
173
-
174
- # DrawTextAlign
175
- DrawTextAlignLeft = 0
176
- DrawTextAlignCenter = 1
177
- DrawTextAlignRight = 2
178
-
179
- # Modifiers
180
- ModifierCtrl = (1 << 0)
181
- ModifierAlt = (1 << 1)
182
- ModifierShift = (1 << 2)
183
- ModifierSuper = (1 << 3)
184
-
185
- # ExtKey
186
- ExtKeyEscape = 1
187
- ExtKeyInsert = 2
188
- ExtKeyDelete = 3
189
- ExtKeyHome = 4
190
- ExtKeyEnd = 5
191
- ExtKeyPageUp = 6
192
- ExtKeyPageDown = 7
193
- ExtKeyUp = 8
194
- ExtKeyDown = 9
195
- ExtKeyLeft = 10
196
- ExtKeyRight = 11
197
- ExtKeyF1 = 12
198
- ExtKeyF2 = 13
199
- ExtKeyF3 = 14
200
- ExtKeyF4 = 15
201
- ExtKeyF5 = 16
202
- ExtKeyF6 = 17
203
- ExtKeyF7 = 18
204
- ExtKeyF8 = 19
205
- ExtKeyF9 = 20
206
- ExtKeyF10 = 21
207
- ExtKeyF11 = 22
208
- ExtKeyF12 = 23
209
- ExtKeyN0 = 24
210
- ExtKeyN1 = 25
211
- ExtKeyN2 = 26
212
- ExtKeyN3 = 27
213
- ExtKeyN4 = 28
214
- ExtKeyN5 = 29
215
- ExtKeyN6 = 30
216
- ExtKeyN7 = 31
217
- ExtKeyN8 = 32
218
- ExtKeyN9 = 33
219
- ExtKeyNDot = 34
220
- ExtKeyNEnter = 35
221
- ExtKeyNAdd = 36
222
- ExtKeyNSubtract = 37
223
- ExtKeyNMultiply = 38
224
- ExtKeyNDivide = 39
225
-
226
- # Align
227
- AlignFill = 0
228
- AlignStart = 1
229
- AlignCenter = 2
230
- AlignEnd = 3
231
-
232
- # At
233
- AtLeading = 0
234
- AtTop = 1
235
- AtTrailing = 2
236
- AtBottom = 3
237
-
238
- # TableValueType
239
- TableValueTypeString = 0
240
- TableValueTypeImage = 1
241
- TableValueTypeInt = 2
242
- TableValueTypeColor = 3
243
-
244
- # SortIndicator
245
- SortIndicatorNone = 0
246
- SortIndicatorAscending = 1
247
- SortIndicatorDescending = 2
248
-
249
- # editable
250
- TableModelColumnNeverEditable = -1
251
- TableModelColumnAlwaysEditable = -2
252
-
253
- # TableSelectionMode
254
- TableSelectionModeNone = 0
255
- TableSelectionModeZeroOrOne = 1
256
- TableSelectionModeOne = 2
257
- TableSelectionModeZeroOrMany = 3
258
- end
1
+ require_relative 'libui/version'
2
+ require_relative 'libui/utils'
3
+ require_relative 'libui/error'
4
+ require 'rbconfig'
5
+
6
+ module LibUI
7
+ class << self
8
+ attr_accessor :ffi_lib
9
+ end
10
+
11
+ host_cpu = case RbConfig::CONFIG['host_cpu']
12
+ when /i\d86/
13
+ 'x86'
14
+ else
15
+ RbConfig::CONFIG['host_cpu']
16
+ end
17
+
18
+ lib_name = [
19
+ # For libui-ng shared libraries compiled with (rake vendor:build)
20
+ "libui.#{RbConfig::CONFIG['host_cpu']}.#{RbConfig::CONFIG['SOEXT']}",
21
+ # For libui-ng shared library downloaded from RubyGems.org
22
+ "libui.#{host_cpu}.#{RbConfig::CONFIG['SOEXT']}",
23
+ # For backward compatibility or manual compilation of libui-ng
24
+ "libui.#{RbConfig::CONFIG['SOEXT']}"
25
+ ]
26
+
27
+ self.ffi_lib = \
28
+ if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
29
+ lib_name.lazy
30
+ .map { |name| File.expand_path(name, ENV['LIBUIDIR']) }
31
+ .find { |path| File.exist?(path) }
32
+ else
33
+ lib_name.lazy
34
+ .map { |name| File.expand_path("../vendor/#{name}", __dir__) }
35
+ .find { |path| File.exist?(path) }
36
+ end
37
+
38
+ require_relative 'libui/ffi'
39
+ require_relative 'libui/libui_base'
40
+
41
+ extend LibUIBase
42
+
43
+ class << self
44
+ def init(opt = nil)
45
+ # Allocate uiInitOptions if not provided
46
+ unless opt
47
+ opt = FFI::InitOptions.malloc
48
+ opt.to_ptr.free = Fiddle::RUBY_FREE
49
+ opt.Size = FFI::InitOptions.size
50
+ end
51
+
52
+ err_ptr = super(opt) # uiInit returns const char* error or NULL on success
53
+ return nil if err_ptr.null?
54
+
55
+ # Convert C string to Ruby string and free the error string per API contract
56
+ err_msg = err_ptr.to_s
57
+ free_init_error(err_ptr)
58
+ warn err_msg
59
+ nil
60
+ end
61
+
62
+ # Gets the window position.
63
+ # Coordinates are measured from the top left corner of the screen.
64
+ # @param w [Fiddle::Pointer] Pointer of uiWindow instance.
65
+ # @return [Array] position of the window. [x, y]
66
+ # @note This method may return inaccurate or dummy values on Unix platforms.
67
+
68
+ def window_position(w)
69
+ x_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
70
+ y_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
71
+ super(w, x_ptr, y_ptr)
72
+ x = x_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
73
+ y = y_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
74
+ [x, y]
75
+ end
76
+
77
+ # FIXME: This is a workaround for a old version of Fiddle.
78
+ # Fiddle 1.1.2 and above should be able to handle one character string.
79
+ # See https://github.com/ruby/fiddle/issues/96
80
+
81
+ def open_type_features_add(otf, a, b, c, d, value)
82
+ a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
83
+ super(otf, a, b, c, d, value)
84
+ end
85
+
86
+ def open_type_features_remove(otf, a, b, c, d)
87
+ a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
88
+ super(otf, a, b, c, d)
89
+ end
90
+
91
+ def open_type_features_get(otf, a, b, c, d, value)
92
+ a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
93
+ super(otf, a, b, c, d, value)
94
+ end
95
+ end
96
+
97
+ ## UI_ENUM https://github.com/libui-ng/libui-ng/blob/master/ui.h
98
+
99
+ # ForEach
100
+ ForEachContinue = 0
101
+ ForEachStop = 1
102
+
103
+ # WindowResizeEdge
104
+ WindowResizeEdgeLeft = 0
105
+ WindowResizeEdgeTop = 1
106
+ WindowResizeEdgeRight = 2
107
+ WindowResizeEdgeBottom = 3
108
+ WindowResizeEdgeTopLeft = 4
109
+ WindowResizeEdgeTopRight = 5
110
+ WindowResizeEdgeBottomLeft = 6
111
+ WindowResizeEdgeBottomRight = 7
112
+
113
+ # DrawBrushType
114
+ DrawBrushTypeSolid = 0
115
+ DrawBrushTypeLinearGradient = 1
116
+ DrawBrushTypeRadialGradient = 2
117
+ DrawBrushTypeImage = 3
118
+
119
+ # DrawLineCap
120
+ DrawLineCapFlat = 0
121
+ DrawLineCapRound = 1
122
+ DrawLineCapSquare = 2
123
+
124
+ # DrawLineJoin
125
+ DrawLineJoinMiter = 0
126
+ DrawLineJoinRound = 1
127
+ DrawLineJoinBevel = 2
128
+
129
+ DrawDefaultMiterLimit = 10.0
130
+
131
+ # DrawFillMode
132
+ DrawFillModeWinding = 0
133
+ DrawFillModeAlternate = 1
134
+
135
+ # AttributeType
136
+ AttributeTypeFamily = 0
137
+ AttributeTypeSize = 1
138
+ AttributeTypeWeight = 2
139
+ AttributeTypeItalic = 3
140
+ AttributeTypeStretch = 4
141
+ AttributeTypeColor = 5
142
+ AttributeTypeBackground = 6
143
+ AttributeTypeUnderline = 7
144
+ AttributeTypeUnderlineColor = 8
145
+ AttributeTypeFeatures = 9
146
+
147
+ # TextWeight
148
+ TextWeightMinimum = 0
149
+ TextWeightThin = 100
150
+ TextWeightUltraLight = 200
151
+ TextWeightLight = 300
152
+ TextWeightBook = 350
153
+ TextWeightNormal = 400
154
+ TextWeightMedium = 500
155
+ TextWeightSemiBold = 600
156
+ TextWeightBold = 700
157
+ TextWeightUltraBold = 800
158
+ TextWeightHeavy = 900
159
+ TextWeightUltraHeavy = 950
160
+ TextWeightMaximum = 1000
161
+
162
+ # TextItalic
163
+ TextItalicNormal = 0
164
+ TextItalicOblique = 1
165
+ TextItalicItalic = 2
166
+
167
+ # TextStretch
168
+ TextStretchUltraCondensed = 0
169
+ TextStretchExtraCondensed = 1
170
+ TextStretchCondensed = 2
171
+ TextStretchSemiCondensed = 3
172
+ TextStretchNormal = 4
173
+ TextStretchSemiExpanded = 5
174
+ TextStretchExpanded = 6
175
+ TextStretchExtraExpanded = 7
176
+ TextStretchUltraExpanded = 8
177
+
178
+ # Underline
179
+ UnderlineNone = 0
180
+ UnderlineSingle = 1
181
+ UnderlineDouble = 2
182
+ UnderlineSuggestion = 3
183
+
184
+ # UnderlineColor
185
+ UnderlineColorCustom = 0
186
+ UnderlineColorSpelling = 1
187
+ UnderlineColorGrammar = 2
188
+ UnderlineColorAuxiliary = 3
189
+
190
+ # DrawTextAlign
191
+ DrawTextAlignLeft = 0
192
+ DrawTextAlignCenter = 1
193
+ DrawTextAlignRight = 2
194
+
195
+ # Modifiers
196
+ ModifierCtrl = (1 << 0)
197
+ ModifierAlt = (1 << 1)
198
+ ModifierShift = (1 << 2)
199
+ ModifierSuper = (1 << 3)
200
+
201
+ # ExtKey
202
+ ExtKeyEscape = 1
203
+ ExtKeyInsert = 2
204
+ ExtKeyDelete = 3
205
+ ExtKeyHome = 4
206
+ ExtKeyEnd = 5
207
+ ExtKeyPageUp = 6
208
+ ExtKeyPageDown = 7
209
+ ExtKeyUp = 8
210
+ ExtKeyDown = 9
211
+ ExtKeyLeft = 10
212
+ ExtKeyRight = 11
213
+ ExtKeyF1 = 12
214
+ ExtKeyF2 = 13
215
+ ExtKeyF3 = 14
216
+ ExtKeyF4 = 15
217
+ ExtKeyF5 = 16
218
+ ExtKeyF6 = 17
219
+ ExtKeyF7 = 18
220
+ ExtKeyF8 = 19
221
+ ExtKeyF9 = 20
222
+ ExtKeyF10 = 21
223
+ ExtKeyF11 = 22
224
+ ExtKeyF12 = 23
225
+ ExtKeyN0 = 24
226
+ ExtKeyN1 = 25
227
+ ExtKeyN2 = 26
228
+ ExtKeyN3 = 27
229
+ ExtKeyN4 = 28
230
+ ExtKeyN5 = 29
231
+ ExtKeyN6 = 30
232
+ ExtKeyN7 = 31
233
+ ExtKeyN8 = 32
234
+ ExtKeyN9 = 33
235
+ ExtKeyNDot = 34
236
+ ExtKeyNEnter = 35
237
+ ExtKeyNAdd = 36
238
+ ExtKeyNSubtract = 37
239
+ ExtKeyNMultiply = 38
240
+ ExtKeyNDivide = 39
241
+
242
+ # Align
243
+ AlignFill = 0
244
+ AlignStart = 1
245
+ AlignCenter = 2
246
+ AlignEnd = 3
247
+
248
+ # At
249
+ AtLeading = 0
250
+ AtTop = 1
251
+ AtTrailing = 2
252
+ AtBottom = 3
253
+
254
+ # TableValueType
255
+ TableValueTypeString = 0
256
+ TableValueTypeImage = 1
257
+ TableValueTypeInt = 2
258
+ TableValueTypeColor = 3
259
+
260
+ # SortIndicator
261
+ SortIndicatorNone = 0
262
+ SortIndicatorAscending = 1
263
+ SortIndicatorDescending = 2
264
+
265
+ # editable
266
+ TableModelColumnNeverEditable = -1
267
+ TableModelColumnAlwaysEditable = -2
268
+
269
+ # TableSelectionMode
270
+ TableSelectionModeNone = 0
271
+ TableSelectionModeZeroOrOne = 1
272
+ TableSelectionModeOne = 2
273
+ TableSelectionModeZeroOrMany = 3
274
+ end
data/vendor/LICENSE.md CHANGED
@@ -1,10 +1,10 @@
1
- Copyright (c) 2022 libui-ng authors
2
-
3
- Copyright (c) 2014 Pietro Gagliardi
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
-
1
+ Copyright (c) 2022 libui-ng authors
2
+
3
+ Copyright (c) 2014 Pietro Gagliardi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+