libui-ruby 1.0.0

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ext.rb +510 -0
  3. data/lib/libui.rb +3 -0
  4. data/lib/version.rb +3 -0
  5. metadata +60 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d137fc4cefa74b9f774b7de75a7396206f79f592
4
+ data.tar.gz: a69ea2dc9859d08bf064c8821bfa3da485b1b6e8
5
+ SHA512:
6
+ metadata.gz: f2399a35758784a763c52bd79101d120aa55cda26bb933e8cd67fbe779ec5a83e82dd7bc9dd4011e5a93e9809c92fa859991983105ba160f44cc099ad6784426
7
+ data.tar.gz: d458c29f873ec5cf468932a48498ca284d09df6adcf8822be373f46f8cc812cdf1d9f02fec3e8458d45cd1c75613e3ae3e0db35a45533f830bf42a3323670c2e
@@ -0,0 +1,510 @@
1
+ require "ffi"
2
+
3
+ module LibUI
4
+ module Ext
5
+ extend FFI::Library
6
+ ffi_lib "libui"
7
+
8
+ DEFAULT_MITER_LIMIT = 10
9
+
10
+ class InitOptions < FFI::Struct
11
+ layout :size, :size_t
12
+ end
13
+
14
+ class DrawContext < FFI::Struct
15
+ layout :c, :pointer
16
+ end
17
+
18
+ class Control < FFI::Struct
19
+ layout :signature, :uint32,
20
+ :os_signature, :uint32,
21
+ :type_signature, :uint32,
22
+ :destroy, :pointer,
23
+ :handle, :pointer,
24
+ :parent, :pointer, #Control
25
+ :set_parent, :pointer, #Control
26
+ :top_level, :int,
27
+ :visible, :int,
28
+ :show, :pointer,
29
+ :hide, :pointer,
30
+ :enabled, :int,
31
+ :enable, :pointer,
32
+ :disable, :pointer
33
+ end
34
+
35
+ class Box < Control; end
36
+ class Checkbox < Control; end
37
+ class Menu < Control; end
38
+ class MenuItem < Control; end
39
+ class Group < Control; end
40
+ class Button < Control; end
41
+ class Label < Control; end
42
+ class Separator < Control; end
43
+ class DatePicker < Control; end
44
+ class TimePicker < Control; end
45
+ class DateTimePicker < Control; end
46
+ class FontButton < Control; end
47
+ class ColorButton < Control; end
48
+ class SpinBox < Control; end
49
+ class Slider < Control; end
50
+ class ProgressBar < Control; end
51
+ class Combobox < Control; end
52
+ class EditableCombobox < Control; end
53
+ class Radiobuttons < Control; end
54
+ class Tab < Control; end
55
+ class TextEntry < Control; end
56
+ class Area < Control; end
57
+ class DrawPath < Control; end
58
+ class TextFont < Control; end
59
+ class TextLayout < Control; end
60
+
61
+ class Window < FFI::Struct
62
+ layout :c, :pointer, #control
63
+ :w, :pointer, #window
64
+ :child, Control,
65
+ :onClosing, :pointer
66
+ end
67
+
68
+ class AreaDrawParams < FFI::Struct
69
+ layout :draw_context, :pointer, #DrawContext, uiDrawContext
70
+ :width, :double,
71
+ :height, :double,
72
+ :clip_x, :double,
73
+ :clip_y, :double,
74
+ :clip_width, :double,
75
+ :clip_height, :double
76
+ end
77
+
78
+ class AreaHandler < FFI::Struct
79
+ # void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
80
+ layout :draw_event, callback([
81
+ LibUI::Ext::AreaHandler.ptr,
82
+ LibUI::Ext::Area,
83
+ LibUI::Ext::AreaDrawParams.ptr], :void),
84
+ # void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
85
+ :mouse_event, callback([:pointer, :pointer, :pointer], :void),
86
+ # void (*MouseCrossed)(uiAreaHandler *, uiArea *, int left);
87
+ :mouse_crossed, callback([:pointer, :pointer, :int], :void),
88
+ # void (*DragBroken)(uiAreaHandler *, uiArea *);
89
+ :drag_broken, callback([:pointer, :pointer], :void),
90
+ # int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *);
91
+ :key_event, callback([:pointer, :pointer, :pointer], :int)
92
+ end
93
+ KEY_MODIFIERS = enum(:ctrl, 1 << 0, :alt, 1 << 1, :shift, 1 << 2, :super, 1 << 3)
94
+ LINE_CAPS = enum(:flat, :round, :square)
95
+ LINE_JOINS = enum(:miter, :round, :bevel)
96
+ TEXT_WEIGHTS = enum(:thin,
97
+ :ultra_light,
98
+ :light, :book,
99
+ :normal,
100
+ :medium,
101
+ :semi_bold,
102
+ :bold,
103
+ :ultra_bold,
104
+ :heavy,
105
+ :ultra_heavy
106
+ )
107
+
108
+ TEXT_ITALIC = enum(:normal, :oblique, :italic)
109
+ TEXT_STRETCH = enum(:ultra_condensed,
110
+ :extra_condensed,
111
+ :condensed,
112
+ :semi_condensed,
113
+ :normal,
114
+ :semi_expanded,
115
+ :expanded,
116
+ :extra_expanded,
117
+ :ultra_expanded
118
+ )
119
+
120
+ class AreaMouseEvent < FFI::Struct
121
+ layout :x, :double,
122
+ :y, :double,
123
+ :area_width, :double,
124
+ :area_height, :double,
125
+ :down, :uintmax_t,
126
+ :up, :uintmax_t,
127
+ :count, :uintmax_t,
128
+ :modifiers, KEY_MODIFIERS,
129
+ :held1to64, :uint64_t
130
+ end
131
+
132
+ class FontFamilies < FFI::Struct
133
+ layout :ff, :pointer
134
+ end
135
+
136
+ class FontDescriptor < FFI::Struct
137
+ layout :family, :string,
138
+ :size, :double,
139
+ :weight, TEXT_WEIGHTS,
140
+ :italic, TEXT_ITALIC,
141
+ :stretch, TEXT_STRETCH
142
+ end
143
+
144
+ class FontMetrics < FFI::Struct
145
+ layout :ascent, :double,
146
+ :descent, :double,
147
+ :leading, :double,
148
+ :underline_pos, :double,
149
+ :underline_thickness, :double
150
+ end
151
+
152
+ class DrawStrokeParams < FFI::Struct
153
+ layout :cap, LINE_CAPS,
154
+ :join, LINE_JOINS,
155
+ :thickness, :double,
156
+ :miter_limit, :double,
157
+ :dashes, :pointer, #double?
158
+ :num_dashes, :size_t,
159
+ :dash_phase, :double
160
+ end
161
+
162
+ BRUSH_TYPES = enum(:solid, :linear_gradient, :radial_gradient, :image)
163
+ FILL_MODES = enum(:winding, :alternate)
164
+
165
+ class DrawBrush < FFI::Struct
166
+ layout :type, BRUSH_TYPES,
167
+ :red, :double,
168
+ :green, :double,
169
+ :blue, :double,
170
+ :alpha, :double,
171
+
172
+ :x0, :double, # linear: start X, radial: start X
173
+ :y0, :double, # linear: start Y, radial: start Y
174
+ :x1, :double, # linear: end X, radial: outer circle center X
175
+ :y1, :double, # linear: end Y, radial: outer circle center Y
176
+ :outer_radius, :double, # radial gradients only
177
+ :stops, :pointer, # pointer to uiDrawBrushGradientStop
178
+ :num_stops, :size_t
179
+ end
180
+
181
+ class DrawMatrix < FFI::Struct
182
+ layout :m11, :double,
183
+ :m12, :double,
184
+ :m21, :double,
185
+ :m22, :double,
186
+ :m31, :double,
187
+ :m32, :double
188
+ end
189
+
190
+ attach_function :uiInit, [ InitOptions ], :string
191
+ attach_function :uiControlShow, [ :pointer ], :void
192
+ attach_function :uiMain, [], :void
193
+ attach_function :uiQuit, [], :void
194
+ attach_function :uiUninit, [], :void
195
+ attach_function :uiFreeInitError, [:char], :void
196
+ attach_function :uiControlDestroy, [:pointer], :void
197
+
198
+
199
+ callback :quit_callback, [:pointer], :int
200
+ attach_function :uiNewWindow,
201
+ [:string,
202
+ :int,
203
+ :int,
204
+ :int],
205
+ Window
206
+ attach_function :uiOnShouldQuit,
207
+ [:quit_callback, # proc/lambda
208
+ :pointer ],
209
+ :void
210
+ attach_function :uiWindowOnClosing,
211
+ [Window,
212
+ :quit_callback, # proc/lambda
213
+ :pointer ],
214
+ :void
215
+ attach_function :uiWindowSetChild, [Window, Control], :void
216
+ attach_function :uiWindowSetTitle,
217
+ [Window,
218
+ :string], # title
219
+ :void
220
+ attach_function :uiWindowSetMargined,
221
+ [Window,
222
+ :int], # margin value
223
+ :void
224
+
225
+ attach_function :uiNewHorizontalBox, [], Box
226
+ attach_function :uiNewVerticalBox, [], Box
227
+ attach_function :uiBoxSetPadded, [Box, :int], :void
228
+ attach_function :uiBoxAppend, [Box, Control, :int], :void
229
+
230
+ callback :checkbox_toggle_callback, [:pointer], :int
231
+ attach_function :uiNewCheckbox, [:string], Checkbox
232
+ attach_function :uiCheckboxChecked, [Checkbox], :int
233
+ attach_function :uiCheckboxSetText, [Checkbox, :string], :void
234
+ attach_function :uiCheckboxOnToggled,
235
+ [Checkbox,
236
+ :checkbox_toggle_callback,
237
+ :pointer],
238
+ :void
239
+
240
+ callback :menu_item_clicked, [:pointer], :int
241
+ attach_function :uiNewMenu, [:string], Menu
242
+ attach_function :uiMenuAppendItem, [Menu, :string], MenuItem
243
+ attach_function :uiMenuAppendPreferencesItem, [Menu], MenuItem
244
+ attach_function :uiMenuAppendAboutItem, [Menu], MenuItem
245
+ attach_function :uiMenuItemDisable, [MenuItem], :void
246
+ attach_function :uiMenuAppendQuitItem, [Menu], :void
247
+ attach_function :uiMenuAppendCheckItem, [Menu, :string], :void
248
+ attach_function :uiMenuAppendSeparator, [Menu], :void
249
+ attach_function :uiMenuItemOnClicked,
250
+ [Menu,
251
+ :menu_item_clicked,
252
+ :pointer],
253
+ :void
254
+
255
+ attach_function :uiNewGroup, [:string], Group
256
+ attach_function :uiGroupSetMargined, [Group, :int], :void
257
+ attach_function :uiGroupMargined, [Group], :int
258
+ attach_function :uiGroupSetChild, [Group, :pointer], :void
259
+ attach_function :uiGroupSetTitle, [Group, :string], :void
260
+
261
+ attach_function :uiNewDatePicker, [], DatePicker
262
+ attach_function :uiNewTimePicker, [], TimePicker
263
+ attach_function :uiNewDateTimePicker, [], DateTimePicker
264
+ attach_function :uiNewFontButton, [], FontButton
265
+ attach_function :uiNewHorizontalSeparator, [], Separator
266
+ attach_function :uiNewProgressBar, [], ProgressBar
267
+
268
+ attach_function :uiNewColorButton, [], ColorButton
269
+ attach_function :uiColorButtonColor, [
270
+ ColorButton,
271
+ :pointer, #red, double
272
+ :pointer, #green, double
273
+ :pointer, #blue, double
274
+ :pointer #alpha, double
275
+ ], :void
276
+
277
+ attach_function :uiColorButtonSetColor, [
278
+ ColorButton,
279
+ :double, #red
280
+ :double, #green
281
+ :double, #blue
282
+ :double #alpha
283
+ ], :void
284
+ callback :color_changed_callback, [:pointer], :int
285
+ attach_function :uiColorButtonOnChanged,
286
+ [ColorButton,
287
+ :color_changed_callback,
288
+ :pointer
289
+ ], :void
290
+
291
+ attach_function :uiNewLabel, [:string], Label
292
+ attach_function :uiLabelSetText, [:string], :void
293
+ attach_function :uiLabelText, [Label], :string
294
+
295
+ callback :button_clicked_callback, [:pointer], :int
296
+ attach_function :uiNewButton, [:string], Button
297
+ attach_function :uiButtonSetText, [Button, :string], :void
298
+ attach_function :uiButtonOnClicked, [Button, :button_clicked_callback, :pointer], :void
299
+
300
+ callback :slider_changed_callback, [:pointer], :int
301
+ attach_function :uiNewSlider, [:long_long, :long_long], Slider
302
+ attach_function :uiSliderSetValue, [Slider, :long_long], :void
303
+ attach_function :uiSliderValue, [Slider], :long_long
304
+ attach_function :uiSliderOnChanged, [
305
+ Slider,
306
+ :slider_changed_callback,
307
+ :pointer
308
+ ], :void
309
+
310
+ callback :spinbox_changed_callback, [:pointer], :int
311
+ attach_function :uiNewSpinbox, [:int, :int], SpinBox
312
+ attach_function :uiSpinboxValue, [SpinBox], :long_long
313
+ attach_function :uiSpinboxSetValue, [SpinBox, :long_long], :void
314
+ attach_function :uiSpinboxOnChanged, [
315
+ SpinBox,
316
+ :spinbox_changed_callback,
317
+ :pointer
318
+ ], :void
319
+
320
+ callback :combobox_selected_callback, [:pointer], :int
321
+ attach_function :uiNewCombobox, [], Combobox
322
+ attach_function :uiComboboxSelected, [Combobox], :long_long
323
+ attach_function :uiComboboxAppend, [Combobox, :string], :void
324
+ attach_function :uiComboboxSetSelected, [Combobox, :long_long], :void # int is the index
325
+ attach_function :uiComboboxOnSelected, [
326
+ Combobox,
327
+ :combobox_selected_callback,
328
+ :pointer
329
+ ], :void
330
+
331
+ callback :editable_combobox_selected_callback, [:pointer], :int
332
+ attach_function :uiEditableComboboxOnChanged, [
333
+ EditableCombobox,
334
+ :editable_combobox_selected_callback,
335
+ :pointer
336
+ ], :void
337
+ attach_function :uiEditableComboboxText, [EditableCombobox], :string
338
+ attach_function :uiEditableComboboxAppend, [EditableCombobox, :string], :void
339
+ attach_function :uiEditableComboboxSetText, [EditableCombobox, :string], :void
340
+ attach_function :uiNewEditableCombobox, [], EditableCombobox
341
+
342
+ attach_function :uiNewRadioButtons, [], Radiobuttons
343
+ attach_function :uiRadioButtonsAppend, [Radiobuttons, :string], Radiobuttons
344
+
345
+ attach_function :uiNewTab, [], Tab
346
+ attach_function :uiTabAppend, [Tab, :string, Control], :void
347
+ attach_function :uiTabInsertAt, [
348
+ Tab,
349
+ :string, # the tab 'name'
350
+ :ulong_long, # "before"
351
+ Control
352
+ ], :void
353
+
354
+ attach_function :uiTabDelete, [
355
+ Tab,
356
+ :ulong_long # index
357
+ ], :void
358
+
359
+ attach_function :uiTabNumPages, [Tab], :ulong_long
360
+ attach_function :uiTabMargined, [
361
+ Tab,
362
+ :ulong_long # the 'page'
363
+ ], :int
364
+
365
+ attach_function :uiTabSetMargined, [
366
+ Tab,
367
+ :ulong_long, # 'page'
368
+ :int # 'margined'
369
+ ], :void
370
+
371
+
372
+ attach_function :uiNewEntry, [], TextEntry
373
+ attach_function :uiEntrySetText, [TextEntry, :string], TextEntry
374
+ attach_function :uiEntryText, [TextEntry], :string
375
+ attach_function :uiEntryReadOnly, [TextEntry], :int
376
+ attach_function :uiEntrySetReadOnly, [TextEntry], :void
377
+ callback :text_entry_on_change, [:pointer], :int
378
+ attach_function :uiEntryOnChanged,
379
+ [TextEntry,
380
+ :text_entry_on_change,
381
+ :pointer ],
382
+ :void
383
+
384
+ attach_function :uiMsgBox, [Window, :string, :string], :void # title and description
385
+ attach_function :uiMsgBoxError, [Window, :string, :string], :void # title and description
386
+
387
+ attach_function :uiNewArea, [AreaHandler], Area
388
+ attach_function :uiAreaQueueRedrawAll, [Area], :void
389
+
390
+ attach_function :uiDrawNewPath, [FILL_MODES], DrawPath
391
+
392
+ attach_function :uiDrawPathAddRectangle, [
393
+ DrawPath,
394
+ :double, #x
395
+ :double, #y
396
+ :double, #width
397
+ :double #height
398
+ ], :void
399
+ attach_function :uiDrawPathEnd, [DrawPath], :void
400
+ #_UI_EXTERN void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b);
401
+ attach_function :uiDrawFill, [:pointer, DrawPath, DrawBrush], :void
402
+ attach_function :uiDrawFreePath, [DrawPath], :void
403
+ attach_function :uiDrawPathNewFigure, [DrawPath, :double, :double], :void # x and y
404
+ attach_function :uiDrawPathLineTo, [DrawPath, :double, :double], :void # x and y
405
+ attach_function :uiDrawPathCloseFigure, [DrawPath], :void
406
+
407
+ #_UI_EXTERN void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p);
408
+ attach_function :uiDrawStroke, [:pointer, :pointer, :pointer, :pointer], :void
409
+
410
+ attach_function :uiDrawMatrixSetIdentity, [DrawMatrix], :void
411
+ attach_function :uiDrawMatrixTranslate, [DrawMatrix, :double, :double], :void #left, top
412
+ attach_function :uiDrawMatrixScale, [
413
+ DrawMatrix,
414
+ :double, #xCenter
415
+ :double, #yCenter
416
+ :double, #x
417
+ :double, #y
418
+ ], :void
419
+
420
+ attach_function :uiDrawMatrixRotate, [
421
+ DrawMatrix,
422
+ :double, #x
423
+ :double, #y
424
+ :double #amount
425
+ ], :void
426
+
427
+ attach_function :uiDrawMatrixSkew, [
428
+ DrawMatrix,
429
+ :double, #x
430
+ :double, #y
431
+ :double, #xamount
432
+ :double #yamount
433
+ ], :void
434
+
435
+ attach_function :uiDrawMatrixMultiply, [
436
+ DrawMatrix, # dest
437
+ DrawMatrix # src
438
+ ], :void
439
+
440
+ attach_function :uiDrawMatrixInvertible, [
441
+ DrawMatrix # m
442
+ ], :void
443
+
444
+ attach_function :uiDrawMatrixInvert, [
445
+ DrawMatrix # m
446
+ ], :void
447
+
448
+ attach_function :uiDrawMatrixTransformPoint, [
449
+ DrawMatrix, # m
450
+ :double, # x
451
+ :double # y
452
+ ], :void
453
+
454
+ attach_function :uiDrawMatrixTransformSize, [
455
+ DrawMatrix, # m
456
+ :double, # x
457
+ :double # y
458
+ ], :void
459
+
460
+ attach_function :uiDrawTransform, [:pointer, DrawMatrix], :void #context
461
+
462
+ attach_function :uiDrawClip, [DrawContext, DrawPath], :void
463
+ attach_function :uiDrawSave, [DrawContext], :void
464
+ attach_function :uiDrawRestore, [DrawContext], :void
465
+
466
+ attach_function :uiDrawListFontFamilies, [], FontFamilies
467
+ attach_function :uiDrawFontFamiliesNumFamilies, [FontFamilies], :uintmax_t
468
+
469
+ attach_function :uiDrawFontFamiliesFamily, [FontFamilies, :uintmax_t], :char
470
+ attach_function :uiDrawFreeFontFamilies, [FontFamilies], :void
471
+
472
+ # TODO example ...
473
+ attach_function :uiDrawLoadClosestFont, [FontDescriptor], TextFont
474
+ attach_function :uiDrawFreeTextFont, [TextFont], :void
475
+ attach_function :uiDrawTextFontHandle, [TextFont], :uintptr_t
476
+ attach_function :uiDrawTextFontDescribe, [TextFont, FontDescriptor], :void
477
+ attach_function :uiDrawTextFontGetMetrics, [TextFont, FontMetrics], :void
478
+
479
+ attach_function :uiDrawNewTextLayout, [
480
+ :string, # text
481
+ TextFont, # defaultFont
482
+ :double, #width
483
+ ], TextLayout
484
+
485
+ attach_function :uiDrawFreeTextLayout, [TextLayout], :void
486
+ attach_function :uiDrawTextLayoutSetWidth, [TextLayout, :double], :void #width
487
+ attach_function :uiDrawTextLayoutExtents, [
488
+ TextLayout,
489
+ :double, #width
490
+ :double #height
491
+ ], :void
492
+
493
+ attach_function :uiDrawTextLayoutSetColor, [
494
+ TextLayout,
495
+ :intmax_t, #startChar
496
+ :intmax_t, #endChar
497
+ :double, #r
498
+ :double, #g
499
+ :double, #b
500
+ :double, #a
501
+ ], :void
502
+
503
+ attach_function :uiDrawText, [
504
+ DrawContext,
505
+ :double, #x
506
+ :double, #y
507
+ TextLayout
508
+ ], :void
509
+ end
510
+ end
@@ -0,0 +1,3 @@
1
+ module LibUI
2
+ end
3
+ require_relative "ext"
@@ -0,0 +1,3 @@
1
+ module LibUI
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libui-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - James Cook
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/ext.rb
34
+ - lib/libui.rb
35
+ - lib/version.rb
36
+ homepage: https://github.com/jamescook/libui-ruby
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.1'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.6.13
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: LibUI FFI Binding
60
+ test_files: []