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.
- checksums.yaml +7 -0
- data/README.md +1505 -0
- data/doc/README.gen +1252 -0
- data/doc/SNIPPETS.md +221 -0
- data/doc/TODO.md +14 -0
- data/lib/libui_paradise/autoinclude.rb +9 -0
- data/lib/libui_paradise/domain_specific_language/README.md +5 -0
- data/lib/libui_paradise/domain_specific_language/button.yml +7 -0
- data/lib/libui_paradise/examples/001_basic_button_example.rb +17 -0
- data/lib/libui_paradise/examples/002_basic_table_image.rb +92 -0
- data/lib/libui_paradise/examples/003_font_button.rb +34 -0
- data/lib/libui_paradise/examples/004_date_time_picker.rb +31 -0
- data/lib/libui_paradise/examples/005_msg_box_error.rb +25 -0
- data/lib/libui_paradise/examples/006_histogram.rb +193 -0
- data/lib/libui_paradise/examples/007_combo_box_example.rb +41 -0
- data/lib/libui_paradise/examples/008_simple_notepad_example.rb +23 -0
- data/lib/libui_paradise/examples/009_checkbox_example.rb +82 -0
- data/lib/libui_paradise/examples/010_grid_example.rb +26 -0
- data/lib/libui_paradise/examples/011_fancy_text_example.rb +21 -0
- data/lib/libui_paradise/examples/012_control_gallery.rb +180 -0
- data/lib/libui_paradise/examples/013_midi_player.rb +91 -0
- data/lib/libui_paradise/examples/014_basic_draw_text.rb +134 -0
- data/lib/libui_paradise/examples/015_font_example.rb +91 -0
- data/lib/libui_paradise/examples/016_search_entry_example.rb +16 -0
- data/lib/libui_paradise/examples/017_tabs_example.rb +22 -0
- data/lib/libui_paradise/examples/018_image_example.rb +82 -0
- data/lib/libui_paradise/examples/019_open_file_button_example.rb +24 -0
- data/lib/libui_paradise/examples/020_unicode_text_example.rb +28 -0
- data/lib/libui_paradise/examples/021_spinbutton_example.rb +25 -0
- data/lib/libui_paradise/examples/022_text_example.rb +16 -0
- data/lib/libui_paradise/examples/023_parse_config_file_example.config +6 -0
- data/lib/libui_paradise/examples/023_parse_config_file_example.rb +13 -0
- data/lib/libui_paradise/examples/024_text_view_example.rb +14 -0
- data/lib/libui_paradise/examples/025_scrolling_area.rb +16 -0
- data/lib/libui_paradise/examples/026_colour_button.rb +51 -0
- data/lib/libui_paradise/examples/027_form_example.rb +37 -0
- data/lib/libui_paradise/examples/028_password_entry_example.rb +17 -0
- data/lib/libui_paradise/examples/029_two_buttons_showing_how_to_enable_and_disable_them.rb +32 -0
- data/lib/libui_paradise/examples/030_table_example.rb +51 -0
- data/lib/libui_paradise/experimental/dsl.rb +17 -0
- data/lib/libui_paradise/extensions/extensions.rb +25 -0
- data/lib/libui_paradise/extensions/hash_fiddle_pointer_widgets.rb +129 -0
- data/lib/libui_paradise/extensions/misc.rb +309 -0
- data/lib/libui_paradise/fiddle/pointer.rb +841 -0
- data/lib/libui_paradise/images/LIBUI_PARADISE_LOGO.png +0 -0
- data/lib/libui_paradise/images/README.md +2 -0
- data/lib/libui_paradise/images/form_example.png +0 -0
- data/lib/libui_paradise/libui_classes/area_handler.rb +52 -0
- data/lib/libui_paradise/libui_classes/button.rb +82 -0
- data/lib/libui_paradise/libui_classes/checkbox.rb +37 -0
- data/lib/libui_paradise/libui_classes/color_button.rb +44 -0
- data/lib/libui_paradise/libui_classes/combobox.rb +55 -0
- data/lib/libui_paradise/libui_classes/editable_combobox.rb +51 -0
- data/lib/libui_paradise/libui_classes/entry.rb +80 -0
- data/lib/libui_paradise/libui_classes/font.rb +78 -0
- data/lib/libui_paradise/libui_classes/font_button.rb +40 -0
- data/lib/libui_paradise/libui_classes/grid.rb +55 -0
- data/lib/libui_paradise/libui_classes/hbox.rb +98 -0
- data/lib/libui_paradise/libui_classes/horizontal_separator.rb +41 -0
- data/lib/libui_paradise/libui_classes/image.rb +82 -0
- data/lib/libui_paradise/libui_classes/label.rb +83 -0
- data/lib/libui_paradise/libui_classes/menu.rb +36 -0
- data/lib/libui_paradise/libui_classes/msg_box.rb +97 -0
- data/lib/libui_paradise/libui_classes/msg_box_error.rb +49 -0
- data/lib/libui_paradise/libui_classes/multiline_entry.rb +59 -0
- data/lib/libui_paradise/libui_classes/non_wrapping_multiline_entry.rb +41 -0
- data/lib/libui_paradise/libui_classes/open_file.rb +42 -0
- data/lib/libui_paradise/libui_classes/password_entry.rb +49 -0
- data/lib/libui_paradise/libui_classes/progressbar.rb +41 -0
- data/lib/libui_paradise/libui_classes/radio_buttons.rb +36 -0
- data/lib/libui_paradise/libui_classes/scrolling_area.rb +85 -0
- data/lib/libui_paradise/libui_classes/search_entry.rb +36 -0
- data/lib/libui_paradise/libui_classes/spinbox.rb +55 -0
- data/lib/libui_paradise/libui_classes/tab.rb +39 -0
- data/lib/libui_paradise/libui_classes/table.rb +45 -0
- data/lib/libui_paradise/libui_classes/text_layout.rb +42 -0
- data/lib/libui_paradise/libui_classes/vbox.rb +51 -0
- data/lib/libui_paradise/libui_classes/window.rb +167 -0
- data/lib/libui_paradise/project/project.rb +26 -0
- data/lib/libui_paradise/prototype/README.md +3 -0
- data/lib/libui_paradise/prototype/prototype.rb +101 -0
- data/lib/libui_paradise/requires/require_the_libui_classes.rb +26 -0
- data/lib/libui_paradise/requires/require_the_libui_paradise_project.rb +11 -0
- data/lib/libui_paradise/version/version.rb +17 -0
- data/lib/libui_paradise.rb +1 -0
- data/libui_paradise.gemspec +49 -0
- metadata +164 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'libui_paradise/autoinclude'
|
6
|
+
|
7
|
+
window = UI.window('Notepad', 500, 300, 1)
|
8
|
+
|
9
|
+
vbox = ui_vbox
|
10
|
+
|
11
|
+
text_view = ui_text_view
|
12
|
+
text_view.set_text(
|
13
|
+
"This is an example.\nAs can be seen, text has been assigned to this.\n"
|
14
|
+
)
|
15
|
+
vbox.add(text_view, 1)
|
16
|
+
button_show_content = ui_button('Paste the content of the text-buffer above')
|
17
|
+
button_show_content.on_clicked {
|
18
|
+
e text_view.text?.to_s
|
19
|
+
}
|
20
|
+
|
21
|
+
vbox.add(button_show_content, 1)
|
22
|
+
window.child = vbox
|
23
|
+
window.intelligent_exit
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'libui_paradise/autoinclude'
|
6
|
+
|
7
|
+
should_quit_callback = proc {
|
8
|
+
UI.control_destroy(MAIN_WINDOW)
|
9
|
+
UI.quit
|
10
|
+
0
|
11
|
+
}
|
12
|
+
|
13
|
+
open_menu_item_clicked = proc {
|
14
|
+
puts "Clicked 'Open'"
|
15
|
+
0
|
16
|
+
}
|
17
|
+
|
18
|
+
save_menu_item_clicked = proc {
|
19
|
+
puts "Clicked 'Save'"
|
20
|
+
0
|
21
|
+
}
|
22
|
+
|
23
|
+
# =========================================================================== #
|
24
|
+
# Create 'File' menu with a few items and callbacks when the items are
|
25
|
+
# clicked.
|
26
|
+
# =========================================================================== #
|
27
|
+
menu = UI.menu('File')
|
28
|
+
open_menu_item = UI.menu_append_item(menu, 'Open')
|
29
|
+
UI.menu_item_on_clicked(open_menu_item, open_menu_item_clicked, nil)
|
30
|
+
save_menu_item = UI.menu_append_item(menu, 'Save')
|
31
|
+
UI.menu_item_on_clicked(save_menu_item, save_menu_item_clicked, nil)
|
32
|
+
UI.menu_append_quit_item(menu)
|
33
|
+
UI.on_should_quit(should_quit_callback, nil)
|
34
|
+
|
35
|
+
# =========================================================================== #
|
36
|
+
# Create 'Edit' menu
|
37
|
+
# =========================================================================== #
|
38
|
+
edit_menu = UI.new_menu('Edit')
|
39
|
+
UI.menu_append_check_item(edit_menu, 'Checkable Item_')
|
40
|
+
UI.menu_append_separator(edit_menu)
|
41
|
+
disabled_item = UI.menu_append_item(edit_menu, 'Disabled Item_')
|
42
|
+
UI.menu_item_disable(disabled_item)
|
43
|
+
|
44
|
+
preferences = UI.menu_append_preferences_item(menu)
|
45
|
+
|
46
|
+
help_menu = UI.menu('Help')
|
47
|
+
UI.menu_append_item(help_menu, 'Help')
|
48
|
+
UI.menu_append_about_item(help_menu)
|
49
|
+
|
50
|
+
vbox = UI.vbox
|
51
|
+
|
52
|
+
a_hbox = UI.hbox
|
53
|
+
UI.box_set_padded(vbox, 1)
|
54
|
+
UI.box_set_padded(a_hbox, 1)
|
55
|
+
|
56
|
+
vbox.add(a_hbox, 1)
|
57
|
+
|
58
|
+
group = UI.new_group('Top Group')
|
59
|
+
UI.group_set_margined(group, 1)
|
60
|
+
a_hbox.add(group, 0)
|
61
|
+
|
62
|
+
inner = UI.vbox
|
63
|
+
UI.box_set_padded(inner, 1)
|
64
|
+
UI.group_set_child(group, inner)
|
65
|
+
|
66
|
+
checkbox = UI.checkbox('Checkbox')
|
67
|
+
checkbox_toggle_callback = proc { |ptr|
|
68
|
+
checked = UI.checkbox_checked(ptr) == 1
|
69
|
+
UI.checkbox_set_text(ptr, "I am the checkbox (#{checked})")
|
70
|
+
}
|
71
|
+
|
72
|
+
UI.checkbox_on_toggled(checkbox, checkbox_toggle_callback, nil)
|
73
|
+
inner.add(checkbox, 0)
|
74
|
+
|
75
|
+
MAIN_WINDOW = UI.window('hello world', 600, 600, 1)
|
76
|
+
|
77
|
+
UI.window_set_margined(MAIN_WINDOW, 1)
|
78
|
+
UI.window_set_child(MAIN_WINDOW, vbox)
|
79
|
+
|
80
|
+
UI.window_on_closing(MAIN_WINDOW, should_quit_callback, nil)
|
81
|
+
MAIN_WINDOW.control_show
|
82
|
+
UI.main_then_quit
|
@@ -0,0 +1,26 @@
|
|
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.main_window('A simple grid-example', 1200, 200, 15)
|
10
|
+
|
11
|
+
grid = ui_grid
|
12
|
+
UI.grid_append(grid, text('Yo1'), 0, 0, 1, 1, 0, 0, 1, 0)
|
13
|
+
UI.grid_append(grid, text('Yo2'), 1, 0, 1, 1, 0, 0, 1, 0)
|
14
|
+
UI.grid_append(grid, text('Yo3'), 2, 0, 1, 1, 0, 0, 1, 0)
|
15
|
+
|
16
|
+
UI.grid_append(grid, text('Yo4'), 0, 1, 1, 1, 0, 0, 1, 0)
|
17
|
+
UI.grid_append(grid, text('Yo5'), 1, 1, 1, 1, 0, 0, 1, 0)
|
18
|
+
UI.grid_append(grid, text('Yo6'), 2, 1, 1, 1, 0, 0, 1, 0)
|
19
|
+
|
20
|
+
grid.is_padded
|
21
|
+
|
22
|
+
vbox = ui_vbox
|
23
|
+
vbox.add(grid)
|
24
|
+
|
25
|
+
window.child = vbox
|
26
|
+
window.intelligent_exit
|
@@ -0,0 +1,21 @@
|
|
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
|
+
main_window = UI.main_window('A fancy test example', 1200, 200, 15)
|
10
|
+
|
11
|
+
string = UI.new_attributed_string
|
12
|
+
attribute = UI.new_color_attribute(0.75, 0.25, 0.5, 0.75)
|
13
|
+
UI.attributed_string_append_unattributed('text color', attribute)
|
14
|
+
|
15
|
+
vbox = UI.vbox
|
16
|
+
vbox.add(attribute)
|
17
|
+
|
18
|
+
main_window.child = vbox
|
19
|
+
main_window.control_show
|
20
|
+
main_window.simple_exit
|
21
|
+
UI.main_then_quit
|
@@ -0,0 +1,180 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'libui_paradise/autoinclude'
|
6
|
+
|
7
|
+
should_quit = proc {
|
8
|
+
puts 'Bye Bye'
|
9
|
+
UI.control_destroy(MAIN_WINDOW)
|
10
|
+
UI.quit
|
11
|
+
0
|
12
|
+
}
|
13
|
+
|
14
|
+
open_menu_item_clicked = proc do
|
15
|
+
puts "Clicked 'Open'"
|
16
|
+
0
|
17
|
+
end
|
18
|
+
|
19
|
+
save_menu_item_clicked = proc {
|
20
|
+
puts "Clicked 'Save'"
|
21
|
+
0
|
22
|
+
}
|
23
|
+
|
24
|
+
# Create 'File' menu with a few items and callbacks
|
25
|
+
# when the items are clicked
|
26
|
+
menu = UI.new_menu('File')
|
27
|
+
open_menu_item = UI.menu_append_item(menu, 'Open')
|
28
|
+
UI.menu_item_on_clicked(open_menu_item, open_menu_item_clicked, nil)
|
29
|
+
save_menu_item = UI.menu_append_item(menu, 'Save')
|
30
|
+
UI.menu_item_on_clicked(save_menu_item, save_menu_item_clicked, nil)
|
31
|
+
UI.menu_append_quit_item(menu)
|
32
|
+
UI.on_should_quit(should_quit, nil)
|
33
|
+
|
34
|
+
# =========================================================================== #
|
35
|
+
# Create the 'Edit' menu
|
36
|
+
# =========================================================================== #
|
37
|
+
edit_menu = UI.new_menu('Edit')
|
38
|
+
UI.menu_append_check_item(edit_menu, 'Checkable Item_')
|
39
|
+
UI.menu_append_separator(edit_menu)
|
40
|
+
disabled_item = UI.menu_append_item(edit_menu, 'Disabled Item_')
|
41
|
+
UI.menu_item_disable(disabled_item)
|
42
|
+
|
43
|
+
preferences = UI.menu_append_preferences_item(menu)
|
44
|
+
|
45
|
+
# =========================================================================== #
|
46
|
+
# Create the 'Help' menu
|
47
|
+
# =========================================================================== #
|
48
|
+
help_menu = UI.new_menu('Help')
|
49
|
+
UI.menu_append_item(help_menu, 'Help')
|
50
|
+
UI.menu_append_about_item(help_menu)
|
51
|
+
|
52
|
+
vbox = ui_padded_vbox
|
53
|
+
hbox = ui_padded_hbox
|
54
|
+
vbox.maximal(hbox)
|
55
|
+
|
56
|
+
group = UI.new_group('Basic Controls')
|
57
|
+
UI.group_set_margined(group, 1)
|
58
|
+
hbox.add(group, 0)
|
59
|
+
|
60
|
+
inner = ui_padded_vbox
|
61
|
+
UI.group_set_child(group, inner)
|
62
|
+
|
63
|
+
button = ui_button('Button')
|
64
|
+
button_clicked_callback = proc {
|
65
|
+
ui_msg_box(MAIN_WINDOW, 'Information', 'You clicked the button')
|
66
|
+
0
|
67
|
+
}
|
68
|
+
UI.button_on_clicked(button, button_clicked_callback, nil)
|
69
|
+
inner.minimal(button)
|
70
|
+
|
71
|
+
checkbox = ui_checkbox('Checkbox')
|
72
|
+
checkbox_toggle_callback = proc { |ptr|
|
73
|
+
checked = UI.checkbox_checked(ptr) == 1
|
74
|
+
UI.window_set_title(MAIN_WINDOW, "Checkbox is #{checked}")
|
75
|
+
UI.checkbox_set_text(ptr, "I am the checkbox (#{checked})")
|
76
|
+
0
|
77
|
+
}
|
78
|
+
UI.checkbox_on_toggled(checkbox, checkbox_toggle_callback, nil)
|
79
|
+
UI.box_append(inner, checkbox, 0)
|
80
|
+
|
81
|
+
UI.box_append(inner, UI.new_label('Label'), 0)
|
82
|
+
UI.box_append(inner, UI.new_horizontal_separator, 0)
|
83
|
+
UI.box_append(inner, UI.new_date_picker, 0)
|
84
|
+
UI.box_append(inner, UI.new_time_picker, 0)
|
85
|
+
UI.box_append(inner, UI.new_date_time_picker, 0)
|
86
|
+
UI.box_append(inner, UI.new_font_button, 0)
|
87
|
+
UI.box_append(inner, UI.new_color_button, 0)
|
88
|
+
|
89
|
+
inner2 = UI.vbox
|
90
|
+
UI.box_set_padded(inner2, 1)
|
91
|
+
UI.box_append(hbox, inner2, 1)
|
92
|
+
|
93
|
+
group = UI.new_group('Numbers')
|
94
|
+
UI.group_set_margined(group, 1)
|
95
|
+
UI.box_append(inner2, group, 0)
|
96
|
+
|
97
|
+
inner = ui_padded_vbox
|
98
|
+
UI.group_set_child(group, inner)
|
99
|
+
|
100
|
+
spinbox = ui_spinbox(0, 100)
|
101
|
+
# =========================================================================== #
|
102
|
+
# === spinbox_changed_callbac
|
103
|
+
#
|
104
|
+
# The function called when the spinbox is changed.
|
105
|
+
# =========================================================================== #
|
106
|
+
spinbox_changed_callback = proc { |ptr|
|
107
|
+
puts "New Spinbox value: #{UI.spinbox_value(ptr)}"
|
108
|
+
0
|
109
|
+
}
|
110
|
+
spinbox.set_value(42)
|
111
|
+
UI.spinbox_on_changed(spinbox, spinbox_changed_callback, nil)
|
112
|
+
inner.append(spinbox, 0)
|
113
|
+
|
114
|
+
slider = UI.new_slider(0, 100)
|
115
|
+
slider_changed_callback = proc { |ptr|
|
116
|
+
puts "New Slider value: #{UI.slider_value(ptr)}"
|
117
|
+
0
|
118
|
+
}
|
119
|
+
UI.slider_on_changed(slider, slider_changed_callback, nil)
|
120
|
+
UI.box_append(inner, slider, 0)
|
121
|
+
|
122
|
+
progressbar = UI.new_progress_bar
|
123
|
+
UI.box_append(inner, progressbar, 0)
|
124
|
+
|
125
|
+
group = UI.new_group('Lists')
|
126
|
+
UI.group_set_margined(group, 1)
|
127
|
+
UI.box_append(inner2, group, 0)
|
128
|
+
|
129
|
+
inner = ui_padded_vbox
|
130
|
+
UI.group_set_child(group, inner)
|
131
|
+
|
132
|
+
combobox_selected_callback = proc { |ptr|
|
133
|
+
puts "New combobox selection: #{UI.combobox_selected(ptr)}"
|
134
|
+
}
|
135
|
+
cbox = ui_combobox
|
136
|
+
UI.combobox_append(cbox, 'combobox Item 1')
|
137
|
+
UI.combobox_append(cbox, 'combobox Item 2')
|
138
|
+
UI.combobox_append(cbox, 'combobox Item 3')
|
139
|
+
inner.add(cbox, 0)
|
140
|
+
UI.combobox_on_selected(cbox, combobox_selected_callback, nil)
|
141
|
+
|
142
|
+
# Show an editable combobox next:
|
143
|
+
ebox = ui_editable_combo_box
|
144
|
+
UI.editable_combobox_append(ebox, 'Editable Item 1')
|
145
|
+
UI.editable_combobox_append(ebox, 'Editable Item 2')
|
146
|
+
UI.editable_combobox_append(ebox, 'Editable Item 3')
|
147
|
+
inner.add(ebox, 0)
|
148
|
+
|
149
|
+
rb = ui_radio_buttons
|
150
|
+
UI.radio_buttons_append(rb, 'Radio Button 1')
|
151
|
+
UI.radio_buttons_append(rb, 'Radio Button 2')
|
152
|
+
UI.radio_buttons_append(rb, 'Radio Button 3')
|
153
|
+
inner.maximal(rb)
|
154
|
+
|
155
|
+
tab = ui_tab
|
156
|
+
hbox1 = ui_hbox
|
157
|
+
UI.tab_append(tab, 'Page 1', hbox1)
|
158
|
+
UI.tab_append(tab, 'Page 2', ui_hbox)
|
159
|
+
UI.tab_append(tab, 'Page 3', ui_hbox)
|
160
|
+
inner2.maximal(tab)
|
161
|
+
|
162
|
+
# =========================================================================== #
|
163
|
+
# === text_changed_callback
|
164
|
+
# =========================================================================== #
|
165
|
+
text_changed_callback = proc { |ptr|
|
166
|
+
puts "Current textbox data: '#{UI.entry_text(ptr)}'"
|
167
|
+
}
|
168
|
+
|
169
|
+
text_entry = ui_entry
|
170
|
+
text_entry.set_text('Please enter your feelings')
|
171
|
+
text_entry.on_changed { text_changed_callback }
|
172
|
+
hbox1.append(text_entry, 1)
|
173
|
+
|
174
|
+
MAIN_WINDOW = UI.window('hello world', 600, 600, 1)
|
175
|
+
UI.window_set_margined(MAIN_WINDOW, 1)
|
176
|
+
UI.window_set_child(MAIN_WINDOW, vbox)
|
177
|
+
|
178
|
+
UI.window_on_closing(MAIN_WINDOW, should_quit, nil)
|
179
|
+
MAIN_WINDOW.control_show
|
180
|
+
UI.main_then_quit
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'libui_paradise/autoinclude'
|
6
|
+
|
7
|
+
music_directory = File.expand_path(ARGV[0] || '~/Music/')
|
8
|
+
midi_files = Dir.glob(File.join(music_directory, '**/*.mid'))
|
9
|
+
.sort_by { |path| File.basename(path) }
|
10
|
+
VERSION = '0.0.1'.freeze
|
11
|
+
|
12
|
+
@pid = nil
|
13
|
+
|
14
|
+
play_midi = proc do
|
15
|
+
if @pid.nil? && @selected_file
|
16
|
+
begin
|
17
|
+
@pid = spawn "timidity #{@selected_file}"
|
18
|
+
@th = Process.detach @pid
|
19
|
+
rescue Errno::ENOENT => e
|
20
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
21
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
0
|
25
|
+
end
|
26
|
+
|
27
|
+
stop_midi = proc do
|
28
|
+
if @pid
|
29
|
+
if @th.alive?
|
30
|
+
Process.kill(:SIGKILL, @pid)
|
31
|
+
@pid = nil
|
32
|
+
else
|
33
|
+
@pid = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
help_menu = UI.new_menu('Help')
|
39
|
+
version_item = UI.menu_append_item(help_menu, 'Version')
|
40
|
+
|
41
|
+
UI.new_window('Tiny Midi Player', 200, 50, 1).tap do |main_window|
|
42
|
+
UI.menu_item_on_clicked(version_item) {
|
43
|
+
UI.msg_box(main_window,
|
44
|
+
'Tiny Midi Player',
|
45
|
+
"Written in Ruby\n" \
|
46
|
+
"https://github.com/kojix2/libui\n Version #{VERSION}"
|
47
|
+
)
|
48
|
+
0
|
49
|
+
}
|
50
|
+
|
51
|
+
UI.window_on_closing(main_window) {
|
52
|
+
UI.control_destroy(main_window)
|
53
|
+
UI.quit
|
54
|
+
0
|
55
|
+
}
|
56
|
+
|
57
|
+
UI.new_horizontal_box.tap do |hbox|
|
58
|
+
UI.new_vertical_box.tap do |vbox|
|
59
|
+
UI.new_button('▶').tap do |button1|
|
60
|
+
UI.button_on_clicked(button1, play_midi)
|
61
|
+
UI.box_append(vbox, button1, 1)
|
62
|
+
end
|
63
|
+
UI.new_button('■').tap do |button2|
|
64
|
+
UI.button_on_clicked(button2, stop_midi)
|
65
|
+
at_exit(&stop_midi)
|
66
|
+
vbox.add(button2, 1)
|
67
|
+
end
|
68
|
+
hbox.add(vbox, 0)
|
69
|
+
end
|
70
|
+
UI.window_set_child(main_window, hbox)
|
71
|
+
|
72
|
+
UI.new_combobox.tap do |cbox|
|
73
|
+
midi_files.each { |path|
|
74
|
+
name = File.basename(path)
|
75
|
+
UI.combobox_append(cbox, name)
|
76
|
+
}
|
77
|
+
UI.combobox_on_selected(cbox) { |ptr|
|
78
|
+
@selected_file = midi_files[UI.combobox_selected(ptr)]
|
79
|
+
if @th && @th.alive?
|
80
|
+
stop_midi.call
|
81
|
+
play_midi.call
|
82
|
+
end
|
83
|
+
0
|
84
|
+
}
|
85
|
+
hbox.add(cbox, 1)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
UI.control_show(main_window)
|
89
|
+
end
|
90
|
+
|
91
|
+
UI.main_then_quit
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === 014_basic_draw_text.rb
|
6
|
+
# =========================================================================== #
|
7
|
+
# This example shows how to display coloured text.
|
8
|
+
# =========================================================================== #
|
9
|
+
require 'libui_paradise/autoinclude'
|
10
|
+
|
11
|
+
# =========================================================================== #
|
12
|
+
# === USE_THIS_FONT
|
13
|
+
#
|
14
|
+
# Specify a certain font to use.
|
15
|
+
# =========================================================================== #
|
16
|
+
USE_THIS_FONT = 'Georgia'
|
17
|
+
|
18
|
+
# =========================================================================== #
|
19
|
+
# === TITLE
|
20
|
+
# =========================================================================== #
|
21
|
+
TITLE = 'Michael Ende (1929-1995) The Neverending Story'
|
22
|
+
|
23
|
+
handler = UI::FFI::AreaHandler.malloc
|
24
|
+
area = UI.area(handler)
|
25
|
+
|
26
|
+
str1 = \
|
27
|
+
' At last Ygramul sensed that something was coming toward ' \
|
28
|
+
'her. With the speed of lightning, she turned about, confronting ' \
|
29
|
+
'Atreyu with an enormous steel-blue face. Her single eye had a ' \
|
30
|
+
'vertical pupil, which stared at Atreyu with inconceivable malignancy. '
|
31
|
+
|
32
|
+
str2 = \
|
33
|
+
' A cry of fear escaped Bastian. '
|
34
|
+
|
35
|
+
str3 = \
|
36
|
+
' A cry of terror passed through the ravine and echoed from ' \
|
37
|
+
'side to side. Ygramul turned her eye to left and right, to see if ' \
|
38
|
+
'someone else had arrived, for that sound could not have been ' \
|
39
|
+
'made by the boy who stood there as though paralyzed with ' \
|
40
|
+
'horror. '
|
41
|
+
|
42
|
+
str4 = \
|
43
|
+
' Could she have heard my cry? Bastion wondered in alarm. ' \
|
44
|
+
"But that's not possible. "
|
45
|
+
|
46
|
+
str5 = \
|
47
|
+
' And then Atreyu heard Ygramuls voice. It was very high ' \
|
48
|
+
'and slightly hoarse, not at all the right kind of voice for that ' \
|
49
|
+
'enormous face. Her lips did not move as she spoke. It was the ' \
|
50
|
+
'buzzing of a great swarm of hornets that shaped itself into ' \
|
51
|
+
'words. '
|
52
|
+
|
53
|
+
str = ''
|
54
|
+
attr_str = UI.new_attributed_string(str)
|
55
|
+
|
56
|
+
# =========================================================================== #
|
57
|
+
# Add an ad-hoc append method.
|
58
|
+
# =========================================================================== #
|
59
|
+
def attr_str.append(
|
60
|
+
this_text,
|
61
|
+
color
|
62
|
+
)
|
63
|
+
case color
|
64
|
+
# =========================================================================== #
|
65
|
+
# === :red
|
66
|
+
# =========================================================================== #
|
67
|
+
when :red # red colour
|
68
|
+
use_this_colour = UI.new_color_attribute(0.0, 0.5, 0.0, 0.7)
|
69
|
+
# =========================================================================== #
|
70
|
+
# === :green
|
71
|
+
# =========================================================================== #
|
72
|
+
when :green # green colour
|
73
|
+
use_this_colour = UI.new_color_attribute(0.5, 0.0, 0.25, 0.7)
|
74
|
+
end
|
75
|
+
start = UI.attributed_string_len(self)
|
76
|
+
# =========================================================================== #
|
77
|
+
# Append the stuff next.
|
78
|
+
# =========================================================================== #
|
79
|
+
UI.attributed_string_append_unattributed(self, this_text)
|
80
|
+
UI.attributed_string_set_attribute(self,
|
81
|
+
use_this_colour,
|
82
|
+
start, # Start position.
|
83
|
+
start + this_text.size # End position.
|
84
|
+
)
|
85
|
+
UI.attributed_string_append_unattributed(self, "\n\n")
|
86
|
+
end
|
87
|
+
|
88
|
+
attr_str.append(str1, :green)
|
89
|
+
attr_str.append(str2, :red)
|
90
|
+
attr_str.append(str3, :green)
|
91
|
+
attr_str.append(str4, :red)
|
92
|
+
attr_str.append(str5, :green)
|
93
|
+
|
94
|
+
handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, adp|
|
95
|
+
area_draw_params = UI::FFI::AreaDrawParams.new(adp)
|
96
|
+
# =========================================================================== #
|
97
|
+
# Designate our font in use next.
|
98
|
+
# =========================================================================== #
|
99
|
+
default_font = UI::FFI::FontDescriptor.malloc
|
100
|
+
default_font.Family = USE_THIS_FONT
|
101
|
+
default_font.Size = 13
|
102
|
+
default_font.Weight = 500
|
103
|
+
default_font.Italic = 0
|
104
|
+
default_font.Stretch = 4
|
105
|
+
params = UI::FFI::DrawTextLayoutParams.malloc
|
106
|
+
|
107
|
+
# UI.font_button_font(font_button, default_font)
|
108
|
+
params.String = attr_str
|
109
|
+
params.DefaultFont = default_font
|
110
|
+
params.Width = area_draw_params.AreaWidth
|
111
|
+
params.Align = 0
|
112
|
+
text_layout = UI.text_layout(params)
|
113
|
+
UI.draw_text(area_draw_params.Context, text_layout, 0, 0)
|
114
|
+
UI.draw_free_text_layout(text_layout)
|
115
|
+
end
|
116
|
+
|
117
|
+
handler.Draw = handler_draw_event
|
118
|
+
# Assigning to local variables
|
119
|
+
# This is intended to protect Fiddle::Closure from garbage collection.
|
120
|
+
handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
121
|
+
handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
122
|
+
handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
123
|
+
handler.KeyEvent = (c4 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
124
|
+
|
125
|
+
box = UI.vbox
|
126
|
+
box.set_padded(1)
|
127
|
+
box.add(area, 1)
|
128
|
+
|
129
|
+
main_window = UI.window(TITLE, 600, 400, 1)
|
130
|
+
UI.window_set_margined(main_window, 1)
|
131
|
+
main_window.child = box
|
132
|
+
main_window.close_properly
|
133
|
+
main_window.control_show
|
134
|
+
UI.main_then_quit
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === 015_font_example_text.rb
|
6
|
+
# =========================================================================== #
|
7
|
+
# This example shows how to display coloured text.
|
8
|
+
#
|
9
|
+
# An AttributedString is a string which also contains information
|
10
|
+
# about styles such as text color, font, font size. It will be
|
11
|
+
# drawn in an UiArea element.
|
12
|
+
# =========================================================================== #
|
13
|
+
require 'libui_paradise/autoinclude'
|
14
|
+
|
15
|
+
# =========================================================================== #
|
16
|
+
# === USE_THIS_FONT
|
17
|
+
#
|
18
|
+
# Specify a certain font to use.
|
19
|
+
# =========================================================================== #
|
20
|
+
USE_THIS_FONT = 'Georgia'
|
21
|
+
|
22
|
+
# =========================================================================== #
|
23
|
+
# === USE_THIS_FONT_SIZE
|
24
|
+
# =========================================================================== #
|
25
|
+
USE_THIS_FONT_SIZE = 25
|
26
|
+
|
27
|
+
# =========================================================================== #
|
28
|
+
# === TITLE
|
29
|
+
# =========================================================================== #
|
30
|
+
TITLE = 'Font Example'
|
31
|
+
|
32
|
+
handler = UI::FFI::AreaHandler.malloc
|
33
|
+
area = UI.new_area(handler)
|
34
|
+
|
35
|
+
str1 = 'At last Ygramul sensed that something was coming toward her.'
|
36
|
+
|
37
|
+
attr_str = fancy_text('')
|
38
|
+
|
39
|
+
def attr_str.append(what)
|
40
|
+
color_attribute = UI.new_color_attribute(0.5, 0.0, 0.25, 0.7)
|
41
|
+
start = UI.attributed_string_len(self)
|
42
|
+
UI.attributed_string_append_unattributed(self, what)
|
43
|
+
UI.attributed_string_set_attribute(self, color_attribute, start, start + what.size)
|
44
|
+
UI.attributed_string_append_unattributed(self, "\n\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
attr_str.append(str1)
|
48
|
+
|
49
|
+
handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) { |_, _, adp|
|
50
|
+
area_draw_params = UI::FFI::AreaDrawParams.new(adp)
|
51
|
+
default_font = font {{
|
52
|
+
font_size: USE_THIS_FONT_SIZE,
|
53
|
+
font_family: USE_THIS_FONT,
|
54
|
+
italic: false,
|
55
|
+
stretch: 2,
|
56
|
+
weight: 500
|
57
|
+
}}
|
58
|
+
|
59
|
+
params = ui_draw_text_layout_params
|
60
|
+
|
61
|
+
params.String = attr_str
|
62
|
+
params.DefaultFont = default_font
|
63
|
+
params.Width = area_draw_params.AreaWidth
|
64
|
+
params.Align = 0
|
65
|
+
text_layout = UI.draw_new_text_layout(params)
|
66
|
+
UI.draw_text(area_draw_params.Context, text_layout, 0, 0)
|
67
|
+
UI.draw_free_text_layout(text_layout)
|
68
|
+
}
|
69
|
+
|
70
|
+
# =========================================================================== #
|
71
|
+
# Assigning to local variables:
|
72
|
+
#
|
73
|
+
# This is intended to protect Fiddle::Closure from garbage collection.
|
74
|
+
#
|
75
|
+
# =========================================================================== #
|
76
|
+
handler.Draw = handler_draw_event
|
77
|
+
handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
78
|
+
handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
79
|
+
# handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
80
|
+
# handler.KeyEvent = (c4 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
81
|
+
|
82
|
+
box = ui_padded_vbox
|
83
|
+
box.maximal(area)
|
84
|
+
box.maximal(ui_hseparator)
|
85
|
+
|
86
|
+
main_window = ui_main_window(TITLE, 600, 400, 1)
|
87
|
+
UI.window_set_margined(main_window, 1)
|
88
|
+
main_window.child = box
|
89
|
+
main_window.simple_exit
|
90
|
+
main_window.control_show
|
91
|
+
main_window.intelligent_exit
|
@@ -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('A search-entry example', 1200, 200, 15)
|
8
|
+
|
9
|
+
search_entry = ui_search_entry
|
10
|
+
box = ui_padded_vbox
|
11
|
+
box.add(search_entry, 1)
|
12
|
+
box.is_padded
|
13
|
+
|
14
|
+
window.child = box
|
15
|
+
window.control_show
|
16
|
+
window.intelligent_exit
|
@@ -0,0 +1,22 @@
|
|
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('A notebook with tabs example', 1200, 200, 15)
|
8
|
+
|
9
|
+
tab = ui_tabs
|
10
|
+
tab.add('Page 1', ui_hbox)
|
11
|
+
tab.add('Page 2', ui_hbox)
|
12
|
+
tab.add('Page 3', ui_hbox)
|
13
|
+
tab.add('Page 4', ui_hbox)
|
14
|
+
tab.add('Page 5', ui_hbox)
|
15
|
+
tab.add('Page 6', ui_hbox)
|
16
|
+
|
17
|
+
box = ui_padded_vbox
|
18
|
+
box.maximal(tab)
|
19
|
+
|
20
|
+
window.child = box
|
21
|
+
window.control_show
|
22
|
+
window.intelligent_exit
|