libui_paradise 0.2.48

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of libui_paradise might be problematic. Click here for more details.

Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2064 -0
  3. data/doc/README.gen +1923 -0
  4. data/doc/SNIPPETS.md +94 -0
  5. data/doc/todo/todo.md +16 -0
  6. data/lib/libui_paradise/autoinclude.rb +9 -0
  7. data/lib/libui_paradise/base/base.rb +154 -0
  8. data/lib/libui_paradise/colours/colours.rb +14 -0
  9. data/lib/libui_paradise/domain_specific_language/README.md +5 -0
  10. data/lib/libui_paradise/domain_specific_language/button.yml +7 -0
  11. data/lib/libui_paradise/examples/complex/001_hbox_example.rb +17 -0
  12. data/lib/libui_paradise/examples/complex/002_tabs_example.rb +25 -0
  13. data/lib/libui_paradise/examples/complex/003_open_file_button_example.rb +38 -0
  14. data/lib/libui_paradise/examples/complex/004_font_button.rb +41 -0
  15. data/lib/libui_paradise/examples/complex/005_search_entry_example.rb +18 -0
  16. data/lib/libui_paradise/examples/complex/006_coloured_boxes_example.rb +22 -0
  17. data/lib/libui_paradise/examples/complex/007_slider_example.rb +31 -0
  18. data/lib/libui_paradise/examples/complex/008_radio_button_example.rb +23 -0
  19. data/lib/libui_paradise/examples/complex/009_separator_example.rb +25 -0
  20. data/lib/libui_paradise/examples/complex/010_table_example.rb +55 -0
  21. data/lib/libui_paradise/examples/complex/011_two_buttons_showing_how_to_enable_and_disable_them.rb +32 -0
  22. data/lib/libui_paradise/examples/complex/012_password_entry_example.rb +29 -0
  23. data/lib/libui_paradise/examples/complex/013_form_example.rb +38 -0
  24. data/lib/libui_paradise/examples/complex/014_text_example.rb +18 -0
  25. data/lib/libui_paradise/examples/complex/015_text_view_example.rb +16 -0
  26. data/lib/libui_paradise/examples/complex/016_grid_example.rb +31 -0
  27. data/lib/libui_paradise/examples/complex/017_unicode_text_example.rb +30 -0
  28. data/lib/libui_paradise/examples/complex/018_spinbutton_example.rb +33 -0
  29. data/lib/libui_paradise/examples/complex/019_combo_box_example.rb +50 -0
  30. data/lib/libui_paradise/examples/complex/020_checkbox_example.rb +81 -0
  31. data/lib/libui_paradise/examples/complex/021_font_example.rb +115 -0
  32. data/lib/libui_paradise/examples/complex/022_simple_notepad_example.rb +25 -0
  33. data/lib/libui_paradise/examples/complex/023_msg_box_error.rb +27 -0
  34. data/lib/libui_paradise/examples/complex/024_parse_config_file_example.config +6 -0
  35. data/lib/libui_paradise/examples/complex/024_parse_config_file_example.rb +15 -0
  36. data/lib/libui_paradise/examples/complex/025_colour_button.rb +53 -0
  37. data/lib/libui_paradise/examples/complex/026_basic_table_image.rb +96 -0
  38. data/lib/libui_paradise/examples/complex/027_basic_button_example.rb +19 -0
  39. data/lib/libui_paradise/examples/complex/028_try_for_automatic_button_press_event_after_a_delay.rb +47 -0
  40. data/lib/libui_paradise/examples/complex/029_progressbar_example.rb +116 -0
  41. data/lib/libui_paradise/examples/complex/030_entry_responds_to_comment_as_synonymous_to_the_enter_key_pressed_example.rb +140 -0
  42. data/lib/libui_paradise/examples/complex/031_notification_functionality_example.rb +96 -0
  43. data/lib/libui_paradise/examples/complex/032_simple_window_example.rb +69 -0
  44. data/lib/libui_paradise/examples/complex/033_daemonize_and_exit_after_delay_example.rb +91 -0
  45. data/lib/libui_paradise/examples/simple/001_open_file_example.rb +35 -0
  46. data/lib/libui_paradise/examples/simple/002_histogram_example.rb +207 -0
  47. data/lib/libui_paradise/examples/simple/003_fancy_text_example.rb +220 -0
  48. data/lib/libui_paradise/examples/simple/004_date_time_picker.rb +52 -0
  49. data/lib/libui_paradise/examples/simple/005_text_drawing_example.rb +185 -0
  50. data/lib/libui_paradise/examples/simple/006_midi_player.rb +96 -0
  51. data/lib/libui_paradise/examples/simple/007_control_gallery.rb +191 -0
  52. data/lib/libui_paradise/examples/simple/008_basic_area_example.rb +56 -0
  53. data/lib/libui_paradise/examples/simple/009_spectrum.rb +107 -0
  54. data/lib/libui_paradise/examples/simple/README.md +7 -0
  55. data/lib/libui_paradise/experimental/dsl.rb +17 -0
  56. data/lib/libui_paradise/extensions/counters.rb +58 -0
  57. data/lib/libui_paradise/extensions/extensions.rb +29 -0
  58. data/lib/libui_paradise/extensions/hash_fiddle_pointer_widgets.rb +150 -0
  59. data/lib/libui_paradise/extensions/misc.rb +754 -0
  60. data/lib/libui_paradise/fiddle/pointer.rb +1157 -0
  61. data/lib/libui_paradise/generic_window/README.md +9 -0
  62. data/lib/libui_paradise/generic_window/generic_window.rb +79 -0
  63. data/lib/libui_paradise/images/LIBUI_PARADISE_LOGO.png +0 -0
  64. data/lib/libui_paradise/images/README.md +2 -0
  65. data/lib/libui_paradise/images/form_example.png +0 -0
  66. data/lib/libui_paradise/libui_classes/box.rb +156 -0
  67. data/lib/libui_paradise/libui_classes/grid.rb +55 -0
  68. data/lib/libui_paradise/libui_classes/libui_classes.rb +1610 -0
  69. data/lib/libui_paradise/project/project.rb +28 -0
  70. data/lib/libui_paradise/prototype/README.md +3 -0
  71. data/lib/libui_paradise/prototype/prototype.rb +107 -0
  72. data/lib/libui_paradise/requires/require_the_libui_classes.rb +29 -0
  73. data/lib/libui_paradise/requires/require_the_libui_paradise_project.rb +12 -0
  74. data/lib/libui_paradise/toplevel_methods/misc.rb +13 -0
  75. data/lib/libui_paradise/version/version.rb +17 -0
  76. data/lib/libui_paradise.rb +1 -0
  77. data/libui_paradise.gemspec +49 -0
  78. data/test/testing_generic_window.rb +19 -0
  79. metadata +156 -0
@@ -0,0 +1,1610 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'libui_paradise/libui_classes/libui_classes.rb
6
+ # =========================================================================== #
7
+ module LibuiParadise
8
+
9
+ module Extensions # === LibuiParadise::Extensions
10
+
11
+ require 'libui_paradise/libui_classes/box.rb'
12
+ require 'libui_paradise/libui_classes/grid.rb'
13
+
14
+ # ========================================================================= #
15
+ # === button (button tag)
16
+ #
17
+ # This method will create a libui-button.
18
+ # ========================================================================= #
19
+ def button(
20
+ text = ''
21
+ )
22
+ text = text.to_s.dup
23
+ if text.start_with? '_'
24
+ text[0,1] = '' # Right now we do not support accelerators.
25
+ end
26
+ ::LibuiParadise::Extensions.button(text)
27
+ end; alias ui_button button # === ui_button
28
+
29
+ # ========================================================================= #
30
+ # === LibuiParadise::Extensions.msg_box
31
+ #
32
+ # Official API documentation for dialogs in libui can be found here:
33
+ #
34
+ # https://github.com/andlabs/libui/blob/master/unix/stddialogs.c
35
+ #
36
+ # For libui-ng it can be found here:
37
+ #
38
+ # https://github.com/libui-ng/libui-ng/blob/master/unix/stddialogs.c
39
+ #
40
+ # The API signature for msgbox in Libui is as follows:
41
+ #
42
+ # GtkWindow *parent
43
+ # const char *title
44
+ # const char *description
45
+ # GtkMessageType type
46
+ # GtkButtonsType buttons
47
+ #
48
+ # So the first string is the title and the second string is the
49
+ # description that will be shown to the user.
50
+ #
51
+ # The following method is a convenience-wrapper over UI.msg_box().
52
+ #
53
+ # A Hash can also be passed into this method, to allow for more
54
+ # flexibility. The following line of code will demonstrate how
55
+ # this can then be used, via a Hash:
56
+ #
57
+ # message_box(
58
+ # text: 'Hello world!'
59
+ # )
60
+ #
61
+ # Or more verbose:
62
+ #
63
+ # LibuiParadise::Extensions.message_box(text: 'Hello world!')
64
+ #
65
+ # ========================================================================= #
66
+ def self.msg_box(
67
+ main_window = :default_window,
68
+ title_to_use = '',
69
+ description_to_use = ''
70
+ )
71
+ # ======================================================================= #
72
+ # === Handle Hashes first
73
+ # ======================================================================= #
74
+ if main_window.is_a? Hash
75
+ # ===================================================================== #
76
+ # === :text
77
+ # ===================================================================== #
78
+ if main_window.has_key? :text
79
+ description_to_use = main_window.delete(:text)
80
+ end
81
+ # ===================================================================== #
82
+ # === :title_to_use
83
+ # ===================================================================== #
84
+ if main_window.has_key? :title_to_use
85
+ title_to_use = main_window.delete(:title_to_use)
86
+ end
87
+ if main_window and main_window.empty? # Handle empty Hashes as well here.
88
+ main_window = :default_window
89
+ end
90
+ end
91
+ case main_window
92
+ # ======================================================================= #
93
+ # === :default_window
94
+ # ======================================================================= #
95
+ when :default_window,
96
+ :default
97
+ main_window = ::LibuiParadise.main_window?
98
+ end
99
+ _ = ::LibUI.msg_box(
100
+ main_window,
101
+ title_to_use,
102
+ description_to_use
103
+ )
104
+ add_to_the_registered_widgets(_, __method__)
105
+ return _
106
+ end; self.instance_eval { alias ui_msg_box msg_box } # === LibuiParadise::Extensions.ui_msg_box
107
+ self.instance_eval { alias message_to_the_user msg_box } # === LibuiParadise::Extensions.message_to_the_user
108
+ self.instance_eval { alias message_box msg_box } # === LibuiParadise::Extensions.message_box
109
+ self.instance_eval { alias popup_over_this_widget msg_box } # === LibuiParadise::Extensions.popup_over_this_widget
110
+
111
+ # ========================================================================= #
112
+ # === LibuiParadise::Extensions.message_box_error
113
+ # ========================================================================= #
114
+ def self.message_box_error(
115
+ main_window = LibuiParadise.main_window?,
116
+ title_to_use = '',
117
+ whatever = ''
118
+ )
119
+ case main_window
120
+ # ======================================================================= #
121
+ # === :default
122
+ # ======================================================================= #
123
+ when :default
124
+ main_window = LibuiParadise.main_window?
125
+ end
126
+ _ = ::LibUI.msg_box_error(
127
+ main_window,
128
+ title_to_use,
129
+ whatever
130
+ )
131
+ add_to_the_registered_widgets(_, __method__)
132
+ return _
133
+ end; self.instance_eval { alias ui_msg_box_error message_box_error } # === LibuiParadise::Extensions.ui_msg_box_error
134
+ self.instance_eval { alias ui_error_msg message_box_error } # === LibuiParadise::Extensions.ui_error_msg
135
+ self.instance_eval { alias ui_error_message message_box_error } # === LibuiParadise::Extensions.ui_error_message
136
+ self.instance_eval { alias error_message_to_the_user message_box_error } # === LibuiParadise::Extensions.error_message_to_the_user
137
+ self.instance_eval { alias error_msg message_box_error } # === LibuiParadise::Extensions.error_msg
138
+
139
+ # ========================================================================= #
140
+ # === message_box_error
141
+ # ========================================================================= #
142
+ def message_box_error(
143
+ main_window = LibuiParadise.main_window?,
144
+ title_to_use = '',
145
+ whatever = ''
146
+ )
147
+ return ::LibuiParadise::Extensions.message_box_error(
148
+ main_window,
149
+ title_to_use,
150
+ whatever
151
+ )
152
+ end; alias ui_msg_box_error message_box_error # === ui_msg_box_error
153
+ alias ui_error_message message_box_error # === ui_error_message
154
+ alias ui_error_msg message_box_error # === ui_error_msg
155
+ alias error_message_to_the_user message_box_error # === error_message_to_the_user
156
+
157
+ # ========================================================================= #
158
+ # === error_msg
159
+ # ========================================================================= #
160
+ def error_msg(text)
161
+ message_box_error(:default, text)
162
+ end
163
+
164
+ # ========================================================================= #
165
+ # === ui_msg_box
166
+ #
167
+ # This method is a convenience-wrapper over UI.msg_box().
168
+ # ========================================================================= #
169
+ def ui_msg_box(
170
+ main_window = :default_window,
171
+ title_to_use = '',
172
+ whatever = ''
173
+ )
174
+ ::LibuiParadise::Extensions.msg_box(
175
+ main_window,
176
+ title_to_use,
177
+ whatever
178
+ )
179
+ end; alias message_to_the_user ui_msg_box # === message_to_the_user
180
+ alias message_box ui_msg_box # === message_box
181
+ alias popup_over_this_widget ui_msg_box # === popup_over_this_widget
182
+ alias popup_message ui_msg_box # === popup_message
183
+ # alias msg_box ui_msg_box # === msg_box
184
+ # ^^^ this would lead to an error.
185
+
186
+ # ========================================================================= #
187
+ # === LibuiParadise::Extensions.wrapper_new_progress_bar
188
+ #
189
+ # The name of this method contains "wrapper_" because there already
190
+ # exists a method called LibUI.new_progress_bar().
191
+ #
192
+ # The upstream C API for the libui-progressbar can be found here:
193
+ #
194
+ # https://github.com/andlabs/libui/blob/master/unix/progressbar.c
195
+ #
196
+ # ========================================================================= #
197
+ def self.wrapper_new_progress_bar
198
+ _ = ::LibUI.new_progress_bar
199
+ add_to_the_registered_widgets(_, :new_progress_bar)
200
+ return _
201
+ end
202
+
203
+ # ========================================================================= #
204
+ # === wrapper_new_progress_bar
205
+ # ========================================================================= #
206
+ def wrapper_new_progress_bar
207
+ return ::LibuiParadise::Extensions.wrapper_new_progress_bar
208
+ end; alias progress_bar wrapper_new_progress_bar # === progress_bar
209
+
210
+ # ========================================================================= #
211
+ # === LibuiParadise::Extensions.open_file
212
+ #
213
+ # This method can be used to open a local file, via a button, the
214
+ # "open-file" button. Furthermore a begin/rescue clause is used to
215
+ # avoid "NULL pointer given" errors. At a later time we may
216
+ # have to fine-tune this, but for now this shall suffice.
217
+ # ========================================================================= #
218
+ def self.open_file(
219
+ main_window = ::LibuiParadise::Extensions.main_window?
220
+ )
221
+ begin
222
+ _ = ::LibUI.open_file(main_window)
223
+ add_to_the_registered_widgets(_, __method__)
224
+ return _
225
+ rescue ArgumentError => _error # Rescue #<ArgumentError: NULL pointer given> here.
226
+ # pp _error
227
+ return nil
228
+ end
229
+ end; self.instance_eval { alias ui_open_file open_file } # === LibuiParadise::Extensions.ui_open_file
230
+
231
+ # ========================================================================= #
232
+ # === ui_open_file
233
+ # ========================================================================= #
234
+ def ui_open_file(
235
+ main_window = ::LibuiParadise::Extensions.main_window?
236
+ )
237
+ return ::LibuiParadise::Extensions.open_file(main_window)
238
+ end
239
+
240
+ # ========================================================================= #
241
+ # === open_file
242
+ #
243
+ # This here creates a problem, because ::Libui.open_file is already
244
+ # defined. We'd have to use an alias to make this work.
245
+ # ========================================================================= #
246
+ # def open_file(
247
+ # main_window = LibuiParadise::Extensions.main_window?
248
+ # )
249
+ # return ::LibuiParadise::Extensions.open_file(main_window)
250
+ # end; alias ui_open_file open_file # === ui_open_file
251
+
252
+ # ========================================================================= #
253
+ # === @main_window
254
+ #
255
+ # This variable can be used to keep track of the main window in use.
256
+ # ========================================================================= #
257
+ @main_window = nil
258
+
259
+ # ========================================================================= #
260
+ # === LibuiParadise::Extensions.main_window?
261
+ # ========================================================================= #
262
+ def self.main_window?
263
+ @main_window
264
+ end
265
+
266
+ # ========================================================================= #
267
+ # === main_window?
268
+ # ========================================================================= #
269
+ def main_window?
270
+ ::LibuiParadise::Extensions.main_window?
271
+ end
272
+
273
+ # ========================================================================= #
274
+ # === LibuiParadise::Extensions.set_main_window
275
+ # ========================================================================= #
276
+ def self.set_main_window(i)
277
+ @main_window = i
278
+ end
279
+
280
+ # ========================================================================= #
281
+ # === LibuiParadise::Extensions.window (window tag)
282
+ #
283
+ # This method will create a new main-window.
284
+ #
285
+ # It will also call UI.simple_exit(). This is done mostly so that we
286
+ # can omit that line whenever we use e. g. ui_main_window().
287
+ # ========================================================================= #
288
+ def self.window(
289
+ the_title = '', # Pick a title for the window here.
290
+ width = 500, # width in n pixels.
291
+ height = 300, # height in n pixels.
292
+ has_menubar = 1, # hasMenubar or has not.
293
+ &block
294
+ )
295
+ case the_title
296
+ # ======================================================================= #
297
+ # === :filename
298
+ # ======================================================================= #
299
+ when :filename,
300
+ :file_name
301
+ # ===================================================================== #
302
+ # __FILE__ contains the desired name. We only need the raw name, though.
303
+ # Well, in 2022 it was realized that the real filename is stored in
304
+ # $PROGRAM_NAME, so ...
305
+ # ===================================================================== #
306
+ the_title = File.basename($PROGRAM_NAME) # (__FILE__)
307
+ end
308
+ raw_has_menubar = 0
309
+ if has_menubar.is_a? Numeric
310
+ raw_has_menubar = has_menubar
311
+ end
312
+ # ======================================================================= #
313
+ # Instantiate a new main-window next:
314
+ # ======================================================================= #
315
+ main_window = LibUI.new_window(
316
+ the_title,
317
+ width,
318
+ height,
319
+ raw_has_menubar
320
+ )
321
+ set_main_window(main_window) # Keep a reference stored here.
322
+ # ======================================================================= #
323
+ # Since as of 30.08.2021 we will also register the main-window.
324
+ #
325
+ # In the long run we may obsolete and deprecate @main_window, since
326
+ # it is no longer needed - but for now we will retain that variable.
327
+ # ======================================================================= #
328
+ add_to_the_registered_widgets(main_window, __method__)
329
+ if has_menubar and has_menubar.is_a?(Hash)
330
+ if has_menubar.has_key? :margin
331
+ if has_menubar[:margin] == true
332
+ main_window.has_margin
333
+ end
334
+ end
335
+ end
336
+ ::LibUI.simple_exit(main_window)
337
+ if block_given?
338
+ yield
339
+ end
340
+ return main_window # Always return it here.
341
+ end; self.instance_eval { alias main_window window } # === LibuiParadise::Extensions.main_window
342
+ self.instance_eval { alias ui_main_window window } # === LibuiParadise::Extensions.ui_main_window
343
+ self.instance_eval { alias margined_window window } # === LibuiParadise::Extensions.margined_window
344
+ self.instance_eval { alias ui_window window } # === LibuiParadise::Extensions.ui_window
345
+ self.instance_eval { alias window_or_vbox window } # === LibuiParadise::Extensions.window_or_vbox
346
+
347
+ # ========================================================================= #
348
+ # === window
349
+ # ========================================================================= #
350
+ def window(
351
+ the_title = '', # Pick a title for the window here.
352
+ width = 500, # width in n pixels.
353
+ height = 300, # height in n pixels.
354
+ has_menubar = 1 # hasMenubar or has not.
355
+ )
356
+ LibuiParadise::Extensions.window(
357
+ the_title, width, height, has_menubar
358
+ )
359
+ end; alias main_window window # === main_window
360
+
361
+ # ========================================================================= #
362
+ # === ui_margined_main_window
363
+ #
364
+ # This variant is like ui_main_window() but it will automatically
365
+ # put a margin on the window, via .is_margined().
366
+ #
367
+ # Note that the variant name "ui_padded_main_window" is a misnomer,
368
+ # since it is a margin rather than padding - but I found that it
369
+ # is easier to not care about this, so for the time being (September
370
+ # 2021) this is how it is. It may be subject to change in the future,
371
+ # though.
372
+ # ========================================================================= #
373
+ def ui_margined_main_window(
374
+ the_title = '', # Pick a title for the window here.
375
+ width = 500, # width in n pixels.
376
+ height = 300, # height in n pixels.
377
+ has_menubar = 1 # hasMenubar or has not.
378
+ )
379
+ _ = LibuiParadise.window(the_title, width, height, has_menubar)
380
+ _.is_margined
381
+ return _
382
+ end; alias ui_margined_window ui_margined_main_window # === ui_margined_window
383
+ alias ui_padded_main_window ui_margined_main_window # === ui_padded_main_window
384
+ alias margined_window ui_margined_main_window # === margined_window
385
+ alias padded_window ui_margined_main_window # === padded_window
386
+ alias ui_padded_window ui_margined_main_window # === ui_padded_window
387
+ alias padded_main_window ui_margined_main_window # === padded_main_window
388
+ alias ui_main_window ui_margined_main_window # === ui_main_window
389
+ alias ui_window ui_margined_main_window # === ui_window
390
+ alias window_or_vbox ui_margined_main_window # === window_or_vbox
391
+
392
+ # ========================================================================= #
393
+ # === LibuiParadise::Extensions.slider
394
+ # ========================================================================= #
395
+ def self.slider(
396
+ start_value = 0,
397
+ end_value = 100
398
+ )
399
+ _ = ::LibUI.new_slider(start_value, end_value)
400
+ # ======================================================================= #
401
+ # Register it at once:
402
+ # ======================================================================= #
403
+ add_to_the_registered_widgets(_, __method__)
404
+ return _
405
+ end; self.instance_eval { alias ui_slider slider } # === LibuiParadise::Extensions.ui_slider
406
+
407
+ # ========================================================================= #
408
+ # === slider
409
+ # ========================================================================= #
410
+ def slider(
411
+ start_value = 0,
412
+ end_value = 100
413
+ )
414
+ return ::LibuiParadise::Extensions.slider(start_value, end_value)
415
+ end; alias ui_slider slider # === ui_slider
416
+
417
+ # ========================================================================= #
418
+ # === LibuiParadise::Extensions.horizontal_separator
419
+ #
420
+ # This method will add a new horizontal separator. The name "hsep"
421
+ # is a shorter alias to this.
422
+ # ========================================================================= #
423
+ def self.horizontal_separator
424
+ ::LibUI.new_horizontal_separator
425
+ end; self.instance_eval { alias ui_hseparator horizontal_separator } # === LibuiParadise::Extensions.ui_hseparator
426
+ self.instance_eval { alias ui_hsep horizontal_separator } # === LibuiParadise::Extensions.ui_hsep
427
+ self.instance_eval { alias hspacer horizontal_separator } # === LibuiParadise::Extensions.hspacer
428
+ self.instance_eval { alias horizontal_spacer horizontal_separator } # === LibuiParadise::Extensions.horizontal_spacer
429
+ self.instance_eval { alias hsep horizontal_separator } # === LibuiParadise::Extensions.hsept
430
+
431
+ # ========================================================================= #
432
+ # === horizontal_separator
433
+ # ========================================================================= #
434
+ def horizontal_separator
435
+ ::LibuiParadise::Extensions.horizontal_separator
436
+ end; alias ui_hseparator horizontal_separator # === ui_hseparator
437
+ alias ui_hsep horizontal_separator # === ui_hsep
438
+ alias hspacer horizontal_separator # === hspacer
439
+ alias horizontal_spacer horizontal_separator # === horizontal_spacer
440
+ alias hsep horizontal_separator # === hsep
441
+ alias libui_hsep horizontal_separator # === libui_hsep
442
+
443
+ # ========================================================================= #
444
+ # === LibuiParadise::Extensions.search_entry
445
+ # ========================================================================= #
446
+ def self.search_entry
447
+ _ = ::LibUI.new_search_entry
448
+ add_to_the_registered_widgets(_, __method__)
449
+ return _
450
+ end; self.instance_eval { alias ui_search_entry search_entry } # === LibuiParadise::Extensions.ui_search_entry
451
+
452
+ # ========================================================================= #
453
+ # === search_entry
454
+ # ========================================================================= #
455
+ def search_entry
456
+ ::LibuiParadise::Extensions.search_entry
457
+ end; alias ui_search_entry search_entry # === ui_search_entry
458
+
459
+ # ========================================================================= #
460
+ # === LibuiParadise::Extensions.entry (entry tag)
461
+ #
462
+ # The upstream C API for libui-entry can be found here:
463
+ #
464
+ # https://github.com/andlabs/libui/blob/master/unix/entry.c
465
+ #
466
+ # This method is tapping into LibUI.new_entry.
467
+ #
468
+ # Usage example:
469
+ #
470
+ # entry1 = LibUI.entry('ATG')
471
+ #
472
+ # ========================================================================= #
473
+ def self.entry(
474
+ optional_text = ''
475
+ )
476
+ optional_text = optional_text.to_s
477
+ entry = ::LibUI.new_entry
478
+ unless optional_text.empty?
479
+ ::LibUI.entry_set_text(entry, optional_text)
480
+ end
481
+ add_to_the_registered_widgets(entry, __method__)
482
+ return entry
483
+ end; self.instance_eval { alias ui_entry entry } # === LibuiParadise::Extensions.ui_entry
484
+
485
+ # ========================================================================= #
486
+ # === entry (entry tag)
487
+ #
488
+ # This method is tapping into LibUI.new_entry.
489
+ #
490
+ # An alias exists to this method, called hcentered_entry. This currently
491
+ # does not work for libui, and is thus only added for compatibility
492
+ # reasons.
493
+ #
494
+ # Usage example:
495
+ #
496
+ # entry1 = ui_entry('ATG')
497
+ #
498
+ # ========================================================================= #
499
+ def entry(
500
+ optional_text = ''
501
+ )
502
+ ::LibuiParadise::Extensions.entry(optional_text)
503
+ end; alias ui_entry entry # === ui_entry
504
+ alias hcentered_entry entry # === hcentered_entry
505
+
506
+ # ========================================================================= #
507
+ # === text?
508
+ #
509
+ # This method will guarantee a String to be returned.
510
+ #
511
+ # This is a bit weird, though. We may have to remove this method one
512
+ # day. I forgot why I added it to entry.rb specifically. After all
513
+ # other widgets also should respond to .text?.
514
+ # ========================================================================= #
515
+ def text?(from_this_pointer)
516
+ _ = ::LibUI.entry_text(from_this_pointer).to_s
517
+ add_to_the_registered_widgets(_, __method__)
518
+ return _
519
+ end
520
+
521
+ # ========================================================================= #
522
+ # === LibuiParadise::Extensions.non_wrapping_multiline_entry
523
+ #
524
+ # The upstream C API for the non-wrapping multiline edit can be found here:
525
+ #
526
+ # https://raw.githubusercontent.com/andlabs/libui/master/unix/multilineentry.c
527
+ #
528
+ # ========================================================================= #
529
+ def self.non_wrapping_multiline_entry
530
+ _ = ::LibUI.new_non_wrapping_multiline_entry
531
+ add_to_the_registered_widgets(_, __method__)
532
+ return _
533
+ end
534
+
535
+ # ========================================================================= #
536
+ # === LibuiParadise::Extensions.font (font tag, fonts tag)
537
+ # ========================================================================= #
538
+ def self.font(&block)
539
+ use_this_font = ::LibUI::FFI::FontDescriptor.malloc
540
+ if block_given?
541
+ yielded = yield
542
+ if yielded.is_a? Hash
543
+ # =================================================================== #
544
+ # === :font_size
545
+ # =================================================================== #
546
+ if yielded.has_key? :font_size
547
+ use_this_font.Size = yielded.delete(:font_size)
548
+ end
549
+ # =================================================================== #
550
+ # === :font_family
551
+ # =================================================================== #
552
+ if yielded.has_key? :font_family
553
+ use_this_font.Family = yielded.delete(:font_family)
554
+ end
555
+ # =================================================================== #
556
+ # === :stretch
557
+ # =================================================================== #
558
+ if yielded.has_key? :stretch
559
+ use_this_font.Stretch = yielded.delete(:stretch)
560
+ end
561
+ # =================================================================== #
562
+ # === :weight
563
+ # =================================================================== #
564
+ if yielded.has_key? :weight
565
+ use_this_font.Weight = yielded.delete(:weight)
566
+ end
567
+ # =================================================================== #
568
+ # === :italic
569
+ # =================================================================== #
570
+ if yielded.has_key? :italic
571
+ _ = yielded.delete(:italic_family)
572
+ if _ == true
573
+ _ = 1
574
+ elsif _ == false
575
+ _ = 0
576
+ end
577
+ use_this_font.Italic = _
578
+ end
579
+ end
580
+ end
581
+ return use_this_font
582
+ end; self.instance_eval { alias ui_font font } # === LibuiParadise::Extensions.ui_font
583
+ self.instance_eval { alias font_descriptor font } # === LibuiParadise::Extensions.font_descriptor
584
+
585
+ # ========================================================================= #
586
+ # === font
587
+ # ========================================================================= #
588
+ def font(&block)
589
+ LibuiParadise::Extensions.font(&block)
590
+ end; alias ui_font font # === ui_font
591
+ alias font_descriptor font # === font_descriptor
592
+
593
+ # ========================================================================= #
594
+ # === LibuiParadise::Extensions.non_wrapping_multiline_entry
595
+ # ========================================================================= #
596
+ def non_wrapping_multiline_entry
597
+ return ::LibuiParadise::Extensions.non_wrapping_multiline_entry
598
+ end
599
+
600
+ # ========================================================================= #
601
+ # === LibuiParadise::Extensions.menu (menu tag)
602
+ # ========================================================================= #
603
+ def self.menu(title = '')
604
+ _ = ::LibUI.new_menu(title)
605
+ add_to_the_registered_widgets(_, __method__)
606
+ return _
607
+ end; self.instance_eval { alias ui_menu menu } # === ui_menu
608
+
609
+ # ========================================================================= #
610
+ # === menu (menu tag)
611
+ # ========================================================================= #
612
+ def menu(
613
+ title = ''
614
+ )
615
+ return ::LibuiParadise::Extensions.menu(title)
616
+ end; alias ui_menu menu # === ui_menu
617
+
618
+ # ========================================================================= #
619
+ # === LibuiParadise::Extensions.vertical_separator
620
+ #
621
+ # This method will add a new vertical separator.
622
+ # ========================================================================= #
623
+ def self.vertical_separator
624
+ ::LibUI.new_vertical_separator
625
+ end; self.instance_eval { alias ui_vseparator vertical_separator } # === LibuiParadise::Extensions.ui_verticalseparator
626
+ self.instance_eval { alias ui_vsep vertical_separator } # === LibuiParadise::Extensions.ui_vsep
627
+ self.instance_eval { alias vspacer vertical_separator } # === LibuiParadise::Extensions.vspacer
628
+ self.instance_eval { alias vertical_spacer vertical_separator } # === LibuiParadise::Extensions.vertical_spacer
629
+ self.instance_eval { alias vsep vertical_separator } # === LibuiParadise::Extensions.vsept
630
+
631
+ # ========================================================================= #
632
+ # === vertical_separator
633
+ # ========================================================================= #
634
+ def vertical_separator
635
+ ::LibuiParadise::Extensions.vertical_separator
636
+ end; alias ui_vseparator vertical_separator # === ui_vseparator
637
+ alias ui_vsep vertical_separator # === ui_vsep
638
+ alias vertical_spacer vertical_separator # === vertical_spacer
639
+ alias vspacer vertical_separator # === vspacer
640
+ alias vsep vertical_separator # === vsep
641
+
642
+ # ========================================================================= #
643
+ # === LibuiParadise::Extensions.spinbox
644
+ #
645
+ # This method will return a spin-button, also called a spin-box.
646
+ #
647
+ # The first argument is the start value; the second argument is the end
648
+ # value.
649
+ # ========================================================================= #
650
+ def self.spinbox(
651
+ start_point = 0,
652
+ end_point = 100
653
+ )
654
+ if start_point.is_a? Hash
655
+ # ===================================================================== #
656
+ # === :end
657
+ # ===================================================================== #
658
+ if start_point.has_key? :end
659
+ end_point = start_point[:end]
660
+ end
661
+ # ===================================================================== #
662
+ # === :start
663
+ # ===================================================================== #
664
+ if start_point.has_key? :start
665
+ start_point = start_point[:start]
666
+ end
667
+ end
668
+ _ = ::LibUI.new_spinbox(start_point.to_i, end_point.to_i)
669
+ add_to_the_registered_widgets(_, __method__)
670
+ return _
671
+ end; self.instance_eval { alias ui_spinbox spinbox } # === LibuiParadise::Extensions.ui_spinbox
672
+ self.instance_eval { alias ui_spinbutton spinbox } # === LibuiParadise::Extensions.ui_spinbutton
673
+ self.instance_eval { alias spinbutton spinbox } # === LibuiParadise::Extensions.spinbutton
674
+
675
+ # ========================================================================= #
676
+ # === LibuiParadise::Extensions.password_entry
677
+ #
678
+ # This method will create and returns a new password entry widget. This
679
+ # means that input will be "disguised" via the '*' character.
680
+ #
681
+ # Usage example:
682
+ #
683
+ # entry = LibuiParadise::Extensions.password_entry
684
+ #
685
+ # ========================================================================= #
686
+ def self.password_entry
687
+ entry = ::LibUI.new_password_entry
688
+ add_to_the_registered_widgets(entry, __method__)
689
+ return entry
690
+ end; self.instance_eval { alias ui_password_entry password_entry } # === LibuiParadise::Extensions.ui_password_entry
691
+
692
+ # ========================================================================= #
693
+ # === password_entry
694
+ #
695
+ # Usage example:
696
+ #
697
+ # entry = ui_password_entry
698
+ #
699
+ # ========================================================================= #
700
+ def password_entry
701
+ ::LibuiParadise::Extensions.password_entry
702
+ end; alias ui_password_entry password_entry # === ui_password_entry
703
+
704
+ # ========================================================================= #
705
+ # === LibuiParadise::Extensions.text_layout
706
+ # ========================================================================= #
707
+ def self.text_layout(
708
+ i = ''
709
+ )
710
+ _ = ::LibUI.draw_new_text_layout(i.to_s)
711
+ add_to_the_registered_widgets(_, __method__)
712
+ return _
713
+ end
714
+
715
+ # ========================================================================= #
716
+ # === text_layout
717
+ # ========================================================================= #
718
+ def text_layout(
719
+ i = ''
720
+ )
721
+ ::LibuiParadise::Extensions.text_layout(i)
722
+ end
723
+
724
+ # ========================================================================= #
725
+ # === spinbox
726
+ #
727
+ # This method will return a spin-button, also called a spin-box.
728
+ # ========================================================================= #
729
+ def spinbox(
730
+ start_point = 0,
731
+ end_point = 100
732
+ )
733
+ ::LibuiParadise::Extensions.spinbox(start_point, end_point)
734
+ end; alias ui_spinbox spinbox # === ui_spinbox
735
+ alias ui_spinbutton spinbox # === ui_spinbutton
736
+ alias up_and_down_counter spinbox # === up_and_down_counter
737
+ alias spinbutton spinbox # === spinbutton
738
+ alias centered_spin_button spinbox # === centered_spin_button
739
+
740
+ # ========================================================================= #
741
+ # === LibuiParadise::Extensions.table
742
+ #
743
+ # The argument should be of type table_params.
744
+ #
745
+ # Example for this:
746
+ #
747
+ # table_params = LibUI::FFI::TableParams.malloc
748
+ # table_params.Model = model
749
+ # table_params.RowBackgroundColorModelColumn = -1
750
+ #
751
+ # ========================================================================= #
752
+ def self.table(i)
753
+ _ = ::LibUI.new_table(i)
754
+ LibuiParadise::Extensions.register_this_fiddle_pointer_widget(_, __method__)
755
+ return _
756
+ end; self.instance_eval { alias ui_table table } # === LibuiParadise::Extensions.ui_table
757
+
758
+ # ========================================================================= #
759
+ # === LibuiParadise::Extensions.checkbox (checkbox tag)
760
+ # ========================================================================= #
761
+ def self.checkbox(i = '')
762
+ _ = ::LibUI.new_checkbox(i)
763
+ add_to_the_registered_widgets(_, __method__)
764
+ return _
765
+ end
766
+
767
+ # ========================================================================= #
768
+ # === checkbox
769
+ # ========================================================================= #
770
+ def checkbox(i = '')
771
+ ::LibuiParadise::Extensions.checkbox(i)
772
+ end; alias ui_checkbox checkbox # === ui_checkbox
773
+ alias ui_check_button checkbox # === ui_check_button
774
+
775
+ # ========================================================================= #
776
+ # === checked_checkbox
777
+ # ========================================================================= #
778
+ def checked_checkbox(i = '')
779
+ _ = checkbox(i)
780
+ _.is_active
781
+ return _
782
+ end
783
+
784
+ # ========================================================================= #
785
+ # === LibuiParadise::Extensions.button (button tag)
786
+ #
787
+ # The upstream API for buttons, in C, can be found here:
788
+ #
789
+ # https://raw.githubusercontent.com/andlabs/libui/master/unix/button.c
790
+ #
791
+ # ========================================================================= #
792
+ def self.button(text)
793
+ _ = ::LibUI.new_button(text)
794
+ ::LibuiParadise::Extensions.register_this_fiddle_pointer_widget(_, __method__)
795
+ return _
796
+ end; self.instance_eval { alias ui_button button } # === LibuiParadise::Extensions.ui_button
797
+
798
+ # ========================================================================= #
799
+ # === LibuiParadise::Extensions.multiline_entry (multiline_entry tag)
800
+ #
801
+ # The upstream code for the linux-variant for a multiline-entry can
802
+ # be found here:
803
+ #
804
+ # https://raw.githubusercontent.com/andlabs/libui/master/unix/multilineentry.c
805
+ #
806
+ # A multiline-entry, also known more traditionally as a "textview",
807
+ # is a widget that allows the user to input text and modify that
808
+ # text as well.
809
+ # ========================================================================= #
810
+ def self.multiline_entry(optional_content = nil)
811
+ _ = ::LibUI.new_multiline_entry
812
+ add_to_the_registered_widgets(_, __method__)
813
+ if optional_content and optional_content.is_a?(String) and !optional_content.empty?
814
+ _.set_text(optional_content)
815
+ end
816
+ return _
817
+ end; self.instance_eval { alias ui_multiline_entry multiline_entry } # === LibuiParadise::Extensions.ui_multiline_entry
818
+ self.instance_eval { alias textview multiline_entry } # === LibuiParadise::Extensions.textview
819
+ self.instance_eval { alias text_view multiline_entry } # === LibuiParadise::Extensions.text_view
820
+ self.instance_eval { alias ui_text_view multiline_entry } # === LibuiParadise::Extensions.ui_text_view
821
+ self.instance_eval { alias ui_textview multiline_entry } # === LibuiParadise::Extensions.ui_textview
822
+ self.instance_eval { alias ui_text_buffer multiline_entry } # === LibuiParadise::Extensions.ui_text_buffer
823
+ self.instance_eval { alias input_field multiline_entry } # === LibuiParadise::Extensions.input_field
824
+ self.instance_eval { alias input multiline_entry } # === LibuiParadise::Extensions.input
825
+
826
+ # ========================================================================= #
827
+ # === Libuiparadise::Extensions.image
828
+ #
829
+ # This is currently limited to .png files only, due to ChunkyPng.
830
+ #
831
+ # At some later point in the future this limitation may be lifted. For
832
+ # now it has to remain in place.
833
+ # ========================================================================= #
834
+ def self.image(
835
+ this_file,
836
+ width = :try_to_infer_automatically,
837
+ height = :infer_automatically
838
+ )
839
+ if (width == :infer_automatically) or
840
+ (height == :infer_automatically)
841
+ unless Object.const_defined? :ChunkyPNG
842
+ begin
843
+ require 'chunky_png'
844
+ rescue LoadError; end
845
+ end
846
+ canvas = ChunkyPNG::Canvas.from_file(this_file)
847
+ data = canvas.to_rgba_stream
848
+ width = canvas.width
849
+ height = canvas.height
850
+ _ = ::LibUI.new_image(width, height) # Create the image here.
851
+ add_to_the_registered_widgets(_, __method__)
852
+ ::LibUI.image_append(
853
+ _,
854
+ data,
855
+ width,
856
+ height,
857
+ width
858
+ )
859
+ return _
860
+ end
861
+ nil
862
+ end; self.instance_eval { alias ui_image image } # === LibuiParadise::Extensions.ui_image
863
+
864
+ # ========================================================================= #
865
+ # === LibuiParadise::Extensions.font_button
866
+ #
867
+ # Create a new font button via this method.
868
+ # ========================================================================= #
869
+ def self.font_button
870
+ _ = ::LibUI.new_font_button
871
+ add_to_the_registered_widgets(_, __method__)
872
+ return _
873
+ end; self.instance_eval { alias ui_font_button font_button } # === Libuiparadise::Extensions.ui_font_button
874
+
875
+ # ========================================================================= #
876
+ # === font_button
877
+ #
878
+ # Create a new font button via this method.
879
+ # ========================================================================= #
880
+ def font_button
881
+ return ::LibuiParadise::Extensions.font_button
882
+ end; alias ui_font_button font_button # === ui_font_button
883
+
884
+ # ========================================================================= #
885
+ # === image
886
+ #
887
+ # This is currently limited to .png files only, due to ChunkyPng.
888
+ #
889
+ # At some later point in the future this limitation may be lifted. For
890
+ # now it has to remain in place.
891
+ # ========================================================================= #
892
+ def image(
893
+ this_file,
894
+ width = :try_to_infer_automatically,
895
+ height = :infer_automatically
896
+ )
897
+ Libuiparadise::Extensions.image(
898
+ this_file, width, height
899
+ )
900
+ end; alias ui_image image # === ui_image
901
+
902
+ # ========================================================================= #
903
+ # === multiline_entry
904
+ # ========================================================================= #
905
+ def multiline_entry(optional_content = nil)
906
+ ::LibuiParadise::Extensions.multiline_entry(optional_content)
907
+ end; alias ui_multiline_entry multiline_entry # === ui_multiline_entry
908
+ alias textview multiline_entry # === textview
909
+ alias text_view multiline_entry # === text_view
910
+ alias ui_text_view multiline_entry # === ui_text_view
911
+ alias ui_textview multiline_entry # === ui_textview
912
+ alias ui_text_buffer multiline_entry # === ui_text_buffer
913
+ alias input_field multiline_entry # === input_field
914
+ alias input multiline_entry # === input
915
+
916
+ # ========================================================================= #
917
+ # === LibuiParadise::Extensions.radio_buttons
918
+ #
919
+ # This method will create some radio buttons.
920
+ #
921
+ # You can pass an Array into this method, which should be an Array of
922
+ # Strings. This is optional. If such an Array is given, though, then
923
+ # these entries will become radio-buttons, with the associated label
924
+ # (the text they display) becoming the label right next to the radio
925
+ # button element (that round circle that the user can select via
926
+ # the mouse cursor).
927
+ # ========================================================================= #
928
+ def self.radio_buttons(
929
+ optional_array = []
930
+ )
931
+ _ = ::LibUI.new_radio_buttons
932
+ if optional_array and optional_array.is_a?(Array) and !optional_array.empty?
933
+ optional_array.each {|this_element|
934
+ ::LibUI.radio_buttons_append(_, this_element)
935
+ }
936
+ end
937
+ add_to_the_registered_widgets(_, __method__)
938
+ return _
939
+ end; self.instance_eval { alias ui_radio_buttons radio_buttons } # === LibuiParadise::Extensionsui_radio_buttons
940
+
941
+ # ========================================================================= #
942
+ # === radio_buttons
943
+ # ========================================================================= #
944
+ def radio_buttons(optional_array = [])
945
+ return ::LibuiParadise::Extensions.radio_buttons(optional_array)
946
+ end; alias ui_radio_buttons radio_buttons # === ui_radio_buttons
947
+
948
+ # ========================================================================= #
949
+ # === LibuiParadise::Extensions.new_colour_button
950
+ #
951
+ # The upstream API for a colour-button (in C) can be found here:
952
+ #
953
+ # https://github.com/andlabs/libui/blob/master/unix/colorbutton.c
954
+ #
955
+ # ========================================================================= #
956
+ def self.colour_button
957
+ _ = ::LibUI.new_color_button
958
+ ::LibuiParadise::Extensions.register_this_fiddle_pointer_widget(_, __method__)
959
+ return _
960
+ end; self.instance_eval { alias new_colour_button colour_button } # === LibuiParadise::Extensions.new_colour_button
961
+ self.instance_eval { alias new_color_button colour_button } # === LibuiParadise::Extensions.new_color_button
962
+ self.instance_eval { alias ui_colour_button colour_button } # === LibuiParadise::Extensions.ui_colour_button
963
+
964
+ # ========================================================================= #
965
+ # === colour_button
966
+ # ========================================================================= #
967
+ def colour_button
968
+ ::LibuiParadise::Extensions.new_colour_button
969
+ end; alias color_button colour_button # === color_button
970
+ alias ui_colour_button colour_button # === ui_color_button
971
+
972
+ # ========================================================================= #
973
+ # === LibuiParadise::Extensions.scrolling_area
974
+ #
975
+ # It seems as if scrolling is not yet easily available in libui.
976
+ #
977
+ # The upstream API is like this:
978
+ #
979
+ # uiArea *area = uiNewScrollingArea(&handler, 400, 400);
980
+ #
981
+ # The two numbers are width and height, as integers, respectively.
982
+ # In total three arguments are required. The first argument is
983
+ # a so-called "AreaHandler".
984
+ #
985
+ # The code may be found here:
986
+ #
987
+ # https://github.com/andlabs/libui/blob/master/windows/areascroll.cpp
988
+ #
989
+ # ========================================================================= #
990
+ def self.scrolling_area(
991
+ widget,
992
+ width = 400,
993
+ height = 400
994
+ )
995
+ case width
996
+ when :default, nil
997
+ width = 400
998
+ end
999
+ case height
1000
+ when :default, nil
1001
+ height = 400
1002
+ end
1003
+ _ = ::LibUI.new_scrolling_area(widget, width, height)
1004
+ # ======================================================================= #
1005
+ # The next part does not yet work - is it even possible to add widgets
1006
+ # to a scrolling area in libui?
1007
+ # if optional_widget
1008
+ # _.add(optional_widget)
1009
+ # end
1010
+ # ======================================================================= #
1011
+ add_to_the_registered_widgets(_, __method__)
1012
+ return _
1013
+ end; self.instance_eval { alias ui_scrolling_area scrolling_area } # === LibuiParadise::Extensions.ui_scrolling_area
1014
+ self.instance_eval { alias ui_scrolled_window scrolling_area } # === LibuiParadise::Extensions.ui_scrolling_window
1015
+
1016
+ # ========================================================================= #
1017
+ # === scrolling_area
1018
+ #
1019
+ # It seems as if scrolling is not yet easily available in libui.
1020
+ #
1021
+ # The upstream API is like this:
1022
+ #
1023
+ # uiArea *area = uiNewScrollingArea(&handler, 400, 400);
1024
+ #
1025
+ # ========================================================================= #
1026
+ def scrolling_area(
1027
+ optional_widget = nil
1028
+ )
1029
+ LibuiParadise::Extensions.scrolling_area(optional_widget)
1030
+ end; alias ui_scrolling_area scrolling_area # === ui_scrolling_area
1031
+ alias ui_scrolled_window scrolling_area # === ui_scrolling_window
1032
+
1033
+ # ========================================================================= #
1034
+ # === bold_button
1035
+ #
1036
+ # This currently does not work. We have to wait until upstream libui
1037
+ # supports bold font text.
1038
+ # ========================================================================= #
1039
+ def bold_button(i)
1040
+ button(i)
1041
+ end
1042
+
1043
+ # ========================================================================= #
1044
+ # === quit_button (quit tag)
1045
+ #
1046
+ # This method can be used to, by default, implement a quit button
1047
+ # that, upon a click-event, will cause the application to exit
1048
+ # and close/quit.
1049
+ # ========================================================================= #
1050
+ def quit_button(
1051
+ optional_arguments = {}
1052
+ )
1053
+ use_this_text = 'Quit'
1054
+ if optional_arguments and optional_arguments.is_a?(Hash)
1055
+ # ===================================================================== #
1056
+ # === :text
1057
+ # ===================================================================== #
1058
+ if optional_arguments.has_key? :text
1059
+ use_this_text = optional_arguments.delete(:text)
1060
+ end
1061
+ end
1062
+ if block_given?
1063
+ yielded = yield
1064
+ case yielded
1065
+ # ===================================================================== #
1066
+ # === :with_emoji
1067
+ # ===================================================================== #
1068
+ when :with_emoji,
1069
+ :with_icon
1070
+ use_this_text = use_this_text.to_s.dup
1071
+ use_this_text << ' 🛑'
1072
+ end
1073
+ end
1074
+ quit_button = button(use_this_text)
1075
+ quit_button.on_clicked {
1076
+ ::LibUI.quit
1077
+ 0
1078
+ }
1079
+ return quit_button
1080
+ end; alias ui_quit_button quit_button # === ui_quit_button
1081
+
1082
+ # ========================================================================= #
1083
+ # === table
1084
+ # ========================================================================= #
1085
+ def table(i)
1086
+ ::LibuiParadise::Extensions.table(i)
1087
+ end; alias ui_table table # === ui_table
1088
+
1089
+ # ========================================================================= #
1090
+ # === LibuiParadise::Extensions.editable_combobox
1091
+ #
1092
+ # This is a combo-box that the user can modify.
1093
+ # ========================================================================= #
1094
+ def self.editable_combobox(
1095
+ optional_array = nil, &block
1096
+ )
1097
+ _ = ::LibUI.new_editable_combobox
1098
+ if block_given?
1099
+ optional_array = yield
1100
+ end
1101
+ if optional_array and optional_array.is_a?(Array)
1102
+ append_this_array_to_that_combobox(optional_array, _)
1103
+ end
1104
+ add_to_the_registered_widgets(_, __method__)
1105
+ return _
1106
+ end; self.instance_eval { alias editable_combo_box editable_combobox } # === LibuiParadise::Extensions.editable_combo_box
1107
+ self.instance_eval { alias ui_editable_combo_box editable_combobox } # === LibuiParadise::Extensions.ui_editable_combo_box
1108
+
1109
+ # ========================================================================= #
1110
+ # === LibuiParadise::Extensions.combobox
1111
+ # ========================================================================= #
1112
+ def self.combobox(
1113
+ optional_array = nil, &block
1114
+ )
1115
+ combobox = ::LibUI.new_combobox
1116
+ # ======================================================================= #
1117
+ # Register it at once:
1118
+ # ======================================================================= #
1119
+ add_to_the_registered_widgets(combobox, __method__)
1120
+ if block_given?
1121
+ optional_array = yield
1122
+ end
1123
+ if optional_array and optional_array.is_a?(Array)
1124
+ # append_this_array_to_that_combobox(optional_array, combobox)
1125
+ combobox.append_this_array(optional_array)
1126
+ end
1127
+ return combobox
1128
+ end; self.instance_eval { alias combo_box combobox } # === LibuiParadise::Extensions.combo_box
1129
+ self.instance_eval { alias ui_combo_box combobox } # === LibuiParadise::Extensions.ui_combo_box
1130
+ self.instance_eval { alias ui_combobox combobox } # === LibuiParadise::Extensions.ui_combobox
1131
+
1132
+ # ========================================================================= #
1133
+ # === selected?
1134
+ #
1135
+ # Unsure whether this works. It appears to work, but I am not even
1136
+ # certain as to why.
1137
+ # ========================================================================= #
1138
+ def selected?(pointer)
1139
+ ::LibUI.combobox_selected(pointer).to_s
1140
+ end
1141
+
1142
+ # ========================================================================= #
1143
+ # === combobox
1144
+ #
1145
+ # The first argument can be an Array.
1146
+ # ========================================================================= #
1147
+ def combobox(
1148
+ optional_array = nil, &block
1149
+ )
1150
+ return ::LibuiParadise::Extensions.combobox(optional_array, &block)
1151
+ end; alias combo_box combobox # === combo_box
1152
+ alias ui_combo_box combobox # === ui_combo_box
1153
+ alias ui_combobox combobox # === ui_combobox
1154
+ alias combo_box_entry combobox # === combo_box_entry
1155
+ alias libui_combo_box combobox # === libui_combo_box
1156
+
1157
+ # ========================================================================= #
1158
+ # === editable_combobox
1159
+ # ========================================================================= #
1160
+ def editable_combobox(
1161
+ optional_array = nil, &block
1162
+ )
1163
+ return ::LibuiParadise::Extensions(optional_array, &block)
1164
+ end; alias editable_combo_box editable_combobox # === editable_combo_box
1165
+ alias ui_editable_combo_box editable_combobox # === ui_editable_combo_box
1166
+
1167
+ # ========================================================================= #
1168
+ # === LibuiParadise::Extensions.label (text tag, label tag)
1169
+ #
1170
+ # Add text to the widget at hand. This is actually called a "label".
1171
+ # ========================================================================= #
1172
+ def self.label(
1173
+ i = ''
1174
+ )
1175
+ if i.include? '</'
1176
+ # ===================================================================== #
1177
+ # For now we must remove "HTML tags" from the given input. Perhaps
1178
+ # at some later point in time we can retain them.
1179
+ # ===================================================================== #
1180
+ i = i.dup if i.frozen?
1181
+ i.gsub!(%r{<[^>]+>}, '')
1182
+ end
1183
+ _ = ::LibUI.new_label(i.to_s)
1184
+ add_to_the_registered_widgets(_, __method__)
1185
+ return _
1186
+ end; self.instance_eval { alias text label } # === LibuiParadise::Extensions.text
1187
+ self.instance_eval { alias ui_text label } # === LibuiParadise::Extensions.ui_text
1188
+ self.instance_eval { alias ui_label label } # === LibuiParadise::Extensions.ui_label
1189
+
1190
+ # ========================================================================= #
1191
+ # === label
1192
+ #
1193
+ # The last two aliases, left_aligned_label, should be different, but
1194
+ # right now I don't know how to do this in libui.
1195
+ # ========================================================================= #
1196
+ def label(
1197
+ i = ''
1198
+ )
1199
+ ::LibuiParadise::Extensions.label(i)
1200
+ end; alias text label # === text
1201
+ alias ui_text label # === ui_text
1202
+ alias ui_label label # === ui_label
1203
+ alias left_aligned_label label # === left_aligned_label
1204
+ alias left_aligned_text label # === left_aligned_text
1205
+
1206
+ # ========================================================================= #
1207
+ # === bold_label
1208
+ #
1209
+ # This currently does not work properly. We may have to re-examine this
1210
+ # eventually at a later point.
1211
+ # ========================================================================= #
1212
+ def bold_label(i = '')
1213
+ return label(i)
1214
+ end
1215
+
1216
+ # ========================================================================= #
1217
+ # === bold_text
1218
+ #
1219
+ # This currently does NOT make the text bold - the method exists solely
1220
+ # as a placeholder, until upstream libui supports bold text as such.
1221
+ # ========================================================================= #
1222
+ def bold_text(i = '')
1223
+ return label(i)
1224
+ end
1225
+
1226
+ # ========================================================================= #
1227
+ # === bold_text_left_aligned
1228
+ # ========================================================================= #
1229
+ def bold_text_left_aligned(i = '')
1230
+ return label(i)
1231
+ end; alias left_aligned_bold_label bold_text_left_aligned # === left_aligned_bold_label
1232
+
1233
+ # ========================================================================= #
1234
+ # === fancy_text
1235
+ #
1236
+ # This text variant can be styled.
1237
+ # ========================================================================= #
1238
+ def fancy_text(i = '')
1239
+ _ = LibUI.new_attributed_string(i.to_s)
1240
+ add_to_the_registered_widgets(_, __method__)
1241
+ return _
1242
+ end; alias attributed_string fancy_text # === attributed_string
1243
+
1244
+ # ========================================================================= #
1245
+ # === LibuiParadise::Extensions.tab
1246
+ #
1247
+ # This could be also called "notebook_tab".
1248
+ # ========================================================================= #
1249
+ def self.tab
1250
+ _ = ::LibUI.new_tab
1251
+ add_to_the_registered_widgets(_, __method__)
1252
+ return _
1253
+ end; self.instance_eval { alias ui_tab tab } # === LibuiParadise::Extensions.ui_tab
1254
+ self.instance_eval { alias ui_tabs tab } # === LibuiParadise::Extensions.ui_tabs
1255
+ self.instance_eval { alias notebook tab } # === LibuiParadise::Extensions.notebook
1256
+ self.instance_eval { alias ui_notebook tab } # === LibuiParadise::Extensions.ui_notebook
1257
+ self.instance_eval { alias notebook_tab tab } # === LibuiParadise::Extensions.notebook_tab
1258
+
1259
+ # ========================================================================= #
1260
+ # === tab
1261
+ #
1262
+ # This could be also called "notebook_tab".
1263
+ # ========================================================================= #
1264
+ def tab
1265
+ ::LibuiParadise::Extensions.tab
1266
+ end; alias ui_tab tab # === ui_tab
1267
+ alias ui_tabs tab # === ui_tabs
1268
+ alias notebook tab # === notebook
1269
+ alias ui_notebook tab # === ui_notebook
1270
+ alias notebook_tab tab # === notebook_tab
1271
+
1272
+ # ========================================================================= #
1273
+ # === LibuiParadise::Extensions.area
1274
+ #
1275
+ # AreaHandler defines the functionality needed for handling events from
1276
+ # an Area.
1277
+ #
1278
+ # Upstream documentation, at the least for Go, can be found here:
1279
+ #
1280
+ # https://github.com/andlabs/ui/blob/master/areahandler.go
1281
+ #
1282
+ # ========================================================================= #
1283
+ def self.area(
1284
+ i = :use_new_area_handler
1285
+ )
1286
+ case i
1287
+ # ======================================================================= #
1288
+ # === :use_new_area_handler
1289
+ # ======================================================================= #
1290
+ when :use_new_area_handler,
1291
+ :default
1292
+ # ===================================================================== #
1293
+ # malloc a new area-handled next:
1294
+ # ===================================================================== #
1295
+ i = ::LibUI::FFI::AreaHandler.malloc
1296
+ i.to_ptr.free = Fiddle::RUBY_FREE # This one is done in upstream LibUI as well.
1297
+ end
1298
+ _ = ::LibUI.new_area(i) # Our new area, with the given handler.
1299
+ add_to_the_registered_widgets(_, __method__)
1300
+ return _
1301
+ end; self.instance_eval { alias area_handler area } # === LibuiParadise::Extensions.area_handler
1302
+
1303
+ # ========================================================================= #
1304
+ # === area
1305
+ #
1306
+ # AreaHandler defines the functionality needed for handling events
1307
+ # from an Area.
1308
+ #
1309
+ # Upstream documentation, at the least for Go, can be found here:
1310
+ #
1311
+ # https://github.com/andlabs/ui/blob/master/areahandler.go
1312
+ #
1313
+ # ========================================================================= #
1314
+ def area(
1315
+ i = :use_new_area_handler
1316
+ )
1317
+ return ::LibuiParadise::Extensions.area(i)
1318
+ end; alias area_handler area # === area_handler
1319
+
1320
+ # ========================================================================= #
1321
+ # === is_on_windows?
1322
+ # ========================================================================= #
1323
+ def is_on_windows?
1324
+ Gem.win_platform?
1325
+ end
1326
+
1327
+ end
1328
+
1329
+ # =========================================================================== #
1330
+ # === LibuiParadise.window
1331
+ # =========================================================================== #
1332
+ def self.window(
1333
+ the_title = '', # Pick a title for the window here.
1334
+ width = 500, # width in n pixels.
1335
+ height = 300, # height in n pixels.
1336
+ has_menubar = 1 # hasMenubar or has not.
1337
+ )
1338
+ ::LibuiParadise::Extensions.window(
1339
+ the_title,
1340
+ width,
1341
+ height,
1342
+ has_menubar
1343
+ )
1344
+ end; self.instance_eval { alias main_window window } # === LibuiParadise.main_window
1345
+ self.instance_eval { alias margined_window window } # === LibuiParadise.margined_window
1346
+ self.instance_eval { alias ui_window window } # === LibuiParadise.ui_window
1347
+ self.instance_eval { alias ui_main_window window } # === LibuiParadise.ui_main_window
1348
+ self.instance_eval { alias ui_padded_main_window window } # === LibuiParadise.margined_window
1349
+ self.instance_eval { alias padded_window window } # === LibuiParadise.padded_window
1350
+ self.instance_eval { alias padded_main_window window } # === LibuiParadise.padded_main_window
1351
+ self.instance_eval { alias window_or_vbox window } # === LibuiParadise.window_or_vbox
1352
+
1353
+ # =========================================================================== #
1354
+ # === LibuiParadise.main_window?
1355
+ # =========================================================================== #
1356
+ def self.main_window?
1357
+ LibuiParadise::Extensions.main_window?
1358
+ end
1359
+
1360
+ # =========================================================================== #
1361
+ # === LibuiParadise::Extensions.editable_combobox
1362
+ # =========================================================================== #
1363
+ def self.editable_combobox(
1364
+ optional_array = nil, &block
1365
+ )
1366
+ return ::LibuiParadise::Extensions.editable_combobox(optional_array, &block)
1367
+ end; self.instance_eval { alias editable_combo_box editable_combobox } # === LibuiParadise.editable_combo_box
1368
+ self.instance_eval { alias ui_editable_combo_box editable_combobox } # === LibuiParadise.ui_editable_combo_box
1369
+
1370
+ # ========================================================================= #
1371
+ # === LibuiParadise.label
1372
+ #
1373
+ # Toplevel method to create a new label, aka new text.
1374
+ # ========================================================================= #
1375
+ def self.label(
1376
+ i = ''
1377
+ )
1378
+ ::LibuiParadise::Extensions.label(i)
1379
+ end; self.instance_eval { alias text label } # === LibuiParadise.text
1380
+ self.instance_eval { alias ui_text label } # === LibuiParadise.ui_text
1381
+ self.instance_eval { alias ui_label label } # === LibuiParadise.ui_label
1382
+
1383
+ # ========================================================================= #
1384
+ # === LibuiParadise.string
1385
+ # ========================================================================= #
1386
+ def self.string(i = '')
1387
+ return ::LibUI.new_attributed_string(i)
1388
+ end; self.instance_eval { alias fancy_text string } # === LibuiParadise.fancy_text
1389
+
1390
+ # =========================================================================== #
1391
+ # === LibuiParadise.table
1392
+ # =========================================================================== #
1393
+ def self.table(i)
1394
+ ::LibuiParadise::Extensions.table(i)
1395
+ end; self.instance_eval { alias ui_table table } # === LibuiParadise.ui_table
1396
+
1397
+ # =========================================================================== #
1398
+ # === LibuiParadise.spinbox
1399
+ # =========================================================================== #
1400
+ def self.spinbox(
1401
+ start_point = 0,
1402
+ end_point = 100
1403
+ )
1404
+ ::LibuiParadise::Extensions.spinbox(start_point, end_point)
1405
+ end; self.instance_eval { alias ui_spinbox spinbox } # === LibuiParadise.ui_spinbox
1406
+ self.instance_eval { alias ui_spinbutton spinbox } # === LibuiParadise.ui_spinbutton
1407
+ self.instance_eval { alias spinbutton spinbox } # === LibuiParadise.spinbutton
1408
+
1409
+ # =========================================================================== #
1410
+ # === LibuiParadise.slider
1411
+ # =========================================================================== #
1412
+ def self.slider(
1413
+ start_value = 0,
1414
+ end_value = 100
1415
+ )
1416
+ ::LibuiParadise::Extensions.slider(start_value, end_value)
1417
+ end; self.instance_eval { alias ui_slider slider } # === LibuiParadise.ui_slider
1418
+
1419
+ # =========================================================================== #
1420
+ # === LibuiParadise.button
1421
+ # =========================================================================== #
1422
+ def self.button(text)
1423
+ ::LibuiParadise::Extensions.button(text)
1424
+ end
1425
+
1426
+ # =========================================================================== #
1427
+ # === LibuiParadise.checkbox
1428
+ # =========================================================================== #
1429
+ def self.checkbox(i = '')
1430
+ ::LibuiParadise::Extensions.checkbox(i)
1431
+ end
1432
+
1433
+ # =========================================================================== #
1434
+ # === LibuiParadise.msg_box
1435
+ # =========================================================================== #
1436
+ def self.msg_box(
1437
+ main_window = :default_window,
1438
+ title_to_use = '',
1439
+ whatever = ''
1440
+ )
1441
+ if main_window.is_a?(String) and title_to_use.is_a?(String) and
1442
+ title_to_use.empty?
1443
+ title_to_use = main_window.dup
1444
+ main_window = :default_window
1445
+ end
1446
+ ::LibuiParadise::Extensions.msg_box(
1447
+ main_window,
1448
+ title_to_use,
1449
+ whatever
1450
+ )
1451
+ end; self.instance_eval { alias ui_msg_box msg_box } # === LibuiParadise.ui_msg_box
1452
+ self.instance_eval { alias message_to_the_user msg_box } # === LibuiParadise.message_to_the_user
1453
+ self.instance_eval { alias message_box msg_box } # === LibuiParadise.message_box
1454
+ self.instance_eval { alias popup_over_this_widget msg_box } # === LibuiParadise.popup_over_this_widget
1455
+ self.instance_eval { alias popup_message msg_box } # === LibuiParadise.popup_message
1456
+
1457
+ # =========================================================================== #
1458
+ # === LibuiParadise.new_progress_bar
1459
+ # =========================================================================== #
1460
+ def self.new_progress_bar
1461
+ return ::LibuiParadise::Extensions.new_progress_bar
1462
+ end
1463
+
1464
+ # ========================================================================= #
1465
+ # === LibuiParadise.vertical_separator
1466
+ # ========================================================================= #
1467
+ def self.vertical_separator
1468
+ ::LibuiParadise::Extensions.vertical_separator
1469
+ end; self.instance_eval { alias ui_vseparator vertical_separator } # === LibuiParadise.ui_vseparator
1470
+ self.instance_eval { alias ui_vsep vertical_separator } # === LibuiParadise.ui_vsep
1471
+ self.instance_eval { alias vsep vertical_separator } # === LibuiParadise.vsep
1472
+
1473
+ # =========================================================================== #
1474
+ # === LibuiParadise.text_layout
1475
+ # =========================================================================== #
1476
+ def self.text_layout(
1477
+ i = ''
1478
+ )
1479
+ ::LibuiParadise::Extensions.text_layout(i)
1480
+ end
1481
+
1482
+ # =========================================================================== #
1483
+ # === LibuiParadise.search_entry
1484
+ # =========================================================================== #
1485
+ def self.search_entry
1486
+ ::LibuiParadise::Extensions.search_entry
1487
+ end; self.instance_eval { alias ui_search_entry search_entry } # === LibuiParadise.ui_search_entry
1488
+
1489
+ # =========================================================================== #
1490
+ # === LibuiParadise.scrolling_area
1491
+ # =========================================================================== #
1492
+ def self.scrolling_area(
1493
+ widget,
1494
+ width = :default,
1495
+ height = :default
1496
+ )
1497
+ ::LibuiParadise::Extensions.scrolling_area(widget, width, height)
1498
+ end
1499
+
1500
+ # =========================================================================== #
1501
+ # === LibuiParadise.radio_buttons
1502
+ # =========================================================================== #
1503
+ def self.radio_buttons(optional_array = [])
1504
+ return ::LibuiParadise::Extensions.radio_buttons(optional_array)
1505
+ end
1506
+
1507
+ # =========================================================================== #
1508
+ # === LibuiParadise.password_entry
1509
+ # =========================================================================== #
1510
+ def self.password_entry
1511
+ ::LibuiParadise::Extensions.password_entry
1512
+ end; self.instance_eval { alias ui_password_entry password_entry } # === LibuiParadise.ui_password_entry
1513
+
1514
+ # =========================================================================== #
1515
+ # === LibuiParadise.non_wrapping_multiline_entry
1516
+ # =========================================================================== #
1517
+ def self.non_wrapping_multiline_entry
1518
+ return ::LibuiParadise::Extensions.non_wrapping_multiline_entry
1519
+ end
1520
+
1521
+ # =========================================================================== #
1522
+ # === LibuiParadise.multiline_entry
1523
+ # =========================================================================== #
1524
+ def self.multiline_entry(optional_content = nil)
1525
+ ::LibuiParadise::Extensions.multiline_entry(optional_content)
1526
+ end; self.instance_eval { alias textview multiline_entry } # === LibuiParadise.textview
1527
+ self.instance_eval { alias text_view multiline_entry } # === LibuiParadise.text_view
1528
+ self.instance_eval { alias ui_text_view multiline_entry } # === LibuiParadise.ui_text_view
1529
+ self.instance_eval { alias ui_textview multiline_entry } # === LibuiParadise.ui_textview
1530
+ self.instance_eval { alias ui_text_buffer multiline_entry } # === LibuiParadise.ui_text_buffer
1531
+ self.instance_eval { alias input_field multiline_entry } # === LibuiParadise.input_field
1532
+
1533
+ # =========================================================================== #
1534
+ # === LibuiParadise.menu
1535
+ # =========================================================================== #
1536
+ def self.menu(title = '')
1537
+ return LibuiParadise::Extensions.menu(title)
1538
+ end; self.instance_eval { alias ui_menu menu } # === LibuiParadise.ui_menu
1539
+
1540
+ # ========================================================================= #
1541
+ # === Libuiparadise.image
1542
+ # ========================================================================= #
1543
+ def self.image(
1544
+ this_file,
1545
+ width = :try_to_infer_automatically,
1546
+ height = :infer_automatically
1547
+ )
1548
+ ::LibuiParadise::Extensions.image(
1549
+ this_file, width, height
1550
+ )
1551
+ end; self.instance_eval { alias ui_image image } # === LibuiParadise.ui_image
1552
+
1553
+ # =========================================================================== #
1554
+ # === LibuiParadise.colour_button
1555
+ # =========================================================================== #
1556
+ def self.colour_button
1557
+ ::LibuiParadise::Extensions.new_colour_button
1558
+ end; self.instance_eval { alias color_button colour_button } # === LibuiParadise.color_button
1559
+
1560
+ # =========================================================================== #
1561
+ # === LibuiParadise.font_button
1562
+ # =========================================================================== #
1563
+ def self.font_button
1564
+ return ::LibuiParadise::Extensions.font_button
1565
+ end
1566
+
1567
+ # ========================================================================= #
1568
+ # === LibuiParadise.horizontal_separator
1569
+ # ========================================================================= #
1570
+ def self.horizontal_separator
1571
+ ::LibuiParadise::Extensions.horizontal_separator
1572
+ end; self.instance_eval { alias ui_hseparator horizontal_separator } # === LibuiParadise.ui_hseparator
1573
+ self.instance_eval { alias ui_hsep horizontal_separator } # === LibuiParadise.ui_hsep
1574
+ self.instance_eval { alias hsep horizontal_separator } # === LibuiParadise.hsep
1575
+
1576
+ # =========================================================================== #
1577
+ # === LibuiParadise.font
1578
+ # =========================================================================== #
1579
+ def self.font(&block)
1580
+ ::LibuiParadise::Extensions.font(&block)
1581
+ end
1582
+
1583
+ # =========================================================================== #
1584
+ # === LibuiParadise.entry
1585
+ # =========================================================================== #
1586
+ def self.entry(
1587
+ optional_text = ''
1588
+ )
1589
+ ::LibuiParadise::Extensions.entry(optional_text)
1590
+ end; self.instance_eval { alias ui_entry entry } # === LibuiParadise.ui_entry
1591
+
1592
+ # =========================================================================== #
1593
+ # === LibuiParadise.open_file
1594
+ #
1595
+ # Simple delegator towards LibuiParadise::Extensions.open_file().
1596
+ # =========================================================================== #
1597
+ def self.open_file(
1598
+ main_window = LibuiParadise::Extensions.main_window?
1599
+ )
1600
+ return ::LibuiParadise::Extensions.open_file(main_window)
1601
+ end; self.instance_eval { alias ui_open_file open_file } # === LibuiParadise.ui_open_file
1602
+
1603
+ # =========================================================================== #
1604
+ # === LibuiParadise.set_main_window
1605
+ # =========================================================================== #
1606
+ def self.set_main_window(i)
1607
+ ::LibuiParadise::Extensions.set_main_window(i)
1608
+ end
1609
+
1610
+ end