libui 0.0.3.alpha → 0.0.8

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: 6483e7a5d01aa51e2013350a38da4926d813416cf8f3f039f9203471bbb59968
4
- data.tar.gz: e37424f71ec7991076a3fdb9cfc007aa2bf8fcd027210513d842b82d1056de21
3
+ metadata.gz: 02ee9e67a91414cbea40a50448a58bbb320f8962f34a35fa9c26d7ed0019878d
4
+ data.tar.gz: cfde88b2432abbf23f9dd0d195db0258c143bfd1ff339f51b3112ccaf4742af2
5
5
  SHA512:
6
- metadata.gz: f3e515578dcfa6d4357c0f0154c9b59db64f75ab94e37e6518916621a11aefd19842f1545c04984d719d8d61b74602e6d976504bf3312df3e6df29e421f20701
7
- data.tar.gz: cdd83d3ec0e75e4730c158aae01cd5e29f24b6d5893a26e95759f7e9e6b92bb23b6008fb9292e53af2d925a1f08c3335be8843ecd895fbd24858b8c0c8836b4c
6
+ metadata.gz: cb131ab13e11e6573058c0ec611c7467557756904b49d4121541f4075518958d3fdf2adc74e21d52f0f433c537faeffd6a77ab4162f7d42321fdec75437d1be0
7
+ data.tar.gz: 0dc6139433b79bec3e0a096f376db6af7eedc6b989ccab25bf4d3a1123afc75d053d43625d5302122952b2a527a8a17665ec9bc1472c1574f5ae4262bef80197
data/README.md CHANGED
@@ -1,19 +1,131 @@
1
- # libui
1
+ # LibUI
2
+
3
+ ![build](https://github.com/kojix2/libui/workflows/build/badge.svg)
2
4
  [![Gem Version](https://badge.fury.io/rb/libui.svg)](https://badge.fury.io/rb/libui)
3
5
 
4
- [libui](https://github.com/andlabs/libui) - a portable GUI library -for Ruby
6
+ :radio_button: [libui](https://github.com/andlabs/libui) - a portable GUI library -for Ruby
5
7
 
6
8
  ## Installation
7
9
 
10
+ ```sh
11
+ gem install libui
8
12
  ```
9
- gem install libui --pre
10
- ```
13
+
14
+ * The gem package contains the [official release](https://github.com/andlabs/libui/releases/tag/alpha4.1) of the libui shared library versions 4.1 for Windows, Mac, and Linux.
15
+ * Namely `libui.dll`, `libui.dylib`, and `libui.so` (only 1.4MB in total).
16
+ * No dependency
17
+ * The libui gem uses the standard Ruby library [Fiddle](https://github.com/ruby/fiddle) to call C functions.
18
+
19
+ | Windows | Mac | Linux |
20
+ |---------|-----|-------|
21
+ |<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">|
11
22
 
12
23
  ## Usage
13
24
 
25
+ ```ruby
26
+ require 'libui'
27
+ UI = LibUI
28
+
29
+ UI.init
30
+
31
+ main_window = UI.new_window('hello world', 300, 200, 1)
32
+ UI.window_on_closing(main_window) do
33
+ puts 'Bye Bye'
34
+ UI.control_destroy(main_window)
35
+ UI.quit
36
+ 0
37
+ end
38
+
39
+ button = UI.new_button('Button')
40
+ UI.button_on_clicked(button) do
41
+ UI.msg_box(main_window, 'Information', 'You clicked the button')
42
+ 0
43
+ end
44
+
45
+ UI.window_set_child(main_window, button)
46
+ UI.control_show(main_window)
47
+
48
+ UI.main
49
+ UI.quit
50
+ ```
51
+
52
+ See [examples](https://github.com/kojix2/libui/tree/main/examples) directory.
53
+
54
+ ### General Rules
55
+
56
+ Compared to original libui written in C,
57
+
58
+ * The method names are snake_case.
59
+ * If the last argument is nil, it can be omitted.
60
+ * You can pass a block as a callback.
61
+ * Please return 0 explicitly in the block.
62
+ * The block will be converted to a Proc object and added to the last argument.
63
+ * Even in that case, it is possible to omit the last argument nil.
64
+
65
+ ### Not object oriented?
66
+
67
+ * At the moment, it is not object-oriented.
68
+ * Instead of providing a half-baked object-oriented approach, leave it as is.
69
+
70
+ ### How to use fiddle pointers?
71
+
72
+ ```ruby
73
+ require 'libui'
74
+ UI = LibUI
75
+ UI.init
76
+ ```
77
+
78
+ Convert a pointer to a string.
79
+
80
+ ```ruby
81
+ label = UI.new_label("Ruby")
82
+ p pointer = UI.label_text(label) # #<Fiddle::Pointer>
83
+ p pointer.to_s # Ruby
84
+ ```
85
+
86
+ If you need to use C structs, you can do the following.
87
+
88
+ ```ruby
89
+ font_button = UI.new_font_button
90
+
91
+ # Allocate memory
92
+ font_descriptor = UI::FFI::FontDescriptor.malloc
93
+
94
+ UI.font_button_on_changed(font_button) do
95
+ UI.font_button_font(font_button, font_descriptor)
96
+ p family: font_descriptor.Family.to_s,
97
+ size: font_descriptor.Size,
98
+ weight: font_descriptor.Weight,
99
+ italic: font_descriptor.Italic,
100
+ stretch: font_descriptor.Stretch
101
+ end
102
+ ```
103
+
104
+ ### How to create an executable (.exe) on Windows
105
+
106
+ OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
107
+ * https://github.com/larsch/ocra/
108
+
14
109
  ## Development
15
110
 
16
- * Keep it simple
111
+ ```sh
112
+ git clone https://github.com/kojix2/libui
113
+ cd libui
114
+ bundle install
115
+ bundle exec rake vendor:all
116
+ bundle exec rake test
117
+ ```
118
+
119
+ Use the following rake tasks to download the libui binary files and save them in the vendor directory.
120
+
121
+ `rake -T`
122
+
123
+ ```
124
+ rake vendor:all # Download libui.so, libui.dylib, and libui.dll to ve...
125
+ rake vendor:linux # Download libui.so for Linux to vendor directory
126
+ rake vendor:mac # Download libui.dylib for Mac to vendor directory
127
+ rake vendor:windows # Download libui.dll for Windows to vendor directory
128
+ ```
17
129
 
18
130
  ## Contributing
19
131
 
@@ -21,10 +133,11 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/kojix2
21
133
 
22
134
  ## Acknowledgement
23
135
 
24
- libui-ruby ispired this project.
136
+ This project is inspired by libui-ruby.
137
+
25
138
  * https://github.com/jamescook/libui-ruby
26
139
 
27
- While libui-ruby uses FFI, this gem uses Fiddle.
140
+ While libui-ruby uses [Ruby-FFI](https://github.com/ffi/ffi), this gem uses [Fiddle](https://github.com/ruby/fiddle).
28
141
 
29
142
  ## License
30
143
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'libui/version'
4
+ require_relative 'libui/utils'
4
5
 
5
6
  module LibUI
6
7
  class Error < StandardError; end
@@ -9,31 +10,70 @@ module LibUI
9
10
  attr_accessor :ffi_lib
10
11
  end
11
12
 
12
- self.ffi_lib = case RbConfig::CONFIG['host_os']
13
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
14
- # File.expand_path("libui.dll", ENV['LIBUIDIR'])
15
- File.expand_path('../vendor/libui.dll', __dir__)
16
- when /darwin|mac os/
17
- # File.expand_path("libui.dylib", ENV['LIBUIDIR'])
18
- File.expand_path('../vendor/libui.dylib', __dir__)
19
- else # TODO: Mac
20
- # File.expand_path("libui.so", ENV['LIBUIDIR'])
21
- File.expand_path('../vendor/libui.so', __dir__)
13
+ lib_name = case RbConfig::CONFIG['host_os']
14
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
15
+ 'libui.dll'
16
+ when /darwin|mac os/
17
+ 'libui.dylib'
18
+ else
19
+ 'libui.so'
20
+ end
21
+
22
+ self.ffi_lib = if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
23
+ File.expand_path(lib_name, ENV['LIBUIDIR'])
24
+ else
25
+ File.expand_path("../vendor/#{lib_name}", __dir__)
22
26
  end
23
27
 
24
28
  require_relative 'libui/ffi'
25
29
 
26
30
  class << self
27
- FFI.ffi_methods.each do |original_method_name|
28
- name = original_method_name.delete_prefix('ui')
29
- .gsub(/::/, '/')
30
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
31
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
32
- .tr('-', '_')
33
- .downcase
34
- define_method(name) do |*args|
31
+ FFI.func_map.each_key do |original_method_name|
32
+ name = Utils.convert_to_ruby_method(original_method_name)
33
+ func = FFI.func_map[original_method_name]
34
+
35
+ define_method(name) do |*args, &blk|
36
+ # Assume that block is the last argument.
37
+ args << blk if blk
38
+
39
+ # The proc object is converted to a Closure::BlockCaller object.
40
+ args.map!.with_index do |arg, idx|
41
+ if arg.is_a?(Proc)
42
+ # The types of the function arguments are recorded beforehand.
43
+ # See the monkey patch in ffi.rb.
44
+ callback = Fiddle::Closure::BlockCaller.new(
45
+ *func.callback_argument_types[idx][1..2], &arg
46
+ )
47
+ # Protect from GC
48
+ # See https://github.com/kojix2/LibUI/issues/8
49
+ receiver = args[0]
50
+ callbacks = receiver.instance_variable_get(:@callbacks) || []
51
+ callbacks << callback
52
+ receiver.instance_variable_set(:@callbacks, callback)
53
+ callback
54
+ else
55
+ arg
56
+ end
57
+ end
58
+
59
+ # Make it possible to omit the last nil. This may be an over-optimization.
60
+ siz = func.argument_types.size - 1
61
+ args[siz] = nil if args.size == siz
62
+
35
63
  FFI.public_send(original_method_name, *args)
36
64
  end
37
65
  end
66
+
67
+ module CustomMethods
68
+ def init(opt = FFI::InitOptions.malloc)
69
+ i = super(opt)
70
+ unless i.size.zero?
71
+ warn 'error'
72
+ warn UI.free_init_error(init)
73
+ end
74
+ end
75
+ end
76
+
77
+ prepend CustomMethods
38
78
  end
39
79
  end
@@ -2,6 +2,74 @@
2
2
 
3
3
  require 'fiddle/import'
4
4
 
5
+ module Fiddle
6
+ # Change the Function to hold a little more information.
7
+ class Function
8
+ # Note:
9
+ # Ruby 2.7 Fiddle::Function dose not have @argument_types
10
+ # Ruby 3.0 Fiddle::Function has @argument_types
11
+ attr_accessor :callback_argument_types, :argument_types
12
+ end
13
+
14
+ module Importer
15
+ def parse_signature(signature, tymap = nil)
16
+ tymap ||= {}
17
+ ctype, func, args = case compact(signature)
18
+ when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
19
+ [TYPE_VOIDP, Regexp.last_match(1), Regexp.last_match(2)]
20
+ when /^([\w\*\s]+[*\s])(\w+)\((.*?)\);?$/
21
+ [parse_ctype(Regexp.last_match(1).strip, tymap), Regexp.last_match(2), Regexp.last_match(3)]
22
+ else
23
+ raise("can't parserake the function prototype: #{signature}")
24
+ end
25
+ symname = func
26
+ callback_argument_types = {} # Added
27
+ argtype = split_arguments(args).collect.with_index do |arg, idx| # Added with_index
28
+ # Check if it is a function pointer or not
29
+ if arg =~ /\(\*.*\)\(.*\)/ # Added
30
+ # From the arguments, create a notation that looks like a function declaration
31
+ # int(*f)(int *, void *) -> int f(int *, void *)
32
+ func_arg = arg.sub('(*', ' ').sub(')', '') # Added
33
+ # Use Fiddle's parse_signature method again.
34
+ callback_argument_types[idx] = parse_signature(func_arg) # Added
35
+ end
36
+ parse_ctype(arg, tymap)
37
+ end
38
+ # Added callback_argument_types. Original method return only 3 values.
39
+ [symname, ctype, argtype, callback_argument_types]
40
+ end
41
+
42
+ def extern(signature, *opts)
43
+ symname, ctype, argtype, callback_argument_types = parse_signature(signature, type_alias)
44
+ opt = parse_bind_options(opts)
45
+ func = import_function(symname, ctype, argtype, opt[:call_type])
46
+
47
+ func.callback_argument_types = callback_argument_types # Added
48
+ # Ruby 2.7 Fiddle::Function dose not have @argument_types
49
+ # Ruby 3.0 Fiddle::Function has @argument_types
50
+ func.argument_types = argtype
51
+
52
+ name = symname.gsub(/@.+/, '')
53
+ @func_map[name] = func
54
+ # define_method(name){|*args,&block| f.call(*args,&block)}
55
+ begin
56
+ /^(.+?):(\d+)/ =~ caller.first
57
+ file = Regexp.last_match(1)
58
+ line = Regexp.last_match(2).to_i
59
+ rescue StandardError
60
+ file, line = __FILE__, __LINE__ + 3
61
+ end
62
+ module_eval(<<-EOS, file, line)
63
+ def #{name}(*args, &block)
64
+ @func_map['#{name}'].call(*args,&block)
65
+ end
66
+ EOS
67
+ module_function(name)
68
+ func
69
+ end
70
+ end
71
+ end
72
+
5
73
  module LibUI
6
74
  module FFI
7
75
  extend Fiddle::Importer
@@ -13,26 +81,24 @@ module LibUI
13
81
  end
14
82
 
15
83
  class << self
16
- attr_reader :ffi_methods
84
+ attr_reader :func_map
17
85
 
18
- # Improved extern method.
19
- # 1. Ignore functions that cannot be attached.
20
- # 2. Available function (names) are stored in @ffi_methods.
21
86
  def try_extern(signature, *opts)
22
- @ffi_methods ||= []
23
- begin
24
- func = extern(signature, *opts)
25
- @ffi_methods << func.name
26
- func
27
- rescue StandardError => e
28
- warn "#{e.class.name}: #{e.message}"
29
- end
87
+ extern(signature, *opts)
88
+ rescue StandardError => e
89
+ warn "#{e.class.name}: #{e.message}"
90
+ end
91
+
92
+ def ffi_methods
93
+ @ffi_methods ||= func_map.each_key.to_a
30
94
  end
31
95
  end
32
96
 
33
97
  typealias('uint32_t', 'unsigned int')
34
98
 
35
- InitOptions = struct(['size_t size'])
99
+ InitOptions = struct [
100
+ 'size_t Size'
101
+ ]
36
102
 
37
103
  try_extern 'const char *uiInit(uiInitOptions *options)'
38
104
  try_extern 'void uiUninit(void)'
@@ -47,20 +113,22 @@ module LibUI
47
113
  try_extern 'void uiOnShouldQuit(int (*f)(void *data), void *data)'
48
114
  try_extern 'void uiFreeText(char *text)'
49
115
 
50
- struct ['uint32_t Signature',
51
- 'uint32_t OSSignature',
52
- 'uint32_t TypeSignature',
53
- 'void (*Destroy)(uiControl *)',
54
- 'uintptr_t (*Handle)(uiControl *)',
55
- 'uiControl *(*Parent)(uiControl *)',
56
- 'void (*SetParent)(uiControl *, uiControl *)',
57
- 'int (*Toplevel)(uiControl *)',
58
- 'int (*Visible)(uiControl *)',
59
- 'void (*Show)(uiControl *)',
60
- 'void (*Hide)(uiControl *)',
61
- 'int (*Enabled)(uiControl *)',
62
- 'void (*Enable)(uiControl *)',
63
- 'void (*Disable)(uiControl *)']
116
+ Control = struct [
117
+ 'uint32_t Signature',
118
+ 'uint32_t OSSignature',
119
+ 'uint32_t TypeSignature',
120
+ 'void (*Destroy)(uiControl *)',
121
+ 'uintptr_t (*Handle)(uiControl *)',
122
+ 'uiControl *(*Parent)(uiControl *)',
123
+ 'void (*SetParent)(uiControl *, uiControl *)',
124
+ 'int (*Toplevel)(uiControl *)',
125
+ 'int (*Visible)(uiControl *)',
126
+ 'void (*Show)(uiControl *)',
127
+ 'void (*Hide)(uiControl *)',
128
+ 'int (*Enabled)(uiControl *)',
129
+ 'void (*Enable)(uiControl *)',
130
+ 'void (*Disable)(uiControl *)'
131
+ ]
64
132
 
65
133
  try_extern 'void uiControlDestroy(uiControl *)'
66
134
  try_extern 'uintptr_t uiControlHandle(uiControl *)'
@@ -83,6 +151,7 @@ module LibUI
83
151
  try_extern 'void uiUserBugCannotSetParentOnToplevel(const char *type)'
84
152
 
85
153
  # uiWindow
154
+
86
155
  try_extern 'char *uiWindowTitle(uiWindow *w)'
87
156
  try_extern 'void uiWindowSetTitle(uiWindow *w, const char *title)'
88
157
  try_extern 'void uiWindowContentSize(uiWindow *w, int *width, int *height)'
@@ -99,12 +168,14 @@ module LibUI
99
168
  try_extern 'uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)'
100
169
 
101
170
  # uiButton
171
+
102
172
  try_extern 'char *uiButtonText(uiButton *b)'
103
173
  try_extern 'void uiButtonSetText(uiButton *b, const char *text)'
104
174
  try_extern 'void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *b, void *data), void *data)'
105
175
  try_extern 'uiButton *uiNewButton(const char *text)'
106
176
 
107
177
  # uiBox
178
+
108
179
  try_extern 'void uiBoxAppend(uiBox *b, uiControl *child, int stretchy)'
109
180
  try_extern 'void uiBoxDelete(uiBox *b, int index)'
110
181
  try_extern 'int uiBoxPadded(uiBox *b)'
@@ -113,6 +184,7 @@ module LibUI
113
184
  try_extern 'uiBox *uiNewVerticalBox(void)'
114
185
 
115
186
  # uiCheckbox
187
+
116
188
  try_extern 'char *uiCheckboxText(uiCheckbox *c)'
117
189
  try_extern 'void uiCheckboxSetText(uiCheckbox *c, const char *text)'
118
190
  try_extern 'void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *c, void *data), void *data)'
@@ -121,6 +193,7 @@ module LibUI
121
193
  try_extern 'uiCheckbox *uiNewCheckbox(const char *text)'
122
194
 
123
195
  # uiEntry
196
+
124
197
  try_extern 'char *uiEntryText(uiEntry *e)'
125
198
  try_extern 'void uiEntrySetText(uiEntry *e, const char *text)'
126
199
  try_extern 'void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *e, void *data), void *data)'
@@ -131,11 +204,13 @@ module LibUI
131
204
  try_extern 'uiEntry *uiNewSearchEntry(void)'
132
205
 
133
206
  # uiLabel
207
+
134
208
  try_extern 'char *uiLabelText(uiLabel *l)'
135
209
  try_extern 'void uiLabelSetText(uiLabel *l, const char *text)'
136
210
  try_extern 'uiLabel *uiNewLabel(const char *text)'
137
211
 
138
212
  # uiTab
213
+
139
214
  try_extern 'void uiTabAppend(uiTab *t, const char *name, uiControl *c)'
140
215
  try_extern 'void uiTabInsertAt(uiTab *t, const char *name, int before, uiControl *c)'
141
216
  try_extern 'void uiTabDelete(uiTab *t, int index)'
@@ -145,6 +220,7 @@ module LibUI
145
220
  try_extern 'uiTab *uiNewTab(void)'
146
221
 
147
222
  # uiGroup
223
+
148
224
  try_extern 'char *uiGroupTitle(uiGroup *g)'
149
225
  try_extern 'void uiGroupSetTitle(uiGroup *g, const char *title)'
150
226
  try_extern 'void uiGroupSetChild(uiGroup *g, uiControl *c)'
@@ -153,27 +229,32 @@ module LibUI
153
229
  try_extern 'uiGroup *uiNewGroup(const char *title)'
154
230
 
155
231
  # uiSpinbox
232
+
156
233
  try_extern 'int uiSpinboxValue(uiSpinbox *s)'
157
234
  try_extern 'void uiSpinboxSetValue(uiSpinbox *s, int value)'
158
235
  try_extern 'void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *s, void *data), void *data)'
159
236
  try_extern 'uiSpinbox *uiNewSpinbox(int min, int max)'
160
237
 
161
238
  # uiSlider
239
+
162
240
  try_extern 'int uiSliderValue(uiSlider *s)'
163
241
  try_extern 'void uiSliderSetValue(uiSlider *s, int value)'
164
242
  try_extern 'void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *s, void *data), void *data)'
165
243
  try_extern 'uiSlider *uiNewSlider(int min, int max)'
166
244
 
167
245
  # uiProgressBar
246
+
168
247
  try_extern 'int uiProgressBarValue(uiProgressBar *p)'
169
248
  try_extern 'void uiProgressBarSetValue(uiProgressBar *p, int n)'
170
249
  try_extern 'uiProgressBar *uiNewProgressBar(void)'
171
250
 
172
251
  # uiSeparator
252
+
173
253
  try_extern 'uiSeparator *uiNewHorizontalSeparator(void)'
174
254
  try_extern 'uiSeparator *uiNewVerticalSeparator(void)'
175
255
 
176
256
  # uiCombobox
257
+
177
258
  try_extern 'void uiComboboxAppend(uiCombobox *c, const char *text)'
178
259
  try_extern 'int uiComboboxSelected(uiCombobox *c)'
179
260
  try_extern 'void uiComboboxSetSelected(uiCombobox *c, int n)'
@@ -181,6 +262,7 @@ module LibUI
181
262
  try_extern 'uiCombobox *uiNewCombobox(void)'
182
263
 
183
264
  # uiEditableCombobox
265
+
184
266
  try_extern 'void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text)'
185
267
  try_extern 'char *uiEditableComboboxText(uiEditableCombobox *c)'
186
268
  try_extern 'void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text)'
@@ -188,13 +270,28 @@ module LibUI
188
270
  try_extern 'uiEditableCombobox *uiNewEditableCombobox(void)'
189
271
 
190
272
  # uiRadioButtons
273
+
191
274
  try_extern 'void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)'
192
275
  try_extern 'int uiRadioButtonsSelected(uiRadioButtons *r)'
193
276
  try_extern 'void uiRadioButtonsSetSelected(uiRadioButtons *r, int n)'
194
277
  try_extern 'void uiRadioButtonsOnSelected(uiRadioButtons *r, void (*f)(uiRadioButtons *, void *), void *data)'
195
278
  try_extern 'uiRadioButtons *uiNewRadioButtons(void)'
196
279
 
197
- # uiDataTimePicker
280
+ # uiDateTimePicker
281
+
282
+ # time.h
283
+ TM = struct [
284
+ 'int tm_sec',
285
+ 'int tm_min',
286
+ 'int tm_hour',
287
+ 'int tm_mday',
288
+ 'int tm_mon',
289
+ 'int tm_year',
290
+ 'int tm_wday',
291
+ 'int tm_yday',
292
+ 'int tm_isdst'
293
+ ]
294
+
198
295
  try_extern 'void uiDateTimePickerTime(uiDateTimePicker *d, struct tm *time)'
199
296
  try_extern 'void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)'
200
297
  try_extern 'void uiDateTimePickerOnChanged(uiDateTimePicker *d, void (*f)(uiDateTimePicker *, void *), void *data)'
@@ -203,6 +300,7 @@ module LibUI
203
300
  try_extern 'uiDateTimePicker *uiNewTimePicker(void)'
204
301
 
205
302
  # uiMultilineEntry
303
+
206
304
  try_extern 'char *uiMultilineEntryText(uiMultilineEntry *e)'
207
305
  try_extern 'void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text)'
208
306
  try_extern 'void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text)'
@@ -213,6 +311,7 @@ module LibUI
213
311
  try_extern 'uiMultilineEntry *uiNewNonWrappingMultilineEntry(void)'
214
312
 
215
313
  # uiMenuItem
314
+
216
315
  try_extern 'void uiMenuItemEnable(uiMenuItem *m)'
217
316
  try_extern 'void uiMenuItemDisable(uiMenuItem *m)'
218
317
  try_extern 'void uiMenuItemOnClicked(uiMenuItem *m, void (*f)(uiMenuItem *sender, uiWindow *window, void *data), void *data)'
@@ -220,6 +319,7 @@ module LibUI
220
319
  try_extern 'void uiMenuItemSetChecked(uiMenuItem *m, int checked)'
221
320
 
222
321
  # uiMenu
322
+
223
323
  try_extern 'uiMenuItem *uiMenuAppendItem(uiMenu *m, const char *name)'
224
324
  try_extern 'uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name)'
225
325
  try_extern 'uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)'
@@ -234,25 +334,315 @@ module LibUI
234
334
  try_extern 'void uiMsgBoxError(uiWindow *parent, const char *title, const char *description)'
235
335
 
236
336
  # uiArea
337
+
338
+ AreaHandler = struct [
339
+ 'void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *)',
340
+ 'void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *)',
341
+ 'void (*MouseCrossed)(uiAreaHandler *, uiArea *, int left)',
342
+ 'void (*DragBroken)(uiAreaHandler *, uiArea *)',
343
+ 'int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *)'
344
+ ]
345
+
346
+ typealias 'uiWindowResizeEdge', 'int'
347
+
237
348
  try_extern 'void uiAreaSetSize(uiArea *a, int width, int height)'
238
349
  try_extern 'void uiAreaQueueRedrawAll(uiArea *a)'
239
350
  try_extern 'void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height)'
240
351
  try_extern 'void uiAreaBeginUserWindowMove(uiArea *a)'
241
- typealias 'uiWindowResizeEdge', 'char' # FIXME: uint8
242
352
  try_extern 'void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge)'
243
353
  try_extern 'uiArea *uiNewArea(uiAreaHandler *ah)'
244
354
  try_extern 'uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)'
245
355
 
356
+ AreaDrawParams = struct [
357
+ 'uiDrawContext *Context',
358
+ 'double AreaWidth',
359
+ 'double AreaHeight',
360
+ 'double ClipX',
361
+ 'double ClipY',
362
+ 'double ClipWidth',
363
+ 'double ClipHeight'
364
+ ]
365
+ typealias 'uiDrawBrushType', 'int'
366
+ typealias 'uiDrawLineCap', 'int'
367
+ typealias 'uiDrawLineJoin', 'int'
368
+ typealias 'uiDrawFillMode', 'int'
369
+
370
+ DrawMatrix = struct [
371
+ 'double M11',
372
+ 'double M12',
373
+ 'double M21',
374
+ 'double M22',
375
+ 'double M31',
376
+ 'double M32'
377
+ ]
378
+
379
+ DrawBrush = struct [
380
+ 'uiDrawBrushType Type',
381
+ 'double R',
382
+ 'double G',
383
+ 'double B',
384
+ 'double A',
385
+ 'double X0',
386
+ 'double Y0',
387
+ 'double X1',
388
+ 'double Y1',
389
+ 'double OuterRadius',
390
+ 'uiDrawBrushGradientStop *Stops',
391
+ 'size_t NumStops'
392
+ ]
393
+
394
+ DrawBrushGradientStop = struct [
395
+ 'double Pos',
396
+ 'double R',
397
+ 'double G',
398
+ 'double B',
399
+ 'double A'
400
+ ]
401
+
402
+ DrawStrokeParams = struct [
403
+ 'uiDrawLineCap Cap',
404
+ 'uiDrawLineJoin Join',
405
+ 'double Thickness',
406
+ 'double MiterLimit',
407
+ 'double *Dashes',
408
+ 'size_t NumDashes',
409
+ 'double DashPhase'
410
+ ]
411
+
412
+ # uiDrawPath
413
+ try_extern 'uiDrawPath *uiDrawNewPath(uiDrawFillMode fillMode)'
414
+ try_extern 'void uiDrawFreePath(uiDrawPath *p)'
415
+ try_extern 'void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)'
416
+ try_extern 'void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative)'
417
+ try_extern 'void uiDrawPathLineTo(uiDrawPath *p, double x, double y)'
418
+ try_extern 'void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative)'
419
+ try_extern 'void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY)'
420
+ try_extern 'void uiDrawPathCloseFigure(uiDrawPath *p)'
421
+ try_extern 'void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height)'
422
+ try_extern 'void uiDrawPathEnd(uiDrawPath *p)'
423
+ try_extern 'void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p)'
424
+ try_extern 'void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b)'
425
+
426
+ # uiDrawMatrix
427
+ try_extern 'void uiDrawMatrixSetIdentity(uiDrawMatrix *m)'
428
+ try_extern 'void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y)'
429
+ try_extern 'void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y)'
430
+ try_extern 'void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount)'
431
+ try_extern 'void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)'
432
+ try_extern 'void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src)'
433
+ try_extern 'int uiDrawMatrixInvertible(uiDrawMatrix *m)'
434
+ try_extern 'int uiDrawMatrixInvert(uiDrawMatrix *m)'
435
+ try_extern 'void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y)'
436
+ try_extern 'void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y)'
437
+
438
+ try_extern 'void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m)'
439
+ try_extern 'void uiDrawClip(uiDrawContext *c, uiDrawPath *path)'
440
+ try_extern 'void uiDrawSave(uiDrawContext *c)'
441
+ try_extern 'void uiDrawRestore(uiDrawContext *c)'
442
+
443
+ # uiAttribute
444
+ try_extern 'void uiFreeAttribute(uiAttribute *a)'
445
+
446
+ typealias 'uiAttributeType', 'int'
447
+
448
+ try_extern 'uiAttributeType uiAttributeGetType(const uiAttribute *a)'
449
+ try_extern 'uiAttribute *uiNewFamilyAttribute(const char *family)'
450
+ try_extern 'const char *uiAttributeFamily(const uiAttribute *a)'
451
+ try_extern 'uiAttribute *uiNewSizeAttribute(double size)'
452
+ try_extern 'double uiAttributeSize(const uiAttribute *a)'
453
+
454
+ typealias 'uiTextWeight', 'int'
455
+
456
+ try_extern 'uiAttribute *uiNewWeightAttribute(uiTextWeight weight)'
457
+ try_extern 'uiTextWeight uiAttributeWeight(const uiAttribute *a)'
458
+
459
+ typealias 'uiTextItalic', 'int'
460
+
461
+ try_extern 'uiAttribute *uiNewItalicAttribute(uiTextItalic italic)'
462
+ try_extern 'uiTextItalic uiAttributeItalic(const uiAttribute *a)'
463
+
464
+ typealias 'uiTextStretch', 'int'
465
+
466
+ try_extern 'uiAttribute *uiNewStretchAttribute(uiTextStretch stretch)'
467
+ try_extern 'uiTextStretch uiAttributeStretch(const uiAttribute *a)'
468
+ try_extern 'uiAttribute *uiNewColorAttribute(double r, double g, double b, double a)'
469
+ try_extern 'void uiAttributeColor(const uiAttribute *a, double *r, double *g, double *b, double *alpha)'
470
+ try_extern 'uiAttribute *uiNewBackgroundAttribute(double r, double g, double b, double a)'
471
+
472
+ typealias 'uiUnderline', 'int'
473
+
474
+ try_extern 'uiAttribute *uiNewUnderlineAttribute(uiUnderline u)'
475
+ try_extern 'uiUnderline uiAttributeUnderline(const uiAttribute *a)'
476
+
477
+ typealias 'uiUnderlineColor', 'int'
478
+
479
+ try_extern 'uiAttribute *uiNewUnderlineColorAttribute(uiUnderlineColor u, double r, double g, double b, double a)'
480
+ try_extern 'void uiAttributeUnderlineColor(const uiAttribute *a, uiUnderlineColor *u, double *r, double *g, double *b, double *alpha)'
481
+
482
+ # uiOpenTypeFeatures
483
+
484
+ typealias 'uiOpenTypeFeaturesForEachFunc', 'void*'
485
+
486
+ try_extern 'uiOpenTypeFeatures *uiNewOpenTypeFeatures(void)'
487
+ try_extern 'void uiFreeOpenTypeFeatures(uiOpenTypeFeatures *otf)'
488
+ try_extern 'uiOpenTypeFeatures *uiOpenTypeFeaturesClone(const uiOpenTypeFeatures *otf)'
489
+ try_extern 'void uiOpenTypeFeaturesAdd(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value)'
490
+ try_extern 'void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b, char c, char d)'
491
+ try_extern 'int uiOpenTypeFeaturesGet(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value)'
492
+ try_extern 'void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeaturesForEachFunc f, void *data)'
493
+ try_extern 'uiAttribute *uiNewFeaturesAttribute(const uiOpenTypeFeatures *otf)'
494
+ try_extern 'const uiOpenTypeFeatures *uiAttributeFeatures(const uiAttribute *a)'
495
+
496
+ # uiAttributedString
497
+
498
+ typealias 'uiAttributedStringForEachAttributeFunc', 'void*'
499
+
500
+ try_extern 'uiAttributedString *uiNewAttributedString(const char *initialString)'
501
+ try_extern 'void uiFreeAttributedString(uiAttributedString *s)'
502
+ try_extern 'const char *uiAttributedStringString(const uiAttributedString *s)'
503
+ try_extern 'size_t uiAttributedStringLen(const uiAttributedString *s)'
504
+ try_extern 'void uiAttributedStringAppendUnattributed(uiAttributedString *s, const char *str)'
505
+ try_extern 'void uiAttributedStringInsertAtUnattributed(uiAttributedString *s, const char *str, size_t at)'
506
+ try_extern 'void uiAttributedStringDelete(uiAttributedString *s, size_t start, size_t end)'
507
+ try_extern 'void uiAttributedStringSetAttribute(uiAttributedString *s, uiAttribute *a, size_t start, size_t end)'
508
+ try_extern 'void uiAttributedStringForEachAttribute(const uiAttributedString *s, uiAttributedStringForEachAttributeFunc f, void *data)'
509
+ try_extern 'size_t uiAttributedStringNumGraphemes(uiAttributedString *s)'
510
+ try_extern 'size_t uiAttributedStringByteIndexToGrapheme(uiAttributedString *s, size_t pos)'
511
+ try_extern 'size_t uiAttributedStringGraphemeToByteIndex(uiAttributedString *s, size_t pos)'
512
+
513
+ # uiFont
514
+
515
+ FontDescriptor = struct [
516
+ 'char *Family',
517
+ 'double Size',
518
+ 'uiTextWeight Weight',
519
+ 'uiTextItalic Italic',
520
+ 'uiTextStretch Stretch'
521
+ ]
522
+
523
+ typealias 'uiDrawTextAlign', 'int'
524
+
525
+ DrawTextLayoutParams = struct [
526
+ 'uiAttributedString *String',
527
+ 'uiFontDescriptor *DefaultFont',
528
+ 'double Width',
529
+ 'uiDrawTextAlign Align'
530
+ ]
531
+
532
+ try_extern 'uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *params)'
533
+ try_extern 'void uiDrawFreeTextLayout(uiDrawTextLayout *tl)'
534
+ try_extern 'void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, double y)'
535
+ try_extern 'void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height)'
536
+
246
537
  # uiFontButton
538
+
247
539
  try_extern 'void uiFontButtonFont(uiFontButton *b, uiFontDescriptor *desc)'
248
540
  try_extern 'void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data)'
249
541
  try_extern 'uiFontButton *uiNewFontButton(void)'
250
542
  try_extern 'void uiFreeFontButtonFont(uiFontDescriptor *desc)'
251
543
 
544
+ typealias 'uiModifiers', 'int'
545
+
546
+ AreaMouseEvent = struct [
547
+ 'double X',
548
+ 'double Y',
549
+ 'double AreaWidth',
550
+ 'double AreaHeight',
551
+ 'int Down',
552
+ 'int Up',
553
+ 'int Count',
554
+ 'uiModifiers Modifiers',
555
+ 'uint64_t Held1To64'
556
+ ]
557
+
558
+ typealias 'uiExtKey', 'int'
559
+
560
+ AreaKeyEvent = struct [
561
+ 'char Key',
562
+ 'uiExtKey ExtKey',
563
+ 'uiModifiers Modifier',
564
+ 'uiModifiers Modifiers',
565
+ 'int Up'
566
+ ]
567
+
252
568
  # uiColorButton
569
+
253
570
  try_extern 'void uiColorButtonColor(uiColorButton *b, double *r, double *g, double *bl, double *a)'
254
571
  try_extern 'void uiColorButtonSetColor(uiColorButton *b, double r, double g, double bl, double a)'
255
572
  try_extern 'void uiColorButtonOnChanged(uiColorButton *b, void (*f)(uiColorButton *, void *), void *data)'
256
573
  try_extern 'uiColorButton *uiNewColorButton(void)'
574
+
575
+ # uiForm
576
+
577
+ try_extern 'void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)'
578
+ try_extern 'void uiFormDelete(uiForm *f, int index)'
579
+ try_extern 'int uiFormPadded(uiForm *f)'
580
+ try_extern 'void uiFormSetPadded(uiForm *f, int padded)'
581
+ try_extern 'uiForm *uiNewForm(void)'
582
+
583
+ typealias 'uiAlign', 'int'
584
+
585
+ typealias 'uiAt', 'int'
586
+
587
+ # uiGrid
588
+
589
+ try_extern 'void uiGridAppend(uiGrid *g, uiControl *c, int left, int top, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign)'
590
+ try_extern 'void uiGridInsertAt(uiGrid *g, uiControl *c, uiControl *existing, uiAt at, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign)'
591
+ try_extern 'int uiGridPadded(uiGrid *g)'
592
+ try_extern 'void uiGridSetPadded(uiGrid *g, int padded)'
593
+ try_extern 'uiGrid *uiNewGrid(void)'
594
+
595
+ # uiImage
596
+
597
+ try_extern 'uiImage *uiNewImage(double width, double height)'
598
+ try_extern 'void uiFreeImage(uiImage *i)'
599
+ try_extern 'void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int byteStride)'
600
+
601
+ # uiTable
602
+ try_extern 'void uiFreeTableValue(uiTableValue *v)'
603
+
604
+ typealias 'uiTableValueType', 'int'
605
+
606
+ try_extern 'uiTableValueType uiTableValueGetType(const uiTableValue *v)'
607
+ try_extern 'uiTableValue *uiNewTableValueString(const char *str)'
608
+ try_extern 'const char *uiTableValueString(const uiTableValue *v)'
609
+ try_extern 'uiTableValue *uiNewTableValueImage(uiImage *img)'
610
+ try_extern 'uiImage *uiTableValueImage(const uiTableValue *v)'
611
+ try_extern 'uiTableValue *uiNewTableValueInt(int i)'
612
+ try_extern 'int uiTableValueInt(const uiTableValue *v)'
613
+ try_extern 'uiTableValue *uiNewTableValueColor(double r, double g, double b, double a)'
614
+ try_extern 'void uiTableValueColor(const uiTableValue *v, double *r, double *g, double *b, double *a)'
615
+
616
+ TableModelHandler = struct [
617
+ 'int (*NumColumns)(uiTableModelHandler *, uiTableModel *)',
618
+ 'uiTableValueType (*ColumnType)(uiTableModelHandler *, uiTableModel *, int)',
619
+ 'int (*NumRows)(uiTableModelHandler *, uiTableModel *)',
620
+ 'uiTableValue *(*CellValue)(uiTableModelHandler *mh, uiTableModel *m, int row, int column)',
621
+ 'void (*SetCellValue)(uiTableModelHandler *, uiTableModel *, int, int, const uiTableValue *)'
622
+ ]
623
+
624
+ try_extern 'uiTableModel *uiNewTableModel(uiTableModelHandler *mh)'
625
+ try_extern 'void uiFreeTableModel(uiTableModel *m)'
626
+ try_extern 'void uiTableModelRowInserted(uiTableModel *m, int newIndex)'
627
+ try_extern 'void uiTableModelRowChanged(uiTableModel *m, int index)'
628
+ try_extern 'void uiTableModelRowDeleted(uiTableModel *m, int oldIndex)'
629
+
630
+ TableTextColumnOptionalParams = struct [
631
+ 'int ColorModelColumn'
632
+ ]
633
+
634
+ TableParams = struct [
635
+ 'uiTableModel *Model',
636
+ 'int RowBackgroundColorModelColumn'
637
+ ]
638
+
639
+ try_extern 'void uiTableAppendTextColumn(uiTable *t, const char *name, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams)'
640
+ try_extern 'void uiTableAppendImageColumn(uiTable *t, const char *name, int imageModelColumn)'
641
+ try_extern 'void uiTableAppendImageTextColumn(uiTable *t, const char *name, int imageModelColumn, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams)'
642
+ try_extern 'void uiTableAppendCheckboxColumn(uiTable *t, const char *name, int checkboxModelColumn, int checkboxEditableModelColumn)'
643
+ try_extern 'void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxModelColumn, int checkboxEditableModelColumn, int textModelColumn, int textEditableModelColumn, uiTableTextColumnOptionalParams *textParams)'
644
+ try_extern 'void uiTableAppendProgressBarColumn(uiTable *t, const char *name, int progressModelColumn)'
645
+ try_extern 'void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonModelColumn, int buttonClickableModelColumn)'
646
+ try_extern 'uiTable *uiNewTable(uiTableParams *params)'
257
647
  end
258
648
  end
@@ -0,0 +1,19 @@
1
+ module LibUI
2
+ module Utils
3
+ class << self
4
+ def convert_to_ruby_method(original_method_name)
5
+ underscore(original_method_name.delete_prefix('ui'))
6
+ end
7
+
8
+ # Converting camel case to underscore case in ruby
9
+ # https://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby#1509939
10
+ def underscore(str)
11
+ str.gsub(/::/, '/')
12
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
13
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
14
+ .tr('-', '_')
15
+ .downcase
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LibUI
4
- VERSION = '0.0.3.alpha'
4
+ VERSION = '0.0.8'
5
5
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.alpha
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-09 00:00:00.000000000 Z
11
+ date: 2021-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - README.md
92
92
  - lib/libui.rb
93
93
  - lib/libui/ffi.rb
94
+ - lib/libui/utils.rb
94
95
  - lib/libui/version.rb
95
96
  - vendor/LICENSE
96
97
  - vendor/README.md
@@ -112,9 +113,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
113
  version: '2.5'
113
114
  required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
- - - ">"
116
+ - - ">="
116
117
  - !ruby/object:Gem::Version
117
- version: 1.3.1
118
+ version: '0'
118
119
  requirements: []
119
120
  rubygems_version: 3.1.4
120
121
  signing_key: