Module: LibUI
- Defined in:
- lib/libui.rb,
lib/libui/ffi.rb,
lib/libui/font.rb,
lib/libui/path.rb,
lib/libui/error.rb,
lib/libui/utils.rb,
lib/libui/version.rb,
lib/libui/platform.rb,
lib/libui/libui_base.rb,
lib/libui/draw_values.rb,
lib/libui/table_model.rb,
lib/libui/area_handler.rb,
lib/libui/fiddle_patch.rb,
lib/libui/callback_registry.rb
Defined Under Namespace
Modules: FFI, Platform, Utils
Classes: AreaHandler, Brush, DrawContext, Error, Font, LibraryLoadError, LibraryNotFoundError, Matrix, Path, StrokeParams, TableModel, TableModelHandler, TableValue
Constant Summary
collapse
- ForEachContinue =
0
- ForEachStop =
1
- WindowResizeEdgeLeft =
0
- WindowResizeEdgeTop =
1
- WindowResizeEdgeRight =
2
- WindowResizeEdgeBottom =
3
- WindowResizeEdgeTopLeft =
4
- WindowResizeEdgeTopRight =
5
- WindowResizeEdgeBottomLeft =
6
- WindowResizeEdgeBottomRight =
7
- DrawBrushTypeSolid =
0
- DrawBrushTypeLinearGradient =
1
- DrawBrushTypeRadialGradient =
2
- DrawBrushTypeImage =
3
- DrawLineCapFlat =
0
- DrawLineCapRound =
1
- DrawLineCapSquare =
2
- DrawLineJoinMiter =
0
- DrawLineJoinRound =
1
- DrawLineJoinBevel =
2
- DrawDefaultMiterLimit =
10.0
- DrawFillModeWinding =
0
- DrawFillModeAlternate =
1
- AttributeTypeFamily =
0
- AttributeTypeSize =
1
- AttributeTypeWeight =
2
- AttributeTypeItalic =
3
- AttributeTypeStretch =
4
- AttributeTypeColor =
5
- AttributeTypeBackground =
6
- AttributeTypeUnderline =
7
- AttributeTypeUnderlineColor =
8
- AttributeTypeFeatures =
9
- TextWeightMinimum =
0
- TextWeightThin =
100
- TextWeightUltraLight =
200
- TextWeightLight =
300
- TextWeightBook =
350
- TextWeightNormal =
400
- TextWeightMedium =
500
- TextWeightSemiBold =
600
- TextWeightBold =
700
- TextWeightUltraBold =
800
- TextWeightHeavy =
900
- TextWeightUltraHeavy =
950
- TextWeightMaximum =
1000
- TextItalicNormal =
0
- TextItalicOblique =
1
- TextItalicItalic =
2
- TextStretchUltraCondensed =
0
1
- TextStretchCondensed =
2
- TextStretchSemiCondensed =
3
- TextStretchNormal =
4
- TextStretchSemiExpanded =
5
- TextStretchExpanded =
6
- TextStretchExtraExpanded =
7
- TextStretchUltraExpanded =
8
- UnderlineNone =
0
- UnderlineSingle =
1
- UnderlineDouble =
2
- UnderlineSuggestion =
3
- UnderlineColorCustom =
0
- UnderlineColorSpelling =
1
- UnderlineColorGrammar =
2
- UnderlineColorAuxiliary =
3
- DrawTextAlignLeft =
0
- DrawTextAlignCenter =
1
- DrawTextAlignRight =
2
- ModifierCtrl =
(1 << 0)
- ModifierAlt =
(1 << 1)
- ModifierShift =
(1 << 2)
- ModifierSuper =
(1 << 3)
- ExtKeyEscape =
1
- ExtKeyInsert =
2
- ExtKeyDelete =
3
- ExtKeyHome =
4
- ExtKeyEnd =
5
- ExtKeyPageUp =
6
- ExtKeyPageDown =
7
- ExtKeyUp =
8
- ExtKeyDown =
9
- ExtKeyLeft =
10
- ExtKeyRight =
11
- ExtKeyF1 =
12
- ExtKeyF2 =
13
- ExtKeyF3 =
14
- ExtKeyF4 =
15
- ExtKeyF5 =
16
- ExtKeyF6 =
17
- ExtKeyF7 =
18
- ExtKeyF8 =
19
- ExtKeyF9 =
20
- ExtKeyF10 =
21
- ExtKeyF11 =
22
- ExtKeyF12 =
23
- ExtKeyN0 =
24
- ExtKeyN1 =
25
- ExtKeyN2 =
26
- ExtKeyN3 =
27
- ExtKeyN4 =
28
- ExtKeyN5 =
29
- ExtKeyN6 =
30
- ExtKeyN7 =
31
- ExtKeyN8 =
32
- ExtKeyN9 =
33
- ExtKeyNDot =
34
- ExtKeyNEnter =
35
- ExtKeyNAdd =
36
- ExtKeyNSubtract =
37
- ExtKeyNMultiply =
38
- ExtKeyNDivide =
39
- AlignFill =
0
- AlignStart =
1
- AlignCenter =
2
- AlignEnd =
3
- AtLeading =
0
- AtTop =
1
- AtTrailing =
2
- AtBottom =
3
- ToolbarDisplayModeIconOnly =
0
- ToolbarDisplayModeIconAndTextHorizontal =
1
- ToolbarDisplayModeIconAndTextVertical =
2
- ToolbarDisplayModeTextOnly =
3
- ImageViewContentCenter =
0
- ImageViewContentFit =
1
- TableValueTypeString =
0
- TableValueTypeImage =
1
- TableValueTypeInt =
2
- TableValueTypeColor =
3
- SortIndicatorNone =
0
- SortIndicatorAscending =
1
- SortIndicatorDescending =
2
- TableModelColumnNeverEditable =
-1
- TableModelColumnAlwaysEditable =
-2
- TableSelectionModeNone =
0
- TableSelectionModeZeroOrOne =
1
- TableSelectionModeOne =
2
- TableSelectionModeZeroOrMany =
3
- VERSION =
'0.3.0.pre3'
Class Attribute Summary collapse
Class Method Summary
collapse
-
.attribute_color(attribute) ⇒ Object
-
.attribute_family(attribute) ⇒ Object
-
.attribute_features(attribute) ⇒ Object
-
.attribute_underline_color(attribute) ⇒ Object
-
.attributed_string_append_unattributed(attributed_string, str = '') ⇒ Object
-
.attributed_string_for_each_attribute(string) ⇒ Object
Values are copied during the callback; native attribute pointers expire as soon as the callback returns.
-
.attributed_string_string(attributed_string) ⇒ Object
-
.button_set_text(button, text = '') ⇒ Object
-
.button_text(button) ⇒ Object
-
.checkbox_set_text(checkbox, text = '') ⇒ Object
-
.checkbox_text(checkbox) ⇒ Object
-
.color_button_color(button) ⇒ Object
-
.combobox_append(combobox, text = '') ⇒ Object
-
.combobox_insert_at(combobox, index, text = '') ⇒ Object
-
.control_on_destroyed(control, callback = nil, data = nil, &block) ⇒ Object
-
.date_time_picker_set_time(picker, value) ⇒ Object
-
.date_time_picker_time(picker) ⇒ Object
-
.draw_clip(context, path) ⇒ Object
-
.draw_fill(context, path, brush) ⇒ Object
-
.draw_matrix_transform_point(matrix, x, y) ⇒ Object
-
.draw_matrix_transform_size(matrix, x, y) ⇒ Object
-
.draw_new_text_layout(string_or_params, font: nil, width: -1,, align: DrawTextAlignLeft) ⇒ Object
-
.draw_stroke(context, path, brush, stroke_params) ⇒ Object
-
.draw_text_layout_extents(layout) ⇒ Object
-
.draw_transform(context, matrix) ⇒ Object
-
.editable_combobox_append(combobox, text = '') ⇒ Object
-
.editable_combobox_set_text(combobox, text = '') ⇒ Object
-
.editable_combobox_text(combobox) ⇒ Object
-
.entry_set_text(entry, text = '') ⇒ Object
-
.entry_text(entry) ⇒ Object
-
.font_button_font(button, descriptor = nil) ⇒ Object
-
.free_table_model(model) ⇒ Object
-
.free_toolbar(toolbar) ⇒ Object
-
.group_set_title(group, title = '') ⇒ Object
-
.group_title(group) ⇒ Object
-
.image_append(image, pixels, width, height, byte_stride) ⇒ Object
The native function copies the pixels before returning.
-
.image_append_rgba(image, pixels, width, height, byte_stride = width * 4) ⇒ Object
Convert straight RGBA (as used by PNG libraries) to premultiplied RGBA.
-
.init(opt = nil) ⇒ Object
-
.label_set_text(label, text = '') ⇒ Object
-
.label_text(label) ⇒ Object
-
.load_control_font(descriptor = nil) ⇒ Object
-
.menu_append_check_item(menu, name = '') ⇒ Object
-
.menu_append_item(menu, name = '') ⇒ Object
-
.msg_box(parent, title, description = '') ⇒ Object
-
.msg_box_error(parent, title, description = '') ⇒ Object
-
.multiline_entry_append(entry, text = '') ⇒ Object
-
.multiline_entry_set_text(entry, text = '') ⇒ Object
-
.multiline_entry_text(entry) ⇒ Object
-
.new_area(handler) ⇒ Object
-
.new_attributed_string(initial_string = '') ⇒ Object
-
.new_button(text = '') ⇒ Object
-
.new_checkbox(text = '') ⇒ Object
-
.new_group(title = '') ⇒ Object
-
.new_label(text = '') ⇒ Object
-
.new_menu(name = '') ⇒ Object
-
.new_scrolling_area(handler, width, height) ⇒ Object
-
.new_table(params = nil, model: nil, row_background_color_model_column: -1)) ⇒ Object
-
.new_table_model(handler) ⇒ Object
-
.new_table_value_string(str = '') ⇒ Object
-
.open_file(window) ⇒ Object
-
.open_folder(window) ⇒ Object
-
.open_type_features_add(otf, a, b, c, d, value) ⇒ Object
FIXME: This is a workaround for a old version of Fiddle.
-
.open_type_features_for_each(features) ⇒ Object
-
.open_type_features_get(otf, a, b, c, d) ⇒ Object
-
.open_type_features_remove(otf, a, b, c, d) ⇒ Object
-
.queue_main(callback = nil, data = nil, &block) ⇒ Object
-
.radio_buttons_append(radio_buttons, text = '') ⇒ Object
-
.save_file(window) ⇒ Object
-
.table_append_checkbox_text_column(table, name, checkbox_column, checkbox_editable_column, text_column, text_editable_column, options = nil, color_model_column: nil) ⇒ Object
-
.table_append_image_text_column(table, name, image_column, text_column, editable_column, options = nil, color_model_column: nil) ⇒ Object
-
.table_append_text_column(table, name, text_column, editable_column, options = nil, color_model_column: nil) ⇒ Object
-
.table_get_selection(table) ⇒ Object
-
.table_set_selection(table, rows) ⇒ Object
-
.table_value_color(value) ⇒ Object
-
.table_value_string(value) ⇒ Object
-
.timer(milliseconds, callback = nil, data = nil, &block) ⇒ Object
-
.toolbar_append_button(toolbar, text, icon = nil) ⇒ Object
-
.toolbar_append_toggle_button(toolbar, text, icon = nil) ⇒ Object
-
.toolbar_item_text(item) ⇒ Object
-
.toolbar_item_tooltip(item) ⇒ Object
-
.uninit ⇒ Object
-
.version ⇒ Object
-
.window_content_size(window) ⇒ Object
-
.window_position(w) ⇒ Array
Gets the window position.
-
.window_set_title(window, title = '') ⇒ Object
-
.window_set_toolbar(window, toolbar) ⇒ Object
-
.window_title(window) ⇒ Object
Class Attribute Details
.ffi_lib ⇒ Object
Returns the value of attribute ffi_lib.
9
10
11
|
# File 'lib/libui.rb', line 9
def ffi_lib
@ffi_lib
end
|
Class Method Details
.attribute_color(attribute) ⇒ Object
487
488
489
|
# File 'lib/libui.rb', line 487
def attribute_color(attribute)
read_outputs('d', 4) { |r, g, b, a| super(attribute, r, g, b, a) }
end
|
.attribute_family(attribute) ⇒ Object
419
420
421
|
# File 'lib/libui.rb', line 419
def attribute_family(attribute)
read_borrowed_text(super(attribute))
end
|
.attribute_features(attribute) ⇒ Object
678
679
680
681
682
683
|
# File 'lib/libui.rb', line 678
def attribute_features(attribute)
borrowed = super(attribute)
return nil if borrowed.nil? || borrowed.null?
open_type_features_for_each(borrowed).to_h
end
|
.attribute_underline_color(attribute) ⇒ Object
491
492
493
494
495
496
497
498
499
|
# File 'lib/libui.rb', line 491
def attribute_underline_color(attribute)
color = nil
underline = read_outputs('i', 1) do |type|
color = read_outputs('d', 4) do |r, g, b, a|
super(attribute, type, r, g, b, a)
end
end
underline + color
end
|
.attributed_string_append_unattributed(attributed_string, str = '') ⇒ Object
328
329
330
|
# File 'lib/libui.rb', line 328
def attributed_string_append_unattributed(attributed_string, str = '')
super(attributed_string, str)
end
|
.attributed_string_for_each_attribute(string) ⇒ Object
Values are copied during the callback; native attribute pointers expire
as soon as the callback returns.
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
|
# File 'lib/libui.rb', line 687
def attributed_string_for_each_attribute(string)
return enum_for(__method__, string) unless block_given?
error = nil
callback = Fiddle::Closure::BlockCaller.new(Fiddle::TYPE_INT,
[Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP,
Fiddle::TYPE_SIZE_T, Fiddle::TYPE_SIZE_T,
Fiddle::TYPE_VOIDP]) do |_string, attribute, first, last, _data|
begin
yield(attribute_snapshot(attribute), first, last) == ForEachStop ? ForEachStop : ForEachContinue
rescue StandardError => e
error = e
ForEachStop
end
end
FFI.uiAttributedStringForEachAttribute(string, callback, nil)
raise error if error
string
end
|
.attributed_string_string(attributed_string) ⇒ Object
423
424
425
|
# File 'lib/libui.rb', line 423
def attributed_string_string(attributed_string)
read_borrowed_text(super(attributed_string))
end
|
.button_set_text(button, text = '') ⇒ Object
248
249
250
|
# File 'lib/libui.rb', line 248
def button_set_text(button, text = '')
super(button, text)
end
|
.button_text(button) ⇒ Object
379
380
381
|
# File 'lib/libui.rb', line 379
def button_text(button)
read_owned_text(super(button))
end
|
.checkbox_set_text(checkbox, text = '') ⇒ Object
252
253
254
|
# File 'lib/libui.rb', line 252
def checkbox_set_text(checkbox, text = '')
super(checkbox, text)
end
|
.checkbox_text(checkbox) ⇒ Object
383
384
385
|
# File 'lib/libui.rb', line 383
def checkbox_text(checkbox)
read_owned_text(super(checkbox))
end
|
479
480
481
|
# File 'lib/libui.rb', line 479
def color_button_color(button)
read_outputs('d', 4) { |r, g, b, a| super(button, r, g, b, a) }
end
|
.combobox_append(combobox, text = '') ⇒ Object
276
277
278
|
# File 'lib/libui.rb', line 276
def combobox_append(combobox, text = '')
super(combobox, text)
end
|
.combobox_insert_at(combobox, index, text = '') ⇒ Object
280
281
282
|
# File 'lib/libui.rb', line 280
def combobox_insert_at(combobox, index, text = '')
super(combobox, index, text)
end
|
.control_on_destroyed(control, callback = nil, data = nil, &block) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/libui.rb', line 35
def control_on_destroyed(control, callback = nil, data = nil, &block)
callback = block if block
unless callback.nil? || callback.respond_to?(:call)
raise TypeError, 'expected a callable destruction callback'
end
CallbackRegistry.on_destroyed(control, callback, data)
nil
end
|
.date_time_picker_set_time(picker, value) ⇒ Object
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
# File 'lib/libui.rb', line 446
def date_time_picker_set_time(picker, value)
local_time = case value
when Time, DateTime then value.to_time.getlocal
when Date then Time.local(value.year, value.month, value.day)
else raise TypeError, 'expected Time, DateTime, or Date'
end
tm = FFI::TM.malloc
tm.to_ptr.free = Fiddle::RUBY_FREE
tm.to_ptr[0, FFI::TM.size] = "\0" * FFI::TM.size
tm.tm_sec = local_time.sec
tm.tm_min = local_time.min
tm.tm_hour = local_time.hour
tm.tm_mday = local_time.day
tm.tm_mon = local_time.month - 1
tm.tm_year = local_time.year - 1900
tm.tm_wday = local_time.wday
tm.tm_yday = local_time.yday - 1
tm.tm_isdst = Fiddle::WINDOWS ? -1 : (local_time.dst? ? 1 : 0)
super(picker, tm)
end
|
.date_time_picker_time(picker) ⇒ Object
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
# File 'lib/libui.rb', line 431
def date_time_picker_time(picker)
tm = FFI::TM.malloc
tm.to_ptr.free = Fiddle::RUBY_FREE
super(picker, tm)
if tm.tm_isdst.negative?
Time.local(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec)
else
Time.local(tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday,
tm.tm_mon + 1, tm.tm_year + 1900, 0, 0,
tm.tm_isdst != 0, nil)
end
end
|
.draw_clip(context, path) ⇒ Object
206
207
208
|
# File 'lib/libui.rb', line 206
def draw_clip(context, path)
super(context, path.is_a?(Path) ? path.to_ptr : path)
end
|
.draw_fill(context, path, brush) ⇒ Object
195
196
197
198
|
# File 'lib/libui.rb', line 195
def draw_fill(context, path, brush)
super(context, path.is_a?(Path) ? path.to_ptr : path,
brush.is_a?(Brush) ? brush.to_ptr : brush)
end
|
505
506
507
508
509
510
511
512
513
514
|
# File 'lib/libui.rb', line 505
def draw_matrix_transform_point(matrix, x, y)
matrix = matrix.to_ptr if matrix.is_a?(Matrix)
x_pointer = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
y_pointer = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
x_pointer[0, Fiddle::SIZEOF_DOUBLE] = [x].pack('d')
y_pointer[0, Fiddle::SIZEOF_DOUBLE] = [y].pack('d')
super(matrix, x_pointer, y_pointer)
[x_pointer[0, Fiddle::SIZEOF_DOUBLE].unpack1('d'),
y_pointer[0, Fiddle::SIZEOF_DOUBLE].unpack1('d')]
end
|
516
517
518
519
520
521
522
523
524
525
|
# File 'lib/libui.rb', line 516
def draw_matrix_transform_size(matrix, x, y)
matrix = matrix.to_ptr if matrix.is_a?(Matrix)
x_pointer = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
y_pointer = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
x_pointer[0, Fiddle::SIZEOF_DOUBLE] = [x].pack('d')
y_pointer[0, Fiddle::SIZEOF_DOUBLE] = [y].pack('d')
super(matrix, x_pointer, y_pointer)
[x_pointer[0, Fiddle::SIZEOF_DOUBLE].unpack1('d'),
y_pointer[0, Fiddle::SIZEOF_DOUBLE].unpack1('d')]
end
|
.draw_new_text_layout(string_or_params, font: nil, width: -1,, align: DrawTextAlignLeft) ⇒ Object
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
# File 'lib/libui.rb', line 348
def draw_new_text_layout(string_or_params, font: nil, width: -1, align: DrawTextAlignLeft)
return super(string_or_params) if font.nil?
raise TypeError, 'expected LibUI::Font' unless font.is_a?(Font)
native_family = Fiddle::Pointer.malloc(font.family.bytesize + 1, Fiddle::RUBY_FREE)
native_family[0, font.family.bytesize + 1] = font.family + "\0"
native_font = FFI::FontDescriptor.malloc
native_font.to_ptr.free = Fiddle::RUBY_FREE
native_font.Family = native_family
native_font.Size = font.size
native_font.Weight = font.weight
native_font.Italic = font.italic
native_font.Stretch = font.stretch
params = FFI::DrawTextLayoutParams.malloc
params.to_ptr.free = Fiddle::RUBY_FREE
params.String = string_or_params
params.DefaultFont = native_font
params.Width = width
params.Align = align
result = super(params)
native_font.to_ptr.to_i
native_family.to_i
result
end
|
.draw_stroke(context, path, brush, stroke_params) ⇒ Object
200
201
202
203
204
|
# File 'lib/libui.rb', line 200
def draw_stroke(context, path, brush, stroke_params)
super(context, path.is_a?(Path) ? path.to_ptr : path,
brush.is_a?(Brush) ? brush.to_ptr : brush,
stroke_params.is_a?(StrokeParams) ? stroke_params.to_ptr : stroke_params)
end
|
.draw_text_layout_extents(layout) ⇒ Object
501
502
503
|
# File 'lib/libui.rb', line 501
def draw_text_layout_extents(layout)
read_outputs('d', 2) { |width, height| super(layout, width, height) }
end
|
210
211
212
|
# File 'lib/libui.rb', line 210
def draw_transform(context, matrix)
super(context, matrix.is_a?(Matrix) ? matrix.to_ptr : matrix)
end
|
.editable_combobox_append(combobox, text = '') ⇒ Object
284
285
286
|
# File 'lib/libui.rb', line 284
def editable_combobox_append(combobox, text = '')
super(combobox, text)
end
|
.editable_combobox_set_text(combobox, text = '') ⇒ Object
288
289
290
|
# File 'lib/libui.rb', line 288
def editable_combobox_set_text(combobox, text = '')
super(combobox, text)
end
|
.editable_combobox_text(combobox) ⇒ Object
399
400
401
|
# File 'lib/libui.rb', line 399
def editable_combobox_text(combobox)
read_owned_text(super(combobox))
end
|
.entry_set_text(entry, text = '') ⇒ Object
256
257
258
|
# File 'lib/libui.rb', line 256
def entry_set_text(entry, text = '')
super(entry, text)
end
|
.entry_text(entry) ⇒ Object
387
388
389
|
# File 'lib/libui.rb', line 387
def entry_text(entry)
read_owned_text(super(entry))
end
|
342
343
344
345
346
|
# File 'lib/libui.rb', line 342
def font_button_font(button, descriptor = nil)
return super(button, descriptor) if descriptor
read_font_descriptor { |native| super(button, native) }
end
|
.free_table_model(model) ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/libui.rb', line 150
def free_table_model(model)
return model.free if model.is_a?(TableModel)
result = super(model)
CallbackRegistry.release_other(model)
result
end
|
110
111
112
113
114
115
116
|
# File 'lib/libui.rb', line 110
def free_toolbar(toolbar)
raise RuntimeError, 'detach toolbar from its window before freeing it' if CallbackRegistry.toolbar_attached?(toolbar)
result = super(toolbar)
CallbackRegistry.release_other(toolbar)
result
end
|
.group_set_title(group, title = '') ⇒ Object
268
269
270
|
# File 'lib/libui.rb', line 268
def group_set_title(group, title = '')
super(group, title)
end
|
.group_title(group) ⇒ Object
395
396
397
|
# File 'lib/libui.rb', line 395
def group_title(group)
read_owned_text(super(group))
end
|
.image_append(image, pixels, width, height, byte_stride) ⇒ Object
The native function copies the pixels before returning. The input must be
premultiplied RGBA, with rows separated by byte_stride bytes.
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
# File 'lib/libui.rb', line 615
def image_append(image, pixels, width, height, byte_stride)
[width, height, byte_stride].each do |number|
raise TypeError, 'image dimensions and stride must be Integers' unless number.is_a?(Integer)
end
raise ArgumentError, 'image dimensions must be positive' if width <= 0 || height <= 0
max_int = (1 << (Fiddle::SIZEOF_INT * 8 - 1)) - 1
raise RangeError, 'image dimensions or stride exceed C int' if [width, height, byte_stride].any? { |number| number > max_int }
raise ArgumentError, 'byte stride is too small' if byte_stride < width * 4
raise TypeError, 'pixels must be a String or Fiddle::Pointer' unless pixels.is_a?(String) || pixels.is_a?(Fiddle::Pointer)
if pixels.is_a?(String) && pixels.bytesize < byte_stride * height
raise ArgumentError, 'pixel buffer is shorter than stride * height'
end
if pixels.is_a?(Fiddle::Pointer) && pixels.size.positive? && pixels.size < byte_stride * height
raise ArgumentError, 'pixel buffer is shorter than stride * height'
end
super(image, pixels, width, height, byte_stride)
end
|
.image_append_rgba(image, pixels, width, height, byte_stride = width * 4) ⇒ Object
Convert straight RGBA (as used by PNG libraries) to premultiplied RGBA.
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
|
# File 'lib/libui.rb', line 635
def image_append_rgba(image, pixels, width, height, byte_stride = width * 4)
raise TypeError, 'pixels must be a String' unless pixels.is_a?(String)
[width, height, byte_stride].each do |number|
raise TypeError, 'image dimensions and stride must be Integers' unless number.is_a?(Integer)
end
raise ArgumentError, 'image dimensions must be positive' if width <= 0 || height <= 0
raise ArgumentError, 'byte stride is too small' if byte_stride < width * 4
raise ArgumentError, 'pixel buffer is shorter than stride * height' if pixels.bytesize < byte_stride * height
converted = pixels.b.dup
height.times do |y|
width.times do |x|
offset = y * byte_stride + x * 4
alpha = converted.getbyte(offset + 3)
3.times do |channel|
converted.setbyte(offset + channel, (converted.getbyte(offset + channel) * alpha + 127) / 255)
end
end
end
image_append(image, converted, width, height, byte_stride)
end
|
.init(opt = nil) ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/libui.rb', line 218
def init(opt = nil)
unless opt
opt = FFI::InitOptions.malloc
opt.to_ptr.free = Fiddle::RUBY_FREE
opt.Size = FFI::InitOptions.size
end
err_ptr = super(opt) return nil if err_ptr.null?
err_msg = err_ptr.to_s
free_init_error(err_ptr)
warn err_msg
nil
end
|
.label_set_text(label, text = '') ⇒ Object
260
261
262
|
# File 'lib/libui.rb', line 260
def label_set_text(label, text = '')
super(label, text)
end
|
.label_text(label) ⇒ Object
391
392
393
|
# File 'lib/libui.rb', line 391
def label_text(label)
read_owned_text(super(label))
end
|
.load_control_font(descriptor = nil) ⇒ Object
336
337
338
339
340
|
# File 'lib/libui.rb', line 336
def load_control_font(descriptor = nil)
return super(descriptor) if descriptor
read_font_descriptor { |native| super(native) }
end
|
308
309
310
|
# File 'lib/libui.rb', line 308
def (, name = '')
super(, name)
end
|
304
305
306
|
# File 'lib/libui.rb', line 304
def (, name = '')
super(, name)
end
|
.msg_box(parent, title, description = '') ⇒ Object
316
317
318
|
# File 'lib/libui.rb', line 316
def msg_box(parent, title, description = '')
super(parent, title, description)
end
|
.msg_box_error(parent, title, description = '') ⇒ Object
320
321
322
|
# File 'lib/libui.rb', line 320
def msg_box_error(parent, title, description = '')
super(parent, title, description)
end
|
.multiline_entry_append(entry, text = '') ⇒ Object
300
301
302
|
# File 'lib/libui.rb', line 300
def multiline_entry_append(entry, text = '')
super(entry, text)
end
|
.multiline_entry_set_text(entry, text = '') ⇒ Object
296
297
298
|
# File 'lib/libui.rb', line 296
def multiline_entry_set_text(entry, text = '')
super(entry, text)
end
|
.multiline_entry_text(entry) ⇒ Object
403
404
405
|
# File 'lib/libui.rb', line 403
def multiline_entry_text(entry)
read_owned_text(super(entry))
end
|
.new_area(handler) ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/libui.rb', line 124
def new_area(handler)
return super(handler) unless handler.is_a?(AreaHandler)
area = super(handler.to_ptr)
CallbackRegistry.control(area, :area_handler, handler)
area
end
|
.new_attributed_string(initial_string = '') ⇒ Object
324
325
326
|
# File 'lib/libui.rb', line 324
def new_attributed_string(initial_string = '')
super(initial_string)
end
|
236
237
238
|
# File 'lib/libui.rb', line 236
def new_button(text = '')
super(text)
end
|
.new_checkbox(text = '') ⇒ Object
240
241
242
|
# File 'lib/libui.rb', line 240
def new_checkbox(text = '')
super(text)
end
|
.new_group(title = '') ⇒ Object
272
273
274
|
# File 'lib/libui.rb', line 272
def new_group(title = '')
super(title)
end
|
.new_label(text = '') ⇒ Object
264
265
266
|
# File 'lib/libui.rb', line 264
def new_label(text = '')
super(text)
end
|
312
313
314
|
# File 'lib/libui.rb', line 312
def (name = '')
super(name)
end
|
132
133
134
135
136
137
138
|
# File 'lib/libui.rb', line 132
def new_scrolling_area(handler, width, height)
return super(handler, width, height) unless handler.is_a?(AreaHandler)
area = super(handler.to_ptr, width, height)
CallbackRegistry.control(area, :area_handler, handler)
area
end
|
.new_table(params = nil, model: nil, row_background_color_model_column: -1)) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/libui.rb', line 158
def new_table(params = nil, model: nil, row_background_color_model_column: -1)
return super(params) if model.nil?
raise ArgumentError, 'provide params or model, not both' unless params.nil?
raise TypeError, 'expected LibUI::TableModel' unless model.is_a?(TableModel)
native = FFI::TableParams.malloc
native.to_ptr.free = Fiddle::RUBY_FREE
native.Model = model.to_ptr
native.RowBackgroundColorModelColumn = row_background_color_model_column
table = super(native)
CallbackRegistry.control(table, :table_model, model)
CallbackRegistry.on_cleanup(table) { model.detach_table }
model.attach_table
table
end
|
.new_table_model(handler) ⇒ Object
140
141
142
143
144
145
146
147
148
|
# File 'lib/libui.rb', line 140
def new_table_model(handler)
return super(handler) unless handler.is_a?(TableModelHandler)
model = super(handler.to_ptr)
raise RuntimeError, 'libui-ng could not create table model' if model.nil? || model.null?
CallbackRegistry.other(model, :table_model_handler, handler)
model
end
|
.new_table_value_string(str = '') ⇒ Object
332
333
334
|
# File 'lib/libui.rb', line 332
def new_table_value_string(str = '')
super(str)
end
|
.open_file(window) ⇒ Object
407
408
409
|
# File 'lib/libui.rb', line 407
def open_file(window)
read_owned_text(super(window))
end
|
.open_folder(window) ⇒ Object
411
412
413
|
# File 'lib/libui.rb', line 411
def open_folder(window)
read_owned_text(super(window))
end
|
.open_type_features_add(otf, a, b, c, d, value) ⇒ Object
595
596
597
598
|
# File 'lib/libui.rb', line 595
def open_type_features_add(otf, a, b, c, d, value)
a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
super(otf, a, b, c, d, value)
end
|
.open_type_features_for_each(features) ⇒ Object
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
|
# File 'lib/libui.rb', line 657
def open_type_features_for_each(features)
return enum_for(__method__, features) unless block_given?
error = nil
callback = Fiddle::Closure::BlockCaller.new(Fiddle::TYPE_INT,
[Fiddle::TYPE_VOIDP] + [Fiddle::TYPE_CHAR] * 4 +
[Fiddle::TYPE_UINT32_T, Fiddle::TYPE_VOIDP]) do |_features, a, b, c, d, value, _data|
begin
tag = [a, b, c, d].pack('C*').force_encoding(Encoding::ASCII_8BIT)
yield(tag, value) == ForEachStop ? ForEachStop : ForEachContinue
rescue StandardError => e
error = e
ForEachStop
end
end
FFI.uiOpenTypeFeaturesForEach(features, callback, nil)
raise error if error
features
end
|
.open_type_features_get(otf, a, b, c, d) ⇒ Object
605
606
607
608
609
610
611
|
# File 'lib/libui.rb', line 605
def open_type_features_get(otf, a, b, c, d)
a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
value = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
return nil if super(otf, a, b, c, d, value).zero?
value[0, Fiddle::SIZEOF_INT].unpack1('L')
end
|
.open_type_features_remove(otf, a, b, c, d) ⇒ Object
600
601
602
603
|
# File 'lib/libui.rb', line 600
def open_type_features_remove(otf, a, b, c, d)
a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
super(otf, a, b, c, d)
end
|
.queue_main(callback = nil, data = nil, &block) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/libui.rb', line 44
def queue_main(callback = nil, data = nil, &block)
callback = block if block
raise TypeError, 'expected a callable callback' unless callback.respond_to?(:call)
key = Object.new
closure = nil
closure = Fiddle::Closure::BlockCaller.new(Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP]) do |native_data|
begin
callback.call(native_data)
rescue StandardError => e
CallbackRegistry.report(e)
ensure
CallbackRegistry.release_global(key)
closure.to_i
end
end
CallbackRegistry.global(key, closure)
FFI.uiQueueMain(closure, data)
rescue StandardError
CallbackRegistry.release_global(key) if key
raise
end
|
292
293
294
|
# File 'lib/libui.rb', line 292
def radio_buttons_append(radio_buttons, text = '')
super(radio_buttons, text)
end
|
.save_file(window) ⇒ Object
415
416
417
|
# File 'lib/libui.rb', line 415
def save_file(window)
read_owned_text(super(window))
end
|
.table_append_checkbox_text_column(table, name, checkbox_column, checkbox_editable_column, text_column, text_editable_column, options = nil, color_model_column: nil) ⇒ Object
186
187
188
189
190
191
192
193
|
# File 'lib/libui.rb', line 186
def table_append_checkbox_text_column(table, name, checkbox_column,
checkbox_editable_column, text_column,
text_editable_column, options = nil,
color_model_column: nil)
super(table, name, checkbox_column, checkbox_editable_column,
text_column, text_editable_column,
table_text_params(options, color_model_column))
end
|
.table_append_image_text_column(table, name, image_column, text_column, editable_column, options = nil, color_model_column: nil) ⇒ Object
180
181
182
183
184
|
# File 'lib/libui.rb', line 180
def table_append_image_text_column(table, name, image_column, text_column,
editable_column, options = nil, color_model_column: nil)
super(table, name, image_column, text_column, editable_column,
table_text_params(options, color_model_column))
end
|
.table_append_text_column(table, name, text_column, editable_column, options = nil, color_model_column: nil) ⇒ Object
174
175
176
177
178
|
# File 'lib/libui.rb', line 174
def table_append_text_column(table, name, text_column, editable_column, options = nil,
color_model_column: nil)
super(table, name, text_column, editable_column,
table_text_params(options, color_model_column))
end
|
.table_get_selection(table) ⇒ Object
527
528
529
530
531
532
533
534
535
536
537
538
|
# File 'lib/libui.rb', line 527
def table_get_selection(table)
selection = super(table)
return nil if selection.nil? || selection.null?
data = FFI::TableSelection.new(selection)
rows = data.Rows
Array.new(data.NumRows) do |index|
rows[index * Fiddle::SIZEOF_INT, Fiddle::SIZEOF_INT].unpack1('i')
end
ensure
free_table_selection(selection) if selection && !selection.null?
end
|
.table_set_selection(table, rows) ⇒ Object
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
|
# File 'lib/libui.rb', line 540
def table_set_selection(table, rows)
unless rows.is_a?(Array)
valid_native = rows.is_a?(FFI::TableSelection) ||
(rows.is_a?(Fiddle::Pointer) && !rows.null?)
raise TypeError, 'expected an Array or native uiTableSelection' unless valid_native
return super(table, rows)
end
max_int = (1 << (Fiddle::SIZEOF_INT * 8 - 1)) - 1
raise RangeError, 'too many selected rows' if rows.length > max_int
rows.each do |row|
raise TypeError, 'row index must be an Integer' unless row.is_a?(Integer)
raise RangeError, 'row index is out of range' unless row.between?(0, max_int)
end
native_rows = if rows.empty?
Fiddle::Pointer.new(0)
else
packed = rows.pack('i*')
pointer = Fiddle::Pointer.malloc(packed.bytesize, Fiddle::RUBY_FREE)
pointer[0, packed.bytesize] = packed
pointer
end
selection = FFI::TableSelection.malloc
selection.to_ptr.free = Fiddle::RUBY_FREE
selection.NumRows = rows.length
selection.Rows = native_rows
result = super(table, selection)
selection.to_ptr.to_i
native_rows.to_i
result
end
|
.table_value_color(value) ⇒ Object
483
484
485
|
# File 'lib/libui.rb', line 483
def table_value_color(value)
read_outputs('d', 4) { |r, g, b, a| super(value, r, g, b, a) }
end
|
.table_value_string(value) ⇒ Object
427
428
429
|
# File 'lib/libui.rb', line 427
def table_value_string(value)
read_borrowed_text(super(value))
end
|
.timer(milliseconds, callback = nil, data = nil, &block) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/libui.rb', line 67
def timer(milliseconds, callback = nil, data = nil, &block)
callback = block if block
raise TypeError, 'expected a callable callback' unless callback.respond_to?(:call)
key = Object.new
closure = nil
closure = Fiddle::Closure::BlockCaller.new(Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]) do |native_data|
result = begin
value = callback.call(native_data)
value == true ? 1 : (value == false || value.nil? ? 0 : Integer(value))
rescue StandardError => e
CallbackRegistry.report(e)
0
end
CallbackRegistry.release_global(key) if result.zero?
closure.to_i
result
end
CallbackRegistry.global(key, closure)
FFI.uiTimer(milliseconds, closure, data)
rescue StandardError
CallbackRegistry.release_global(key) if key
raise
end
|
98
99
100
101
102
|
# File 'lib/libui.rb', line 98
def toolbar_append_button(toolbar, text, icon = nil)
item = super(toolbar, text, icon)
CallbackRegistry.track_other_child(toolbar, item)
item
end
|
104
105
106
107
108
|
# File 'lib/libui.rb', line 104
def toolbar_append_toggle_button(toolbar, text, icon = nil)
item = super(toolbar, text, icon)
CallbackRegistry.track_other_child(toolbar, item)
item
end
|
.toolbar_item_text(item) ⇒ Object
467
468
469
|
# File 'lib/libui.rb', line 467
def toolbar_item_text(item)
read_owned_text(super(item))
end
|
471
472
473
|
# File 'lib/libui.rb', line 471
def toolbar_item_tooltip(item)
read_owned_text(super(item))
end
|
.uninit ⇒ Object
92
93
94
95
96
|
# File 'lib/libui.rb', line 92
def uninit
result = super
CallbackRegistry.clear
result
end
|
.version ⇒ Object
214
215
216
|
# File 'lib/libui.rb', line 214
def version
super.to_s
end
|
.window_content_size(window) ⇒ Object
475
476
477
|
# File 'lib/libui.rb', line 475
def window_content_size(window)
read_outputs('i', 2) { |width, height| super(window, width, height) }
end
|
.window_position(w) ⇒ Array
Note:
This method may return inaccurate or dummy values on Unix platforms.
Gets the window position.
Coordinates are measured from the top left corner of the screen.
582
583
584
585
586
587
588
589
|
# File 'lib/libui.rb', line 582
def window_position(w)
x_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
y_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
super(w, x_ptr, y_ptr)
x = x_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
y = y_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
[x, y]
end
|
.window_set_title(window, title = '') ⇒ Object
244
245
246
|
# File 'lib/libui.rb', line 244
def window_set_title(window, title = '')
super(window, title)
end
|
118
119
120
121
122
|
# File 'lib/libui.rb', line 118
def window_set_toolbar(window, toolbar)
result = super(window, toolbar)
CallbackRegistry.attach_toolbar(window, toolbar)
result
end
|
.window_title(window) ⇒ Object
375
376
377
|
# File 'lib/libui.rb', line 375
def window_title(window)
read_owned_text(super(window))
end
|