andlabs / ui

Platform-native GUI library for Go.
Other
8.33k stars 651 forks source link

Exit button #334

Closed richrarobi closed 5 years ago

richrarobi commented 5 years ago

What is the best way to implement an Exit button. I have tried calling ui.Destroy (on Linux) it leaves the app "running" - needs ctrl-c to get back to prompt. (This was derived from your gallery example, I am trying to implement a simple buttons only control panel) If I just close the main box the app exits properly. I can't find an example of exit, and can't see what syntax for Quit...

(Perhaps a quit or exit button for the gallery example?) Thanks

andlabs commented 5 years ago

What is your code for the exit button, and for the window closing event?

richrarobi commented 5 years ago

Derived from one of the example buttons:-

button = ui.NewButton("Exit") button.OnClicked(func(*ui.Button) { mainwin.Destroy() }) grid.Append(button, 3, 0, 1, 1, false, ui.AlignFill, false, ui.AlignFill)

richrarobi commented 5 years ago

Sorry, hit the wrong button!

andlabs commented 5 years ago

And what is your mainwin OnClosing?

richrarobi commented 5 years ago

learn.go.zip This is the "whole program" - when I hit exit, it doesn't go back to a prompt, or exit if it has its own window.

richrarobi commented 5 years ago

Might have sorted it, I changed ui.Destroy to ui.Quit. Now I get the close window prompt... My newness to gtk3, I guess? ( Is this the "best" way?)

richrarobi commented 5 years ago

In a direct call within command line box, it goes straight back to the prompt properly. (with ui.Quit within the action for exit button)

andlabs commented 5 years ago

Yes, ui.Quit is the function that you call to tell ui.Main to return.

richrarobi commented 5 years ago

Thanks ....