impress

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: MIT Imports: 5 Imported by: 20

README

impress. Go GUI cross-platform library

PkgGoDev

See project wiki for a library overview.

Some usage examples are in the examples folder.

Basic Principles of Library Design

  • Performance of the application as well as native applications.
  • Simple and clean application code.
  • Limited use of other libraries (graphic, low-level or native).
  • Creating a GUI application without form designer or hard-coded widgets.
  • Minimal library API to follow the Go-way.

The basic idea is to avoid the event-driven programming paradigm. See "What's wrong with event-driven programming" page.

Hello World Example

Let's say hello:

package main

import (
	"image"
	"image/color"

	"github.com/codeation/impress"
	"github.com/codeation/impress/event"

	_ "github.com/codeation/impress/duo"
)

var (
	background = color.RGBA{255, 255, 255, 0}
	foreground = color.RGBA{0, 0, 0, 0}
	underline  = color.RGBA{255, 0, 0, 0}
)

func main() {
	app := impress.NewApplication(image.Rect(0, 0, 640, 480), "Hello World Application")
	defer app.Close()

	font := impress.NewFont(15, map[string]string{"family": "Verdana"})
	defer font.Close()

	w := app.NewWindow(image.Rect(0, 0, 640, 480), background)
	defer w.Drop()

	w.Text("Hello, world!", font, image.Pt(280, 210), foreground)
	w.Line(image.Pt(270, 230), image.Pt(380, 230), underline)
	w.Show()
	app.Sync()

	for {
		action := <-app.Chan()
		if action == event.DestroyEvent || action == event.KeyExit {
			break
		}
	}
}

See an explanation of the source code in a library overview.

To run this example on Debian/ Ubuntu:
git clone https://github.com/codeation/impress.git
cd impress

wget https://github.com/codeation/it/releases/latest/download/it-linux.zip
unzip it-linux.zip
rm it-linux.zip

go run ./examples/simple/
To run this example on macOS:
  1. Install Homebrew if you don't have it installed.
  2. Install GTK+ 3 (brew install gtk+3) and pkg-config (brew install pkg-config) if you don't have it installed.
  3. Build impress terminal from source (see impress terminal page):
git clone https://github.com/codeation/it.git
cd it
make
cd ..
  1. Then run example:
git clone https://github.com/codeation/impress.git
cd impress
IMPRESS_TERMINAL_PATH=../it/it go run ./examples/simple/

GTK-3 driver

The library uses a separate application for drawing instead of binding low-level library to a Golang.

Pros:

  • To compile the application, it is not necessary to install low-level libraries.
  • There are no additional restrictions on the application, such as GTK functions should only be called by the main thread.
  • It will be possible to run several applications for a low-level drawing from different devices, thereby using the screens of different devices for the same application.
  • Abnormal termination of low-level drawing application may not result in data loss.

Cons:

  • Some loss of speed due to data transfer between applications.
  • Additional complexity due to state synchronization between applications.

You can download the compiled binary it file or make it again from the source.

You can specify the full path and name for the GUI driver via the environment variable, for example:

IMPRESS_TERMINAL_PATH=/path/it go run ./examples/simple/

or just copy the downloaded GUI driver to the working directory and run example:

go run ./examples/simple/

Project State

Notes
  • The project is in a beta stage. It's suitable for developing in-house applications.
  • The project tested on Debian 11.6 and macOS Big Sur.
  • The library may contain bugs.
  • The API is stable, but the details are subject to change.

In fact, Go is the most suitable language for developing GUI applications. It's fast enough to spin an interactive application. It is multi-tasking to handle the states of separate windows. It is compact so that the application starts instantly. It is high level to develop complex application.

A cross-platform mind-map application is being developed to prove the underlying principles of the library.

Stay tuned for more.

Short term roadmap
  • Recommended Event Propagation module.
  • Additional library with a set of widgets (text input, dialog, etc.).
  • Developer version of the library with debugging and profiling.
Long term roadmap
  • WebAssembly driver for turning a browser into a client terminal.
  • Two or more cooperate drivers for the same GUI application.
  • GTK-4 driver version when Debian will contain GTK-4 apps.
  • Apple Silicon native driver for macOS.
  • iOS app used as GUI app remote client.

Contributing

First, welcome:

  • Any clue of the project's importance (star, post, etc.).
  • Any advice on the library design and principles.
  • Contribution to project, project wiki, examples.
  • Bug report, open issue.
  • Or any help to correct grammatical or writing errors (PR or issue).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(current driver.Driver)

Register is an internal function that makes the GUI driver available.

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

Application represents application top level window

func NewApplication

func NewApplication(rect image.Rectangle, title string) *Application

NewApplication creates main application window

func (*Application) Chan added in v0.1.10

func (app *Application) Chan() <-chan event.Eventer

Chan returns event channel

func (*Application) Close

func (app *Application) Close()

Close destroys application resources

func (*Application) NewFrame added in v0.2.4

func (app *Application) NewFrame(rect image.Rectangle) *Frame

NewFrame create new inner frame with a specified size

func (*Application) NewMenu added in v0.1.7

func (app *Application) NewMenu(label string) *Menu

NewMenu returns a new top-level menu node

func (*Application) NewWindow

func (app *Application) NewWindow(rect image.Rectangle, background color.Color) *Window

NewWindow creates new inner window with a specified size and background color

func (*Application) Size

func (app *Application) Size(rect image.Rectangle)

Size sets application window size

func (*Application) Sync added in v0.2.3

func (app *Application) Sync()

Sync flushes graphics content to screen driver

func (*Application) Title

func (app *Application) Title(title string)

Title sets application window title

type Font

type Font struct {
	Height     int
	Baseline   int
	Ascent     int
	Descent    int
	Attributes map[string]string
	// contains filtered or unexported fields
}

Font represents a font selection

func NewFont

func NewFont(height int, attributes map[string]string) *Font

NewFont return a font selection struct. Note than "family" and other attributes are driver specific. Open duo/font.go for details.

func (*Font) Close

func (f *Font) Close()

Close destroys font selection

func (*Font) Size

func (f *Font) Size(text string) image.Point

Size returns the width and height of the drawing area

func (*Font) Split

func (f *Font) Split(text string, edge int, indent int) []string

Split breaks the text into lines that fit in the specified width; indent is a width to indent first line

type Frame added in v0.2.4

type Frame struct {
	// contains filtered or unexported fields
}

func (*Frame) Drop added in v0.2.4

func (f *Frame) Drop()

Drop deletes frame Note that a dropped frame can no longer be used

func (*Frame) NewFrame added in v0.2.4

func (f *Frame) NewFrame(rect image.Rectangle) *Frame

NewFrame create new child frame with a specified size

func (*Frame) NewWindow added in v0.2.4

func (f *Frame) NewWindow(rect image.Rectangle, background color.Color) *Window

NewWindow creates new frame window with a specified size and background color

func (*Frame) Raise added in v0.2.4

func (f *Frame) Raise()

Raise brings the frame to the forefront

func (*Frame) Size added in v0.2.4

func (f *Frame) Size(rect image.Rectangle)

Size changes frame size and position

type Image

type Image struct {
	Size image.Point
	// contains filtered or unexported fields
}

Image represents a draw-ready image

func NewImage

func NewImage(img image.Image) *Image

NewImage returns a image resources struct

func (*Image) Close

func (i *Image) Close()

Close destroys image resources

type Menu struct {
	// contains filtered or unexported fields
}

Menu represents any menu node

func (m *Menu) NewItem(label string, event event.Menu)

NewItem adds a item to menu node

func (m *Menu) NewMenu(label string) *Menu

NewMenu returns new submenu node

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window represents inner window

func (*Window) Clear

func (w *Window) Clear()

Clear clears current window

func (*Window) Drop

func (w *Window) Drop()

Drop deletes window Note that a dropped window can no longer be used

func (*Window) Fill

func (w *Window) Fill(rect image.Rectangle, foreground color.Color)

Fill draws a rectangle with specified size and foreground color

func (*Window) Image

func (w *Window) Image(rect image.Rectangle, img *Image)

ImageScale draws a image into specified rectangle

func (*Window) Line

func (w *Window) Line(from image.Point, to image.Point, foreground color.Color)

Line draws a color line connecting two specified points

func (*Window) Raise added in v0.1.7

func (w *Window) Raise()

Raise brings the window to the forefront

func (*Window) Show

func (w *Window) Show()

Show sends the contents of the window to the screen Note that a drawings are not visible until Show

func (*Window) Size

func (w *Window) Size(rect image.Rectangle)

Size changes window size and position

func (*Window) Text

func (w *Window) Text(text string, font *Font, from image.Point, foreground color.Color)

Text draws a text at specified location using a specified font and foreground color

Directories

Path Synopsis
examples
geo
joint
domain
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.
drawrecv
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.
drawsend
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.
eventchan
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.
iface
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.
iosplit
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.
rpc
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.

Jump to

Keyboard shortcuts

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