windows

package
v1.9.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package windows provides top-level windows.

Index

Examples

Constants

This section is empty.

Variables

View Source
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

func NewWindow(title string, child base.Widget) (*Window, error)

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

func (w *Window) Child() base.Element

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) GetSize

func (w *Window) GetSize() (int, int)

get windows client Size

func (*Window) Message

func (w *Window) Message(text string) *dialog.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

func (w *Window) MinSize() base.Size

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) OnDestroy

func (w *Window) OnDestroy()

func (*Window) OnSizeAllocate

func (w *Window) OnSizeAllocate(width, height int)

func (*Window) OpenFileDialog

func (w *Window) OpenFileDialog() *dialog.OpenFile

OpenFileDialog returns a builder that can be used to construct an open file dialog, and then show that dialog.

func (*Window) SaveFileDialog

func (w *Window) SaveFileDialog() *dialog.SaveFile

SaveFileDialog returns a builder that can be used to construct a save file dialog, and then show that dialog.

func (*Window) Screenshot

func (w *Window) Screenshot() (image.Image, error)

Screenshot returns an image of the window, as displayed on screen.

func (*Window) Scroll

func (w *Window) Scroll() (horizontal, vertical bool)

Scroll returns the flags that determine whether scrolling is allowed in the horizontal and vertical directions.

func (*Window) SetChild

func (w *Window) SetChild(child base.Widget) error

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

func (w *Window) SetIcon(img image.Image) error

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

func (w *Window) SetOnClosing(callback func() bool)

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

func (w *Window) SetOnResize(callback func(int, int) bool)

set callback for windows resize

func (*Window) SetScroll

func (w *Window) SetScroll(horizontal, vertical bool)

SetScroll sets whether scrolling is allowed in the horizontal and vertical directions.

func (*Window) SetTitle

func (w *Window) SetTitle(title string) error

SetTitle changes the caption in the title bar for the window.

func (*Window) Title

func (w *Window) Title() string

Title returns the current caption in the title bar for the window.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL