Documentation
¶
Overview ¶
Package windows provides top-level windows.
Index ¶
- Variables
- type Window
- func (w *Window) Child() base.Element
- func (w *Window) Close()
- func (w *Window) GetSize() (int, int)
- func (w *Window) Message(text string) *dialog.Message
- func (w *Window) MinSize() base.Size
- func (w *Window) OnDeleteEvent() bool
- func (w *Window) OnDestroy()
- func (w *Window) OnSizeAllocate(width, height int)
- func (w *Window) OpenFileDialog() *dialog.OpenFile
- func (w *Window) SaveFileDialog() *dialog.SaveFile
- func (w *Window) Screenshot() (image.Image, error)
- func (w *Window) Scroll() (horizontal, vertical bool)
- func (w *Window) SetChild(child base.Widget) error
- func (w *Window) SetIcon(img image.Image) error
- func (w *Window) SetOnClosing(callback func() bool)
- func (w *Window) SetOnResize(callback func(int, int) bool)
- func (w *Window) SetScroll(horizontal, vertical bool)
- func (w *Window) SetTitle(title string) error
- func (w *Window) Title() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSetChildrenNotReentrant is returned if a reentrant call to the method // SetChild is called. ErrSetChildrenNotReentrant = errors.New("method SetChild is not reentrant") )
Functions ¶
This section is empty.
Types ¶
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window represents a top-level window that contain other widgets.
func NewWindow ¶
NewWindow create a new top-level window for the application.
Example ¶
package main
import (
"fmt"
"time"
"github.com/LiEnby/goey/loop"
"github.com/LiEnby/goey/windows"
)
func main() {
// All calls that modify GUI objects need to be schedule ont he GUI thread.
// This callback will be used to create the top-level window.
createWindow := func() error {
// Create a top-level window.
mw, err := windows.NewWindow("Test", nil /*empty window*/)
if err != nil {
// This error will be reported back up through the call to
// Run below. No need to print or log it here.
return err
}
// We can start a goroutine, but note that we can't modify GUI objects
// directly.
go func() {
fmt.Println("Up")
time.Sleep(50 * time.Millisecond)
fmt.Println("Down")
// Note: No work after this call to Do, since the call to Run may be
// terminated when the call to Do returns.
_ = loop.Do(func() error {
mw.Close()
return nil
})
}()
return nil
}
// Start the GUI thread.
err := loop.Run(createWindow)
if err != nil {
fmt.Println("Error: ", err)
}
}
Output: Up Down
func (*Window) Child ¶
Child returns the mounted child for the window. In general, this method should not be used.
func (*Window) Close ¶
func (w *Window) Close()
Close destroys the window, and releases all associated resources.
func (*Window) Message ¶
Message returns a builder that can be used to construct a message dialog, and then show that dialog.
Example ¶
package main
import (
"fmt"
"github.com/LiEnby/goey/loop"
"github.com/LiEnby/goey/windows"
)
func main() {
// All calls that modify GUI objects need to be schedule ont he GUI thread.
// This callback will be used to create the top-level window.
createWindow := func() error {
// Create a top-level window.
mw, err := windows.NewWindow("Test", nil /*empty window*/)
if err != nil {
// This error will be reported back up through the call to
// Run below. No need to print or log it here.
return err
}
// We can start a goroutine, but note that we can't modify GUI objects
// directly.
go func() {
// Show the error message.
_ = loop.Do(func() error {
return mw.Message("This is an example message.").WithInfo().Show()
})
// Note: No work after this call to Do, since the call to Run may be
// terminated when the call to Do returns.
_ = loop.Do(func() error {
mw.Close()
return nil
})
}()
return nil
}
// Start the GUI thread.
err := loop.Run(createWindow)
if err != nil {
fmt.Println("Error: ", err)
}
}
func (*Window) MinSize ¶
MinSize returns the minimum size required to layout the child. The minimum size depends on the child, but also on what dimensions are allowed to scroll.
func (*Window) OnDeleteEvent ¶
func (w *Window) OnDeleteEvent() bool
func (*Window) OnSizeAllocate ¶
func (w *Window) OnSizeAllocate(width, height int)
func (*Window) OpenFileDialog ¶
OpenFileDialog returns a builder that can be used to construct an open file dialog, and then show that dialog.
func (*Window) SaveFileDialog ¶
SaveFileDialog returns a builder that can be used to construct a save file dialog, and then show that dialog.
func (*Window) Screenshot ¶
Screenshot returns an image of the window, as displayed on screen.
func (*Window) Scroll ¶
Scroll returns the flags that determine whether scrolling is allowed in the horizontal and vertical directions.
func (*Window) SetChild ¶
SetChild changes the child widget of the window. As necessary, GUI widgets will be created or destroyed so that the GUI widgets match the widgets described by the parameter children. The position of contained widgets will be updated to match the new layout properties.
func (*Window) SetIcon ¶
SetIcon changes the icon associated with the window.
On Cocoa, individual windows do not have icons. Instead, there is a single icon for the entire application.
func (*Window) SetOnClosing ¶
SetOnClosing changes the event callback for when the user tries to close the window. This callback can also be used to save or close any resources before the window is closed.
Returning true from the callback will prevent the window from closing.
func (*Window) SetOnResize ¶
set callback for windows resize
func (*Window) SetScroll ¶
SetScroll sets whether scrolling is allowed in the horizontal and vertical directions.