2022-10-21 11:40:08 -05:00
|
|
|
# gui
|
2019-05-31 11:01:46 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
Package gui implements a abstraction layer for Go visual elements.
|
2019-05-31 11:01:46 -05:00
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
Definitions:
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
* Toolkit: the underlying GUI library (MacOS gui, Windows gui, gtk, qt, etc)
|
|
|
|
* Node: A binary tree of all the underlying widgets
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
Principles:
|
|
|
|
|
|
|
|
* Make code using this package simple to use
|
|
|
|
* Hide complexity internally here
|
|
|
|
* Isolate the GUI toolkit
|
2022-11-13 08:53:03 -06:00
|
|
|
* 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.
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
Quick Start
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
```go
|
|
|
|
// 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() {
|
2022-11-13 08:53:03 -06:00
|
|
|
gui.Init()
|
2022-10-21 11:40:08 -05:00
|
|
|
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
|
|
|
|
|
2022-10-21 12:59:46 -05:00
|
|
|
This worked on debian sid on 2022/10/20
|
2022-10-21 11:40:08 -05:00
|
|
|
I didn't record the dependances needed
|
|
|
|
|
|
|
|
```go
|
|
|
|
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](./helloworld)
|
|
|
|
```
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
Toolkits
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
* andlabs - [https://github.com/andlabs/ui](https://github.com/andlabs/ui)
|
|
|
|
* gocui - [https://github.com/awesome-gocui/gocui](https://github.com/awesome-gocui/gocui)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
The next step is to allow this to work against go-gtk and go-qt.
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
TODO: Add Fyne, WASM, native macos & windows, android and
|
2022-10-21 11:40:08 -05:00
|
|
|
hopefully also things like libSDL, faiface/pixel, slint
|
|
|
|
|
|
|
|
## Bugs
|
|
|
|
|
|
|
|
"The author's idea of friendly may differ to that of many other people."
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
-- quote from the minimalistic window manager 'evilwm'
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-05 10:19:04 -05:00
|
|
|
## References
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-05 10:19:04 -05:00
|
|
|
Useful links and other
|
2023-02-25 14:05:25 -06:00
|
|
|
external things which might be useful
|
2022-10-21 13:33:55 -05:00
|
|
|
|
2022-11-09 08:38:50 -06:00
|
|
|
* [Wikipedia Graphical widget](https://en.wikipedia.org/wiki/Graphical_widget)
|
2023-02-25 14:05:25 -06:00
|
|
|
* [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.org/) Attempt to model go.uber.org
|
2022-10-21 13:13:41 -05:00
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
## Functions
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [GetDebug](/structs.go#L25)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
`func GetDebug() bool`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [GetDebugToolkit](/structs.go#L37)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
`func GetDebugToolkit() bool`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [IndentPrintln](/structs.go#L188)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
`func IndentPrintln(a ...interface{})`
|
2022-10-21 12:59:46 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [Init](/main.go#L41)
|
2022-10-21 12:59:46 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
`func Init()`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [LoadToolkit](/plugin.go#L37)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
`func LoadToolkit(name string)`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
loads and initializes a toolkit (andlabs/ui, gocui, etc)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [Main](/main.go#L56)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
`func Main(f func())`
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [Queue](/main.go#L77)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
`func Queue(f func())`
|
|
|
|
|
|
|
|
Other goroutines must use this to access the GUI
|
|
|
|
|
|
|
|
You can not acess / process the GUI thread directly from
|
|
|
|
other goroutines. This is due to the nature of how
|
|
|
|
Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
|
|
|
|
For example: gui.Queue(NewWindow())
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [SetDebug](/structs.go#L29)
|
|
|
|
|
|
|
|
`func SetDebug(s bool)`
|
|
|
|
|
|
|
|
### func [SetDebugToolkit](/structs.go#L41)
|
2022-10-21 12:59:46 -05:00
|
|
|
|
|
|
|
`func SetDebugToolkit(s bool)`
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [ShowDebugValues](/structs.go#L45)
|
2022-10-21 12:59:46 -05:00
|
|
|
|
|
|
|
`func ShowDebugValues()`
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### func [StandardClose](/main.go#L83)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
`func StandardClose(n *Node)`
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
The window is destroyed but the application does not quit
|
|
|
|
|
|
|
|
### func [StandardExit](/main.go#L90)
|
|
|
|
|
|
|
|
`func StandardExit(n *Node)`
|
|
|
|
|
|
|
|
The window is destroyed but the application does not quit
|
|
|
|
|
|
|
|
### func [Watchdog](/watchdog.go#L16)
|
|
|
|
|
|
|
|
`func Watchdog()`
|
|
|
|
|
|
|
|
This program sits here.
|
|
|
|
If you exit here, the whole thing will os.Exit()
|
|
|
|
|
|
|
|
This goroutine can be used like a watchdog timer
|
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
## Types
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### type [GuiConfig](/structs.go#L68)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
`type GuiConfig struct { ... }`
|
|
|
|
|
|
|
|
#### Variables
|
|
|
|
|
|
|
|
```golang
|
|
|
|
var Config GuiConfig
|
|
|
|
```
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### type [GuiOptions](/structs.go#L56)
|
2022-11-06 12:59:24 -06:00
|
|
|
|
|
|
|
`type GuiOptions struct { ... }`
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
This struct can be used with go-arg
|
|
|
|
|
|
|
|
### type [Node](/structs.go#L87)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
`type Node struct { ... }`
|
|
|
|
|
|
|
|
The Node is simply the name and the size of whatever GUI element exists
|
|
|
|
|
|
|
|
#### func [NewWindow](/window.go#L15)
|
|
|
|
|
|
|
|
`func NewWindow() *Node`
|
|
|
|
|
|
|
|
This routine creates a blank window with a Title and size (W x H)
|
|
|
|
|
|
|
|
This routine can not have any arguements due to the nature of how
|
|
|
|
it can be passed via the 'andlabs/ui' queue which, because it is
|
|
|
|
cross platform, must pass UI changes into the OS threads (that is
|
|
|
|
my guess).
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
### type [Symbol](/plugin.go#L17)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
`type Symbol any`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
## Sub Packages
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
* [toolkit](./toolkit)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
---
|
|
|
|
Readme created from Go doc with [goreadme](https://github.com/posener/goreadme)
|