import "bitbucket.org/rj/goey"
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.
There are screenshots of some of the example applications linked in the README, located at https://bitbucket.org/rj/goey/src/default/README.md.
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.
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
align.go button.go button_linux.go checkbox.go checkbox_linux.go dateinput.go dateinput_linux.go decoration.go decoration_linux.go doc.go empty.go expand.go hbox.go hr.go hr_linux.go img.go img_linux.go intinput.go intinput_linux.go label.go label_linux.go layout.go length.go loop.go loop_linux.go mainwindow.go mainwindow_linux.go message.go message_linux.go padding.go paragraph.go paragraph_linux.go progress.go progress_linux.go selectinput.go selectinput_linux.go slider.go slider_linux.go tabs.go tabs_linux.go textarea.go textarea_linux.go textinput.go textinput_linux.go vbox.go widget_linux.go
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.
var (
// ErrQuit indicates that the event loop should terminate. This return
// will only be used on platforms that expose their loop iteration function
// in addition to Run.
ErrQuit = errors.New("quit message")
// ErrNotRunning indicates that the main loop is not running.
ErrNotRunning = errors.New("main loop is not running")
// ErrAlreadyRunning indicates that the main loop is already running.
ErrAlreadyRunning = errors.New("main loop is already running")
)var (
// ErrSetChildrenNotReentrant is returned if a reentrant call to the method
// SetChild is called.
ErrSetChildrenNotReentrant = errors.New("method SetChild is not reentrant")
)Do runs the passed function on the GUI thread. If the event loop is not running, this function will return an error (ErrNotRunning). Any error from the callback will also be returned.
Because this function involves asynchronous communication with the GUI thread, it can deadlock if called from the GUI thread. It is therefore not safe to use in any event callbacks from widgets. However, since those callbacks are already executing on the GUI thread, the use of Do is also unnecessary in that context.
Note, this function contains a race-condition, in that the the action may be scheduled while the event loop is being terminated, in which case the scheduled action may never be run. Presumably, those actions don't need to be run on the GUI thread, so they can be schedule using a different mechanism.
Code:
err := Do(func() error {
// Inside this closure, we will be executing only on the GUI thread.
_, err := fmt.Println("Hello.")
// Return the error (if any) back to the caller.
return err
})
// Report on the success or failure
fmt.Println("Previous call to fmt.Println resulted in ", err)
Loop runs one interation of the event loop. This function's use by user code should be very rare.
This function is only safe to call on the GUI thread.
Run locks the OS thread to act as a GUI thread, and then iterates over the event loop until there are no more instances of Window open. If the main loop is already running, this function will return an error (ErrAlreadyRunning).
Modification of the GUI should happen only on the GUI thread. This includes creating any windows, mounting any widgets, or updating the properties of any elements.
The parameter action takes a closure that can be used to initialize the GUI. Any further modifications to the GUI also need to be scheduled on the GUI thread, which can be done using the function Do.
Code:
// This init function will be used to create a window on the GUI thread. init := func() error { // Create an empty window. window, err := NewWindow("Test", nil) if err != nil { fmt.Println("Error:", err) return err } go func() { // Because of goroutine, we are now off the GUI thread. // Schedule an action. err := Do(func() error { window.Close() fmt.Println("...like tears in rain") return nil }) if err != nil { fmt.Println("Error:", err) } }() return nil } err := Run(init) if err != nil { fmt.Println("Error:", err) }
Output:
...like tears in rain
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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
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.
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 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.
Code:
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() }}, }} }
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a button control in the GUI. The newly created widget will be a child of the widget specified by parent.
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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a checkbox control in the GUI.
The newly created widget will be a child of the widget specified by parent.
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.
Close removes the element from the GUI, and frees any associated resources.
Handle returns the platform-native handle for the control.
Layout determines the best size for an element that satisfies the constraints.
MinIntrinsicHeight returns the minimum height that this element requires to be correctly displayed.
MinIntrinsicWidth returns the minimum width that this element requires to be correctly displayed.
SetBounds updates the position of the widget.
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 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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a text field in the GUI. The newly created widget will be a child of the widget specified by parent.
type Decoration struct {
Fill color.RGBA // Background colour used to fill interior.
Stroke color.RGBA // Stroke colour 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() *base.Kind
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a button in the GUI. The newly created widget will be a child of the widget specified by parent.
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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
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 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 behaviour 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. Note that
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a button in the GUI. The newly created widget will be a child of the widget specified by parent.
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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
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 struct {
}HR describes a widget that is a horizontal separator.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
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 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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates an image control in the GUI. The newly created widget will be a child of the widget specified by parent.
UpdateDimensions calculates default values for Width and Height if either or zero based on the image dimensions. The member Image cannot be nil.
Insets describe padding that should ba added around a widget.
DefaultInsets returns the (perhaps platform-dependent) default insets for widgets inside of a top-level window.
UniformInsets returns a padding description where the padding is equal on all four sides.
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
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 string) // 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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a text field in the GUI. The newly created widget will be a child of the widget specified by parent.
Label describes a widget that provides a descriptive label for other fields.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a label control in the GUI. The newly created widget will be a child of the widget specified by parent.
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 (a MainAxisAlign) IsPacked() bool
IsPacked returns true if the main axis alignment is a one where children will be packed together.
type Message struct {
// contains filtered or unexported fields
}Message is a builder to construct a message dialog to the user.
NewMessage initializes a new message object with the specified text. Use of the method Message on an existing Window is preferred, as the message can be set as a child of the top-level window.
Code:
// The following creates a modal dialog with a message.
err := NewMessage("Some text for the body of the dialog box.").WithTitle("Example").WithInfo().Show()
if err != nil {
fmt.Println("Error: ", err)
}
Show completes building of the message, and shows the message to the user.
WithError adds an icon to the message indicating that an error has occurred.
WithInfo adds an icon to the message indicating that the message is informational.
WithTitle adds a title to the message's dialog.
WithWarn adds an icon to the message indicating that the message is a warning.
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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a paragraph in the GUI. The newly created widget will be a child of the widget specified by parent.
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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a button in the GUI. The newly created widget will be a child of the widget specified by parent.
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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a progress control in the GUI. The newly created widget will be a child of the widget specified by parent.
UpdateRange sets a default range when Min and Max are uninitialized.
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() *base.Kind
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a select control (combobox) in the GUI. The newly created widget will be a child of the widget specified by parent.
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.
Code:
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 := 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") }
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a slider control in the GUI. The newly created widget will be a child of the widget specified by parent.
UpdateRange sets a default range when Min and Max are uninitialized.
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 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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a tabs control in the GUI. The newly created widget will be a child of the widget specified by parent.
UpdateValue ensures that the index for the currently selected tab is with the allowed range.
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 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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
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 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.
Code:
// 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() }, }, }} }
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
Mount creates a text field in the GUI. The newly created widget will be a child of the widget specified by parent.
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.
Kind returns the concrete type for use in the Widget interface. Users should not need to use this method directly.
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 struct {
// contains filtered or unexported fields
}Window represents a top-level window that contain other widgets.
NewWindow create a new top-level window for the application.
Code:
// 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. Do(func() error { mw.Close() return nil }) }() return nil } // Start the GUI thread. err := Run(createWindow) if err != nil { fmt.Println("Error: ", err) }
Output:
Up Down
Child returns the mounted child for the window. In general, this method should not be used.
Close destroys the window, and releases all associated resources.
Message returns a message constructor that can be used to build and then show a dialog box with a message.
Code:
// 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. 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. Do(func() error { mw.Close() return nil }) }() return nil } // Start the GUI thread. err := Run(createWindow) if err != nil { fmt.Println("Error: ", err) }
Scroll returns the flags that determine whether scrolling is allowed in the horizontal and vertical directions.
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.
SetIcon changes the icon associated with the window.
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.
SetScroll sets whether scrolling is allowed in the horizontal and vertical directions.
SetTitle changes the caption in the title bar for the main window.
| Path | Synopsis |
|---|---|
| base | Package base provides interfaces for the description, creation, and updating of GUI widgets. |
| example/closing | This package provides an example application built using the goey package that demonstrates using the OnClosing callback for windows. |
| example/colour | This package provides an example application built using the goey package that demonstrates using the Image widget. |
| example/controls | This package provides an example application built using the goey package that demonstrates most of the controls that are available. |
| example/decoration | This package provides an example application built using the goey package that demontrates using the Decoration widget. |
| example/feettometer | This package provides an example application built using the goey package that rebuilds the classic Tcl/Tk tutorial application. |
| example/menu | This package provides an example application built using the goey package that shows a sidebar an array of buttons. |
| example/messagebox | This package provides an example application built using the goey package that shows the use of message boxes. |
| example/onebutton | This package provides an example application built using the goey package that shows a single button. |
| example/threebuttons | This package provides an example application built using the goey package that demonstrates three buttons with different behaviours. |
| example/todos | This package provides an example application built using the goey package that rebuilds the classic Todos tutorial application. |
| example/twofields | This package provides an example application built using the goey package that demonstrates two multiline text fields. |
| icons | Package icons provides a widget that displays a single icon from the Material Design Icons set. |
| mock | Package mock provides a mock widget to be used for testing the layout algorithms of container widgets. |
| syscall | Package syscall provides platform-dependent routines required to support the package goey. |
Package goey imports 19 packages (graph) and is imported by 12 packages. Updated 2018-10-08. Refresh now. Tools for package owners.