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.
Quick Start
// This creates a simple hello world window package main import ( "log" "git.wit.org/wit/gui" ) var window *gui.Node // This is the beginning of the binary tree of widgets // go will sit here until the window exits func main() { gui.Init() gui.Main(helloworld) } // This initializes the first window and 2 tabs func helloworld() { gui.Config.Title = "Hello World golang wit/gui Window" gui.Config.Width = 640 gui.Config.Height = 480 window := gui.NewWindow() addTab(window, "A Simple Tab Demo") addTab(window, "A Second Tab") } func addTab(w *gui.Node, title string) { tab := w.NewTab(title) group := tab.NewGroup("foo bar") group.NewButton("hello", func() { log.Println("world") }) }
Debian Build ¶
This worked on debian sid on 2022/10/20 I didn't record the dependances needed
GO111MODULE="off" go get -v -t -u git.wit.org/wit/gui cd ~/go/src/git.wit.org/wit/gui/cmds/helloworld/ GO111MODULE="off" go build -v -x ./helloworld
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
Index ¶
- Constants
- func DebugWidgetWindow(w *Node)
- func DebugWindow()
- func ExampleCatcher(f func())
- func Indent(b bool, a ...interface{})
- func SetDebug(s bool)
- func SetFlag(s string, b bool)
- func ShowDebugValues()
- func StandardExit()
- func Watchdog()
- type GuiArgs
- type Node
- func (n *Node) Add(str string)
- func (n *Node) AddDropdownName(name string)
- func (n *Node) AddText(str string)
- func (n *Node) AppendText(str string)
- func (n *Node) At(w int, h int) *Node
- func (n *Node) Checked() bool
- func (n *Node) CloseToolkit(name string) bool
- func (n *Node) DebugFlags(makeWindow bool)
- func (n *Node) DebugGoChannels(makeWindow bool)
- func (n *Node) DebugGolangWindow(makeWindow bool)
- func (n *Node) DebugTab(title string) *Node
- func (n *Node) Default() *Node
- func (n *Node) Delete(d *Node)
- func (n *Node) Disable() *Node
- func (n *Node) DoMargin() *Node
- func (n *Node) Dump()
- func (n *Node) Enable() *Node
- func (n *Node) FindId(i int) *Node
- func (n *Node) GetText() string
- func (n *Node) Hide() *Node
- func (n *Node) InitEmbed(resFS embed.FS) *Node
- 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(name string, b bool) *Node
- func (parent *Node) NewButton(name string, custom func()) *Node
- func (n *Node) NewCheckbox(name string) *Node
- func (n *Node) NewCombobox(name string) *Node
- func (n *Node) NewDropdown(name string) *Node
- func (n *Node) NewGrid(name string, w int, h int) *Node
- func (parent *Node) NewGroup(name string) *Node
- func (parent *Node) NewImage(name string) *Node
- func (parent *Node) NewLabel(text string) *Node
- func (parent *Node) NewSlider(name string, x int, y int) *Node
- func (parent *Node) NewSpinner(name string, x int, y int) *Node
- func (n *Node) NewTab(text string) *Node
- func (parent *Node) NewTextbox(name string) *Node
- func (parent *Node) NewWindow(title string) *Node
- func (n *Node) Pad() *Node
- func (n *Node) Parent() *Node
- func (n *Node) Set(val any)
- func (n *Node) SetDropdownName(name string)
- func (n *Node) SetNext(w int, h int)
- func (n *Node) SetText(text string) *Node
- func (n *Node) Show() *Node
- func (n *Node) Standard() *Node
- func (n *Node) StandardClose()
- func (n *Node) Unmargin() *Node
- func (n *Node) Unpad() *Node
- func (n *Node) Window(title string) *Node
- type Symbol
Constants ¶
const Xaxis = 0 // stack things horizontally
const Yaxis = 1 // stack things vertically
Variables ¶
This section is empty.
Functions ¶
func ExampleCatcher ¶ added in v0.7.4
func ExampleCatcher(f func())
func ShowDebugValues ¶
func ShowDebugValues()
func StandardExit ¶
func StandardExit()
The window is destroyed and the application exits TODO: properly exit the plugin since Quit() doesn't do it
func Watchdog ¶
func Watchdog()
This program sits here. If you exit here, the whole thing will os.Exit() TODO: use Ticker
This goroutine can be used like a watchdog timer
Types ¶
type GuiArgs ¶
type GuiArgs struct { GuiToolkit []string `arg:"--gui-toolkit" help:"The order to attempt loading plugins [gocui,andlabs,gtk,qt]"` GuiDebug bool `arg:"--gui-debug" help:"open the GUI debugger"` GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"` }
This struct can be used with the go-arg package
type Node ¶
type Node struct { WidgetType toolkit.WidgetType Text string // what is visable to the user Name string // a name useful for programming // used for anything that needs a range (for example: a slider) X int Y int // the grid max width and height // ignore max height when there is no space left? 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 AtW int AtH int // used for values I int S string B bool // this function is run when there are mouse or keyboard events Custom func() // contains filtered or unexported fields }
The Node is a binary tree. This is how all GUI elements are stored simply the name and the size of whatever GUI element exists
func New ¶ added in v0.8.1
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) AddDropdownName ¶
add a new entry to the dropdown name
func (*Node) DebugFlags ¶ added in v0.7.3
Let's you toggle on and off the various types of debugging output These checkboxes should be in the same order as the are printed
func (*Node) Default ¶ added in v0.8.1
try to load andlabs, if that doesn't work, fall back to the console
func (*Node) ListChildren ¶
func (n *Node) ListChildren(dump bool, dropdown *Node, mapNodes map[string]*Node) {
func (*Node) LoadToolkitEmbed ¶ added in v0.8.6
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) SetDropdownName ¶
Set the dropdown menu to 'name'
func (*Node) Standard ¶ added in v0.7.4
This should not really do anything. as per the docs, the "Standard()" way should be the default way
Source Files ¶
- box.go
- button.go
- chan.go
- checkbox.go
- common.go
- debug.go
- debugFlags.go
- debugGochan.go
- debugGolang.go
- debugWidget.go
- debugWindow.go
- doc.go
- dropdown.go
- grid.go
- group.go
- image.go
- int.go
- label.go
- log.go
- main.go
- node.go
- plugin.go
- redraw.go
- slider.go
- spinner.go
- structs.go
- tab.go
- textbox.go
- watchdog.go
- window.go
Directories ¶
Path | Synopsis |
---|---|
cmds
|
|
buttonplugin
This creates a simple hello world window
|
This creates a simple hello world window |
console-ui-helloworld
This creates a simple hello world window
|
This creates a simple hello world window |
debug
A simple helloworld window
|
A simple helloworld window |
helloworld
This is a simple example
|
This is a simple example |
plugin-consoleonly
This creates a simple hello world window
|
This creates a simple hello world window |
textbox
This creates a simple hello world window
|
This creates a simple hello world window |