Coder Social home page Coder Social logo

ui's Introduction

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

ui's People

Contributors

jfreymuth avatar

Stargazers

Florian Thienel avatar Doru Carastan avatar 103.cloud avatar Alex avatar  avatar  avatar  avatar ik5 avatar Robin avatar Wade Welles avatar Casey Weed avatar Daniel Theophanes avatar

Watchers

James Cloos avatar  avatar

Forkers

mewbak

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.