Documentation ¶
Overview ¶
Package gui implements a abstraction layer for Go visual elements.
Definitions:
- Toolkit: the underlying GUI library (MacOS gui, Windows gui, gtk, qt, etc)
- Node: A binary tree of all the underlying widgets
Principles:
- Make code using this package simple to use
- Hide complexity internally here
- Isolate the GUI toolkit
- Widget names should try to match [Wikipedia Graphical widget]
- When in doubt, search upward in the binary tree
- It's ok to guess. Try to do something sensible.
Debian Build ¶
This worked on debian sid (mate-desktop) on 2023/12/03 I didn't record the dependances needed (gtk-dev)
export GO111MODULE="off" go get go.wit.com/gui
When I am working on toolkit plugins, then I work directly from ~/go/src/go.wit.com/gui/
Hello World Example
// This creates a simple hello world window package main import ( "log" "go.wit.com/gui" ) var myGui *gui.Node // This is the beginning of the binary tree of widgets // go will sit here until the window exits func main() { myGui = gui.New().Default() helloworld() } // This initializes the first window, a group and a button func helloworld() { window := myGui.NewWindow("hello world") group := window.NewGroup("foo bar") group.NewButton("hello", func() { log.Println("world") }) }
Hopefully this code example will remain syntactically consistant.
External Toolkits
- andlabs - https://github.com/andlabs/ui
- gocui - https://github.com/awesome-gocui/gocui
The next step is to allow this to work against go-gtk and go-qt.
TODO: Add Fyne, WASM, native macos & windows, android and hopefully also things like libSDL, faiface/pixel, slint
Bugs ¶
"The author's idea of friendly may differ to that of many other people."
-- quote from the minimalistic window manager 'evilwm'
References ¶
Useful links and other external things which might be useful
* [Wikipedia Graphical widget](https://en.wikipedia.org/wiki/Graphical_widget) * [GO Style Guide](https://google.github.io/styleguide/go/index) Code this way * [MS Windows Application Library Kit](https://github.com/lxn/walk) * [Federated git pull](https://github.com/forgefed/forgefed) Hopefully this will work for me with gitea * [Github mirror](https://github.com/wit-go/gui) This repo on mirror. Hopefully I won't have to use this. * [WIT GO projects](https://go.wit.com/) Attempt to model go.uber.org
Index ¶
- Constants
- Variables
- func ArgToolkit() string
- func Indent(b bool, a ...interface{})
- func StandardExit()
- func Watchdog()
- type ArgsGui
- type Grid
- type GridOffset
- type Node
- func (n *Node) AddText(str string) bool
- func (n *Node) AppendText(str string)
- func (n *Node) At(w int, h int) *Node
- func (n *Node) Bool() bool
- func (n *Node) Checked() bool
- func (n *Node) Children() []*Node
- func (n *Node) CloseToolkit(name string) bool
- func (n *Node) Default() *Node
- func (n *Node) Delete(d *Node)
- func (n *Node) Destroy()
- func (n *Node) Disable() *Node
- func (n *Node) Draw() *Node
- func (n *Node) Dump()
- func (n *Node) Enable() *Node
- func (n *Node) Expand() *Node
- func (n *Node) GetProgName() string
- func (n *Node) Hidden() bool
- func (n *Node) Hide() *Node
- func (n *Node) InitEmbed(resFS embed.FS) *Node
- func (n *Node) Int() int
- func (n *Node) ListChildren(dump bool)
- func (n *Node) ListToolkits()
- func (n *Node) LoadToolkit(name string) *Node
- func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node
- func (n *Node) Margin() *Node
- func (parent *Node) NewBox(progname string, b bool) *Node
- func (parent *Node) NewButton(name string, custom func()) *Node
- func (n *Node) NewCheckbox(name string) *Node
- func (n *Node) NewCombobox() *Node
- func (n *Node) NewDropdown() *Node
- func (parent *Node) NewEntryLine(name string) *Node
- func (n *Node) NewGrid(progname string, w int, h int) *Node
- func (parent *Node) NewGroup(name string) *Node
- func (parent *Node) NewHorizontalBox(progname string) *Node
- func (parent *Node) NewImage(name string) *Node
- func (parent *Node) NewLabel(text string) *Node
- func (parent *Node) NewSeparator(progname string) *Node
- func (parent *Node) NewSlider(progname string, x int, y int) *Node
- func (parent *Node) NewSpinner(progname string, x int, y int) *Node
- func (parent *Node) NewTextbox(name string) *Node
- func (parent *Node) NewVerticalBox(progname string) *Node
- func (parent *Node) NewWindow(title string) *Node
- func (n *Node) Pad() *Node
- func (n *Node) Parent() *Node
- func (parent *Node) RawWindow(title string) *Node
- func (n *Node) Ready() bool
- func (n *Node) Set(val any)
- func (n *Node) SetExpand(b bool) *Node
- func (n *Node) SetProgName(s string) *Node
- func (n *Node) SetText(text string) *Node
- func (n *Node) Show() *Node
- func (n *Node) StandardClose()
- func (n *Node) StandardExit()
- func (n *Node) String() string
- func (n *Node) Strings() []string
- func (n *Node) TestDraw()
- func (n *Node) UnDraw() *Node
- func (n *Node) Unmargin() *Node
- func (n *Node) Unpad() *Node
- type RangeMovedToWidget
- type Symbol
Constants ¶
const Xaxis = 0 // stack things horizontally
const Yaxis = 1 // stack things vertically
Variables ¶
var CHANGE *log.LogFlag
var GUI *log.LogFlag
var INFO *log.LogFlag
var NODE *log.LogFlag
var NOW *log.LogFlag
var PLUG *log.LogFlag
Functions ¶
func StandardExit ¶
func StandardExit()
The window is destroyed and the application exits TODO: properly exit the plugin since Quit() doesn't do it
Types ¶
type ArgsGui ¶
type ArgsGui struct { GuiPlugin string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"` GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"` }
This struct can be used with the go-arg package
type GridOffset ¶ added in v0.12.2
type Node ¶
type Node struct { WidgetType widget.WidgetType // this function is run when there are mouse or keyboard events Custom func() // used for anything that needs a range (for example: a slider) X int Y int // the grid widget max width and height // the max height can be implemented in the toolkit plugin // to restrict the number of rows to display W int H int // where the next widget should be put in this grid NextW int NextH int // if this widget is in a grid, this is the position of a widget AtW int AtH int // contains filtered or unexported fields }
func New ¶
func New() *Node
There should only be one of these per application This is due to restrictions by being cross platform some toolkit's on some operating systems don't support more than one Keep things simple. Do the default expected thing whenever possible
func (*Node) AddText ¶
add a new text string to widgets that support multiple string values These must be unique. return false if the string already exists
func (*Node) AppendText ¶
appends text to the existing text TODO: this is an experiement
func (*Node) CloseToolkit ¶
func (*Node) Enable ¶
enables a widget so the user can see it and work/click/etc on it by default, widgets are enabled when they are created
func (*Node) GetProgName ¶ added in v0.12.5
TODO: ensure these are unique and make a way to look them up myButton = myGroup.NewButton("hit ball", nil).SetName("HIT") myButton.GetName() should return "HIT" n = Find("HIT") should return myButton
func (*Node) ListChildren ¶
func (n *Node) ListChildren(dump bool, dropdown *Node, mapNodes map[string]*Node) {
func (*Node) ListToolkits ¶
func (n *Node) ListToolkits()
func (*Node) LoadToolkit ¶
func (*Node) NewCheckbox ¶
func (*Node) NewCombobox ¶
func (*Node) NewDropdown ¶
func (*Node) NewEntryLine ¶
func (*Node) NewGroup ¶
TODO: make a "Group" a "Grid" ? probably since right now group is just a pre-canned andlabs/ui gtk,macos,windows thing
func (*Node) NewHorizontalBox ¶ added in v0.12.2
func (*Node) NewSeparator ¶ added in v0.12.9
func (*Node) NewTextbox ¶
func (*Node) NewVerticalBox ¶ added in v0.12.2
func (*Node) RawWindow ¶ added in v0.11.1
allow window create without actually sending it to the toolkit
func (*Node) SetProgName ¶ added in v0.12.5
should get the reference name used for programming and debugging
func (*Node) StandardClose ¶
func (n *Node) StandardClose()
The window is destroyed but the application does not quit
func (*Node) StandardExit ¶ added in v0.12.11
func (n *Node) StandardExit()
The window is destroyed and the application exits TODO: properly exit the plugin since Quit() doesn't do it
type RangeMovedToWidget ¶ added in v0.12.5
Range(1, 10) includes the values 1 and 10 almost all toolkits use integers so there doesn't seem to be a good idea to use 'type any' here as it just makes things more complicated for no good reason