libui_paradise 0.2.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2072 -0
  3. data/doc/README.gen +1931 -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 +213 -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 +1158 -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 +1611 -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 +20 -0
  79. metadata +156 -0
@@ -0,0 +1,1611 @@
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
+ alias create_entry entry # === create_entry
506
+
507
+ # ========================================================================= #
508
+ # === text?
509
+ #
510
+ # This method will guarantee a String to be returned.
511
+ #
512
+ # This is a bit weird, though. We may have to remove this method one
513
+ # day. I forgot why I added it to entry.rb specifically. After all
514
+ # other widgets also should respond to .text?.
515
+ # ========================================================================= #
516
+ def text?(from_this_pointer)
517
+ _ = ::LibUI.entry_text(from_this_pointer).to_s
518
+ add_to_the_registered_widgets(_, __method__)
519
+ return _
520
+ end
521
+
522
+ # ========================================================================= #
523
+ # === LibuiParadise::Extensions.non_wrapping_multiline_entry
524
+ #
525
+ # The upstream C API for the non-wrapping multiline edit can be found here:
526
+ #
527
+ # https://raw.githubusercontent.com/andlabs/libui/master/unix/multilineentry.c
528
+ #
529
+ # ========================================================================= #
530
+ def self.non_wrapping_multiline_entry
531
+ _ = ::LibUI.new_non_wrapping_multiline_entry
532
+ add_to_the_registered_widgets(_, __method__)
533
+ return _
534
+ end
535
+
536
+ # ========================================================================= #
537
+ # === LibuiParadise::Extensions.font (font tag, fonts tag)
538
+ # ========================================================================= #
539
+ def self.font(&block)
540
+ use_this_font = ::LibUI::FFI::FontDescriptor.malloc
541
+ if block_given?
542
+ yielded = yield
543
+ if yielded.is_a? Hash
544
+ # =================================================================== #
545
+ # === :font_size
546
+ # =================================================================== #
547
+ if yielded.has_key? :font_size
548
+ use_this_font.Size = yielded.delete(:font_size)
549
+ end
550
+ # =================================================================== #
551
+ # === :font_family
552
+ # =================================================================== #
553
+ if yielded.has_key? :font_family
554
+ use_this_font.Family = yielded.delete(:font_family)
555
+ end
556
+ # =================================================================== #
557
+ # === :stretch
558
+ # =================================================================== #
559
+ if yielded.has_key? :stretch
560
+ use_this_font.Stretch = yielded.delete(:stretch)
561
+ end
562
+ # =================================================================== #
563
+ # === :weight
564
+ # =================================================================== #
565
+ if yielded.has_key? :weight
566
+ use_this_font.Weight = yielded.delete(:weight)
567
+ end
568
+ # =================================================================== #
569
+ # === :italic
570
+ # =================================================================== #
571
+ if yielded.has_key? :italic
572
+ _ = yielded.delete(:italic_family)
573
+ if _ == true
574
+ _ = 1
575
+ elsif _ == false
576
+ _ = 0
577
+ end
578
+ use_this_font.Italic = _
579
+ end
580
+ end
581
+ end
582
+ return use_this_font
583
+ end; self.instance_eval { alias ui_font font } # === LibuiParadise::Extensions.ui_font
584
+ self.instance_eval { alias font_descriptor font } # === LibuiParadise::Extensions.font_descriptor
585
+
586
+ # ========================================================================= #
587
+ # === font
588
+ # ========================================================================= #
589
+ def font(&block)
590
+ LibuiParadise::Extensions.font(&block)
591
+ end; alias ui_font font # === ui_font
592
+ alias font_descriptor font # === font_descriptor
593
+
594
+ # ========================================================================= #
595
+ # === LibuiParadise::Extensions.non_wrapping_multiline_entry
596
+ # ========================================================================= #
597
+ def non_wrapping_multiline_entry
598
+ return ::LibuiParadise::Extensions.non_wrapping_multiline_entry
599
+ end
600
+
601
+ # ========================================================================= #
602
+ # === LibuiParadise::Extensions.menu (menu tag)
603
+ # ========================================================================= #
604
+ def self.menu(title = '')
605
+ _ = ::LibUI.new_menu(title)
606
+ add_to_the_registered_widgets(_, __method__)
607
+ return _
608
+ end; self.instance_eval { alias ui_menu menu } # === ui_menu
609
+
610
+ # ========================================================================= #
611
+ # === menu (menu tag)
612
+ # ========================================================================= #
613
+ def menu(
614
+ title = ''
615
+ )
616
+ return ::LibuiParadise::Extensions.menu(title)
617
+ end; alias ui_menu menu # === ui_menu
618
+
619
+ # ========================================================================= #
620
+ # === LibuiParadise::Extensions.vertical_separator
621
+ #
622
+ # This method will add a new vertical separator.
623
+ # ========================================================================= #
624
+ def self.vertical_separator
625
+ ::LibUI.new_vertical_separator
626
+ end; self.instance_eval { alias ui_vseparator vertical_separator } # === LibuiParadise::Extensions.ui_verticalseparator
627
+ self.instance_eval { alias ui_vsep vertical_separator } # === LibuiParadise::Extensions.ui_vsep
628
+ self.instance_eval { alias vspacer vertical_separator } # === LibuiParadise::Extensions.vspacer
629
+ self.instance_eval { alias vertical_spacer vertical_separator } # === LibuiParadise::Extensions.vertical_spacer
630
+ self.instance_eval { alias vsep vertical_separator } # === LibuiParadise::Extensions.vsept
631
+
632
+ # ========================================================================= #
633
+ # === vertical_separator
634
+ # ========================================================================= #
635
+ def vertical_separator
636
+ ::LibuiParadise::Extensions.vertical_separator
637
+ end; alias ui_vseparator vertical_separator # === ui_vseparator
638
+ alias ui_vsep vertical_separator # === ui_vsep
639
+ alias vertical_spacer vertical_separator # === vertical_spacer
640
+ alias vspacer vertical_separator # === vspacer
641
+ alias vsep vertical_separator # === vsep
642
+
643
+ # ========================================================================= #
644
+ # === LibuiParadise::Extensions.spinbox
645
+ #
646
+ # This method will return a spin-button, also called a spin-box.
647
+ #
648
+ # The first argument is the start value; the second argument is the end
649
+ # value.
650
+ # ========================================================================= #
651
+ def self.spinbox(
652
+ start_point = 0,
653
+ end_point = 100
654
+ )
655
+ if start_point.is_a? Hash
656
+ # ===================================================================== #
657
+ # === :end
658
+ # ===================================================================== #
659
+ if start_point.has_key? :end
660
+ end_point = start_point[:end]
661
+ end
662
+ # ===================================================================== #
663
+ # === :start
664
+ # ===================================================================== #
665
+ if start_point.has_key? :start
666
+ start_point = start_point[:start]
667
+ end
668
+ end
669
+ _ = ::LibUI.new_spinbox(start_point.to_i, end_point.to_i)
670
+ add_to_the_registered_widgets(_, __method__)
671
+ return _
672
+ end; self.instance_eval { alias ui_spinbox spinbox } # === LibuiParadise::Extensions.ui_spinbox
673
+ self.instance_eval { alias ui_spinbutton spinbox } # === LibuiParadise::Extensions.ui_spinbutton
674
+ self.instance_eval { alias spinbutton spinbox } # === LibuiParadise::Extensions.spinbutton
675
+
676
+ # ========================================================================= #
677
+ # === LibuiParadise::Extensions.password_entry
678
+ #
679
+ # This method will create and returns a new password entry widget. This
680
+ # means that input will be "disguised" via the '*' character.
681
+ #
682
+ # Usage example:
683
+ #
684
+ # entry = LibuiParadise::Extensions.password_entry
685
+ #
686
+ # ========================================================================= #
687
+ def self.password_entry
688
+ entry = ::LibUI.new_password_entry
689
+ add_to_the_registered_widgets(entry, __method__)
690
+ return entry
691
+ end; self.instance_eval { alias ui_password_entry password_entry } # === LibuiParadise::Extensions.ui_password_entry
692
+
693
+ # ========================================================================= #
694
+ # === password_entry
695
+ #
696
+ # Usage example:
697
+ #
698
+ # entry = ui_password_entry
699
+ #
700
+ # ========================================================================= #
701
+ def password_entry
702
+ ::LibuiParadise::Extensions.password_entry
703
+ end; alias ui_password_entry password_entry # === ui_password_entry
704
+
705
+ # ========================================================================= #
706
+ # === LibuiParadise::Extensions.text_layout
707
+ # ========================================================================= #
708
+ def self.text_layout(
709
+ i = ''
710
+ )
711
+ _ = ::LibUI.draw_new_text_layout(i.to_s)
712
+ add_to_the_registered_widgets(_, __method__)
713
+ return _
714
+ end
715
+
716
+ # ========================================================================= #
717
+ # === text_layout
718
+ # ========================================================================= #
719
+ def text_layout(
720
+ i = ''
721
+ )
722
+ ::LibuiParadise::Extensions.text_layout(i)
723
+ end
724
+
725
+ # ========================================================================= #
726
+ # === spinbox
727
+ #
728
+ # This method will return a spin-button, also called a spin-box.
729
+ # ========================================================================= #
730
+ def spinbox(
731
+ start_point = 0,
732
+ end_point = 100
733
+ )
734
+ ::LibuiParadise::Extensions.spinbox(start_point, end_point)
735
+ end; alias ui_spinbox spinbox # === ui_spinbox
736
+ alias ui_spinbutton spinbox # === ui_spinbutton
737
+ alias up_and_down_counter spinbox # === up_and_down_counter
738
+ alias spinbutton spinbox # === spinbutton
739
+ alias centered_spin_button spinbox # === centered_spin_button
740
+
741
+ # ========================================================================= #
742
+ # === LibuiParadise::Extensions.table
743
+ #
744
+ # The argument should be of type table_params.
745
+ #
746
+ # Example for this:
747
+ #
748
+ # table_params = LibUI::FFI::TableParams.malloc
749
+ # table_params.Model = model
750
+ # table_params.RowBackgroundColorModelColumn = -1
751
+ #
752
+ # ========================================================================= #
753
+ def self.table(i)
754
+ _ = ::LibUI.new_table(i)
755
+ LibuiParadise::Extensions.register_this_fiddle_pointer_widget(_, __method__)
756
+ return _
757
+ end; self.instance_eval { alias ui_table table } # === LibuiParadise::Extensions.ui_table
758
+
759
+ # ========================================================================= #
760
+ # === LibuiParadise::Extensions.checkbox (checkbox tag)
761
+ # ========================================================================= #
762
+ def self.checkbox(i = '')
763
+ _ = ::LibUI.new_checkbox(i)
764
+ add_to_the_registered_widgets(_, __method__)
765
+ return _
766
+ end
767
+
768
+ # ========================================================================= #
769
+ # === checkbox
770
+ # ========================================================================= #
771
+ def checkbox(i = '')
772
+ ::LibuiParadise::Extensions.checkbox(i)
773
+ end; alias ui_checkbox checkbox # === ui_checkbox
774
+ alias ui_check_button checkbox # === ui_check_button
775
+
776
+ # ========================================================================= #
777
+ # === checked_checkbox
778
+ # ========================================================================= #
779
+ def checked_checkbox(i = '')
780
+ _ = checkbox(i)
781
+ _.is_active
782
+ return _
783
+ end
784
+
785
+ # ========================================================================= #
786
+ # === LibuiParadise::Extensions.button (button tag)
787
+ #
788
+ # The upstream API for buttons, in C, can be found here:
789
+ #
790
+ # https://raw.githubusercontent.com/andlabs/libui/master/unix/button.c
791
+ #
792
+ # ========================================================================= #
793
+ def self.button(text)
794
+ _ = ::LibUI.new_button(text)
795
+ ::LibuiParadise::Extensions.register_this_fiddle_pointer_widget(_, __method__)
796
+ return _
797
+ end; self.instance_eval { alias ui_button button } # === LibuiParadise::Extensions.ui_button
798
+
799
+ # ========================================================================= #
800
+ # === LibuiParadise::Extensions.multiline_entry (multiline_entry tag)
801
+ #
802
+ # The upstream code for the linux-variant for a multiline-entry can
803
+ # be found here:
804
+ #
805
+ # https://raw.githubusercontent.com/andlabs/libui/master/unix/multilineentry.c
806
+ #
807
+ # A multiline-entry, also known more traditionally as a "textview",
808
+ # is a widget that allows the user to input text and modify that
809
+ # text as well.
810
+ # ========================================================================= #
811
+ def self.multiline_entry(optional_content = nil)
812
+ _ = ::LibUI.new_multiline_entry
813
+ add_to_the_registered_widgets(_, __method__)
814
+ if optional_content and optional_content.is_a?(String) and !optional_content.empty?
815
+ _.set_text(optional_content)
816
+ end
817
+ return _
818
+ end; self.instance_eval { alias ui_multiline_entry multiline_entry } # === LibuiParadise::Extensions.ui_multiline_entry
819
+ self.instance_eval { alias textview multiline_entry } # === LibuiParadise::Extensions.textview
820
+ self.instance_eval { alias text_view multiline_entry } # === LibuiParadise::Extensions.text_view
821
+ self.instance_eval { alias ui_text_view multiline_entry } # === LibuiParadise::Extensions.ui_text_view
822
+ self.instance_eval { alias ui_textview multiline_entry } # === LibuiParadise::Extensions.ui_textview
823
+ self.instance_eval { alias ui_text_buffer multiline_entry } # === LibuiParadise::Extensions.ui_text_buffer
824
+ self.instance_eval { alias input_field multiline_entry } # === LibuiParadise::Extensions.input_field
825
+ self.instance_eval { alias input multiline_entry } # === LibuiParadise::Extensions.input
826
+
827
+ # ========================================================================= #
828
+ # === Libuiparadise::Extensions.image
829
+ #
830
+ # This is currently limited to .png files only, due to ChunkyPng.
831
+ #
832
+ # At some later point in the future this limitation may be lifted. For
833
+ # now it has to remain in place.
834
+ # ========================================================================= #
835
+ def self.image(
836
+ this_file,
837
+ width = :try_to_infer_automatically,
838
+ height = :infer_automatically
839
+ )
840
+ if (width == :infer_automatically) or
841
+ (height == :infer_automatically)
842
+ unless Object.const_defined? :ChunkyPNG
843
+ begin
844
+ require 'chunky_png'
845
+ rescue LoadError; end
846
+ end
847
+ canvas = ChunkyPNG::Canvas.from_file(this_file)
848
+ data = canvas.to_rgba_stream
849
+ width = canvas.width
850
+ height = canvas.height
851
+ _ = ::LibUI.new_image(width, height) # Create the image here.
852
+ add_to_the_registered_widgets(_, __method__)
853
+ ::LibUI.image_append(
854
+ _,
855
+ data,
856
+ width,
857
+ height,
858
+ width
859
+ )
860
+ return _
861
+ end
862
+ nil
863
+ end; self.instance_eval { alias ui_image image } # === LibuiParadise::Extensions.ui_image
864
+
865
+ # ========================================================================= #
866
+ # === LibuiParadise::Extensions.font_button
867
+ #
868
+ # Create a new font button via this method.
869
+ # ========================================================================= #
870
+ def self.font_button
871
+ _ = ::LibUI.new_font_button
872
+ add_to_the_registered_widgets(_, __method__)
873
+ return _
874
+ end; self.instance_eval { alias ui_font_button font_button } # === Libuiparadise::Extensions.ui_font_button
875
+
876
+ # ========================================================================= #
877
+ # === font_button
878
+ #
879
+ # Create a new font button via this method.
880
+ # ========================================================================= #
881
+ def font_button
882
+ return ::LibuiParadise::Extensions.font_button
883
+ end; alias ui_font_button font_button # === ui_font_button
884
+
885
+ # ========================================================================= #
886
+ # === image
887
+ #
888
+ # This is currently limited to .png files only, due to ChunkyPng.
889
+ #
890
+ # At some later point in the future this limitation may be lifted. For
891
+ # now it has to remain in place.
892
+ # ========================================================================= #
893
+ def image(
894
+ this_file,
895
+ width = :try_to_infer_automatically,
896
+ height = :infer_automatically
897
+ )
898
+ Libuiparadise::Extensions.image(
899
+ this_file, width, height
900
+ )
901
+ end; alias ui_image image # === ui_image
902
+
903
+ # ========================================================================= #
904
+ # === multiline_entry
905
+ # ========================================================================= #
906
+ def multiline_entry(optional_content = nil)
907
+ ::LibuiParadise::Extensions.multiline_entry(optional_content)
908
+ end; alias ui_multiline_entry multiline_entry # === ui_multiline_entry
909
+ alias textview multiline_entry # === textview
910
+ alias text_view multiline_entry # === text_view
911
+ alias ui_text_view multiline_entry # === ui_text_view
912
+ alias ui_textview multiline_entry # === ui_textview
913
+ alias ui_text_buffer multiline_entry # === ui_text_buffer
914
+ alias input_field multiline_entry # === input_field
915
+ alias input multiline_entry # === input
916
+
917
+ # ========================================================================= #
918
+ # === LibuiParadise::Extensions.radio_buttons
919
+ #
920
+ # This method will create some radio buttons.
921
+ #
922
+ # You can pass an Array into this method, which should be an Array of
923
+ # Strings. This is optional. If such an Array is given, though, then
924
+ # these entries will become radio-buttons, with the associated label
925
+ # (the text they display) becoming the label right next to the radio
926
+ # button element (that round circle that the user can select via
927
+ # the mouse cursor).
928
+ # ========================================================================= #
929
+ def self.radio_buttons(
930
+ optional_array = []
931
+ )
932
+ _ = ::LibUI.new_radio_buttons
933
+ if optional_array and optional_array.is_a?(Array) and !optional_array.empty?
934
+ optional_array.each {|this_element|
935
+ ::LibUI.radio_buttons_append(_, this_element)
936
+ }
937
+ end
938
+ add_to_the_registered_widgets(_, __method__)
939
+ return _
940
+ end; self.instance_eval { alias ui_radio_buttons radio_buttons } # === LibuiParadise::Extensionsui_radio_buttons
941
+
942
+ # ========================================================================= #
943
+ # === radio_buttons
944
+ # ========================================================================= #
945
+ def radio_buttons(optional_array = [])
946
+ return ::LibuiParadise::Extensions.radio_buttons(optional_array)
947
+ end; alias ui_radio_buttons radio_buttons # === ui_radio_buttons
948
+
949
+ # ========================================================================= #
950
+ # === LibuiParadise::Extensions.new_colour_button
951
+ #
952
+ # The upstream API for a colour-button (in C) can be found here:
953
+ #
954
+ # https://github.com/andlabs/libui/blob/master/unix/colorbutton.c
955
+ #
956
+ # ========================================================================= #
957
+ def self.colour_button
958
+ _ = ::LibUI.new_color_button
959
+ ::LibuiParadise::Extensions.register_this_fiddle_pointer_widget(_, __method__)
960
+ return _
961
+ end; self.instance_eval { alias new_colour_button colour_button } # === LibuiParadise::Extensions.new_colour_button
962
+ self.instance_eval { alias new_color_button colour_button } # === LibuiParadise::Extensions.new_color_button
963
+ self.instance_eval { alias ui_colour_button colour_button } # === LibuiParadise::Extensions.ui_colour_button
964
+
965
+ # ========================================================================= #
966
+ # === colour_button
967
+ # ========================================================================= #
968
+ def colour_button
969
+ ::LibuiParadise::Extensions.new_colour_button
970
+ end; alias color_button colour_button # === color_button
971
+ alias ui_colour_button colour_button # === ui_color_button
972
+
973
+ # ========================================================================= #
974
+ # === LibuiParadise::Extensions.scrolling_area
975
+ #
976
+ # It seems as if scrolling is not yet easily available in libui.
977
+ #
978
+ # The upstream API is like this:
979
+ #
980
+ # uiArea *area = uiNewScrollingArea(&handler, 400, 400);
981
+ #
982
+ # The two numbers are width and height, as integers, respectively.
983
+ # In total three arguments are required. The first argument is
984
+ # a so-called "AreaHandler".
985
+ #
986
+ # The code may be found here:
987
+ #
988
+ # https://github.com/andlabs/libui/blob/master/windows/areascroll.cpp
989
+ #
990
+ # ========================================================================= #
991
+ def self.scrolling_area(
992
+ widget,
993
+ width = 400,
994
+ height = 400
995
+ )
996
+ case width
997
+ when :default, nil
998
+ width = 400
999
+ end
1000
+ case height
1001
+ when :default, nil
1002
+ height = 400
1003
+ end
1004
+ _ = ::LibUI.new_scrolling_area(widget, width, height)
1005
+ # ======================================================================= #
1006
+ # The next part does not yet work - is it even possible to add widgets
1007
+ # to a scrolling area in libui?
1008
+ # if optional_widget
1009
+ # _.add(optional_widget)
1010
+ # end
1011
+ # ======================================================================= #
1012
+ add_to_the_registered_widgets(_, __method__)
1013
+ return _
1014
+ end; self.instance_eval { alias ui_scrolling_area scrolling_area } # === LibuiParadise::Extensions.ui_scrolling_area
1015
+ self.instance_eval { alias ui_scrolled_window scrolling_area } # === LibuiParadise::Extensions.ui_scrolling_window
1016
+
1017
+ # ========================================================================= #
1018
+ # === scrolling_area
1019
+ #
1020
+ # It seems as if scrolling is not yet easily available in libui.
1021
+ #
1022
+ # The upstream API is like this:
1023
+ #
1024
+ # uiArea *area = uiNewScrollingArea(&handler, 400, 400);
1025
+ #
1026
+ # ========================================================================= #
1027
+ def scrolling_area(
1028
+ optional_widget = nil
1029
+ )
1030
+ LibuiParadise::Extensions.scrolling_area(optional_widget)
1031
+ end; alias ui_scrolling_area scrolling_area # === ui_scrolling_area
1032
+ alias ui_scrolled_window scrolling_area # === ui_scrolling_window
1033
+
1034
+ # ========================================================================= #
1035
+ # === bold_button
1036
+ #
1037
+ # This currently does not work. We have to wait until upstream libui
1038
+ # supports bold font text.
1039
+ # ========================================================================= #
1040
+ def bold_button(i)
1041
+ button(i)
1042
+ end
1043
+
1044
+ # ========================================================================= #
1045
+ # === quit_button (quit tag)
1046
+ #
1047
+ # This method can be used to, by default, implement a quit button
1048
+ # that, upon a click-event, will cause the application to exit
1049
+ # and close/quit.
1050
+ # ========================================================================= #
1051
+ def quit_button(
1052
+ optional_arguments = {}
1053
+ )
1054
+ use_this_text = 'Quit'
1055
+ if optional_arguments and optional_arguments.is_a?(Hash)
1056
+ # ===================================================================== #
1057
+ # === :text
1058
+ # ===================================================================== #
1059
+ if optional_arguments.has_key? :text
1060
+ use_this_text = optional_arguments.delete(:text)
1061
+ end
1062
+ end
1063
+ if block_given?
1064
+ yielded = yield
1065
+ case yielded
1066
+ # ===================================================================== #
1067
+ # === :with_emoji
1068
+ # ===================================================================== #
1069
+ when :with_emoji,
1070
+ :with_icon
1071
+ use_this_text = use_this_text.to_s.dup
1072
+ use_this_text << ' 🛑'
1073
+ end
1074
+ end
1075
+ quit_button = button(use_this_text)
1076
+ quit_button.on_clicked {
1077
+ ::LibUI.quit
1078
+ 0
1079
+ }
1080
+ return quit_button
1081
+ end; alias ui_quit_button quit_button # === ui_quit_button
1082
+
1083
+ # ========================================================================= #
1084
+ # === table
1085
+ # ========================================================================= #
1086
+ def table(i)
1087
+ ::LibuiParadise::Extensions.table(i)
1088
+ end; alias ui_table table # === ui_table
1089
+
1090
+ # ========================================================================= #
1091
+ # === LibuiParadise::Extensions.editable_combobox
1092
+ #
1093
+ # This is a combo-box that the user can modify.
1094
+ # ========================================================================= #
1095
+ def self.editable_combobox(
1096
+ optional_array = nil, &block
1097
+ )
1098
+ _ = ::LibUI.new_editable_combobox
1099
+ if block_given?
1100
+ optional_array = yield
1101
+ end
1102
+ if optional_array and optional_array.is_a?(Array)
1103
+ append_this_array_to_that_combobox(optional_array, _)
1104
+ end
1105
+ add_to_the_registered_widgets(_, __method__)
1106
+ return _
1107
+ end; self.instance_eval { alias editable_combo_box editable_combobox } # === LibuiParadise::Extensions.editable_combo_box
1108
+ self.instance_eval { alias ui_editable_combo_box editable_combobox } # === LibuiParadise::Extensions.ui_editable_combo_box
1109
+
1110
+ # ========================================================================= #
1111
+ # === LibuiParadise::Extensions.combobox
1112
+ # ========================================================================= #
1113
+ def self.combobox(
1114
+ optional_array = nil, &block
1115
+ )
1116
+ combobox = ::LibUI.new_combobox
1117
+ # ======================================================================= #
1118
+ # Register it at once:
1119
+ # ======================================================================= #
1120
+ add_to_the_registered_widgets(combobox, __method__)
1121
+ if block_given?
1122
+ optional_array = yield
1123
+ end
1124
+ if optional_array and optional_array.is_a?(Array)
1125
+ # append_this_array_to_that_combobox(optional_array, combobox)
1126
+ combobox.append_this_array(optional_array)
1127
+ end
1128
+ return combobox
1129
+ end; self.instance_eval { alias combo_box combobox } # === LibuiParadise::Extensions.combo_box
1130
+ self.instance_eval { alias ui_combo_box combobox } # === LibuiParadise::Extensions.ui_combo_box
1131
+ self.instance_eval { alias ui_combobox combobox } # === LibuiParadise::Extensions.ui_combobox
1132
+
1133
+ # ========================================================================= #
1134
+ # === selected?
1135
+ #
1136
+ # Unsure whether this works. It appears to work, but I am not even
1137
+ # certain as to why.
1138
+ # ========================================================================= #
1139
+ def selected?(pointer)
1140
+ ::LibUI.combobox_selected(pointer).to_s
1141
+ end
1142
+
1143
+ # ========================================================================= #
1144
+ # === combobox
1145
+ #
1146
+ # The first argument can be an Array.
1147
+ # ========================================================================= #
1148
+ def combobox(
1149
+ optional_array = nil, &block
1150
+ )
1151
+ return ::LibuiParadise::Extensions.combobox(optional_array, &block)
1152
+ end; alias combo_box combobox # === combo_box
1153
+ alias ui_combo_box combobox # === ui_combo_box
1154
+ alias ui_combobox combobox # === ui_combobox
1155
+ alias combo_box_entry combobox # === combo_box_entry
1156
+ alias libui_combo_box combobox # === libui_combo_box
1157
+
1158
+ # ========================================================================= #
1159
+ # === editable_combobox
1160
+ # ========================================================================= #
1161
+ def editable_combobox(
1162
+ optional_array = nil, &block
1163
+ )
1164
+ return ::LibuiParadise::Extensions(optional_array, &block)
1165
+ end; alias editable_combo_box editable_combobox # === editable_combo_box
1166
+ alias ui_editable_combo_box editable_combobox # === ui_editable_combo_box
1167
+
1168
+ # ========================================================================= #
1169
+ # === LibuiParadise::Extensions.label (text tag, label tag)
1170
+ #
1171
+ # Add text to the widget at hand. This is actually called a "label".
1172
+ # ========================================================================= #
1173
+ def self.label(
1174
+ i = ''
1175
+ )
1176
+ if i.include? '</'
1177
+ # ===================================================================== #
1178
+ # For now we must remove "HTML tags" from the given input. Perhaps
1179
+ # at some later point in time we can retain them.
1180
+ # ===================================================================== #
1181
+ i = i.dup if i.frozen?
1182
+ i.gsub!(%r{<[^>]+>}, '')
1183
+ end
1184
+ _ = ::LibUI.new_label(i.to_s)
1185
+ add_to_the_registered_widgets(_, __method__)
1186
+ return _
1187
+ end; self.instance_eval { alias text label } # === LibuiParadise::Extensions.text
1188
+ self.instance_eval { alias ui_text label } # === LibuiParadise::Extensions.ui_text
1189
+ self.instance_eval { alias ui_label label } # === LibuiParadise::Extensions.ui_label
1190
+
1191
+ # ========================================================================= #
1192
+ # === label
1193
+ #
1194
+ # The last two aliases, left_aligned_label, should be different, but
1195
+ # right now I don't know how to do this in libui.
1196
+ # ========================================================================= #
1197
+ def label(
1198
+ i = ''
1199
+ )
1200
+ ::LibuiParadise::Extensions.label(i)
1201
+ end; alias text label # === text
1202
+ alias ui_text label # === ui_text
1203
+ alias ui_label label # === ui_label
1204
+ alias left_aligned_label label # === left_aligned_label
1205
+ alias left_aligned_text label # === left_aligned_text
1206
+
1207
+ # ========================================================================= #
1208
+ # === bold_label
1209
+ #
1210
+ # This currently does not work properly. We may have to re-examine this
1211
+ # eventually at a later point.
1212
+ # ========================================================================= #
1213
+ def bold_label(i = '')
1214
+ return label(i)
1215
+ end
1216
+
1217
+ # ========================================================================= #
1218
+ # === bold_text
1219
+ #
1220
+ # This currently does NOT make the text bold - the method exists solely
1221
+ # as a placeholder, until upstream libui supports bold text as such.
1222
+ # ========================================================================= #
1223
+ def bold_text(i = '')
1224
+ return label(i)
1225
+ end
1226
+
1227
+ # ========================================================================= #
1228
+ # === bold_text_left_aligned
1229
+ # ========================================================================= #
1230
+ def bold_text_left_aligned(i = '')
1231
+ return label(i)
1232
+ end; alias left_aligned_bold_label bold_text_left_aligned # === left_aligned_bold_label
1233
+
1234
+ # ========================================================================= #
1235
+ # === fancy_text
1236
+ #
1237
+ # This text variant can be styled.
1238
+ # ========================================================================= #
1239
+ def fancy_text(i = '')
1240
+ _ = LibUI.new_attributed_string(i.to_s)
1241
+ add_to_the_registered_widgets(_, __method__)
1242
+ return _
1243
+ end; alias attributed_string fancy_text # === attributed_string
1244
+
1245
+ # ========================================================================= #
1246
+ # === LibuiParadise::Extensions.tab
1247
+ #
1248
+ # This could be also called "notebook_tab".
1249
+ # ========================================================================= #
1250
+ def self.tab
1251
+ _ = ::LibUI.new_tab
1252
+ add_to_the_registered_widgets(_, __method__)
1253
+ return _
1254
+ end; self.instance_eval { alias ui_tab tab } # === LibuiParadise::Extensions.ui_tab
1255
+ self.instance_eval { alias ui_tabs tab } # === LibuiParadise::Extensions.ui_tabs
1256
+ self.instance_eval { alias notebook tab } # === LibuiParadise::Extensions.notebook
1257
+ self.instance_eval { alias ui_notebook tab } # === LibuiParadise::Extensions.ui_notebook
1258
+ self.instance_eval { alias notebook_tab tab } # === LibuiParadise::Extensions.notebook_tab
1259
+
1260
+ # ========================================================================= #
1261
+ # === tab
1262
+ #
1263
+ # This could be also called "notebook_tab".
1264
+ # ========================================================================= #
1265
+ def tab
1266
+ ::LibuiParadise::Extensions.tab
1267
+ end; alias ui_tab tab # === ui_tab
1268
+ alias ui_tabs tab # === ui_tabs
1269
+ alias notebook tab # === notebook
1270
+ alias ui_notebook tab # === ui_notebook
1271
+ alias notebook_tab tab # === notebook_tab
1272
+
1273
+ # ========================================================================= #
1274
+ # === LibuiParadise::Extensions.area
1275
+ #
1276
+ # AreaHandler defines the functionality needed for handling events from
1277
+ # an Area.
1278
+ #
1279
+ # Upstream documentation, at the least for Go, can be found here:
1280
+ #
1281
+ # https://github.com/andlabs/ui/blob/master/areahandler.go
1282
+ #
1283
+ # ========================================================================= #
1284
+ def self.area(
1285
+ i = :use_new_area_handler
1286
+ )
1287
+ case i
1288
+ # ======================================================================= #
1289
+ # === :use_new_area_handler
1290
+ # ======================================================================= #
1291
+ when :use_new_area_handler,
1292
+ :default
1293
+ # ===================================================================== #
1294
+ # malloc a new area-handled next:
1295
+ # ===================================================================== #
1296
+ i = ::LibUI::FFI::AreaHandler.malloc
1297
+ i.to_ptr.free = Fiddle::RUBY_FREE # This one is done in upstream LibUI as well.
1298
+ end
1299
+ _ = ::LibUI.new_area(i) # Our new area, with the given handler.
1300
+ add_to_the_registered_widgets(_, __method__)
1301
+ return _
1302
+ end; self.instance_eval { alias area_handler area } # === LibuiParadise::Extensions.area_handler
1303
+
1304
+ # ========================================================================= #
1305
+ # === area
1306
+ #
1307
+ # AreaHandler defines the functionality needed for handling events
1308
+ # from an Area.
1309
+ #
1310
+ # Upstream documentation, at the least for Go, can be found here:
1311
+ #
1312
+ # https://github.com/andlabs/ui/blob/master/areahandler.go
1313
+ #
1314
+ # ========================================================================= #
1315
+ def area(
1316
+ i = :use_new_area_handler
1317
+ )
1318
+ return ::LibuiParadise::Extensions.area(i)
1319
+ end; alias area_handler area # === area_handler
1320
+
1321
+ # ========================================================================= #
1322
+ # === is_on_windows?
1323
+ # ========================================================================= #
1324
+ def is_on_windows?
1325
+ Gem.win_platform?
1326
+ end
1327
+
1328
+ end
1329
+
1330
+ # =========================================================================== #
1331
+ # === LibuiParadise.window
1332
+ # =========================================================================== #
1333
+ def self.window(
1334
+ the_title = '', # Pick a title for the window here.
1335
+ width = 500, # width in n pixels.
1336
+ height = 300, # height in n pixels.
1337
+ has_menubar = 1 # hasMenubar or has not.
1338
+ )
1339
+ ::LibuiParadise::Extensions.window(
1340
+ the_title,
1341
+ width,
1342
+ height,
1343
+ has_menubar
1344
+ )
1345
+ end; self.instance_eval { alias main_window window } # === LibuiParadise.main_window
1346
+ self.instance_eval { alias margined_window window } # === LibuiParadise.margined_window
1347
+ self.instance_eval { alias ui_window window } # === LibuiParadise.ui_window
1348
+ self.instance_eval { alias ui_main_window window } # === LibuiParadise.ui_main_window
1349
+ self.instance_eval { alias ui_padded_main_window window } # === LibuiParadise.margined_window
1350
+ self.instance_eval { alias padded_window window } # === LibuiParadise.padded_window
1351
+ self.instance_eval { alias padded_main_window window } # === LibuiParadise.padded_main_window
1352
+ self.instance_eval { alias window_or_vbox window } # === LibuiParadise.window_or_vbox
1353
+
1354
+ # =========================================================================== #
1355
+ # === LibuiParadise.main_window?
1356
+ # =========================================================================== #
1357
+ def self.main_window?
1358
+ LibuiParadise::Extensions.main_window?
1359
+ end
1360
+
1361
+ # =========================================================================== #
1362
+ # === LibuiParadise::Extensions.editable_combobox
1363
+ # =========================================================================== #
1364
+ def self.editable_combobox(
1365
+ optional_array = nil, &block
1366
+ )
1367
+ return ::LibuiParadise::Extensions.editable_combobox(optional_array, &block)
1368
+ end; self.instance_eval { alias editable_combo_box editable_combobox } # === LibuiParadise.editable_combo_box
1369
+ self.instance_eval { alias ui_editable_combo_box editable_combobox } # === LibuiParadise.ui_editable_combo_box
1370
+
1371
+ # ========================================================================= #
1372
+ # === LibuiParadise.label
1373
+ #
1374
+ # Toplevel method to create a new label, aka new text.
1375
+ # ========================================================================= #
1376
+ def self.label(
1377
+ i = ''
1378
+ )
1379
+ ::LibuiParadise::Extensions.label(i)
1380
+ end; self.instance_eval { alias text label } # === LibuiParadise.text
1381
+ self.instance_eval { alias ui_text label } # === LibuiParadise.ui_text
1382
+ self.instance_eval { alias ui_label label } # === LibuiParadise.ui_label
1383
+
1384
+ # ========================================================================= #
1385
+ # === LibuiParadise.string
1386
+ # ========================================================================= #
1387
+ def self.string(i = '')
1388
+ return ::LibUI.new_attributed_string(i)
1389
+ end; self.instance_eval { alias fancy_text string } # === LibuiParadise.fancy_text
1390
+
1391
+ # =========================================================================== #
1392
+ # === LibuiParadise.table
1393
+ # =========================================================================== #
1394
+ def self.table(i)
1395
+ ::LibuiParadise::Extensions.table(i)
1396
+ end; self.instance_eval { alias ui_table table } # === LibuiParadise.ui_table
1397
+
1398
+ # =========================================================================== #
1399
+ # === LibuiParadise.spinbox
1400
+ # =========================================================================== #
1401
+ def self.spinbox(
1402
+ start_point = 0,
1403
+ end_point = 100
1404
+ )
1405
+ ::LibuiParadise::Extensions.spinbox(start_point, end_point)
1406
+ end; self.instance_eval { alias ui_spinbox spinbox } # === LibuiParadise.ui_spinbox
1407
+ self.instance_eval { alias ui_spinbutton spinbox } # === LibuiParadise.ui_spinbutton
1408
+ self.instance_eval { alias spinbutton spinbox } # === LibuiParadise.spinbutton
1409
+
1410
+ # =========================================================================== #
1411
+ # === LibuiParadise.slider
1412
+ # =========================================================================== #
1413
+ def self.slider(
1414
+ start_value = 0,
1415
+ end_value = 100
1416
+ )
1417
+ ::LibuiParadise::Extensions.slider(start_value, end_value)
1418
+ end; self.instance_eval { alias ui_slider slider } # === LibuiParadise.ui_slider
1419
+
1420
+ # =========================================================================== #
1421
+ # === LibuiParadise.button
1422
+ # =========================================================================== #
1423
+ def self.button(text)
1424
+ ::LibuiParadise::Extensions.button(text)
1425
+ end
1426
+
1427
+ # =========================================================================== #
1428
+ # === LibuiParadise.checkbox
1429
+ # =========================================================================== #
1430
+ def self.checkbox(i = '')
1431
+ ::LibuiParadise::Extensions.checkbox(i)
1432
+ end
1433
+
1434
+ # =========================================================================== #
1435
+ # === LibuiParadise.msg_box
1436
+ # =========================================================================== #
1437
+ def self.msg_box(
1438
+ main_window = :default_window,
1439
+ title_to_use = '',
1440
+ whatever = ''
1441
+ )
1442
+ if main_window.is_a?(String) and title_to_use.is_a?(String) and
1443
+ title_to_use.empty?
1444
+ title_to_use = main_window.dup
1445
+ main_window = :default_window
1446
+ end
1447
+ ::LibuiParadise::Extensions.msg_box(
1448
+ main_window,
1449
+ title_to_use,
1450
+ whatever
1451
+ )
1452
+ end; self.instance_eval { alias ui_msg_box msg_box } # === LibuiParadise.ui_msg_box
1453
+ self.instance_eval { alias message_to_the_user msg_box } # === LibuiParadise.message_to_the_user
1454
+ self.instance_eval { alias message_box msg_box } # === LibuiParadise.message_box
1455
+ self.instance_eval { alias popup_over_this_widget msg_box } # === LibuiParadise.popup_over_this_widget
1456
+ self.instance_eval { alias popup_message msg_box } # === LibuiParadise.popup_message
1457
+
1458
+ # =========================================================================== #
1459
+ # === LibuiParadise.new_progress_bar
1460
+ # =========================================================================== #
1461
+ def self.new_progress_bar
1462
+ return ::LibuiParadise::Extensions.new_progress_bar
1463
+ end
1464
+
1465
+ # ========================================================================= #
1466
+ # === LibuiParadise.vertical_separator
1467
+ # ========================================================================= #
1468
+ def self.vertical_separator
1469
+ ::LibuiParadise::Extensions.vertical_separator
1470
+ end; self.instance_eval { alias ui_vseparator vertical_separator } # === LibuiParadise.ui_vseparator
1471
+ self.instance_eval { alias ui_vsep vertical_separator } # === LibuiParadise.ui_vsep
1472
+ self.instance_eval { alias vsep vertical_separator } # === LibuiParadise.vsep
1473
+
1474
+ # =========================================================================== #
1475
+ # === LibuiParadise.text_layout
1476
+ # =========================================================================== #
1477
+ def self.text_layout(
1478
+ i = ''
1479
+ )
1480
+ ::LibuiParadise::Extensions.text_layout(i)
1481
+ end
1482
+
1483
+ # =========================================================================== #
1484
+ # === LibuiParadise.search_entry
1485
+ # =========================================================================== #
1486
+ def self.search_entry
1487
+ ::LibuiParadise::Extensions.search_entry
1488
+ end; self.instance_eval { alias ui_search_entry search_entry } # === LibuiParadise.ui_search_entry
1489
+
1490
+ # =========================================================================== #
1491
+ # === LibuiParadise.scrolling_area
1492
+ # =========================================================================== #
1493
+ def self.scrolling_area(
1494
+ widget,
1495
+ width = :default,
1496
+ height = :default
1497
+ )
1498
+ ::LibuiParadise::Extensions.scrolling_area(widget, width, height)
1499
+ end
1500
+
1501
+ # =========================================================================== #
1502
+ # === LibuiParadise.radio_buttons
1503
+ # =========================================================================== #
1504
+ def self.radio_buttons(optional_array = [])
1505
+ return ::LibuiParadise::Extensions.radio_buttons(optional_array)
1506
+ end
1507
+
1508
+ # =========================================================================== #
1509
+ # === LibuiParadise.password_entry
1510
+ # =========================================================================== #
1511
+ def self.password_entry
1512
+ ::LibuiParadise::Extensions.password_entry
1513
+ end; self.instance_eval { alias ui_password_entry password_entry } # === LibuiParadise.ui_password_entry
1514
+
1515
+ # =========================================================================== #
1516
+ # === LibuiParadise.non_wrapping_multiline_entry
1517
+ # =========================================================================== #
1518
+ def self.non_wrapping_multiline_entry
1519
+ return ::LibuiParadise::Extensions.non_wrapping_multiline_entry
1520
+ end
1521
+
1522
+ # =========================================================================== #
1523
+ # === LibuiParadise.multiline_entry
1524
+ # =========================================================================== #
1525
+ def self.multiline_entry(optional_content = nil)
1526
+ ::LibuiParadise::Extensions.multiline_entry(optional_content)
1527
+ end; self.instance_eval { alias textview multiline_entry } # === LibuiParadise.textview
1528
+ self.instance_eval { alias text_view multiline_entry } # === LibuiParadise.text_view
1529
+ self.instance_eval { alias ui_text_view multiline_entry } # === LibuiParadise.ui_text_view
1530
+ self.instance_eval { alias ui_textview multiline_entry } # === LibuiParadise.ui_textview
1531
+ self.instance_eval { alias ui_text_buffer multiline_entry } # === LibuiParadise.ui_text_buffer
1532
+ self.instance_eval { alias input_field multiline_entry } # === LibuiParadise.input_field
1533
+
1534
+ # =========================================================================== #
1535
+ # === LibuiParadise.menu
1536
+ # =========================================================================== #
1537
+ def self.menu(title = '')
1538
+ return LibuiParadise::Extensions.menu(title)
1539
+ end; self.instance_eval { alias ui_menu menu } # === LibuiParadise.ui_menu
1540
+
1541
+ # ========================================================================= #
1542
+ # === Libuiparadise.image
1543
+ # ========================================================================= #
1544
+ def self.image(
1545
+ this_file,
1546
+ width = :try_to_infer_automatically,
1547
+ height = :infer_automatically
1548
+ )
1549
+ ::LibuiParadise::Extensions.image(
1550
+ this_file, width, height
1551
+ )
1552
+ end; self.instance_eval { alias ui_image image } # === LibuiParadise.ui_image
1553
+
1554
+ # =========================================================================== #
1555
+ # === LibuiParadise.colour_button
1556
+ # =========================================================================== #
1557
+ def self.colour_button
1558
+ ::LibuiParadise::Extensions.new_colour_button
1559
+ end; self.instance_eval { alias color_button colour_button } # === LibuiParadise.color_button
1560
+
1561
+ # =========================================================================== #
1562
+ # === LibuiParadise.font_button
1563
+ # =========================================================================== #
1564
+ def self.font_button
1565
+ return ::LibuiParadise::Extensions.font_button
1566
+ end
1567
+
1568
+ # ========================================================================= #
1569
+ # === LibuiParadise.horizontal_separator
1570
+ # ========================================================================= #
1571
+ def self.horizontal_separator
1572
+ ::LibuiParadise::Extensions.horizontal_separator
1573
+ end; self.instance_eval { alias ui_hseparator horizontal_separator } # === LibuiParadise.ui_hseparator
1574
+ self.instance_eval { alias ui_hsep horizontal_separator } # === LibuiParadise.ui_hsep
1575
+ self.instance_eval { alias hsep horizontal_separator } # === LibuiParadise.hsep
1576
+
1577
+ # =========================================================================== #
1578
+ # === LibuiParadise.font
1579
+ # =========================================================================== #
1580
+ def self.font(&block)
1581
+ ::LibuiParadise::Extensions.font(&block)
1582
+ end
1583
+
1584
+ # =========================================================================== #
1585
+ # === LibuiParadise.entry
1586
+ # =========================================================================== #
1587
+ def self.entry(
1588
+ optional_text = ''
1589
+ )
1590
+ ::LibuiParadise::Extensions.entry(optional_text)
1591
+ end; self.instance_eval { alias ui_entry entry } # === LibuiParadise.ui_entry
1592
+
1593
+ # =========================================================================== #
1594
+ # === LibuiParadise.open_file
1595
+ #
1596
+ # Simple delegator towards LibuiParadise::Extensions.open_file().
1597
+ # =========================================================================== #
1598
+ def self.open_file(
1599
+ main_window = LibuiParadise::Extensions.main_window?
1600
+ )
1601
+ return ::LibuiParadise::Extensions.open_file(main_window)
1602
+ end; self.instance_eval { alias ui_open_file open_file } # === LibuiParadise.ui_open_file
1603
+
1604
+ # =========================================================================== #
1605
+ # === LibuiParadise.set_main_window
1606
+ # =========================================================================== #
1607
+ def self.set_main_window(i)
1608
+ ::LibuiParadise::Extensions.set_main_window(i)
1609
+ end
1610
+
1611
+ end