gui

package module
v0.8.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: BSD-3-Clause Imports: 17 Imported by: 0

README

gui

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](./helloworld)

Toolkits

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

Functions

func GetDebug

func GetDebug() bool

func GetDebugToolkit

func GetDebugToolkit() bool

func IndentPrintln

func IndentPrintln(a ...interface{})

func Init

func Init()

func LoadToolkit

func LoadToolkit(name string)

loads and initializes a toolkit (andlabs/ui, gocui, etc)

func Main

func Main(f func())

func Queue

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())

func SetDebug

func SetDebug(s bool)

func SetDebugToolkit

func SetDebugToolkit(s bool)

func ShowDebugValues

func ShowDebugValues()

func StandardClose

func StandardClose(n *Node)

The window is destroyed but the application does not quit

func StandardExit

func StandardExit(n *Node)

The window is destroyed but the application does not quit

func Watchdog

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

Types

type GuiConfig

type GuiConfig struct { ... }

Variables
var Config GuiConfig
type GuiOptions

type GuiOptions struct { ... }

This struct can be used with go-arg

type Node

type Node struct { ... }

The Node is simply the name and the size of whatever GUI element exists

func NewWindow

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).

type Symbol

type Symbol any

Sub Packages


Readme created from Go doc with goreadme

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

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

View Source
const Xaxis = 0 // stack things horizontally
View Source
const Yaxis = 1 // stack things vertically

Variables

This section is empty.

Functions

func DebugWidgetWindow

func DebugWidgetWindow(w *Node)

func DebugWindow

func DebugWindow()

Creates a window helpful for debugging this package

func ExampleCatcher added in v0.7.4

func ExampleCatcher(f func())

func Indent

func Indent(b bool, a ...interface{})

func SetDebug

func SetDebug(s bool)

func SetFlag added in v0.6.5

func SetFlag(s string, b bool)

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) Add added in v0.6.5

func (n *Node) Add(str string)

func (*Node) AddDropdownName

func (n *Node) AddDropdownName(name string)

add a new entry to the dropdown name

func (*Node) AddText added in v0.7.3

func (n *Node) AddText(str string)

func (*Node) AppendText

func (n *Node) AppendText(str string)

func (*Node) At added in v0.8.6

func (n *Node) At(w int, h int) *Node

func (*Node) Checked

func (n *Node) Checked() bool

func (*Node) CloseToolkit added in v0.8.1

func (n *Node) CloseToolkit(name string) bool

func (*Node) DebugFlags added in v0.7.3

func (n *Node) DebugFlags(makeWindow bool)

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) DebugGoChannels added in v0.7.3

func (n *Node) DebugGoChannels(makeWindow bool)

func (*Node) DebugGolangWindow added in v0.7.3

func (n *Node) DebugGolangWindow(makeWindow bool)

func (*Node) DebugTab

func (n *Node) DebugTab(title string) *Node

func (*Node) Default added in v0.8.1

func (n *Node) Default() *Node

try to load andlabs, if that doesn't work, fall back to the console

func (*Node) Delete added in v0.7.3

func (n *Node) Delete(d *Node)

func (*Node) Disable added in v0.7.3

func (n *Node) Disable() *Node

func (*Node) DoMargin added in v0.7.4

func (n *Node) DoMargin() *Node

func (*Node) Dump

func (n *Node) Dump()

func (*Node) Enable added in v0.7.3

func (n *Node) Enable() *Node

func (*Node) FindId added in v0.7.6

func (n *Node) FindId(i int) *Node

find widget by number

func (*Node) GetText

func (n *Node) GetText() string

func (*Node) Hide added in v0.7.3

func (n *Node) Hide() *Node

func (*Node) InitEmbed added in v0.8.6

func (n *Node) InitEmbed(resFS embed.FS) *Node

func (*Node) ListChildren

func (n *Node) ListChildren(dump bool)

func (n *Node) ListChildren(dump bool, dropdown *Node, mapNodes map[string]*Node) {

func (*Node) ListToolkits added in v0.8.6

func (n *Node) ListToolkits()

func (*Node) LoadToolkit added in v0.8.1

func (n *Node) LoadToolkit(name string) *Node

func (*Node) LoadToolkitEmbed added in v0.8.6

func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node

func (*Node) Margin added in v0.7.4

func (n *Node) Margin() *Node

func (*Node) NewBox added in v0.7.3

func (parent *Node) NewBox(name string, b bool) *Node

func (*Node) NewButton

func (parent *Node) NewButton(name string, custom func()) *Node

func (*Node) NewCheckbox

func (n *Node) NewCheckbox(name string) *Node

func (*Node) NewCombobox added in v0.6.5

func (n *Node) NewCombobox(name string) *Node

func (*Node) NewDropdown

func (n *Node) NewDropdown(name string) *Node

func (*Node) NewGrid added in v0.6.5

func (n *Node) NewGrid(name string, w int, h int) *Node

func (*Node) NewGroup

func (parent *Node) NewGroup(name string) *Node

TODO: make a "Group" a "Grid" ? probably since right now group is just a pre-canned andlabs/ui gtk,macos,windows thing

func (*Node) NewImage added in v0.7.3

func (parent *Node) NewImage(name string) *Node

func (*Node) NewLabel

func (parent *Node) NewLabel(text string) *Node

func (*Node) NewSlider

func (parent *Node) NewSlider(name string, x int, y int) *Node

func (*Node) NewSpinner

func (parent *Node) NewSpinner(name string, x int, y int) *Node

func (*Node) NewTab

func (n *Node) NewTab(text string) *Node

func (*Node) NewTextbox

func (parent *Node) NewTextbox(name string) *Node

func (*Node) NewWindow added in v0.8.1

func (parent *Node) NewWindow(title string) *Node

func (*Node) Pad added in v0.7.4

func (n *Node) Pad() *Node

func (*Node) Parent

func (n *Node) Parent() *Node

func (*Node) Set added in v0.6.5

func (n *Node) Set(val any)

func (*Node) SetDropdownName

func (n *Node) SetDropdownName(name string)

Set the dropdown menu to 'name'

func (*Node) SetNext added in v0.7.3

func (n *Node) SetNext(w int, h int)

func (*Node) SetText

func (n *Node) SetText(text string) *Node

func (*Node) Show added in v0.7.3

func (n *Node) Show() *Node

func (*Node) Standard added in v0.7.4

func (n *Node) Standard() *Node

This should not really do anything. as per the docs, the "Standard()" way should be the default way

func (*Node) StandardClose

func (n *Node) StandardClose()

The window is destroyed but the application does not quit

func (*Node) Unmargin added in v0.7.4

func (n *Node) Unmargin() *Node

func (*Node) Unpad added in v0.7.4

func (n *Node) Unpad() *Node

func (*Node) Window

func (n *Node) Window(title string) *Node

type Symbol

type Symbol any

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL