libui_paradise 0.3.9 → 0.4.13

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -39,6 +39,7 @@ class NotificationFunctionalityExample < LibuiParadise::Base # === LibuiParadise
39
39
  # === reset (reset tag)
40
40
  # ========================================================================= #
41
41
  def reset
42
+ reset_the_internal_hash
42
43
  default_title_width_height(TITLE, WIDTH, HEIGHT)
43
44
  end
44
45
 
@@ -49,7 +50,7 @@ class NotificationFunctionalityExample < LibuiParadise::Base # === LibuiParadise
49
50
  # ======================================================================= #
50
51
  # === @window
51
52
  # ======================================================================= #
52
- @window = ui_padded_main_window(title?, width?, height?, 0)
53
+ @window = create_padded_main_window(title?, width?, height?, 0)
53
54
  end
54
55
 
55
56
  # ========================================================================= #
@@ -53,6 +53,7 @@ class DaemonizeAndExitAfterDelayExample < LibuiParadise::Base # === LibuiParadis
53
53
  # === reset (reset tag)
54
54
  # ========================================================================= #
55
55
  def reset
56
+ reset_the_internal_hash
56
57
  default_title_width_height(TITLE, WIDTH, HEIGHT)
57
58
  end
58
59
 
@@ -63,7 +64,7 @@ class DaemonizeAndExitAfterDelayExample < LibuiParadise::Base # === LibuiParadis
63
64
  # ======================================================================= #
64
65
  # === @window
65
66
  # ======================================================================= #
66
- @window = ui_padded_main_window(title?, width?, height?, 0)
67
+ @window = create_padded_main_window(title?, width?, height?, 0)
67
68
  end
68
69
 
69
70
  # ========================================================================= #
@@ -71,7 +72,7 @@ class DaemonizeAndExitAfterDelayExample < LibuiParadise::Base # === LibuiParadis
71
72
  # ========================================================================= #
72
73
  def run
73
74
  super()
74
- Thread.abort_on_exception = true
75
+ abort_on_exception
75
76
  run_in_the_background
76
77
  Thread.new {
77
78
  add_these_widgets_to_the_main_window(
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require '034_bold_text_example.rb'
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ # =========================================================================== #
10
+ # === FONT_FAMILY_TO_USE
11
+ # =========================================================================== #
12
+ FONT_FAMILY_TO_USE = 'Georgia'
13
+
14
+ window = margined_window(:filename, :default, 200, 0)
15
+
16
+ outer_vbox = padded_vbox
17
+
18
+ handler = LibUI::FFI::AreaHandler.malloc
19
+ handler.to_ptr.free = Fiddle::RUBY_FREE
20
+ area = LibUI.new_area(handler)
21
+
22
+ # Michael Ende (1929-1995)
23
+ # The Neverending Story is a fantasy novel by German writer Michael Ende,
24
+ # The English version, translated by Ralph Manheim, was published in 1983.
25
+
26
+ TITLE = 'Michael Ende'
27
+
28
+ str1 = ' With thelignancy. '
29
+ str2 = ' A cry of fear escaped Bastian. '
30
+ str3 = ' A cry of te '
31
+ str4 = ' Could shele'
32
+ str5 = ' And thens. '
33
+
34
+ str = ''
35
+ attr_str = LibUI.new_attributed_string(str)
36
+
37
+ # =========================================================================== #
38
+ # === attr_str.append
39
+ #
40
+ # The first argument is the text that should be appended.
41
+ # =========================================================================== #
42
+ def attr_str.append(this_text, color)
43
+ c = case color
44
+ # :red
45
+ when :red
46
+ [0.0, 0.5, 0.0, 0.7]
47
+ # :green
48
+ when :green
49
+ [0.5, 0.0, 0.25, 0.7]
50
+ end
51
+ color_attribute = LibUI.new_color_attribute(*c)
52
+ start_position = LibuiParadise.string_length(self) # self is a Fiddle::Pointer.
53
+ # ========================================================================= #
54
+ # 1) append the unattributed string
55
+ # ========================================================================= #
56
+ LibUI.attributed_string_append_unattributed(self, this_text)
57
+ # ========================================================================= #
58
+ # 2) style the attributed string next
59
+ # ========================================================================= #
60
+ LibUI.attributed_string_set_attribute(self, color_attribute, start_position, start_position + this_text.size)
61
+ # ========================================================================= #
62
+ # 3) Add two newlines
63
+ # ========================================================================= #
64
+ LibUI.attributed_string_append_unattributed(self, "\n\n")
65
+ end
66
+
67
+ attr_str.append(str1, :green)
68
+ attr_str.append(str2, :red)
69
+ attr_str.append(str3, :green)
70
+ attr_str.append(str4, :red)
71
+ attr_str.append(str5, :green)
72
+
73
+ handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, adp|
74
+ area_draw_params = LibUI::FFI::AreaDrawParams.new(adp)
75
+ default_font = LibUI::FFI::FontDescriptor.malloc
76
+ default_font.to_ptr.free = Fiddle::RUBY_FREE
77
+ default_font.Family = FONT_FAMILY_TO_USE
78
+ default_font.Size = 13
79
+ default_font.Weight = 500
80
+ default_font.Italic = 0
81
+ default_font.Stretch = 4
82
+ params = LibUI::FFI::DrawTextLayoutParams.malloc
83
+ params.to_ptr.free = Fiddle::RUBY_FREE
84
+
85
+ # LibUI.font_button_font(font_button, default_font)
86
+ params.String = attr_str
87
+ params.DefaultFont = default_font
88
+ params.Width = area_draw_params.AreaWidth
89
+ params.Align = 0
90
+ text_layout = LibUI.draw_new_text_layout(params)
91
+ LibUI.draw_text(area_draw_params.Context, text_layout, 0, 0)
92
+ LibUI.draw_free_text_layout(text_layout)
93
+ end
94
+
95
+ handler.Draw = handler_draw_event
96
+
97
+ # Assigning to local variables
98
+ # This is intended to protect Fiddle::Closure from garbage collection.
99
+ do_nothing = Fiddle::Closure::BlockCaller.new(0, [0]) {}
100
+ key_event = Fiddle::Closure::BlockCaller.new(1, [0]) { 0 }
101
+ handler.MouseEvent = do_nothing
102
+ handler.MouseCrossed = do_nothing
103
+ handler.DragBroken = do_nothing
104
+ handler.KeyEvent = key_event
105
+
106
+ box = outer_vbox
107
+ box << area
108
+
109
+ window = padded_window(TITLE, :default, 400, 1)
110
+ window << box
111
+ window.intelligent_exit
112
+
113
+ LibUI.control_show(window)
114
+ LibUI.main
115
+ LibUI.uninit
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require '035_parse_into_table_example.rb'
6
+ # =========================================================================== #
7
+ require 'libui_paradise/autoinclude'
8
+
9
+ module LibuiParadise
10
+
11
+ module GUI
12
+
13
+ module LibUI
14
+
15
+ class ParseIntoTableExample # === LibuiParadise::GUI::LibUI::ParseIntoTableExample
16
+
17
+ require 'libui_paradise'
18
+ include LibuiParadise::BaseModule
19
+
20
+ # ========================================================================= #
21
+ # === TITLE
22
+ # ========================================================================= #
23
+ TITLE = 'Parse into table example'
24
+
25
+ # ========================================================================= #
26
+ # === WIDTH
27
+ # ========================================================================= #
28
+ WIDTH = 1200
29
+
30
+ # ========================================================================= #
31
+ # === HEIGHT
32
+ # ========================================================================= #
33
+ HEIGHT = 120
34
+
35
+ # ========================================================================= #
36
+ # === initialize
37
+ # ========================================================================= #
38
+ def initialize(
39
+ run_already = true
40
+ )
41
+ reset
42
+ run if run_already
43
+ end
44
+
45
+ # ========================================================================= #
46
+ # === reset (reset tag)
47
+ # ========================================================================= #
48
+ def reset
49
+ reset_the_internal_hash
50
+ title_width_height(TITLE, WIDTH, HEIGHT)
51
+ end
52
+
53
+ # ========================================================================= #
54
+ # === create_skeleton (create tag, skeleton tag)
55
+ # ========================================================================= #
56
+ def create_skeleton
57
+ # ======================================================================= #
58
+ # === @window
59
+ # ======================================================================= #
60
+ @window = create_padded_main_window(title?, width?, height?, 0)
61
+ end
62
+
63
+ # ========================================================================= #
64
+ # === run
65
+ # ========================================================================= #
66
+ def run
67
+ create_skeleton_then_connect_skeleton
68
+ outer_vbox = padded_vbox
69
+ # ======================================================================= #
70
+ # First add the two buttons on top:
71
+ # ======================================================================= #
72
+ outer_vbox.add_hsep
73
+ grid = parse_into_table('/Depot/j/animals.yml')
74
+
75
+ outer_vbox.minimal(grid)
76
+ @window << outer_vbox
77
+ @window.intelligent_exit
78
+ end
79
+
80
+ # ========================================================================= #
81
+ # === run_this_method_on_enter_key_event
82
+ # ========================================================================= #
83
+ def run_this_method_on_enter_key_event(
84
+ entry = @entry
85
+ )
86
+ entry.set_text(
87
+ entry.text?[0 .. -2].to_s
88
+ )
89
+ end
90
+
91
+ # ========================================================================= #
92
+ # === evaluate_the_current_input
93
+ # ========================================================================= #
94
+ def evaluate_the_current_input(
95
+ entry = @entry,
96
+ pointer = nil,
97
+ &block
98
+ )
99
+ _ = entry.text?
100
+ if _.end_with?('#')
101
+ yield if block_given?
102
+ end
103
+ end
104
+
105
+ end; end; end; end
106
+
107
+ if __FILE__ == $PROGRAM_NAME
108
+ LibuiParadise::GUI::LibUI::ParseIntoTableExample.new
109
+ end
@@ -17,7 +17,7 @@ button = LibUI.new_button('Open File')
17
17
  LibUI.button_on_clicked(button) {
18
18
  result = ::LibUI.open_file(main_window).to_s
19
19
  if File.exist?(result)
20
- e 'The file exists. \o/'
20
+ e "The file exists, at `#{result}`. \o/"
21
21
  end
22
22
  }
23
23
 
@@ -64,9 +64,9 @@ def construct_graph(datapoints, width, height, should_extend)
64
64
  locations = point_locations(datapoints, width, height)
65
65
  path = LibUI.draw_new_path(0) # winding
66
66
  first_location = locations[0] # x and y
67
- UI.draw_path_new_figure(path, first_location[0], first_location[1])
67
+ LibUI.draw_path_new_figure(path, first_location[0], first_location[1])
68
68
  locations.each { |loc|
69
- UI.draw_path_line_to(path, loc[0], loc[1])
69
+ LibUI.draw_path_line_to(path, loc[0], loc[1])
70
70
  }
71
71
 
72
72
  if should_extend
@@ -85,8 +85,8 @@ handler_draw_event = Fiddle::Closure::BlockCaller.new(
85
85
  ) do |_area_handler, _area, area_draw_params|
86
86
  area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params)
87
87
  path = UI.draw_new_path(0) # winding
88
- UI.draw_path_add_rectangle(path, 0, 0, area_draw_params.AreaWidth, area_draw_params.AreaHeight)
89
- UI.draw_path_end(path)
88
+ LibUI.draw_path_add_rectangle(path, 0, 0, area_draw_params.AreaWidth, area_draw_params.AreaHeight)
89
+ LibUI.draw_path_end(path)
90
90
  set_solid_brush(brush, 0xFFFFFF, 1.0) # white
91
91
  UI.draw_fill(area_draw_params.Context, path, brush.to_ptr)
92
92
  UI.draw_free_path(path)
@@ -166,8 +166,8 @@ UI.box_append(hbox, vbox, 0)
166
166
  UI.box_append(hbox, histogram, 1)
167
167
 
168
168
  datapoints = Array.new(10) do
169
- UI.new_spinbox(0, 100).tap do |datapoint|
170
- UI.spinbox_set_value(datapoint, Random.new.rand(90))
169
+ LibUI.new_spinbox(0, 100).tap do |datapoint|
170
+ LibUI.spinbox_set_value(datapoint, Random.new.rand(90))
171
171
  UI.spinbox_on_changed(datapoint) {
172
172
  # Redraw the drawing area next:
173
173
  UI.area_queue_redraw_all(histogram)
@@ -21,13 +21,31 @@ USE_THIS_FONT = 'Hack' # Or 'Courier New'.
21
21
 
22
22
  # =========================================================================== #
23
23
  # === append_with_attribute
24
+ #
25
+ # The first argument is the String that is to be appended.
26
+ #
27
+ # To append a bigger font, use something like this:
28
+ #
29
+ # bigger_font = UI.new_size_attribute(62)
30
+ # append_with_attribute(attr_str, 'font size', bigger_font, nil)
31
+ #
32
+ # To append bold text, use:
33
+ #
34
+ # attr1 = LibUI.new_weight_attribute(LibUI::TextWeightBold)
35
+ # append_with_attribute(attr_str, 'font weight', attr1)
36
+ #
24
37
  # =========================================================================== #
25
- def append_with_attribute(attr_str, what, attr1, attr2)
26
- start_pos = LibUI.attributed_string_len(attr_str)
27
- end_pos = start_pos + what.length
28
- LibUI.attributed_string_append_unattributed(attr_str, what)
29
- LibUI.attributed_string_set_attribute(attr_str, attr1, start_pos, end_pos)
30
- LibUI.attributed_string_set_attribute(attr_str, attr2, start_pos, end_pos) if attr2
38
+ def append_with_attribute(
39
+ widget,
40
+ use_this_text,
41
+ attr1,
42
+ attr2 # This is rarely needed.
43
+ )
44
+ start_pos = LibUI.attributed_string_len(widget)
45
+ end_pos = start_pos + what.length
46
+ LibUI.attributed_string_append_unattributed(widget, use_this_text)
47
+ LibUI.attributed_string_set_attribute(widget, attr1, start_pos, end_pos)
48
+ LibUI.attributed_string_set_attribute(widget, attr2, start_pos, end_pos) if attr2
31
49
  end
32
50
 
33
51
  # =========================================================================== #
@@ -48,23 +66,27 @@ def make_attribute_string
48
66
 
49
67
  # ========================================================================= #
50
68
  # === Use a bigger font next
69
+ #
70
+ # The bigger font will be use for the String "font size".
51
71
  # ========================================================================= #
52
- bigger_font = UI.new_size_attribute(45)
72
+ bigger_font = UI.new_size_attribute(62)
53
73
  append_with_attribute(attr_str, 'font size', bigger_font, nil)
54
- UI.attributed_string_append_unattributed(attr_str, ', ')
74
+
75
+ LibUI.attributed_string_append_unattributed(attr_str, ', ') # Then append ','.
55
76
 
56
77
  # ========================================================================= #
57
78
  # === Make bold text next (bold tag)
58
79
  # ========================================================================= #
59
80
  attr1 = LibUI.new_weight_attribute(LibUI::TextWeightBold)
60
81
  append_with_attribute(attr_str, 'font weight', attr1, nil)
82
+
61
83
  LibUI.attributed_string_append_unattributed(attr_str, ', ')
62
84
 
63
- attr1 = LibUI.new_italic_attribute(UI::TextItalicItalic)
85
+ attr1 = LibUI.new_italic_attribute(LibUI::TextItalicItalic)
64
86
  append_with_attribute(attr_str, 'font italicness', attr1, nil)
65
87
  UI.attributed_string_append_unattributed(attr_str, ', ')
66
88
 
67
- attr1 = LibUI.new_stretch_attribute(UI::TextStretchCondensed)
89
+ attr1 = LibUI.new_stretch_attribute(LibUI::TextStretchCondensed)
68
90
  append_with_attribute(attr_str, 'font stretch', attr1, nil)
69
91
  UI.attributed_string_append_unattributed(attr_str, ', ')
70
92
 
@@ -79,31 +101,31 @@ def make_attribute_string
79
101
  append_with_attribute(attr_str, 'text background color', attr1, nil)
80
102
  UI.attributed_string_append_unattributed(attr_str, ', ')
81
103
 
82
- attr1 = UI.new_underline_attribute(UI::UnderlineSingle)
104
+ attr1 = UI.new_underline_attribute(LibUI::UnderlineSingle)
83
105
  append_with_attribute(attr_str, 'underline style', attr1, nil)
84
106
  UI.attributed_string_append_unattributed(attr_str, ', ')
85
107
 
86
108
  UI.attributed_string_append_unattributed(attr_str, 'and ')
87
- attr1 = LibUI.new_underline_attribute(UI::UnderlineDouble)
88
- attr2 = LibUI.new_underline_color_attribute(UI::UnderlineColorCustom, 1.0, 0.0, 0.5, 1.0)
109
+ attr1 = LibUI.new_underline_attribute(LibUI::UnderlineDouble)
110
+ attr2 = LibUI.new_underline_color_attribute(LibUI::UnderlineColorCustom, 1.0, 0.0, 0.5, 1.0)
89
111
  append_with_attribute(attr_str, 'underline color', attr1, attr2)
90
112
  UI.attributed_string_append_unattributed(attr_str, '. ')
91
113
 
92
114
  UI.attributed_string_append_unattributed(attr_str, 'Furthermore, there are attributes allowing for ')
93
- attr1 = LibUI.new_underline_attribute(UI::UnderlineSuggestion)
94
- attr2 = LibUI.new_underline_color_attribute(UI::UnderlineColorSpelling, 0, 0, 0, 0)
115
+ attr1 = LibUI.new_underline_attribute(LibUI::UnderlineSuggestion)
116
+ attr2 = LibUI.new_underline_color_attribute(LibUI::UnderlineColorSpelling, 0, 0, 0, 0)
95
117
  append_with_attribute(attr_str, 'special underlines for indicating spelling errors', attr1, attr2)
96
- UI.attributed_string_append_unattributed(attr_str, ' (and other types of errors) ')
118
+ LibUI.attributed_string_append_unattributed(attr_str, ' (and other types of errors) ')
97
119
 
98
- UI.attributed_string_append_unattributed(attr_str,
120
+ LibUI.attributed_string_append_unattributed(attr_str,
99
121
  'and control over OpenType features such as ligatures (for instance, ')
100
- otf = UI.new_open_type_features
122
+ otf = LibUI.new_open_type_features
101
123
  UI.open_type_features_add(otf, 'l', 'i', 'g', 'a', 0)
102
- attr1 = UI.new_features_attribute(otf)
124
+ attr1 = LibUI.new_features_attribute(otf)
103
125
  append_with_attribute(attr_str, 'afford', attr1, nil)
104
126
  UI.attributed_string_append_unattributed(attr_str, ' vs. ')
105
127
  UI.open_type_features_add(otf, 'l', 'i', 'g', 'a', 1)
106
- attr1 = UI.new_features_attribute(otf)
128
+ attr1 = LibUI.new_features_attribute(otf)
107
129
  append_with_attribute(attr_str, 'afford', attr1, nil)
108
130
  UI.free_open_type_features(otf)
109
131
  UI.attributed_string_append_unattributed(attr_str, ").\n")
@@ -112,7 +134,7 @@ def make_attribute_string
112
134
  'Use the controls '\
113
135
  'opposite to the text '\
114
136
  'to control properties of the text.')
115
- attr_str
137
+ attr_str # And return the String here.
116
138
  end
117
139
 
118
140
  # =========================================================================== #
@@ -147,17 +169,17 @@ def draw_event(adp, attr_str, font_button, alignment)
147
169
  params.Width = area_draw_params.AreaWidth
148
170
  params.Align = UI.combobox_selected(alignment)
149
171
  text_layout = UI.draw_new_text_layout(params)
150
- UI.draw_text(area_draw_params.Context, text_layout, 0, 0)
151
- UI.draw_free_text_layout(text_layout)
152
- UI.free_font_button_font(default_font)
172
+ LibUI.draw_text(area_draw_params.Context, text_layout, 0, 0)
173
+ LibUI.draw_free_text_layout(text_layout)
174
+ LibUI.free_font_button_font(default_font)
153
175
  end
154
176
 
155
- UI.init
177
+ LibUI.init
156
178
 
157
179
  handler = UI::FFI::AreaHandler.malloc
158
180
  handler.to_ptr.free = Fiddle::RUBY_FREE
159
181
  handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _area, adp|
160
- draw_event(adp, @attr_str, @font_button, @alignment)
182
+ draw_event(adp, @attr_str, @font_button, @combobox)
161
183
  end
162
184
 
163
185
  handler.Draw = handler_draw_event
@@ -178,6 +200,9 @@ LibUI.on_should_quit {
178
200
  # =========================================================================== #
179
201
  @attr_str = make_attribute_string
180
202
 
203
+ # =========================================================================== #
204
+ # Create the main window next:
205
+ # =========================================================================== #
181
206
  main_window = LibUI.new_window('Text-Drawing Example', WIDTH, 480, 1)
182
207
  LibUI.window_set_margined(main_window, 1)
183
208
  LibUI.window_on_closing(main_window) {
@@ -186,6 +211,9 @@ LibUI.window_on_closing(main_window) {
186
211
  0
187
212
  }
188
213
 
214
+ # =========================================================================== #
215
+ # Add a hbox:
216
+ # =========================================================================== #
189
217
  hbox = LibUI.new_horizontal_box
190
218
  LibUI.box_set_padded(hbox, 1)
191
219
  LibUI.window_set_child(main_window, hbox)
@@ -207,15 +235,15 @@ LibUI.box_append(vbox, form, 0)
207
235
 
208
236
  # =========================================================================== #
209
237
  # Add a combobox entry next.
210
- # @alignment = ui_combobox(%w( Left Center Right ))
211
- # =========================================================================== #
212
- @alignment = LibUI.new_combobox
213
- LibUI.combobox_append(@alignment, 'Left')
214
- LibUI.combobox_append(@alignment, 'Center')
215
- LibUI.combobox_append(@alignment, 'Right')
216
- LibUI.combobox_set_selected(@alignment, 0)
217
- LibUI.combobox_on_selected(@alignment) { on_combobox_selected(@area) }
218
- LibUI.form_append(form, 'Alignment', @alignment, 0)
238
+ # @combobox = ui_combobox(%w( Left Center Right ))
239
+ # =========================================================================== #
240
+ @combobox = LibUI.new_combobox
241
+ LibUI.combobox_append(@combobox, 'Left')
242
+ LibUI.combobox_append(@combobox, 'Center')
243
+ LibUI.combobox_append(@combobox, 'Right')
244
+ LibUI.combobox_set_selected(@combobox, 0)
245
+ LibUI.combobox_on_selected(@combobox) { on_combobox_selected(@area) }
246
+ LibUI.form_append(form, 'Alignment', @combobox, 0)
219
247
 
220
248
  # =========================================================================== #
221
249
  # Add a new area next:
@@ -66,11 +66,11 @@ def make_attribute_string
66
66
  append_with_attribute(attr_str, 'underline color', attr1, attr2)
67
67
  UI.attributed_string_append_unattributed(attr_str, '. ')
68
68
 
69
- UI.attributed_string_append_unattributed(attr_str, 'Furthermore, there are attributes allowing for ')
69
+ LibUI.attributed_string_append_unattributed(attr_str, 'Furthermore, there are attributes allowing for ')
70
70
  attr1 = UI.new_underline_attribute(UI::UnderlineSuggestion)
71
71
  attr2 = UI.new_underline_color_attribute(UI::UnderlineColorSpelling, 0, 0, 0, 0)
72
72
  append_with_attribute(attr_str, 'special underlines for indicating spelling errors', attr1, attr2)
73
- UI.attributed_string_append_unattributed(attr_str, ' (and other types of errors) ')
73
+ LibUI.attributed_string_append_unattributed(attr_str, ' (and other types of errors) ')
74
74
 
75
75
  UI.attributed_string_append_unattributed(attr_str,
76
76
  'and control over OpenType features such as ligatures (for instance, ')
@@ -173,7 +173,7 @@ UI.combobox_append(@alignment, 'Center')
173
173
  UI.combobox_append(@alignment, 'Right')
174
174
  UI.combobox_set_selected(@alignment, 0)
175
175
  UI.combobox_on_selected(@alignment) { on_combobox_selected(@area) }
176
- UI.form_append(form, 'Alignment', @alignment, 0)
176
+ LibUI.form_append(form, 'Alignment', @alignment, 0)
177
177
 
178
178
  @area = LibUI.new_area(handler)
179
179
  LibUI.box_append(hbox, @area, 1)
@@ -80,7 +80,8 @@ end
80
80
  UI.box_append(inner, checkbox, 0)
81
81
 
82
82
  # Label
83
- UI.box_append(inner, UI.new_label('Label'), 0)
83
+ label = UI.new_label('Label')
84
+ UI.box_append(inner, label, 0)
84
85
 
85
86
  # Separator
86
87
  UI.box_append(inner, UI.new_horizontal_separator, 0)
@@ -1,7 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  # =========================================================================== #
3
3
  require 'libui'
4
- require 'ffi-portaudio' # https://github.com/nanki/ffi-portaudio
4
+
5
+ begin
6
+ require 'ffi-portaudio' # https://github.com/nanki/ffi-portaudio
7
+ rescue LoadError
8
+ puts 'Install this: https://github.com/nanki/ffi-portaudio'
9
+ end
10
+
5
11
  require 'numo/pocketfft' # https://github.com/yoshoku/numo-pocketfft
6
12
 
7
13
  # =========================================================================== #
@@ -61,11 +61,11 @@ LibUI.box_append(hbox, table, 1)
61
61
  LibUI.control_show(main_window)
62
62
 
63
63
  LibUI.window_on_closing(main_window) {
64
- e 'Bye Bye'
65
- UI.quit
64
+ # e 'Bye Bye'
65
+ LibUI.quit
66
66
  1
67
67
  }
68
68
 
69
- UI.main
70
- UI.free_table_model(model)
71
- UI.uninit
69
+ LibUI.main
70
+ LibUI.free_table_model(model)
71
+ LibUI.uninit
@@ -0,0 +1,28 @@
1
+ # =========================================================================== #
2
+ # === 013_scrolling_pane_example.rb
3
+ # =========================================================================== #
4
+ # This currently does not work. libui-ng first has to add support for
5
+ # that.
6
+ # =========================================================================== #
7
+ require 'libui'
8
+
9
+ alias e puts
10
+
11
+ LibUI.init
12
+
13
+ main_window = LibUI.new_window('Scrolling pane example', 300, 200, 1)
14
+
15
+ scroll_area = LibUI.new_scrolling_area
16
+ pp scroll_area.class
17
+ hbox = LibUI.new_horizontal_box
18
+ LibUI.window_set_child(main_window, hbox)
19
+
20
+ LibUI.control_show(main_window)
21
+
22
+ LibUI.window_on_closing(main_window) {
23
+ LibUI.quit
24
+ 1
25
+ }
26
+
27
+ LibUI.main
28
+ LibUI.uninit
@@ -0,0 +1,30 @@
1
+ # =========================================================================== #
2
+ # === 014_simple_entry_example.rb
3
+ # =========================================================================== #
4
+ require 'libui'
5
+
6
+ alias e puts
7
+
8
+ LibUI.init
9
+
10
+ main_window = LibUI.new_window('Two entries example - right one is read-only', 300, 200, 1)
11
+
12
+ hbox = LibUI.new_horizontal_box
13
+ LibUI.box_set_padded(hbox, 1)
14
+ entry1 = LibUI.new_entry
15
+ entry2 = LibUI.new_entry
16
+ LibUI.entry_set_read_only(entry2, 1)
17
+
18
+ LibUI.box_append(hbox, entry1, 1)
19
+ LibUI.box_append(hbox, entry2, 1)
20
+
21
+ LibUI.window_set_child(main_window, hbox)
22
+ LibUI.control_show(main_window)
23
+
24
+ LibUI.window_on_closing(main_window) {
25
+ LibUI.quit
26
+ 1
27
+ }
28
+
29
+ LibUI.main
30
+ LibUI.uninit
@@ -0,0 +1,32 @@
1
+ # =========================================================================== #
2
+ # === 015_slider_example.rb
3
+ # =========================================================================== #
4
+ require 'libui'
5
+
6
+ alias e puts
7
+
8
+ LibUI.init
9
+
10
+ main_window = LibUI.new_window('Slider example', 800, 240, 1)
11
+
12
+ hbox = LibUI.new_horizontal_box
13
+ LibUI.box_set_padded(hbox, 1)
14
+ slider1 = LibUI.new_slider(0, 10)
15
+ LibUI.slider_set_has_tool_tip(slider1, 1) # Testing this.
16
+
17
+ LibUI.slider_on_changed(slider1) {
18
+ e 'My value was changed to: '+LibUI.slider_value(slider1).to_s
19
+ }
20
+
21
+ LibUI.box_append(hbox, slider1, 1)
22
+
23
+ LibUI.window_set_child(main_window, hbox)
24
+ LibUI.control_show(main_window)
25
+
26
+ LibUI.window_on_closing(main_window) {
27
+ LibUI.quit
28
+ 1
29
+ }
30
+
31
+ LibUI.main
32
+ LibUI.uninit