Categorygithub.com/jfreymuth/ui
modulepackage
0.0.0-20190922151901-09fa35e8af53
Repository: https://github.com/jfreymuth/ui.git
Documentation: pkg.go.dev

# README

package ui

Lightweight go desktop ui

this package is highly experimental, drastic changes may occur

What this package tries to do

  • be intuitive for users; applications created with this packge should superficially behave like other ui toolkits, even in subtle ways
  • be intuitive for programmers; writing applications should be straightforward and not require much boilerplate or magic incantations
  • make it easy to create custom components
  • be the basis of a potential ecosystem; many parts of this package can easily be replaced, and the replacements should work well together (e.g. someone could write a different renderer, or an alternative library of components)
  • not be dependent on cgo in principle; while the current backend uses cgo, one could write e.g. an X11 backend in pure go.

What this package does not try to do

  • be the "official" go ui package
  • be useful in all situations (a big limitation right now is that applications can only use a single window)
  • be suited for mobile or web applications

Overview

The design of this package is inspired by immediate mode ui and uses similar techniques to minimize the complexity of components. Many ui libraries make heavy use of inheritance, which can be imitated in go through struct embedding. However this approach has disadvantages and is generally considered unidiomatic. This package follows a different approach by hiding most of the complexity in the ui.State struct instead of an abstract base class. This leads to the Component interface being very small, and components can be extremly lightweight.

There are three parts to this package:

ui and ui/draw

ui defines important interfaces and constants. It also provides the type State, which is central to the functionality of the library.

ui/draw contains data structures for drawing. Components do not draw directly, but rather create a list of commands that will be passed on to the renderer.

ui/toolkit

ui/toolkit is a collection of widgets. It provides common widgets (buttons, text fields etc.), simple layouts and basic themeing support.

ui/impl/...

The packages in ui/impl make up the backend. They are designed to be replaced by better packages later. These are the only packages with external dependencies.

It consists of the following packages (so far):

Usage

import (
	"github.com/jfreymuth/ui"
	"github.com/jfreymuth/ui/impl/gofont"
	"github.com/jfreymuth/ui/impl/icons"
	"github.com/jfreymuth/ui/impl/sdl"
	"github.com/jfreymuth/ui/toolkit"
)

func main() {
	button := toolkit.NewButton("Button", func(state *ui.State) {
		toolkit.ShowMessageDialog(state, "Message", "The button was pressed!", "Ok")
	})

	root := toolkit.NewRoot(button)

	sdl.Show(sdl.Options{
		Title: "Example",
		Width: 400, Height: 300,
		FontLookup: gofont.Lookup,
		IconLookup: &icons.Lookup{},
		Root:       root,
	})
}

Examples

  • examples/editor: a basic text editor, showcases the text area and demonstrates how to implement "save before quitting" comfirmations
  • examples/synth: a very simple synthesizer, demonstrates custom widgets and also some concurrency
  • examples/test: rather messy, but uses almost every single widget

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
The State is a components connection to the application.

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author