libui 0.0.10 → 0.0.14

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: f5856ad97384408635e170c1ea252dc3dbdfa1ba3955bfc8b8c1ac2c29585ac1
4
- data.tar.gz: 67a9b78e39b61805afca932fc80365b59e068493f2da937c57b03e1500a2adf5
3
+ metadata.gz: ee9a02c819baa560dac3db19f6385c1c92e12ee00f0baa943728fb36381efb58
4
+ data.tar.gz: b168c699519a2cd32b9ae0b4549af8657137a7315214f5985f1ab602f6a56010
5
5
  SHA512:
6
- metadata.gz: 5204e35c1c0f4b0c5f8acd69a4a1d76b6482a1fb298376c99ce29632a202c1340a39e017b68c563b4539a74e721b1611cd3a732b4a9983ef2a0fb3eef7a80b3c
7
- data.tar.gz: 8fb83fe3d145646bacb598dc88413364d534493f275c2e0ef637e9718908fe895796a1cb95cdb56f6c6d24b216f23ed68a7812a0c0978a5c700a014ecd0d1573
6
+ metadata.gz: 23f37b10d06d6c2d00eca6f30d7a3eea22d8ad117a857b606d86e40306c7c723f4223e1431cdb13e339b4476425fb27b593c3a763ff8d7c0552dfce565131e8a
7
+ data.tar.gz: 6ff9da25e26d31fd109f6d8982475d73060a6271b9a437fa3884bf6eb3257c0b7612a8b93d9c5a17def325c545b507ba0d55c14ffbda1e52ce7d1556c8b12b5a
data/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  ![build](https://github.com/kojix2/libui/workflows/build/badge.svg)
4
4
  [![Gem Version](https://badge.fury.io/rb/libui.svg)](https://badge.fury.io/rb/libui)
5
+ <a href="https://github.com/AndyObtiva/glimmer-dsl-libui"><img alt="glimmer-dsl-libui" src="https://github.com/AndyObtiva/glimmer/blob/master/images/glimmer-logo-hi-res.svg" width="50" height="50" align="right"></a>
5
6
 
6
- :radio_button: [libui](https://github.com/andlabs/libui) - a portable GUI library - for Ruby
7
+ :radio_button: [libui](https://github.com/libui-ng/libui-ng) - a portable GUI library - for Ruby
7
8
 
8
9
  ## Installation
9
10
 
@@ -20,7 +21,10 @@ gem install libui
20
21
  |---------|-----|-------|
21
22
  |<img src="https://user-images.githubusercontent.com/5798442/103118046-900ea780-46b0-11eb-81fc-32626762e4df.png">|<img src="https://user-images.githubusercontent.com/5798442/103118059-99980f80-46b0-11eb-9d12-324ec4d297c9.png">|<img src="https://user-images.githubusercontent.com/5798442/103118068-a0bf1d80-46b0-11eb-8c5c-3bdcc3dcfb26.png">|
22
23
 
23
- Note: If you are using the 32-bit (x86) version of Ruby, you need to download the 32-bit (x86) native dll. See [Development](#development).
24
+ Note:
25
+ * If you are using the 32-bit (x86) version of Ruby, you need to download the 32-bit (x86) native dll. See [Development](#development).
26
+ * ARM64/AARCH64 Support is limited. See ([#47](https://github.com/kojix2/LibUI/issues/47))
27
+ * On Windows, libui may not work due to missing DLLs. In that case, you need to install [Visual C++ Redistributable](https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist). See ([#48](https://github.com/kojix2/LibUI/issues/48))
24
28
 
25
29
  ## Usage
26
30
 
@@ -64,12 +68,18 @@ Compared to original libui written in C,
64
68
  * You can pass a block as a callback.
65
69
  * The block will be converted to a Proc object and added to the last argument.
66
70
  * Even in that case, it is possible to omit the last argument nil.
67
-
71
+
72
+ You can use [the documentation for libui's Go bindings](https://pkg.go.dev/github.com/andlabs/ui) as a reference.
73
+
68
74
  ### Not object oriented?
69
75
 
70
- * At the moment, it is not object-oriented.
71
- * Instead of providing a half-baked object-oriented approach, leave it as is.
72
- * [A list of DSLs for LibUI.](https://github.com/kojix2/LibUI/wiki/DSL-for-LibUI)
76
+ LibUI is not object-oriented, but provides high portability with minimal implementation.
77
+ If you want to write in an object-oriented way, please use the following DSLs built on top of LibUI.
78
+
79
+ ### DSLs for LibUI
80
+
81
+ * [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
82
+ * [libui_paradise](https://rubygems.org/gems/libui_paradise)
73
83
 
74
84
  ### How to use fiddle pointers?
75
85
 
@@ -94,6 +104,8 @@ font_button = UI.new_font_button
94
104
 
95
105
  # Allocate memory
96
106
  font_descriptor = UI::FFI::FontDescriptor.malloc
107
+ font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
108
+ # font_descriptor = UI::FFI::FontDescriptor.malloc(Fiddle::RUBY_FREE) # fiddle 1.0.1 or higher
97
109
 
98
110
  UI.font_button_on_changed(font_button) do
99
111
  UI.font_button_font(font_button, font_descriptor)
@@ -179,6 +191,12 @@ Would you like to add your commits to libui?
179
191
  * Small corrections, such as typofixes, are appreciated.
180
192
  * Did you find any bugs? Write it in the [issues](https://github.com/kojix2/LibUI/issue) section!
181
193
 
194
+ ```
195
+ Do you need commit rights to my repository?
196
+ Do you want to get admin rights and take over the project?
197
+ If so, please feel free to contact me @kojix2.
198
+ ```
199
+
182
200
  ## Acknowledgement
183
201
 
184
202
  This project is inspired by libui-ruby.
data/lib/libui/ffi.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'fiddle/import'
4
2
  require_relative 'fiddle_patch'
5
3
 
@@ -34,6 +32,9 @@ module LibUI
34
32
  'size_t Size'
35
33
  ]
36
34
 
35
+ # https://github.com/andlabs/libui/blob/master/ui.h
36
+ # keep same order
37
+
37
38
  try_extern 'const char *uiInit(uiInitOptions *options)'
38
39
  try_extern 'void uiUninit(void)'
39
40
  try_extern 'void uiFreeInitError(const char *err)'
@@ -214,17 +215,33 @@ module LibUI
214
215
  # uiDateTimePicker
215
216
 
216
217
  # time.h
217
- TM = struct [
218
- 'int tm_sec',
219
- 'int tm_min',
220
- 'int tm_hour',
221
- 'int tm_mday',
222
- 'int tm_mon',
223
- 'int tm_year',
224
- 'int tm_wday',
225
- 'int tm_yday',
226
- 'int tm_isdst'
227
- ]
218
+ TM = if Fiddle::WINDOWS
219
+ struct [
220
+ 'int tm_sec',
221
+ 'int tm_min',
222
+ 'int tm_hour',
223
+ 'int tm_mday',
224
+ 'int tm_mon',
225
+ 'int tm_year',
226
+ 'int tm_wday',
227
+ 'int tm_yday',
228
+ 'int tm_isdst'
229
+ ]
230
+ else # The GNU C Library (glibc)
231
+ struct [
232
+ 'int tm_sec',
233
+ 'int tm_min',
234
+ 'int tm_hour',
235
+ 'int tm_mday',
236
+ 'int tm_mon',
237
+ 'int tm_year',
238
+ 'int tm_wday',
239
+ 'int tm_yday',
240
+ 'int tm_isdst',
241
+ 'long tm_gmtoff',
242
+ 'const char *tm_zone'
243
+ ]
244
+ end
228
245
 
229
246
  try_extern 'void uiDateTimePickerTime(uiDateTimePicker *d, struct tm *time)'
230
247
  try_extern 'void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)'
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module LibUI
4
2
  module LibUIBase
5
3
  FFI.func_map.each_key do |original_method_name|
@@ -12,24 +10,33 @@ module LibUI
12
10
 
13
11
  # The proc object is converted to a Closure::BlockCaller object.
14
12
  args.map!.with_index do |arg, idx|
15
- if arg.is_a?(Proc)
16
- # The types of the function arguments are recorded beforehand.
17
- # See the monkey patch in ffi.rb.
18
- callback = Fiddle::Closure::BlockCaller.new(
19
- *func.callback_argument_types[idx][1..2], &arg
20
- )
21
- # Protect from GC
22
- # See https://github.com/kojix2/LibUI/issues/8
23
- receiver = args[0]
24
- if receiver.instance_variable_defined?(:@callbacks)
25
- receiver.instance_variable_get(:@callbacks) << callback
26
- else
27
- receiver.instance_variable_set(:@callbacks, [callback])
28
- end
29
- callback
13
+ next arg unless arg.is_a?(Proc)
14
+
15
+ # now arg must be Proc
16
+
17
+ # The types of the function arguments are stored in advance.
18
+ # See the monkey patch in ffi.rb.
19
+ _f, ret_type, arg_types = func.callback_argument_types[idx]
20
+ # TODO: raise some nice error if _f is nil.
21
+
22
+ callback = Fiddle::Closure::BlockCaller.new(
23
+ ret_type, arg_types, &arg
24
+ )
25
+ # Protect from GC
26
+ # by giving the owner object a reference to the callback.
27
+ # See https://github.com/kojix2/LibUI/issues/8
28
+ owner = if idx == 0 or # UI.queue_main{}
29
+ owner.frozen? # UI.timer(100) {}
30
+ LibUIBase # or UI is better?
31
+ else
32
+ args[0] # receiver
33
+ end
34
+ if owner.instance_variable_defined?(:@callbacks)
35
+ owner.instance_variable_get(:@callbacks) << callback
30
36
  else
31
- arg
37
+ owner.instance_variable_set(:@callbacks, [callback])
32
38
  end
39
+ callback
33
40
  end
34
41
 
35
42
  # Make it possible to omit the last nil. This may be an over-optimization.
data/lib/libui/version.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module LibUI
4
- VERSION = '0.0.10'
2
+ VERSION = '0.0.14'
5
3
  end
data/lib/libui.rb CHANGED
@@ -1,7 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'libui/version'
4
2
  require_relative 'libui/utils'
3
+ require 'rbconfig'
5
4
 
6
5
  module LibUI
7
6
  class Error < StandardError; end
@@ -24,12 +23,199 @@ module LibUI
24
23
  extend LibUIBase
25
24
 
26
25
  class << self
27
- def init(opt = FFI::InitOptions.malloc)
26
+ def init(opt = nil)
27
+ unless opt
28
+ opt = FFI::InitOptions.malloc
29
+ opt.to_ptr.free = Fiddle::RUBY_FREE
30
+ end
28
31
  i = super(opt)
29
32
  return if i.size.zero?
30
33
 
31
34
  warn 'error'
32
35
  warn UI.free_init_error(init)
33
36
  end
37
+
38
+ def open_type_features_add(otf, a, b, c, d, value)
39
+ a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
40
+ super(otf, a, b, c, d, value)
41
+ end
42
+
43
+ def open_type_features_remove(otf, a, b, c, d)
44
+ a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
45
+ super(otf, a, b, c, d)
46
+ end
47
+
48
+ def open_type_features_get(otf, a, b, c, d, value)
49
+ a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
50
+ super(otf, a, b, c, d, value)
51
+ end
34
52
  end
53
+
54
+ # UI_ENUM
55
+ # https://github.com/andlabs/libui/blob/master/ui.h
56
+
57
+ # ForEach
58
+ ForEachContinue = 0
59
+ ForEachStop = 1
60
+
61
+ # WindowResizeEdge
62
+ WindowResizeEdgeLeft = 0
63
+ WindowResizeEdgeTop = 1
64
+ WindowResizeEdgeRight = 2
65
+ WindowResizeEdgeBottom = 3
66
+ WindowResizeEdgeTopLeft = 4
67
+ WindowResizeEdgeTopRight = 5
68
+ WindowResizeEdgeBottomLeft = 6
69
+ WindowResizeEdgeBottomRight = 7
70
+
71
+ # DrawBrushType
72
+ DrawBrushTypeSolid = 0
73
+ DrawBrushTypeLinearGradient = 1
74
+ DrawBrushTypeRadialGradient = 2
75
+ DrawBrushTypeImage = 3
76
+
77
+ # DrawLineCap
78
+ DrawLineCapFlat = 0
79
+ DrawLineCapRound = 1
80
+ DrawLineCapSquare = 2
81
+
82
+ # DrawLineJoin
83
+ DrawLineJoinMiter = 0
84
+ DrawLineJoinRound = 1
85
+ DrawLineJoinBevel = 2
86
+
87
+ DrawDefaultMiterLimit = 10.0
88
+
89
+ # DrawFillMode
90
+ DrawFillModeWinding = 0
91
+ DrawFillModeAlternate = 1
92
+
93
+ # AttributeType
94
+ AttributeTypeFamily = 0
95
+ AttributeTypeSize = 1
96
+ AttributeTypeWeight = 2
97
+ AttributeTypeItalic = 3
98
+ AttributeTypeStretch = 4
99
+ AttributeTypeColor = 5
100
+ AttributeTypeBackground = 6
101
+ AttributeTypeUnderline = 7
102
+ AttributeTypeUnderlineColor = 8
103
+ AttributeTypeFeatures = 9
104
+
105
+ # TextWeight
106
+ TextWeightMinimum = 0
107
+ TextWeightThin = 100
108
+ TextWeightUltraLight = 200
109
+ TextWeightLight = 300
110
+ TextWeightBook = 350
111
+ TextWeightNormal = 400
112
+ TextWeightMedium = 500
113
+ TextWeightSemiBold = 600
114
+ TextWeightBold = 700
115
+ TextWeightUltraBold = 800
116
+ TextWeightHeavy = 900
117
+ TextWeightUltraHeavy = 950
118
+ TextWeightMaximum = 1000
119
+
120
+ # TextItalic
121
+ TextItalicNormal = 0
122
+ TextItalicOblique = 1
123
+ TextItalicItalic = 2
124
+
125
+ # TextStretch
126
+ TextStretchUltraCondensed = 0
127
+ TextStretchExtraCondensed = 1
128
+ TextStretchCondensed = 2
129
+ TextStretchSemiCondensed = 3
130
+ TextStretchNormal = 4
131
+ TextStretchSemiExpanded = 5
132
+ TextStretchExpanded = 6
133
+ TextStretchExtraExpanded = 7
134
+ TextStretchUltraExpanded = 8
135
+
136
+ # Underline
137
+ UnderlineNone = 0
138
+ UnderlineSingle = 1
139
+ UnderlineDouble = 2
140
+ UnderlineSuggestion = 3
141
+
142
+ # UnderlineColor
143
+ UnderlineColorCustom = 0
144
+ UnderlineColorSpelling = 1
145
+ UnderlineColorGrammar = 2
146
+ UnderlineColorAuxiliary = 3
147
+
148
+ # DrawTextAlign
149
+ DrawTextAlignLeft = 0
150
+ DrawTextAlignCenter = 1
151
+ DrawTextAlignRight = 2
152
+
153
+ # Modifiers
154
+ ModifierCtrl = (1 << 0)
155
+ ModifierAlt = (1 << 1)
156
+ ModifierShift = (1 << 2)
157
+ ModifierSuper = (1 << 3)
158
+
159
+ # ExtKey
160
+ ExtKeyEscape = 1
161
+ ExtKeyInsert = 2
162
+ ExtKeyDelete = 3
163
+ ExtKeyHome = 4
164
+ ExtKeyEnd = 5
165
+ ExtKeyPageUp = 6
166
+ ExtKeyPageDown = 7
167
+ ExtKeyUp = 8
168
+ ExtKeyDown = 9
169
+ ExtKeyLeft = 10
170
+ ExtKeyRight = 11
171
+ ExtKeyF1 = 12
172
+ ExtKeyF2 = 13
173
+ ExtKeyF3 = 14
174
+ ExtKeyF4 = 15
175
+ ExtKeyF5 = 16
176
+ ExtKeyF6 = 17
177
+ ExtKeyF7 = 18
178
+ ExtKeyF8 = 19
179
+ ExtKeyF9 = 20
180
+ ExtKeyF10 = 21
181
+ ExtKeyF11 = 22
182
+ ExtKeyF12 = 23
183
+ ExtKeyN0 = 24
184
+ ExtKeyN1 = 25
185
+ ExtKeyN2 = 26
186
+ ExtKeyN3 = 27
187
+ ExtKeyN4 = 28
188
+ ExtKeyN5 = 29
189
+ ExtKeyN6 = 30
190
+ ExtKeyN7 = 31
191
+ ExtKeyN8 = 32
192
+ ExtKeyN9 = 33
193
+ ExtKeyNDot = 34
194
+ ExtKeyNEnter = 35
195
+ ExtKeyNAdd = 36
196
+ ExtKeyNSubtract = 37
197
+ ExtKeyNMultiply = 38
198
+ ExtKeyNDivide = 39
199
+
200
+ # Align
201
+ AlignFill = 0
202
+ AlignStart = 1
203
+ AlignCenter = 2
204
+ AlignEnd = 3
205
+
206
+ # At
207
+ AtLeading = 0
208
+ AtTop = 1
209
+ AtTrailing = 2
210
+ AtBottom = 3
211
+
212
+ # TableValueType
213
+ TableValueTypeString = 0
214
+ TableValueTypeImage = 1
215
+ TableValueTypeInt = 2
216
+ TableValueTypeColor = 3
217
+
218
+ # editable
219
+ TableModelColumnNeverEditable = -1
220
+ TableModelColumnAlwaysEditable = -2
35
221
  end
metadata CHANGED
@@ -1,85 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-26 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubyzip
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
+ dependencies: []
83
13
  description:
84
14
  email:
85
15
  - 2xijok@gmail.com
@@ -119,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
49
  - !ruby/object:Gem::Version
120
50
  version: '0'
121
51
  requirements: []
122
- rubygems_version: 3.2.22
52
+ rubygems_version: 3.3.3
123
53
  signing_key:
124
54
  specification_version: 4
125
55
  summary: Ruby bindings to libui