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:
|
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
```go
|
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
|
2023-12-03 16:08:39 -06:00
|
|
|
```
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
Principles:
|
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
```go
|
2022-10-21 11:40:08 -05:00
|
|
|
* 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.
|
2023-12-03 16:08:39 -06:00
|
|
|
```
|
|
|
|
|
|
|
|
## Debian Build
|
|
|
|
|
|
|
|
This worked on debian sid (mate-desktop) on 2023/12/03
|
|
|
|
I didn't record the dependances needed (gtk-dev)
|
|
|
|
|
|
|
|
```go
|
|
|
|
export GO111MODULE="off"
|
|
|
|
make
|
|
|
|
```
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
Hello World Example
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
```go
|
|
|
|
// This creates a simple hello world window
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2024-01-01 17:47:23 -06:00
|
|
|
"go.wit.com/wit/gui/gui"
|
2022-10-21 11:40:08 -05:00
|
|
|
)
|
|
|
|
|
2024-01-03 22:57:28 -06:00
|
|
|
var myGui *gui.Node // This is your gui object
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
// go will sit here until the window exits
|
|
|
|
func main() {
|
2024-01-03 22:57:28 -06:00
|
|
|
myGui = gui.Init()
|
2022-10-21 11:40:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// This initializes the first window and 2 tabs
|
|
|
|
func helloworld() {
|
2024-01-03 22:57:28 -06:00
|
|
|
window := myGui.NewWindow()
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2024-01-03 22:57:28 -06:00
|
|
|
group := window.NewGroup("foo bar")
|
2022-10-21 11:40:08 -05:00
|
|
|
group.NewButton("hello", func() {
|
|
|
|
log.Println("world")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
External Toolkits
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
```go
|
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)
|
2023-12-03 16:08:39 -06:00
|
|
|
```
|
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
|
|
|
|
2023-12-29 03:00:03 -06:00
|
|
|
* Wikipedia Graphical widget - [https://en.wikipedia.org/wiki/Graphical_widget](https://en.wikipedia.org/wiki/Graphical_widget)
|
2024-01-01 17:47:23 -06:00
|
|
|
* Github mirror - [https://github.com/wit-go/gui](https://github.com/wit-go/gui)
|
2023-12-29 03:00:03 -06:00
|
|
|
* Federated git pull - [https://github.com/forgefed/forgefed](https://github.com/forgefed/forgefed)
|
|
|
|
* GO Style Guide - [https://google.github.io/styleguide/go/index](https://google.github.io/styleguide/go/index)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
```go
|
|
|
|
* [Wikipedia Graphical widget]
|
|
|
|
* [Github mirror]
|
|
|
|
* [Federated git pull]
|
|
|
|
* [GO Style Guide]
|
|
|
|
```
|
2022-10-21 12:59:46 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
## Functions
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### func [DebugWidgetWindow](/debugWidget.go#L52)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
`func DebugWidgetWindow(w *Node)`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### func [DebugWindow](/debugWindow.go#L21)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
`func DebugWindow()`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
Creates a window helpful for debugging this package
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### func [ExampleCatcher](/chan.go#L37)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
`func ExampleCatcher(f func())`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### func [Indent](/debug.go#L124)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
`func Indent(b bool, a ...interface{})`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### func [SetDebug](/debug.go#L28)
|
2022-11-13 08:53:03 -06:00
|
|
|
|
|
|
|
`func SetDebug(s bool)`
|
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### func [SetFlag](/debug.go#L50)
|
2022-10-21 12:59:46 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
`func SetFlag(s string, b bool)`
|
2022-10-21 12:59:46 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### func [ShowDebugValues](/debug.go#L82)
|
2022-10-21 12:59:46 -05:00
|
|
|
|
|
|
|
`func ShowDebugValues()`
|
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### func [StandardExit](/main.go#L153)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
`func StandardExit()`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
The window is destroyed and the application exits
|
|
|
|
TODO: properly exit the plugin since Quit() doesn't do it
|
2022-11-13 08:53:03 -06:00
|
|
|
|
|
|
|
### func [Watchdog](/watchdog.go#L16)
|
|
|
|
|
|
|
|
`func Watchdog()`
|
|
|
|
|
|
|
|
This program sits here.
|
|
|
|
If you exit here, the whole thing will os.Exit()
|
2023-12-03 16:08:39 -06:00
|
|
|
TODO: use Ticker
|
2022-11-13 08:53:03 -06:00
|
|
|
|
|
|
|
This goroutine can be used like a watchdog timer
|
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
## Types
|
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### type [GuiArgs](/structs.go#L29)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
`type GuiArgs struct { ... }`
|
|
|
|
|
|
|
|
This struct can be used with the go-arg package
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
#### Variables
|
|
|
|
|
|
|
|
```golang
|
2023-12-03 16:08:39 -06:00
|
|
|
var GuiArg GuiArgs
|
2022-10-21 11:40:08 -05:00
|
|
|
```
|
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
### type [Node](/structs.go#L59)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
`type Node struct { ... }`
|
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
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
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
#### func [New](/main.go#L120)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
`func New() *Node`
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
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
|
2022-10-21 11:40:08 -05:00
|
|
|
|
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
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
* [log](./log)
|
|
|
|
|
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)
|