gui

package module
v0.12.15 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: BSD-3-Clause Imports: 11 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.

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"
make

Hello World Example

// This creates a simple hello world window
package main

import 	(
	"log"
	"go.wit.com/wit/gui/gui"
)

var myGui *gui.Node // This is your gui object

// go will sit here until the window exits
func main() {
	myGui = gui.Init()
}

// This initializes the first window and 2 tabs
func helloworld() {
	window := myGui.NewWindow()

	group := window.NewGroup("foo bar")
	group.NewButton("hello", func() {
		log.Println("world")
	})
}

External Toolkits

* andlabs - [https://github.com/andlabs/ui](https://github.com/andlabs/ui)
* gocui - [https://github.com/awesome-gocui/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]
* [Github mirror]
* [Federated git pull]
* [GO Style Guide]

Functions

func DebugWidgetWindow

func DebugWidgetWindow(w *Node)

func DebugWindow

func DebugWindow()

Creates a window helpful for debugging this package

func ExampleCatcher

func ExampleCatcher(f func())

func Indent

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

func SetDebug

func SetDebug(s bool)

func SetFlag

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 { ... }

This struct can be used with the go-arg package

Variables
var GuiArg GuiArgs
type Node

type Node struct { ... }

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

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

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.

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

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

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

Variables

View Source
var CHANGE *log.LogFlag
View Source
var INFO *log.LogFlag
View Source
var NODE *log.LogFlag
View Source
var PLUG *log.LogFlag

Functions

func ArgToolkit

func ArgToolkit() string

returns the toolkit

func Indent

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

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 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 Grid added in v0.12.2

type Grid struct {
	Width  int
	Height int
}

type GridOffset added in v0.12.2

type GridOffset struct {
	X int
	Y int
}

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

func (n *Node) AddText(str string) bool

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

func (n *Node) AppendText(str string)

appends text to the existing text TODO: this is an experiement

func (*Node) At

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

func (*Node) Bool added in v0.12.11

func (n *Node) Bool() bool

func (*Node) Checked

func (n *Node) Checked() bool

func (*Node) Children added in v0.9.9

func (n *Node) Children() []*Node

func (*Node) CloseToolkit

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

func (*Node) Default

func (n *Node) Default() *Node

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

func (*Node) Delete

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

func (*Node) Destroy added in v0.12.9

func (n *Node) Destroy()

func (*Node) Disable

func (n *Node) Disable() *Node

disables a widget so the user can see it, but can not interact or change it.

func (*Node) Draw added in v0.11.1

func (n *Node) Draw() *Node

TODO: should do this recursively

func (*Node) Dump

func (n *Node) Dump()

func (*Node) Enable

func (n *Node) Enable() *Node

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

func (n *Node) Expand() *Node

func (*Node) GetProgName added in v0.12.5

func (n *Node) GetProgName() string

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) Hidden added in v0.12.5

func (n *Node) Hidden() bool

is the widget currently viewable?

func (*Node) Hide

func (n *Node) Hide() *Node

func (*Node) InitEmbed

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

func (*Node) Int added in v0.12.11

func (n *Node) Int() int

func (*Node) ListChildren

func (n *Node) ListChildren(dump bool)

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

func (*Node) ListToolkits

func (n *Node) ListToolkits()

func (*Node) LoadToolkit

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

func (*Node) LoadToolkitEmbed

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

func (*Node) Margin

func (n *Node) Margin() *Node

func (*Node) NewBox

func (parent *Node) NewBox(progname 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

func (n *Node) NewCombobox() *Node

func (*Node) NewDropdown

func (n *Node) NewDropdown() *Node

func (*Node) NewEntryLine

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

func (*Node) NewGrid

func (n *Node) NewGrid(progname 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) NewHorizontalBox added in v0.12.2

func (parent *Node) NewHorizontalBox(progname string) *Node

func (*Node) NewImage

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

func (*Node) NewLabel

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

func (*Node) NewSeparator added in v0.12.9

func (parent *Node) NewSeparator(progname string) *Node

func (*Node) NewSlider

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

func (*Node) NewSpinner

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

func (*Node) NewTextbox

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

func (*Node) NewVerticalBox added in v0.12.2

func (parent *Node) NewVerticalBox(progname string) *Node

func (*Node) NewWindow

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

func (*Node) Pad

func (n *Node) Pad() *Node

func (*Node) Parent

func (n *Node) Parent() *Node

func (*Node) RawWindow added in v0.11.1

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

allow window create without actually sending it to the toolkit

func (*Node) Ready added in v0.10.3

func (n *Node) Ready() bool

func (*Node) Set

func (n *Node) Set(val any)

func (*Node) SetExpand added in v0.12.5

func (n *Node) SetExpand(b bool) *Node

func (*Node) SetProgName added in v0.12.5

func (n *Node) SetProgName(s string) *Node

should get the reference name used for programming and debugging

func (*Node) SetText

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

func (*Node) Show

func (n *Node) Show() *Node

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

func (*Node) String added in v0.12.11

func (n *Node) String() string

func (*Node) Strings added in v0.12.11

func (n *Node) Strings() []string

func (*Node) TestDraw added in v0.12.5

func (n *Node) TestDraw()

func (*Node) UnDraw added in v0.11.1

func (n *Node) UnDraw() *Node

TODO: should do this recursively

func (*Node) Unmargin

func (n *Node) Unmargin() *Node

func (*Node) Unpad

func (n *Node) Unpad() *Node

type RangeMovedToWidget added in v0.12.5

type RangeMovedToWidget struct {
	Low  int
	High int
}

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

type Symbol

type Symbol any

Jump to

Keyboard shortcuts

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