libui_paradise 0.1.49

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

Potentially problematic release.


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

Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1505 -0
  3. data/doc/README.gen +1252 -0
  4. data/doc/SNIPPETS.md +221 -0
  5. data/doc/TODO.md +14 -0
  6. data/lib/libui_paradise/autoinclude.rb +9 -0
  7. data/lib/libui_paradise/domain_specific_language/README.md +5 -0
  8. data/lib/libui_paradise/domain_specific_language/button.yml +7 -0
  9. data/lib/libui_paradise/examples/001_basic_button_example.rb +17 -0
  10. data/lib/libui_paradise/examples/002_basic_table_image.rb +92 -0
  11. data/lib/libui_paradise/examples/003_font_button.rb +34 -0
  12. data/lib/libui_paradise/examples/004_date_time_picker.rb +31 -0
  13. data/lib/libui_paradise/examples/005_msg_box_error.rb +25 -0
  14. data/lib/libui_paradise/examples/006_histogram.rb +193 -0
  15. data/lib/libui_paradise/examples/007_combo_box_example.rb +41 -0
  16. data/lib/libui_paradise/examples/008_simple_notepad_example.rb +23 -0
  17. data/lib/libui_paradise/examples/009_checkbox_example.rb +82 -0
  18. data/lib/libui_paradise/examples/010_grid_example.rb +26 -0
  19. data/lib/libui_paradise/examples/011_fancy_text_example.rb +21 -0
  20. data/lib/libui_paradise/examples/012_control_gallery.rb +180 -0
  21. data/lib/libui_paradise/examples/013_midi_player.rb +91 -0
  22. data/lib/libui_paradise/examples/014_basic_draw_text.rb +134 -0
  23. data/lib/libui_paradise/examples/015_font_example.rb +91 -0
  24. data/lib/libui_paradise/examples/016_search_entry_example.rb +16 -0
  25. data/lib/libui_paradise/examples/017_tabs_example.rb +22 -0
  26. data/lib/libui_paradise/examples/018_image_example.rb +82 -0
  27. data/lib/libui_paradise/examples/019_open_file_button_example.rb +24 -0
  28. data/lib/libui_paradise/examples/020_unicode_text_example.rb +28 -0
  29. data/lib/libui_paradise/examples/021_spinbutton_example.rb +25 -0
  30. data/lib/libui_paradise/examples/022_text_example.rb +16 -0
  31. data/lib/libui_paradise/examples/023_parse_config_file_example.config +6 -0
  32. data/lib/libui_paradise/examples/023_parse_config_file_example.rb +13 -0
  33. data/lib/libui_paradise/examples/024_text_view_example.rb +14 -0
  34. data/lib/libui_paradise/examples/025_scrolling_area.rb +16 -0
  35. data/lib/libui_paradise/examples/026_colour_button.rb +51 -0
  36. data/lib/libui_paradise/examples/027_form_example.rb +37 -0
  37. data/lib/libui_paradise/examples/028_password_entry_example.rb +17 -0
  38. data/lib/libui_paradise/examples/029_two_buttons_showing_how_to_enable_and_disable_them.rb +32 -0
  39. data/lib/libui_paradise/examples/030_table_example.rb +51 -0
  40. data/lib/libui_paradise/experimental/dsl.rb +17 -0
  41. data/lib/libui_paradise/extensions/extensions.rb +25 -0
  42. data/lib/libui_paradise/extensions/hash_fiddle_pointer_widgets.rb +129 -0
  43. data/lib/libui_paradise/extensions/misc.rb +309 -0
  44. data/lib/libui_paradise/fiddle/pointer.rb +841 -0
  45. data/lib/libui_paradise/images/LIBUI_PARADISE_LOGO.png +0 -0
  46. data/lib/libui_paradise/images/README.md +2 -0
  47. data/lib/libui_paradise/images/form_example.png +0 -0
  48. data/lib/libui_paradise/libui_classes/area_handler.rb +52 -0
  49. data/lib/libui_paradise/libui_classes/button.rb +82 -0
  50. data/lib/libui_paradise/libui_classes/checkbox.rb +37 -0
  51. data/lib/libui_paradise/libui_classes/color_button.rb +44 -0
  52. data/lib/libui_paradise/libui_classes/combobox.rb +55 -0
  53. data/lib/libui_paradise/libui_classes/editable_combobox.rb +51 -0
  54. data/lib/libui_paradise/libui_classes/entry.rb +80 -0
  55. data/lib/libui_paradise/libui_classes/font.rb +78 -0
  56. data/lib/libui_paradise/libui_classes/font_button.rb +40 -0
  57. data/lib/libui_paradise/libui_classes/grid.rb +55 -0
  58. data/lib/libui_paradise/libui_classes/hbox.rb +98 -0
  59. data/lib/libui_paradise/libui_classes/horizontal_separator.rb +41 -0
  60. data/lib/libui_paradise/libui_classes/image.rb +82 -0
  61. data/lib/libui_paradise/libui_classes/label.rb +83 -0
  62. data/lib/libui_paradise/libui_classes/menu.rb +36 -0
  63. data/lib/libui_paradise/libui_classes/msg_box.rb +97 -0
  64. data/lib/libui_paradise/libui_classes/msg_box_error.rb +49 -0
  65. data/lib/libui_paradise/libui_classes/multiline_entry.rb +59 -0
  66. data/lib/libui_paradise/libui_classes/non_wrapping_multiline_entry.rb +41 -0
  67. data/lib/libui_paradise/libui_classes/open_file.rb +42 -0
  68. data/lib/libui_paradise/libui_classes/password_entry.rb +49 -0
  69. data/lib/libui_paradise/libui_classes/progressbar.rb +41 -0
  70. data/lib/libui_paradise/libui_classes/radio_buttons.rb +36 -0
  71. data/lib/libui_paradise/libui_classes/scrolling_area.rb +85 -0
  72. data/lib/libui_paradise/libui_classes/search_entry.rb +36 -0
  73. data/lib/libui_paradise/libui_classes/spinbox.rb +55 -0
  74. data/lib/libui_paradise/libui_classes/tab.rb +39 -0
  75. data/lib/libui_paradise/libui_classes/table.rb +45 -0
  76. data/lib/libui_paradise/libui_classes/text_layout.rb +42 -0
  77. data/lib/libui_paradise/libui_classes/vbox.rb +51 -0
  78. data/lib/libui_paradise/libui_classes/window.rb +167 -0
  79. data/lib/libui_paradise/project/project.rb +26 -0
  80. data/lib/libui_paradise/prototype/README.md +3 -0
  81. data/lib/libui_paradise/prototype/prototype.rb +101 -0
  82. data/lib/libui_paradise/requires/require_the_libui_classes.rb +26 -0
  83. data/lib/libui_paradise/requires/require_the_libui_paradise_project.rb +11 -0
  84. data/lib/libui_paradise/version/version.rb +17 -0
  85. data/lib/libui_paradise.rb +1 -0
  86. data/libui_paradise.gemspec +49 -0
  87. metadata +164 -0
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This example display a single image. This is hardcoded to a local
6
+ # path, so change that constant if you want another image.
7
+ # =========================================================================== #
8
+ require 'libui_paradise/autoinclude'
9
+ require 'chunky_png'
10
+
11
+ # =========================================================================== #
12
+ # === THIS_FILE
13
+ # =========================================================================== #
14
+ THIS_FILE = '/home/x/data/images/NJOY/MEDITERRANEAN.png'
15
+ main_window = ui_main_window('The Red Turtle', 310, 350, 0)
16
+
17
+ hbox = ui_padded_hbox
18
+ main_window.child = hbox
19
+ main_window.intelligent_exit
20
+
21
+ # =========================================================================== #
22
+ # === IMAGES
23
+ #
24
+ # Must store it here to free it up lateron again.
25
+ # =========================================================================== #
26
+ IMAGES = []
27
+
28
+ canvas = ChunkyPNG::Canvas.from_file(THIS_FILE)
29
+ data = canvas.to_rgba_stream
30
+ width = canvas.width
31
+ height = canvas.height
32
+ # ========================================================================= #
33
+ # Add a new image here:
34
+ # ========================================================================= #
35
+ image = UI.new_image(width, height)
36
+ UI.image_append(image, data, width, height, width*4)
37
+ IMAGES << image # Store all images in the following area.
38
+
39
+ # =========================================================================== #
40
+ # Protects BlockCaller objects from garbage collection.
41
+ # =========================================================================== #
42
+ @blockcaller = []
43
+ # =========================================================================== #
44
+ # === rbcallback
45
+ # =========================================================================== #
46
+ def rbcallback(*args, &block)
47
+ args << [0] if args.size == 1 # Argument types are ommited
48
+ blockcaller = Fiddle::Closure::BlockCaller.new(*args, &block)
49
+ @blockcaller << blockcaller
50
+ blockcaller
51
+ end
52
+
53
+ model_handler = UI::FFI::TableModelHandler.malloc
54
+ model_handler.NumColumns = rbcallback(4) { 1 }
55
+ model_handler.ColumnType = rbcallback(4) { 1 } # Image
56
+ model_handler.NumRows = rbcallback(4) { 1 }
57
+ model_handler.CellValue = rbcallback(1, [1, 1, 1, 1]) do |_, _, row, _column|
58
+ UI.new_table_value_image(IMAGES[row])
59
+ end
60
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
61
+
62
+ model = UI.new_table_model(model_handler)
63
+
64
+ table_params = UI::FFI::TableParams.malloc
65
+ table_params.Model = model
66
+ table_params.RowBackgroundColorModelColumn = -1
67
+
68
+ table = UI.new_table(table_params)
69
+ UI.table_append_image_column(table, 'www.ghibli.jp/works/red-turtle', -1)
70
+ hbox.add(table)
71
+
72
+ main_window.show_the_controls
73
+
74
+ UI.window_on_closing(main_window) {
75
+ UI.control_destroy(main_window)
76
+ UI.free_table_model(model)
77
+ IMAGES.each { |i| UI.free_image(i) }
78
+ UI.quit
79
+ 0
80
+ }
81
+
82
+ UI.main_then_quit
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This example shows how to use the grid-related aspects of ruby-libui.
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ window = ui_padded_main_window('An open-file button-example', 1200, 200, 15)
10
+
11
+ outer_vbox = ui_padded_vbox
12
+ button_open_file = ui_button('Open file')
13
+ button_open_file.on_clicked {
14
+ begin
15
+ filename = ui_open_file(window).to_s
16
+ e "The filename was: #{filename}"
17
+ rescue ArgumentError => error # Rescue from "NULL pointer given"
18
+ pp error
19
+ end
20
+ }
21
+ outer_vbox << button_open_file
22
+
23
+ window.child = outer_vbox
24
+ window.intelligent_quit
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This example just shows that unicode text works.
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ window = ui_margined_main_window('Unicode Text Example', 1200, 200, 15)
10
+
11
+ outer_vbox = ui_padded_vbox
12
+ text = ui_text(
13
+ "This is some text. You do not even have to wrap it - the newlines will
14
+ appear in the text as-is.
15
+
16
+ If something is supported then unicode should be able to show that.
17
+
18
+ Let's test this next with some unicode:
19
+
20
+ 🎉 用户界面 사용자 인터페이스
21
+ ₀₁₂₃₄₅₆₇₈₉
22
+
23
+ ")
24
+
25
+ outer_vbox << text
26
+
27
+ window.child = outer_vbox
28
+ window.intelligent_quit
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This example just shows a spinbutton example.
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ window = ui_main_window('Spinbutton Example', 200, 100, 1)
10
+
11
+ outer_vbox = ui_padded_vbox
12
+ spinbutton = ui_spinbutton(0, 100)
13
+ spinbutton.set_value(42)
14
+
15
+ spinbox_changed_callback = proc { |ptr|
16
+ puts "Changed value to: #{UI.spinbox_value(ptr)}"
17
+ 0
18
+ }
19
+
20
+ UI.spinbox_on_changed(spinbutton, spinbox_changed_callback, nil)
21
+
22
+ outer_vbox << spinbutton
23
+
24
+ window.child = outer_vbox
25
+ window.intelligent_quit
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'libui_paradise/autoinclude'
6
+
7
+ window = ui_main_window('Text Example', 200, 100, 1)
8
+
9
+ outer_vbox = ui_padded_vbox
10
+ text = ui_text
11
+
12
+ outer_vbox << text
13
+
14
+ text.set_text('Hello world!')
15
+ window.child = outer_vbox
16
+ window.intelligent_quit
@@ -0,0 +1,6 @@
1
+ width: 1000
2
+ height: 150
3
+ padding: 5
4
+ title: Parse Config File Example
5
+ favicon: :tabble
6
+ font_in_use: Sans 22
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'libui_paradise/autoinclude'
6
+
7
+ use_this_config_file = '023_parse_config_file_example.config'
8
+ window = LibuiParadise.parse_this_config_file(use_this_config_file)
9
+ outer_vbox = padded_vbox
10
+ text = text('The config file was '+use_this_config_file)
11
+ outer_vbox << text
12
+ window.child = outer_vbox
13
+ window.intelligent_quit
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'libui_paradise/autoinclude'
6
+
7
+ window = ui_main_window('Text View Example', 500, 300, 0)
8
+
9
+ outer_vbox = ui_padded_vbox
10
+ text = multiline_entry
11
+ text.set_text('Hello world!')
12
+ outer_vbox << text
13
+ window.child = outer_vbox
14
+ window.intelligent_quit
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This example currently does not work.
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ window = padded_window('Scrolling Area', 500, 300, 0)
10
+
11
+ outer_vbox = padded_vbox
12
+ text = ui_text('OK!')
13
+ scrolling_area = LibuiParadise.scrolling_area(text)
14
+ outer_vbox << scrolling_area
15
+ window.child = outer_vbox
16
+ window.intelligent_quit
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This button doesn't work properly right now. :(
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ window = main_window('Colour Button', 500, 300, 0)
10
+ outer_vbox = padded_vbox
11
+ our_colour_button = ui_colour_button
12
+
13
+ # colour_button.on_changed {|callback|
14
+ # pp callback.class
15
+ # rgba = callback.color
16
+ # pp rgba
17
+ # }
18
+
19
+ # on_changed_proc = proc {|callback|
20
+ # rgba = callback.color
21
+ # pp rgba
22
+ # }
23
+
24
+ xyz = proc {|pointer|
25
+ # rgba = pointer.color
26
+ #pp rgba
27
+ pp pointer.to_s
28
+ nil
29
+ }
30
+
31
+ LibUI.color_button_on_changed(our_colour_button, xyz, nil)
32
+ # # rgba = pointer.color
33
+ # # pp rgba
34
+ # pp pointer
35
+ # pp pointer.to_s
36
+ # }
37
+
38
+
39
+ # UI.color_button_on_changed(color_button) do
40
+ # UI.area_queue_redraw_all(histogram)
41
+ # end
42
+
43
+ #, on_changed_proc.call, nil)
44
+
45
+ #UI.spinbox_on_changed(spinbox) do |ptr|
46
+ # puts "New Spinbox value: #{UI.spinbox_value(ptr)}"
47
+ #end
48
+
49
+ outer_vbox.minimal(our_colour_button, 1)
50
+ window.child = outer_vbox
51
+ window.intelligent_quit
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require '027_form_example.rb'
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ window = margined_window('Form Example', 250, 150, 0)
10
+
11
+ outer_vbox = padded_vbox
12
+
13
+ hbox1 = padded_hbox
14
+ hbox1.minimal(ui_text('First Name'), 0)
15
+ @first_name_entry = ui_entry
16
+ hbox1.minimal(@first_name_entry, 0)
17
+ outer_vbox.minimal(hbox1, 0)
18
+
19
+ hbox2 = padded_hbox
20
+ hbox2.minimal(ui_text('Last Name'), 0)
21
+ @last_name_entry = ui_entry
22
+ hbox2.minimal(@last_name_entry, 0)
23
+ outer_vbox.minimal(hbox2, 0)
24
+
25
+ button_display_name = button('Display Name')
26
+ button_display_name.on_clicked {
27
+ ui_msg_box(
28
+ :default,
29
+ 'Name',
30
+ "#{@first_name_entry.text?} #{@last_name_entry.text?}"
31
+ )
32
+ }
33
+
34
+ outer_vbox.minimal(button_display_name, 1)
35
+
36
+ window.child = outer_vbox
37
+ window.intelligent_quit
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require '028_password_entry_example.rb'
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ window = margined_window('Password Entry Example', 280, 80, 0)
10
+
11
+ outer_vbox = padded_vbox
12
+ entry = ui_password_entry
13
+ outer_vbox.minimal(ui_text('Password: '), 0)
14
+ outer_vbox.minimal(entry, 0)
15
+
16
+ window.child = outer_vbox
17
+ window.intelligent_quit
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require '029_two_buttons_showing_how_to_enable_and_disable_them.rb'
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ main_window = padded_main_window(
10
+ 'Two buttons showing how to enable and disable them', 300, 60, 0
11
+ )
12
+
13
+ outer_hbox = padded_hbox
14
+
15
+ button1 = button('Button #1')
16
+ button2 = button('Button #2')
17
+ button2.disable # Start-state for this button.
18
+
19
+ outer_hbox.minimal(button1, 1)
20
+ outer_hbox.minimal(button2, 1)
21
+
22
+ button1.on_clicked {|widget|
23
+ button2.enable
24
+ button1.disable
25
+ }
26
+ button2.on_clicked {|widget|
27
+ button1.enable
28
+ button2.disable
29
+ }
30
+
31
+ main_window.child = outer_hbox
32
+ main_window.intelligent_exit
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # Todo:
6
+ # - Add editable entry to the table
7
+ # =========================================================================== #
8
+ require 'libui_paradise/autoinclude'
9
+
10
+ main_window = padded_window('30) Table example', 300, 200, 1)
11
+ hbox = padded_hbox
12
+ data = [
13
+ %w( cat calm meow ),
14
+ %w( dog loyal woof ),
15
+ %w( chicken bird cock-a-doodle-doo ),
16
+ %w( horse fast neigh ),
17
+ %w( cow slow moo )
18
+ ]
19
+
20
+ # Protect BlockCaller objects from garbage collection.
21
+ @block_callers = []
22
+ def rbcallback(*args, &block)
23
+ args << [0] if args.size == 1 # Argument types are ommited
24
+ block_caller = Fiddle::Closure::BlockCaller.new(*args, &block)
25
+ @block_callers << block_caller
26
+ block_caller
27
+ end
28
+
29
+ model_handler = LibUI::FFI::TableModelHandler.malloc
30
+ model_handler.to_ptr.free = Fiddle::RUBY_FREE
31
+
32
+ model_handler.NumColumns = rbcallback(4) { 2 }
33
+ model_handler.ColumnType = rbcallback(4) { 0 }
34
+ model_handler.NumRows = rbcallback(4) { 5 }
35
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
36
+ UI.new_table_value_string(data[row][column])
37
+ end
38
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
39
+
40
+ model = LibUI.new_table_model(model_handler)
41
+
42
+ table_params = ui_table_params_malloc(model)
43
+
44
+ table = ui_table(table_params)
45
+ table.append_text_column('Animal', 0, -1)
46
+ table.append_text_column('Description', 1, -1)
47
+ table.append_text_column('Fancy Stuff', 2, -1)
48
+
49
+ hbox.add(table, 1)
50
+ main_window.child = hbox
51
+ main_window.intelligent_quit
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'libui_paradise/autoinclude'
6
+
7
+ def do_call_this_method
8
+ e 'Hello World!'
9
+ end
10
+
11
+ window {
12
+
13
+ button {
14
+
15
+ }
16
+
17
+ }
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === LibuiParadise::Extensions
6
+ # =========================================================================== #
7
+ # require 'libui_paradise/extensions/extensions.rb
8
+ # include Libuiparadise::Extensions
9
+ # =========================================================================== #
10
+ require 'libui' # Mandatory require-call.
11
+
12
+ module LibuiParadise
13
+
14
+ module Extensions # === LibuiParadise::Extensions
15
+
16
+ require 'libui_paradise/extensions/hash_fiddle_pointer_widgets.rb'
17
+ require 'libui_paradise/fiddle/pointer.rb'
18
+ require 'libui_paradise/libui_classes/window.rb'
19
+ require 'libui_paradise/extensions/misc.rb'
20
+
21
+ end; end
22
+
23
+ alias e puts
24
+
25
+ LibuiParadise::Extensions.initializer # Make UI known here.
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'libui_paradise/extensions/hash_fiddle_pointer_widgets.rb'
6
+ # =========================================================================== #
7
+ module LibuiParadise
8
+
9
+ module Extensions # === LibuiParadise::Extensions
10
+
11
+ # ========================================================================= #
12
+ # === @hash_fiddle_pointer_widgets
13
+ # ========================================================================= #
14
+ @hash_fiddle_pointer_widgets = {}
15
+
16
+ # ========================================================================= #
17
+ # === LibuiParadise::Extensions.hash_fiddle_pointer_widgets?
18
+ # ========================================================================= #
19
+ def self.hash_fiddle_pointer_widgets?
20
+ @hash_fiddle_pointer_widgets
21
+ end
22
+
23
+ # ========================================================================= #
24
+ # === main_hash?
25
+ # ========================================================================= #
26
+ def main_hash?
27
+ ::LibuiParadise::Extensions.hash_fiddle_pointer_widgets?
28
+ end
29
+
30
+ # ========================================================================= #
31
+ # === LibuiParadise::Extensions.register_this_fiddle_pointer_widget
32
+ #
33
+ # This method registers the particular widget in use.
34
+ #
35
+ # Every new_* method available on UI.new* - actually on LibUI.new* -
36
+ # that creates a new widget be registered via this method here. That
37
+ # way we have a Hash that contains lots of Fiddle::Pointers and we
38
+ # can, at a later time, modify these Fiddle::Pointer or call
39
+ # toplevel methods with these registered pointers. This will only work
40
+ # if we have registered these pointers though, which is why each
41
+ # method that creates a new libui-widget has to make use of this method
42
+ # here.
43
+ #
44
+ # The only exception to the above rule is the main window. The main
45
+ # window is always stored at @main_window instead. Perhaps it
46
+ # should also use the method here, but I found it simpler to
47
+ # just refer to it via @main_window.
48
+ #
49
+ # The mandatory entries must be:
50
+ #
51
+ # object_id -> [:the_fiddle_pointer_widget, :the_type]
52
+ #
53
+ # The object_id will be determined automatically, so it can be
54
+ # omitted.
55
+ #
56
+ # The very last argument of the two-member Array should be a symbol,
57
+ # such as :grid. This is automatically ensured via a call to
58
+ # __method__ which returns a Symbol.
59
+ # ========================================================================= #
60
+ def self.register_this_fiddle_pointer_widget(
61
+ the_fiddle_pointer_widget,
62
+ the_type_of_the_widget = nil
63
+ )
64
+ object_id_to_use = the_fiddle_pointer_widget.object_id
65
+ # ======================================================================= #
66
+ # Next, store it on the main Hash.
67
+ # ======================================================================= #
68
+ @hash_fiddle_pointer_widgets[object_id_to_use] =
69
+ [
70
+ the_fiddle_pointer_widget,
71
+ the_type_of_the_widget
72
+ ]
73
+ end; self.instance_eval { alias add_to_the_registered_widgets register_this_fiddle_pointer_widget } # === LibuiParadise::Extensions.add_to_the_registered_widgets
74
+
75
+ # ========================================================================= #
76
+ # === last_pointer?
77
+ #
78
+ # This used to return the "current" widget pointer, but past September
79
+ # 2021 this is rarely in use anymore. Use current_widget_pointer?
80
+ # instead, based on the main Hash that keeps all widgets registered.
81
+ # ========================================================================= #
82
+ def last_pointer?
83
+ LibuiParadise::Extensions.current_widget_pointer?
84
+ end; alias current_pointer? last_pointer? # === current_pointer?
85
+ alias current_widget_pointer? last_pointer? # === current_widget_pointer?
86
+
87
+ # ========================================================================= #
88
+ # === LibuiParadise::Extensions.current_widget_pointer?
89
+ # ========================================================================= #
90
+ def self.current_widget_pointer?
91
+ LibuiParadise::Extensions.hash_fiddle_pointer_widgets?.values.last.first
92
+ end
93
+
94
+ # ========================================================================= #
95
+ # === current_widget_pointer_type?
96
+ # ========================================================================= #
97
+ def current_widget_pointer_type?
98
+ LibuiParadise::Extensions.hash_fiddle_pointer_widgets?.values.last.last
99
+ end
100
+
101
+ # ========================================================================= #
102
+ # === register_this_fiddle_pointer_widget
103
+ # ========================================================================= #
104
+ def register_this_fiddle_pointer_widget(
105
+ the_fiddle_pointer_widget,
106
+ the_type_of_the_widget = nil
107
+ )
108
+ ::LibuiParadise::Extensions.register_this_fiddle_pointer_widget(
109
+ the_fiddle_pointer_widget,
110
+ the_type_of_the_widget
111
+ )
112
+ end; alias add_to_the_registered_widgets register_this_fiddle_pointer_widget # === add_to_the_registered_widgets
113
+
114
+ end
115
+
116
+ # ========================================================================= #
117
+ # === LibuiParadise.register_this_fiddle_pointer_widget
118
+ # ========================================================================= #
119
+ def self.register_this_fiddle_pointer_widget(
120
+ the_fiddle_pointer_widget,
121
+ the_type_of_the_widget = nil
122
+ )
123
+ ::LibuiParadise::Extensions.register_this_fiddle_pointer_widget(
124
+ the_fiddle_pointer_widget,
125
+ the_type_of_the_widget
126
+ )
127
+ end; self.instance_eval { alias add_to_the_registered_widgets register_this_fiddle_pointer_widget } # === LibuiParadise.add_to_the_registered_widgets
128
+
129
+ end