libui_paradise 0.3.9 → 0.4.13

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