2014-07-07 14:03:39 -05:00
|
|
|
// 7 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
// Window represents a top-level window on screen that contains other Controls.
|
|
|
|
// Windows in package ui can only contain one control; the Stack and Grid layout Controls allow you to pack multiple Controls in a Window.
|
|
|
|
// Note that a Window is not itself a Control.
|
|
|
|
type Window interface {
|
2014-07-19 08:44:32 -05:00
|
|
|
// SetControl sets the Window's child Control.
|
|
|
|
SetControl(c Control)
|
2014-07-07 14:03:39 -05:00
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
// Title and SetTitle get and set the Window's title, respectively.
|
|
|
|
Title() string
|
|
|
|
SetTitle(title string)
|
2014-07-07 14:03:39 -05:00
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
// Show and Hide bring the Window on-screen and off-screen, respectively.
|
|
|
|
Show()
|
|
|
|
Hide()
|
2014-07-07 14:03:39 -05:00
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
// Close closes the Window.
|
2014-07-07 14:03:39 -05:00
|
|
|
// Any Controls within the Window are destroyed, and the Window itself is also destroyed.
|
|
|
|
// Attempting to use a Window after it has been closed results in undefined behavior.
|
2014-07-12 15:17:06 -05:00
|
|
|
// Close unconditionally closes the Window; it neither raises OnClosing nor checks for a return from OnClosing.
|
2014-07-19 08:44:32 -05:00
|
|
|
Close()
|
2014-07-07 14:03:39 -05:00
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
// OnClosing registers an event handler that is triggered when the user clicks the Window's close button.
|
2014-07-07 14:03:39 -05:00
|
|
|
// On systems where whole applications own windows, OnClosing is also triggered when the user asks to close the application.
|
|
|
|
// If this handler returns true, the Window is closed as defined by Close above.
|
|
|
|
// If this handler returns false, the Window is not closed.
|
2014-07-19 08:44:32 -05:00
|
|
|
OnClosing(func() bool)
|
2014-07-07 14:03:39 -05:00
|
|
|
}
|
2014-07-07 14:30:55 -05:00
|
|
|
|
2014-07-19 08:44:32 -05:00
|
|
|
// NewWindow creates a new Window with the given title text and size.
|
|
|
|
func NewWindow(title string, width int, height int) Window {
|
2014-07-07 14:30:55 -05:00
|
|
|
return newWindow(title, width, height)
|
|
|
|
}
|
2014-07-21 23:07:41 -05:00
|
|
|
|
|
|
|
// everything below is kept here because they're the same on all platforms
|
|
|
|
// TODO move event stuff here and make windowbase
|
|
|
|
|
|
|
|
func (w *window) SetControl(control Control) {
|
|
|
|
if w.child != nil { // unparent existing control
|
|
|
|
w.child.unparent()
|
|
|
|
}
|
|
|
|
control.unparent()
|
|
|
|
control.parent(w)
|
|
|
|
w.child = control
|
2014-07-22 16:45:29 -05:00
|
|
|
// each call to unparent() and parent() will cause the old/new parents to be redrawn; we don't have to worry about that here
|
2014-07-21 23:07:41 -05:00
|
|
|
}
|