goey

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: BSD-3-Clause Imports: 17 Imported by: 14

README

Goey

Package goey provides a declarative, cross-platform GUI for the Go language. The range of controls, their supported properties and events, should roughly match what is available in HTML. However, properties and events may be limited to support portability. Additionally, styling of the controls will be limited, with the look of controls matching the native platform.

Documentation Go Report Card Gitlab Build Status Windows Build Status

Install

The package can be installed from the command line using the go tool. However, depending on your OS, please check for special instructions below.

go get bitbucket.org/rj/goey
Windows

No special instructions are required to build this package on windows. CGO is not used.

Linux

This package requires the use of CGO to access GTK, which must be installed. The GTK libraries should be installed before issuing go get or you will have error messages during the building of some of the internal packages.

On Ubuntu:

sudo apt-get install libgtk-3-dev
Linux with GNUstep

This package can be built to target Cocoa using GNUstep, which must be installed. Most users are unlikely to want to use this option, but it can be useful for development. The libraries for GNUstep must be installed before issuing go get or you will have error message during the building of some of the internal packages.

On Ubuntu:

sudo apt-get install gnustep-devel

To force the use of GNUstep, build using the build tag cocoa.

BSD

This package requires the use of CGO to access GTK, which must be installed. The GTK libraries should be installed before issuing go get or you will have error messages during the building of some of the internal packages.

MacOS

There is a in-progress port for Cocoa. It is currently being developed using GNUstep on Linux, but has been developed based on documentation from Apple. All controls, except for the date control (which is not available in GNUstep), are implemented. However, additional testing, especially on Darwin, is still required.

If you can either test on Macs, or provide build systems, please contact us.

Getting Started

Package documentation and examples are on godoc.

The minimal GUI example application is onebutton, and additional example applications are in the example folder. Some of the example show the options available for the widgets, for example align and paragraph.

New layout widgets can be developed entirely in Go. For testing, a mock widget is provided in the mock package.

Windows

To get properly themed controls, a manifest is required. Please look at the source code for the example applications for an example. The manifest needs to be compiled with github.com/akavel/rsrc to create a .syso that will be recognize by the go build program. Additionally, you could use build flags (-ldflags="-H windowsgui") to change the type of application built.

Screenshots

Windows Linux (GTK) MacOS (Cocoa)
Screenshot Screenshot Screenshot
Screenshot Screenshot Screenshot
Screenshot Screenshot Screenshot
Screenshot Screenshot Screenshot
Screenshot Screenshot Screenshot
Screenshot Screenshot Screenshot
Screenshot Screenshot Screenshot
Screenshot Screenshot Screenshot

Contribute

Feedback and PRs welcome.

In particular, if anyone has the expertise to provide a port for MacOS, that would provide support for all major desktop operating systems.

Go Report Card

  • fyne: Cross platform GUI in Go based on Material Design.
  • gio: Gio implements portable immediate mode GUI programs in Go.
  • gotk3: Go bindings for GTK3.
  • nuklear: This project provides Go bindings for nuklear.h -- a small ANSI C GUI library.
  • walk: A Windows GUI toolkit for the Go Programming Language.
  • ui: Platform-native GUI library for Go.

License

BSD (c) Robert Johnstone

Documentation

Overview

Package goey provides a declarative, cross-platform GUI. The range of controls, their supported properties and events, should roughly match what is available in HTML. However, properties and events may be limited to support portability. Additionally, styling of the controls will be limited, with the look of controls matching the native platform.

The minimal GUI example application is bitbucket.org/rj/goey/example/onebutton, and additional example applications are in the example folder.

Screenshots

There are screenshots of some of the example applications linked in the README, located at https://bitbucket.org/rj/goey/src/default/README.md.

Windows

To get properly themed controls, a manifest is required. Please look at the source for the example applications for an example. This file needs to be compiled with github.com/akavel/rsrc to create a .syso that will be recognize by the go build program. Additionally, you could use build flags (-ldflags="-H windowsgui") to change the type of application built.

CGO is not required.

Linux

Although this package does not use CGO, some of its dependencies do. The build machine also requires that GTK+ 3 is installed. This should be installed before issuing `go get` or you will have error messages during the building of some of the dependencies.

On Ubuntu:

sudo apt-get install libgtk-3-dev

Darwin (MacOS)

A port to darwin using the Cocoa API is in the repository, but is only available under the macos branch. Development has been done on linux using GNUstep, so the build tags will need to be updated to build on a darwin system.

Index

Examples

Constants

View Source
const (
	DIP  = base.DIP  // Device-independent pixel (1/96 inch)
	PT   = base.PT   // Point (1/72 inch)
	PC   = base.PC   // Pica (1/6 inch or 12 points)
	Inch = base.Inch // Inch from a British imperial system of measurements
)

Common lengths used when describing GUIs. Note that the DIP (device-independent pixel) is the natural unit for this package. Because of limited precision, the PT listed here is somewhat smaller than its correct value.

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 Align

type Align struct {
	HAlign       Alignment   // Horizontal alignment of child widget.
	VAlign       Alignment   // Vertical alignment of child widget.
	WidthFactor  float64     // If greater than zero, ratio of container width to child width.
	HeightFactor float64     // If greater than zero, ratio of container height to child height.
	Child        base.Widget // Child widget.
}

Align describes a widget that aligns a single child widget within its borders.

The default position is for the child widget to be centered. To change the position of the child, the horizontal and vertical alignment (the fields HAlign and VAlign) should be adjusted.

The size of the control depends on the WidthFactor and HeightFactor. If zero, the widget will try to be as large as possible or match the child, depending on whether the box constraints are bound or not. If a factor is greater than zero, then the widget will try to size itself to be that much larger than the child widget.

func (*Align) Kind

func (*Align) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Align) Mount

func (w *Align) Mount(parent base.Control) (base.Element, error)

Mount creates an aligned layout for child widgets in the GUI. The newly created widget will be a child of the widget specified by parent.

type Alignment

type Alignment int16

Alignment represents the position of a child widget along one dimension. Some common values for alignment, such as AlignStart, AlignCenter, and AlignEnd, are given constants, but other values are possible. For example, to align a child with an position of 25%, use (AlignStart + AlignCenter) / 2.

const (
	AlignStart  Alignment = -32768 // Widget is aligned at the start (left or top).
	AlignCenter Alignment = 0      // Widget is aligned at the center.
	AlignEnd    Alignment = 0x7fff // Widget is aligned at the end (right or bottom).
)

Common values for alignment, representing the position of child widget.

type Button

type Button struct {
	Text     string // Text is a caption for the button.
	Disabled bool   // Disabled is a flag indicating that the user cannot interact with this button.
	Default  bool   // Default is a flag indicating that the button represents the default action for the interface.
	OnClick  func() // OnClick will be called whenever the user presses the button.
	OnFocus  func() // OnFocus will be called whenever the button receives the keyboard focus.
	OnBlur   func() // OnBlur will be called whenever the button loses the keyboard focus.
}

Button describes a widget that users can click to initiate an action.

Simultaneously setting both disabled and default to true is not supported. It may or may not work, depending on the platform.

Example
clickCount := 0

// In a full application, this variable would be updated to point to
// the main window for the application.
var mainWindow *Window
// These functions are used to update the GUI.  See below
var update func()
var render func() base.Widget

// Update function
update = func() {
	err := mainWindow.SetChild(render())
	if err != nil {
		panic(err)
	}
}

// Render function generates a tree of Widgets to describe the desired
// state of the GUI.
render = func() base.Widget {
	// Prep - text for the button
	text := "Click me!"
	if clickCount > 0 {
		text = text + "  (" + strconv.Itoa(clickCount) + ")"
	}
	// The GUI contains a single widget, this button.
	return &VBox{
		AlignMain:  MainCenter,
		AlignCross: CrossCenter,
		Children: []base.Widget{
			&Button{Text: text, OnClick: func() {
				clickCount++
				update()
			}},
		},
	}
}
Output:

func (*Button) Kind

func (*Button) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Button) Mount

func (w *Button) Mount(parent base.Control) (base.Element, error)

Mount creates a button control in the GUI. The newly created widget will be a child of the widget specified by parent.

type Checkbox

type Checkbox struct {
	Text     string           // Text is a caption for the checkbox.
	Value    bool             // Is the checkbox checked?
	Disabled bool             // Disabled is a flag indicating that the user cannot interact with this checkbox.
	OnChange func(value bool) // OnChange will be called whenever the value (checked or unchecked) changes.
	OnFocus  func()           // OnFocus will be called whenever the checkbox receives the keyboard focus.
	OnBlur   func()           // OnBlur will be called whenever the checkbox loses the keyboard focus.
}

Checkbox describes a widget that users input or update a flag. The model for the value is a boolean value.

func (*Checkbox) Kind

func (*Checkbox) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Checkbox) Mount

func (w *Checkbox) Mount(parent base.Control) (base.Element, error)

Mount creates a checkbox control in the GUI.

The newly created widget will be a child of the widget specified by parent.

type Control

type Control struct {
	// contains filtered or unexported fields
}

Control is an opaque type used as a platform-specific handle to a control created using the platform GUI. As an example, this will refer to a HWND when targeting Windows, but a *GtkWidget when targeting GTK.

Unless developping new widgets, users should not need to use this type.

Any method's on this type will be platform specific.

func (*Control) Close

func (w *Control) Close()

Close removes the element from the GUI, and frees any associated resources.

func (*Control) Handle

func (w *Control) Handle() uintptr

Handle returns the platform-native handle for the control.

func (*Control) Layout

func (w *Control) Layout(bc base.Constraints) base.Size

Layout determines the best size for an element that satisfies the constraints.

func (*Control) MinIntrinsicHeight

func (w *Control) MinIntrinsicHeight(width base.Length) base.Length

MinIntrinsicHeight returns the minimum height that this element requires to be correctly displayed.

func (*Control) MinIntrinsicWidth

func (w *Control) MinIntrinsicWidth(base.Length) base.Length

MinIntrinsicWidth returns the minimum width that this element requires to be correctly displayed.

func (*Control) OnDestroy

func (w *Control) OnDestroy()

func (*Control) SetBounds

func (w *Control) SetBounds(bounds base.Rectangle)

SetBounds updates the position of the widget.

func (*Control) TakeFocus

func (w *Control) TakeFocus() bool

TakeFocus is a wrapper around GrabFocus.

func (*Control) TypeKeys

func (w *Control) TypeKeys(text string) chan error

TypeKeys sends events to the control as if the string was typed by a user.

type CrossAxisAlign

type CrossAxisAlign uint8

CrossAxisAlign identifies the different types of alignment that are possible along the cross axis for vertical box and horizontal box layouts.

const (
	Stretch     CrossAxisAlign = iota // Children will be stretched so that the extend across box
	CrossStart                        // Children will be aligned to the left or top of the box
	CrossCenter                       // Children will be aligned in the center of the box
	CrossEnd                          // Children will be aligned to the right or bottom of the box
)

Allowed values for alignment of the cross axis in a vertical box (VBox) or horizontal box (HBox).

type DateInput

type DateInput struct {
	Value    time.Time             // Values is the current string for the field
	Disabled bool                  // Disabled is a flag indicating that the user cannot interact with this field
	OnChange func(value time.Time) // OnChange will be called whenever the user changes the value for this field
	OnFocus  func()                // OnFocus will be called whenever the field receives the keyboard focus
	OnBlur   func()                // OnBlur will be called whenever the field loses the keyboard focus
}

DateInput describes a widget that users input or update a single date. The model for the value is a time.Time value.

func (*DateInput) Kind

func (*DateInput) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*DateInput) Mount

func (w *DateInput) Mount(parent base.Control) (base.Element, error)

Mount creates a text field in the GUI. The newly created widget will be a child of the widget specified by parent.

type Decoration

type Decoration struct {
	Fill   color.RGBA  // Background color used to fill interior.
	Stroke color.RGBA  // Stroke color used to draw outline.
	Insets Insets      // Space between border of the decoration and the child element.
	Radius base.Length // Radius of the widgets corners.
	Child  base.Widget // Child widget.
}

Decoration describes a widget that provides a border and background, and possibly containing a single child widget.

The size of the control will match the size of the child element, although padding will be added between the border of the decoration and the child element as specified by the field Insets.

func (*Decoration) Kind

func (*Decoration) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Decoration) Mount

func (w *Decoration) Mount(parent base.Control) (base.Element, error)

Mount creates a button in the GUI. The newly created widget will be a child of the widget specified by parent.

type Empty

type Empty struct {
}

Empty describes a widget that is either a horizontal or vertical gap.

The size of the control will be a (perhaps platform dependent) spacing between controls. This applies to both the width and height.

func (*Empty) Kind

func (*Empty) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Empty) Mount

func (w *Empty) Mount(parent base.Control) (base.Element, error)

Mount creates a horizontal layout for child widgets in the GUI. The newly created widget will be a child of the widget specified by parent.

type Expand

type Expand struct {
	Factor int         // Fraction (minus one) of available space used by this widget
	Child  base.Widget // Child widget.
}

Expand wraps another widget to indicate that the widget should expand to occupy any available space in a HBox or VBox. When used in any other context, the widget will be ignored, and behavior delegated to the child widget.

In an HBox or VBox, the widget will be positioned according to the rules of its child. However, any excess space along the main axis will be added based on the ratio of the widget's factor to the sum of factors for all widgets in the box.

func (*Expand) Kind

func (*Expand) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Expand) Mount

func (w *Expand) Mount(parent base.Control) (base.Element, error)

Mount creates a button in the GUI. The newly created widget will be a child of the widget specified by parent.

type HBox

type HBox struct {
	AlignMain  MainAxisAlign  // Control distribution of excess horizontal space when positioning children.
	AlignCross CrossAxisAlign // Control distribution of excess vertical space when positioning children.
	Children   []base.Widget  // Children.
}

HBox describes a layout widget that arranges its child widgets into a row. Children are positioned in order from the left towards the right. The main axis for alignment is therefore horizontal, with the cross axis for alignment is vertical.

The size of the box will try to set a width sufficient to contain all of its children. Extra space will be distributed according to the value of AlignMain. Subject to the box constraints during layout, the height should match the largest minimum height of the child widgets.

func (*HBox) Kind

func (*HBox) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*HBox) Mount

func (w *HBox) Mount(parent base.Control) (base.Element, error)

Mount creates a horizontal layout for child widgets in the GUI. The newly created widget will be a child of the widget specified by parent.

type HR

type HR struct {
}

HR describes a widget that is a horizontal separator.

func (*HR) Kind

func (*HR) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*HR) Mount

func (w *HR) Mount(parent base.Control) (base.Element, error)

Mount creates a horizontal rule control in the GUI. The newly created widget will be a child of the widget specified by parent.

type Img

type Img struct {
	Image         image.Image // Image to be displayed.
	Width, Height base.Length // Dimensions for the image (see notes on sizing).
}

Img describes a widget that contains a bitmap image.

The size of the control depends on the value of Width and Height. The fields Width and Height may be left uninitialized, in which case they will be modified in-place. If both of these fields are left as zero, then the size will be calculated from the image's size assuming that its resolution is 92 DPI. If only one dimension is zero, then it will be calculate to maintain the aspect ratio of the image.

func (*Img) Kind

func (*Img) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Img) Mount

func (w *Img) Mount(parent base.Control) (base.Element, error)

Mount creates an image control in the GUI. The newly created widget will be a child of the widget specified by parent.

func (*Img) UpdateDimensions

func (w *Img) UpdateDimensions()

UpdateDimensions calculates default values for Width and Height if either or zero based on the image dimensions. The member Image cannot be nil.

type Insets

type Insets struct {
	Top    base.Length
	Right  base.Length
	Bottom base.Length
	Left   base.Length
}

Insets describe padding that should be added around a widget.

func DefaultInsets

func DefaultInsets() Insets

DefaultInsets returns the (perhaps platform-dependent) default insets for widgets inside of a top-level window.

func UniformInsets

func UniformInsets(l base.Length) Insets

UniformInsets returns a padding description where the padding is equal on all four sides.

func (*Insets) Dx added in v0.9.0

func (i *Insets) Dx() base.Length

Dx returns the total left and right insets.

func (*Insets) Dy added in v0.9.0

func (i *Insets) Dy() base.Length

Dy returns the total top and top insets.

type IntInput

type IntInput struct {
	Value       int64             // Value is the current value for the field
	Placeholder string            // Placeholder is a descriptive text that can be displayed when the field is empty
	Disabled    bool              // Disabled is a flag indicating that the user cannot interact with this field
	Min, Max    int64             // Min and Max set the range of Value
	OnChange    func(value int64) // OnChange will be called whenever the user changes the value for this field
	OnFocus     func()            // OnFocus will be called whenever the field receives the keyboard focus
	OnBlur      func()            // OnBlur will be called whenever the field loses the keyboard focus
	OnEnterKey  func(value int64) // OnEnterKey will be called whenever the use hits the enter key
}

IntInput describes a widget that users input or update a single integer value. The model for the value is a int64.

If the field Min and Max are both zero, then a default range will be initialized covering the entire range of int64. Note that on some platforms, the control internally is a float64, so the entire range of int64 cannot be covered without lose of precision.

func (*IntInput) Kind

func (*IntInput) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*IntInput) Mount

func (w *IntInput) Mount(parent base.Control) (base.Element, error)

Mount creates a text field in the GUI. The newly created widget will be a child of the widget specified by parent.

func (*IntInput) UpdateRange

func (w *IntInput) UpdateRange()

UpdateRange sets a default range when the fields Min and Max are both default initialized. The default range matches the range of int64.

func (*IntInput) UpdateValue

func (w *IntInput) UpdateValue()

UpdateValue clamps the field Value to the range [Min,Max].

type Label

type Label struct {
	Text string // Text is the contents of the label
}

Label describes a widget that provides a descriptive label for other fields.

Labels should not be empty, and should not contain leading or trailing spaces. If violated, the behaviour of the Label will depend on the GUI platform targeted.

func (*Label) Kind

func (*Label) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Label) Mount

func (w *Label) Mount(parent base.Control) (base.Element, error)

Mount creates a label control in the GUI. The newly created widget will be a child of the widget specified by parent.

type MainAxisAlign

type MainAxisAlign uint8

MainAxisAlign identifies the different types of alignment that are possible along the main axis for a vertical box or horizontal box layout.

const (
	MainStart    MainAxisAlign = iota // Children will be packed together at the top or left of the box
	MainCenter                        // Children will be packed together and centered in the box.
	MainEnd                           // Children will be packed together at the bottom or right of the box
	SpaceAround                       // Children will be spaced apart
	SpaceBetween                      // Children will be spaced apart, but the first and last children will but the ends of the box.
	Homogeneous                       // Children will be allocated equal space.
)

Allowed values for alignment of the main axis in a vertical box (VBox) or horizontal box (HBox).

func (MainAxisAlign) IsPacked

func (a MainAxisAlign) IsPacked() bool

IsPacked returns true if the main axis alignment is a one where children will be packed together.

type P

type P struct {
	Text  string        // Text is the content of the paragraph
	Align TextAlignment // Align is the text alignment for the paragraph
}

P describes a widget that contains significant text, which can reflow if necessary.

For a short run of text, the widget will try to match the size of the text. For longer runs of text, the widget will try to keep the width between 20em and 80em.

func (*P) Kind

func (*P) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*P) Mount

func (w *P) Mount(parent base.Control) (base.Element, error)

Mount creates a paragraph in the GUI. The newly created widget will be a child of the widget specified by parent.

type Padding

type Padding struct {
	Insets Insets      // Space between edge of element and the child element.
	Child  base.Widget // Child widget.
}

Padding describes a widget that adds some space around a single child widget.

The size of the control will match the size of the child element, although padding will be added between the border of the padding and the child element as specified by the field Insets.

func (*Padding) Kind

func (*Padding) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Padding) Mount

func (w *Padding) Mount(parent base.Control) (base.Element, error)

Mount creates a button in the GUI. The newly created widget will be a child of the widget specified by parent.

type Progress

type Progress struct {
	Value    int // Value is the current value to be displayed
	Min, Max int // Min and Max set the range of Value
}

Progress describes a widget that shows a progress bar. The model for the value is an int.

If both Min and Max are zero, then Max will be updated to 100. Other cases where Min == Max are not allowed.

func (*Progress) Kind

func (*Progress) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Progress) Mount

func (w *Progress) Mount(parent base.Control) (base.Element, error)

Mount creates a progress control in the GUI. The newly created widget will be a child of the widget specified by parent.

func (*Progress) UpdateRange

func (w *Progress) UpdateRange()

UpdateRange sets a default range when the fields Min and Max are both default initialized.

func (*Progress) UpdateValue

func (w *Progress) UpdateValue()

UpdateValue clamps the field Value to the range [Min,Max].

type SelectInput

type SelectInput struct {
	Items    []string        // Items is an array of strings representing the user's possible choices
	Value    int             // Value is the index of the currently selected item
	Unset    bool            // Unset is a flag indicating that no choice has yet been made
	Disabled bool            // Disabled is a flag indicating that the user cannot interact with this field
	OnChange func(value int) // OnChange will be called whenever the user changes the value for this field
	OnFocus  func()          // OnFocus will be called whenever the field receives the keyboard focus
	OnBlur   func()          // OnBlur will be called whenever the field loses the keyboard focus
}

SelectInput describes a widget that users can click to select one from a fixed list of choices.

func (*SelectInput) Kind

func (*SelectInput) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*SelectInput) Mount

func (w *SelectInput) Mount(parent base.Control) (base.Element, error)

Mount creates a select control (combobox) in the GUI. The newly created widget will be a child of the widget specified by parent.

func (*SelectInput) UpdateValue

func (w *SelectInput) UpdateValue()

UpdateValue will ensure that the Value is within the range of choices provided by w.Items.

type Slider

type Slider struct {
	Value    float64       // Value is the current value for the field
	Disabled bool          // Disabled is a flag indicating that the user cannot interact with this field
	Min, Max float64       // Min and Max set the range of Value
	OnChange func(float64) // OnChange will be called whenever the user changes the value for this field
	OnFocus  func()        // OnFocus will be called whenever the slider receives the keyboard focus.
	OnBlur   func()        // OnBlur will be called whenever the slider loses the keyboard focus.
}

Slider describes a widget that users input or update a single real value. The model for the value is a float64.

If both Min and Max are zero, then Max will be updated to 100. Other cases where Min == Max are not allowed.

Example
value := 0.0

// In a full application, this variable would be updated to point to
// the main window for the application.
var mainWindow *Window
// These functions are used to update the GUI.  See below
var update func()
var render func() base.Widget

// Update function
update = func() {
	err := mainWindow.SetChild(render())
	if err != nil {
		panic(err)
	}
}

// Render function generates a tree of Widgets to describe the desired
// state of the GUI.
render = func() base.Widget {
	// Prep - text for the button
	text := "Value: " + strconv.FormatFloat(value, 'f', 1, 64)
	// The GUI contains a single widget, this button.
	return &VBox{
		AlignMain:  MainCenter,
		AlignCross: CrossCenter,
		Children: []base.Widget{
			&Label{Text: text},
			&Slider{
				Value: value,
				OnChange: func(v float64) {
					value = v
					update()
				},
			},
		},
	}
}

err := loop.Run(func() error {
	w, err := NewWindow("Slider", render())
	if err != nil {
		return err
	}

	mainWindow = w
	return nil
})
if err != nil {
	fmt.Println("Error:", err)
} else {
	fmt.Println("OK")
}
Output:

func (*Slider) Kind

func (*Slider) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Slider) Mount

func (w *Slider) Mount(parent base.Control) (base.Element, error)

Mount creates a slider control in the GUI. The newly created widget will be a child of the widget specified by parent.

If both fields Min and Max are zero, a default range will be created going from 0 to 100.

The field Value will be updated to lie within the range.

func (*Slider) UpdateRange

func (w *Slider) UpdateRange()

UpdateRange sets a default range when the fields Min and Max are both default initialized.

func (*Slider) UpdateValue

func (w *Slider) UpdateValue()

UpdateValue clamps the field Value to the range [Min,Max].

type TabItem

type TabItem struct {
	Caption string      // Text to describe the contents of this tab
	Child   base.Widget // Child widget for the tab
}

TabItem describes a tab for a Tab widget.

type Tabs

type Tabs struct {
	Value    int       // Index of the selected tab
	Children []TabItem // Description of the tabs
	Insets   Insets    // Space between edge of element and the child element.

	OnChange func(int) // OnChange will be called whenever the user selects a different tab
}

Tabs describes a widget that shows a tabs.

The size of the control will match the size of the currently selected child element, although padding will added as required to provide space for the border and the tabs. However, when the user switches tabs, a relayout of the entire window is not forced.

When calling UpdateProps, setting Value to an integer less than zero will leave the currently selected tab unchanged.

func (*Tabs) Kind

func (*Tabs) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*Tabs) Mount

func (w *Tabs) Mount(parent base.Control) (base.Element, error)

Mount creates a tabs control in the GUI. The newly created widget will be a child of the widget specified by parent.

func (*Tabs) UpdateValue

func (w *Tabs) UpdateValue()

UpdateValue ensures that the index for the currently selected tab is with the allowed range.

type TextAlignment

type TextAlignment uint8

TextAlignment identifies the different types of text alignment that are possible.

const (
	JustifyLeft   TextAlignment = iota // Text aligned to the left (ragged right)
	JustifyCenter                      // Text aligned to the center
	JustifyRight                       // Text aligned to the right (ragged left)
	JustifyFull                        // Text justified so that both left and right are flush
)

Allowed values for text alignment for text in paragraphs.

type TextArea

type TextArea struct {
	Value       string             // Values is the current string for the field
	Placeholder string             // Placeholder is a descriptive text that can be displayed when the field is empty
	Disabled    bool               // Disabled is a flag indicating that the user cannot interact with this field
	ReadOnly    bool               // ReadOnly is a flag indicate that the contents cannot be modified by the user
	MinLines    int                // MinLines describes the minimum number of lines that should be visible for layout
	OnChange    func(value string) // OnChange will be called whenever the user changes the value for this field
	OnFocus     func()             // OnFocus will be called whenever the field receives the keyboard focus
	OnBlur      func()             // OnBlur will be called whenever the field loses the keyboard focus
}

TextArea describes a widget that users input or update a multi-line of text. The model for the value is a string value.

Using a placeholder may not be supported on all platforms. No errors will be generated, but the placeholder text may not appear on screen.

func (*TextArea) Kind

func (*TextArea) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*TextArea) Mount

func (w *TextArea) Mount(parent base.Control) (base.Element, error)

Mount creates a text area control in the GUI. The newly created widget will be a child of the widget specified by parent.

type TextInput

type TextInput struct {
	Value       string             // Value is the current string for the field
	Placeholder string             // Placeholder is a descriptive text that can be displayed when the field is empty
	Disabled    bool               // Disabled is a flag indicating that the user cannot interact with this field
	Password    bool               // Password is a flag indicating that the characters should be hidden
	ReadOnly    bool               // ReadOnly is a flag indicate that the contents cannot be modified by the user
	OnChange    func(value string) // OnChange will be called whenever the user changes the value for this field
	OnFocus     func()             // OnFocus will be called whenever the field receives the keyboard focus
	OnBlur      func()             // OnBlur will be called whenever the field loses the keyboard focus
	OnEnterKey  func(value string) // OnEnterKey will be called whenever the use hits the enter key
}

TextInput describes a widget that users input or update a single line of text. The model for the value is a string value.

Note that changing the value of the field Password is not supported on all platforms.

Example
// In a full application, this variable would be updated to point to
// the main window for the application.
var mainWindow *Window
// These functions are used to update the GUI.  See below
var update func()
var render func() base.Widget

// Update function
update = func() {
	err := mainWindow.SetChild(render())
	if err != nil {
		panic(err)
	}
}

// Render function generates a tree of Widgets to describe the desired
// state of the GUI.
render = func() base.Widget {
	// Prep - text for the button
	// The GUI contains a single widget, this button.
	return &VBox{Children: []base.Widget{
		&Label{Text: "Enter you text below:"},
		&TextInput{
			Value:       "",
			Placeholder: "Enter your data here",
			OnChange: func(value string) {
				fmt.Println("Change: ", value)
				// In a real example, you would update your data, and then
				// need to render the window again.
				update()
			},
		},
	}}
}
Output:

func (*TextInput) Kind

func (*TextInput) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*TextInput) Mount

func (w *TextInput) Mount(parent base.Control) (base.Element, error)

Mount creates a text field in the GUI. The newly created widget will be a child of the widget specified by parent.

type VBox

type VBox struct {
	AlignMain  MainAxisAlign
	AlignCross CrossAxisAlign
	Children   []base.Widget
}

VBox describes a layout widget that arranges its child widgets into a column. Children are positioned in order from the top towards the bottom. The main axis for alignment is therefore vertical, with the cross axis for alignment is horizontal.

The size of the box will try to set a width sufficient to contain all of its children. Extra space will be distributed according to the value of AlignMain. Subject to the box constraints during layout, the height should match the largest minimum height of the child widgets.

func (*VBox) Kind

func (*VBox) Kind() *base.Kind

Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.

func (*VBox) Mount

func (w *VBox) Mount(parent base.Control) (base.Element, error)

Mount creates a vertical layout for child widgets in the GUI. The newly created widget will be a child of the widget specified by parent.

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
// 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 := NewWindow("Test", &VBox{
		Children: []base.Widget{
			&Button{Text: "Click me!"},
		},
	})
	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) 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
// 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 := NewWindow("Test", &Button{Text: "Click me!"})
	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)
}
Output:

func (*Window) MinSize added in v0.9.0

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

Directories

Path Synopsis
Package animate provides animation for GUIs built using the package goey.
Package animate provides animation for GUIs built using the package goey.
Package base provides interfaces for the description, creation, and updating of GUI widgets.
Package base provides interfaces for the description, creation, and updating of GUI widgets.
Package dialog provides common dialog boxes, such as message boxes, and open and save file dialogs.
Package dialog provides common dialog boxes, such as message boxes, and open and save file dialogs.
example
align
This package provides an example application built using the goey package that shows use of the Align layout widget.
This package provides an example application built using the goey package that shows use of the Align layout widget.
closing
This package provides an example application built using the goey package that demonstrates using the OnClosing callback for windows.
This package provides an example application built using the goey package that demonstrates using the OnClosing callback for windows.
colour
This package provides an example application built using the goey package that demonstrates using the Image widget.
This package provides an example application built using the goey package that demonstrates using the Image widget.
controls
This package provides an example application built using the goey package that demonstrates most of the controls that are available.
This package provides an example application built using the goey package that demonstrates most of the controls that are available.
debounce
This package provides an example application built using the goey package that shows how an event be debounced.
This package provides an example application built using the goey package that shows how an event be debounced.
decoration
This package provides an example application built using the goey package that demontrates using the Decoration widget.
This package provides an example application built using the goey package that demontrates using the Decoration widget.
feettometer
This package provides an example application built using the goey package that rebuilds the classic Tcl/Tk tutorial application.
This package provides an example application built using the goey package that rebuilds the classic Tcl/Tk tutorial application.
icons
This package provides an application built using the goey package that demonstrates using a custom widget.
This package provides an application built using the goey package that demonstrates using a custom widget.
menu
This package provides an example application built using the goey package that shows a sidebar an array of buttons.
This package provides an example application built using the goey package that shows a sidebar an array of buttons.
messagebox
This package provides an example application built using the goey package that shows the use of message boxes.
This package provides an example application built using the goey package that shows the use of message boxes.
onebutton
This package provides an example application built using the goey package that shows a single button.
This package provides an example application built using the goey package that shows a single button.
paragraph
This package provides an example application built using the goey package that demonstrates using the Image widget.
This package provides an example application built using the goey package that demonstrates using the Image widget.
threebuttons
This package provides an example application built using the goey package that demonstrates three buttons with different behaviours.
This package provides an example application built using the goey package that demonstrates three buttons with different behaviours.
todos
This package provides an example application built using the goey package that rebuilds the classic Todos tutorial application.
This package provides an example application built using the goey package that rebuilds the classic Todos tutorial application.
twofields
This package provides an example application built using the goey package that demonstrates two multiline text fields.
This package provides an example application built using the goey package that demonstrates two multiline text fields.
wipe
This package provides an example application built using the goey package that demonstrates using animation.
This package provides an example application built using the goey package that demonstrates using animation.
Package icons provides a widget that displays a single icon from the Material Design Icons set.
Package icons provides a widget that displays a single icon from the Material Design Icons set.
internal
cocoa
Package cocoa provides platform-dependent routines required to support the package goey when targeting Cocoa or GNUstep.
Package cocoa provides platform-dependent routines required to support the package goey when targeting Cocoa or GNUstep.
cocoaloop
Package cocoaloop provides an API wrapper around C calls to Cocoa.
Package cocoaloop provides an API wrapper around C calls to Cocoa.
gtk
Package gtk provides an API wrapper around C calls to GTK.
Package gtk provides an API wrapper around C calls to GTK.
gtkloop
Package gtkloop provides an API wrapper around C calls to GTK.
Package gtkloop provides an API wrapper around C calls to GTK.
js
nopanic
Package nopanic provides a utility to wrap function to prevent any panics from escaping.
Package nopanic provides a utility to wrap function to prevent any panics from escaping.
windows
Package windows provides platform-dependent routines required to support the package goey.
Package windows provides platform-dependent routines required to support the package goey.
logo Module
Package loop provides a GUI event loop.
Package loop provides a GUI event loop.
Package mock provides a mock widget to be used for testing the layout algorithms of container widgets.
Package mock provides a mock widget to be used for testing the layout algorithms of container widgets.

Jump to

Keyboard shortcuts

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