Skip to content

Commit

Permalink
Use UI.uninit instead of calling UI.quit twice
Browse files Browse the repository at this point in the history
Related to #45
Reported by @rubyFeedback and @AndyObtiva 
Thanks!!!
  • Loading branch information
kojix2 authored Jun 25, 2023
1 parent 601e981 commit 042eb04
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 74 deletions.
5 changes: 2 additions & 3 deletions examples/basic_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@
UI.window_set_child(main_window, box)

UI.window_on_closing(main_window) do
UI.control_destroy(main_window)
UI.quit
0
1
end
UI.control_show(main_window)

UI.main
UI.quit
UI.uninit
5 changes: 2 additions & 3 deletions examples/basic_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
1
end

UI.window_set_child(main_window, button)
UI.control_show(main_window)

UI.main
UI.quit
UI.uninit
5 changes: 2 additions & 3 deletions examples/basic_draw_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ def attr_str.append(what, color)
UI.window_set_child(main_window, box)

UI.window_on_closing(main_window) do
UI.control_destroy(main_window)
UI.quit
0
1
end
UI.control_show(main_window)

UI.main
UI.quit
UI.uninit
5 changes: 2 additions & 3 deletions examples/basic_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
main_window = UI.new_window('Basic Entry', 300, 50, 1)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
1
end

hbox = UI.new_horizontal_box
Expand All @@ -33,4 +32,4 @@

UI.control_show(main_window)
UI.main
UI.quit
UI.uninit
7 changes: 3 additions & 4 deletions examples/basic_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ def rbcallback(*args, &block)

UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.free_table_model(model)
UI.quit
0
1
end

UI.main
UI.quit
UI.free_table_model(model)
UI.uninit
9 changes: 4 additions & 5 deletions examples/basic_table_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ def rbcallback(*args, &block)

UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.free_table_model(model)
IMAGES.each { |i| UI.free_image(i) }
UI.quit
0
1
end

UI.main
UI.quit
UI.free_table_model(model)
IMAGES.each { |i| UI.free_image(i) }
UI.uninit
5 changes: 2 additions & 3 deletions examples/basic_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
1
end

UI.main
UI.quit
UI.uninit
33 changes: 22 additions & 11 deletions examples/control_gallery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@

UI.init

should_quit = proc do
puts 'Bye Bye'
UI.control_destroy(MAIN_WINDOW)
UI.quit
0
end

# File menu
menu = UI.new_menu('File')
open_menu_item = UI.menu_append_item(menu, 'Open')
Expand All @@ -22,9 +15,21 @@
pt = UI.save_file(MAIN_WINDOW)
puts pt unless pt.null?
end

UI.menu_append_separator(menu)
should_quit_item = UI.menu_append_check_item(menu, 'Should Quit_')
UI.menu_item_set_checked(should_quit_item, 1)
UI.menu_append_quit_item(menu)
UI.on_should_quit(should_quit)
# onShouldQuit callback is called when the user presses the quit menu item.
UI.on_should_quit do
if UI.menu_item_checked(should_quit_item) == 1
puts 'Bye Bye (on_should_quit)'
UI.control_destroy(MAIN_WINDOW) # You have to destroy the window manually.
1 # UI.quit is automatically called in the C function onQuitClicked().
else
UI.msg_box(MAIN_WINDOW, 'Warning', 'Please check "Should Quit"')
0 # Don't quit
end
end

# Edit menu
edit_menu = UI.new_menu('Edit')
Expand All @@ -43,7 +48,13 @@
# Main Window
MAIN_WINDOW = UI.new_window('Control Gallery', 600, 500, 1)
UI.window_set_margined(MAIN_WINDOW, 1)
UI.window_on_closing(MAIN_WINDOW, should_quit)
UI.window_on_closing(MAIN_WINDOW) do
puts 'Bye Bye'
UI.quit
# return 1 to destroys the window automatically.
# return 0 to keep the window. (You can destroy it manually.)
1
end

vbox = UI.new_vertical_box
UI.window_set_child(MAIN_WINDOW, vbox)
Expand Down Expand Up @@ -187,4 +198,4 @@
UI.control_show(MAIN_WINDOW)

UI.main
UI.quit
UI.uninit
5 changes: 2 additions & 3 deletions examples/date_time_picker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
main_window = UI.new_window('Date Time Pickers', 300, 200, 1)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
1
end
UI.window_set_child(main_window, vbox)
UI.control_show(main_window)

UI.main
UI.quit
UI.uninit
7 changes: 1 addition & 6 deletions examples/draw_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,13 @@ def draw_event(adp, attr_str, font_button, alignment)
handler.DragBroken = do_nothing
handler.KeyEvent = key_event

UI.on_should_quit do
UI.control_destroy(main_window)
end

@attr_str = make_attribute_string

main_window = UI.new_window('Text-Drawing Example', 640, 480, 1)
UI.window_set_margined(main_window, 1)
UI.window_on_closing(main_window) do
UI.control_destroy(main_window)
UI.quit
0
1
end

hbox = UI.new_horizontal_box
Expand Down
5 changes: 2 additions & 3 deletions examples/font_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
1
end

UI.window_set_child(main_window, font_button)
UI.control_show(main_window)

UI.main
UI.quit
UI.uninit
5 changes: 2 additions & 3 deletions examples/gpt2_notepad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ def predict_text(s, max = 30)
main_window = UI.new_window('GPT-2 Notepad', 500, 300, 1)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
1
end

hbox = UI.new_vertical_box
Expand Down Expand Up @@ -98,4 +97,4 @@ def predict_text(s, max = 30)

UI.control_show(main_window)
UI.main
UI.quit
UI.uninit
10 changes: 4 additions & 6 deletions examples/histogram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,13 @@ def set_solid_brush(brush, color, alpha)
UI.window_set_margined(MAIN_WINDOW, 1)
UI.window_set_child(MAIN_WINDOW, hbox)

should_quit = proc do |_ptr|
UI.control_destroy(MAIN_WINDOW)
UI.window_on_closing(MAIN_WINDOW) do
puts 'Bye Bye'
UI.quit
0
1
end

UI.window_on_closing(MAIN_WINDOW, should_quit)
UI.on_should_quit(should_quit)
UI.control_show(MAIN_WINDOW)

UI.main
UI.quit
UI.uninit
5 changes: 2 additions & 3 deletions examples/midi_player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ def create_gui
UI.menu_item_on_clicked(version_item) { show_version(main_window) }

UI.window_on_closing(main_window) do
UI.control_destroy(main_window)
UI.quit
0
1
end

UI.new_horizontal_box.tap do |hbox|
Expand Down Expand Up @@ -101,7 +100,7 @@ def create_gui
UI.control_show(main_window)
end
UI.main
UI.quit
UI.uninit
end
end

Expand Down
5 changes: 2 additions & 3 deletions examples/simple_notepad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
main_window = UI.new_window('Notepad', 500, 300, 1)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
1
end

vbox = UI.new_vertical_box
Expand All @@ -22,4 +21,4 @@

UI.control_show(main_window)
UI.main
UI.quit
UI.uninit
5 changes: 2 additions & 3 deletions examples/spectrum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ def spec
UI.window_set_child(main_window, box)

UI.window_on_closing(main_window) do
UI.control_destroy(main_window)
UI.quit
stream.close
::FFI::PortAudio::API.Pa_Terminate
0
1
end
UI.control_show(main_window)

Expand All @@ -107,4 +106,4 @@ def spec
end
end
UI.main
UI.quit
UI.uninit
17 changes: 8 additions & 9 deletions examples/turing_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,12 @@ def uint8_zeros_256(ch, ar)

# menu File Quit

quit_proc = proc do
@running = false
menu_file_quit = UI.menu_append_quit_item(menu_file)
UI.on_should_quit do
UI.control_destroy(@main_window)
UI.quit
0
1
end

menu_file_quit = UI.menu_append_item(menu_file, 'Quit')
UI.menu_item_on_clicked(menu_file_quit, quit_proc)

# menu Help

menu_help = UI.new_menu('Help')
Expand Down Expand Up @@ -594,7 +590,10 @@ def uint8_zeros_256(ch, ar)
UI.window_set_margined(@main_window, 1)
UI.window_set_child(@main_window, vbox)

UI.window_on_closing(@main_window, quit_proc)
UI.window_on_closing(@main_window) do
UI.quit
1
end
UI.control_show(@main_window)

# queue
Expand All @@ -612,4 +611,4 @@ def uint8_zeros_256(ch, ar)
end

UI.main
UI.quit
UI.uninit

0 comments on commit 042eb04

Please sign in to comment.