impress

package module
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 5 Imported by: 20

README

impress

Cross platform GUI Library for Go

PkgGoDev

Proof of Concept Version

Notes:

  • This project is still in the early stages of development and is not yet in a usable state.
  • The project tested on Ubuntu 21.04 and MacOS Big Sur (11.5)

Basic Principles of Library Building Design

  • Performance of the application as well as native applications.
  • Simple and clean application code for using GUI.
  • Limited use of other libraries (graphic, low-level or native).
  • Creating a GUI application without form designer or hard-coded widgets.

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

Examples

Let's say hello:

package main

import (
	"log"

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

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

	font, err := impress.NewFont(`{"family":"Verdana"}`, 15)
	if err != nil {
		log.Fatal(err)
	}
	defer font.Close()

	w := app.NewWindow(impress.NewRect(0, 0, 640, 480), impress.NewColor(255, 255, 255))
	w.Text("Hello, world!", font, impress.NewPoint(280, 210), impress.NewColor(0, 0, 0))
	w.Line(impress.NewPoint(270, 230), impress.NewPoint(380, 230), impress.NewColor(255, 0, 0))
	w.Show()

	app.Wait()
}

See project wiki for a library overview.

Some usage examples are located in examples folder.

Installation

The library uses a separate application as a GUI driver for rendering, event collecting, etc. You can download the compiled binary 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/simple.go

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

go run ./examples/simple/simple.go

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

Contributing

First of all, welcome:

  • any advice on the library design and principles
  • help to correct grammatical and writing errors
  • contribution in the near future

Using

See documentation, examples folder and project wiki.

A cross-platform mind-map application is being developed to check the library's applicability.

Stay tuned for more.

Documentation

Index

Constants

View Source
const (
	GeneralEventType   = 10
	KeyboardEventType  = 20
	ButtonEventType    = 30
	MotionEventType    = 40
	MenuEventType      = 50
	ConfigureEventType = 60
)

Event types

View Source
const (
	ButtonActionPress   = 4
	ButtonActionDouble  = 5
	ButtonActionTriple  = 6
	ButtonActionRelease = 7
)

Button action type

View Source
const (
	ButtonLeft   = 1
	ButtonMiddle = 2
	ButtonRight  = 3
)

Button number

Variables

View Source
var (
	UnknownEvent = GeneralEvent{Event: 0}
	DestroyEvent = GeneralEvent{Event: 1}
	DoneEvent    = GeneralEvent{Event: 2}
)

Signal events

View Source
var (
	KeyLeft      = KeyboardEvent{Name: "Left"}
	KeyRight     = KeyboardEvent{Name: "Right"}
	KeyUp        = KeyboardEvent{Name: "Up"}
	KeyDown      = KeyboardEvent{Name: "Down"}
	KeyBackSpace = KeyboardEvent{Rune: 8, Name: "BackSpace"}
	KeyTab       = KeyboardEvent{Rune: 9, Name: "Tab"}
	KeyEnter     = KeyboardEvent{Rune: 13, Name: "Return"}
	KeyDelete    = KeyboardEvent{Rune: 127, Name: "Delete"}
)

Keyboard events

View Source
var (
	KeySave = KeyboardEvent{Rune: 115, Name: "s", Control: true}
	KeyExit = KeyboardEvent{Rune: 119, Name: "w", Control: true}
)

Platform specified keyboard events

Functions

func Register

func Register(d Driver)

Register makes a GUI driver available

Types

type Actor

type Actor interface {
	Chan() chan Eventer
}

Actor is an event receiver interface

type Application

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

Application represents application top level window

func NewApplication

func NewApplication(rect Rect, title string) *Application

NewApplication creates main application window

func (*Application) Close

func (app *Application) Close()

Close makes invocation of the main loop return

func (*Application) Event

func (app *Application) Event() Eventer

Event returns next application event

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 Rect, color Color) *Window

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

func (*Application) OnEvent

func (app *Application) OnEvent(event Eventer, handler func())

OnEvent connects function call back to an event

func (*Application) Size

func (app *Application) Size(rect Rect)

Size sets application window size

func (*Application) Start

func (app *Application) Start(f func())

Start starts the specified func but does not wait for it to complete

func (*Application) Title

func (app *Application) Title(title string)

Title sets application window title

func (*Application) Wait

func (app *Application) Wait()

Wait waits for main application loop to complete

type ButtonEvent

type ButtonEvent struct {
	Action int
	Button int
	Point  Point
}

ButtonEvent is mouse button event

func (ButtonEvent) Type

func (e ButtonEvent) Type() int

Type returns event type

type Color

type Color struct {
	R, G, B int
}

Color represents a 24-bit color, having 8 bits for each of red, green, blue.

func NewColor

func NewColor(r, g, b int) Color

NewColor is same as Color{r, g, b}

type ConfigureEvent added in v0.1.8

type ConfigureEvent struct {
	Size Size
}

Configure event

func (ConfigureEvent) Type added in v0.1.8

func (e ConfigureEvent) Type() int

Type returns event type

type Driver

type Driver interface {
	Init()
	Done()
	Title(title string)
	Size(rect Rect)
	NewWindow(rect Rect, color Color) Painter
	NewFont(font *Font) (Fonter, error)
	NewImage(img *Image) (Imager, error)
	NewMenu(label string) Menuer
	Chan() <-chan Eventer
}

Driver is the interface to a application level functions

type Eventer

type Eventer interface {
	Type() int
}

Eventer is the interface that groups GUI events

type Font

type Font struct {
	Fonter   Fonter
	Height   int
	Baseline int
	Ascent   int
	Descent  int
	Attr     map[string]string
}

Font represents a font selection

func NewFont

func NewFont(options string, height int) (*Font, error)

NewFont return a font selection struct

func (*Font) Close

func (f *Font) Close()

Close destroys font selection

func (*Font) Size

func (f *Font) Size(text string) Size

Size returns the width and height of the drawing area

func (*Font) Split

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

Split breaks the text into lines that fit in the specified width

type Fonter

type Fonter interface {
	Close()
	Split(text string, edge int) []string
	Size(text string) Size
}

Fonter is the interface to a font functions

type GeneralEvent

type GeneralEvent struct {
	Event int
}

GeneralEvent is a general purpose notification

func (GeneralEvent) Type

func (e GeneralEvent) Type() int

Type returns event type

type Image

type Image struct {
	Imager        Imager
	Width, Height int
	PixNRGBA      []byte
}

Image represents a draw-ready image

func NewImage

func NewImage(img image.Image) (*Image, error)

NewImage returns a image resources struct

func (*Image) Close

func (i *Image) Close()

Close destroys image resources

type Imager

type Imager interface {
	Close()
}

Imager is the interface to a image functions

type KeyboardEvent

type KeyboardEvent struct {
	Rune    rune
	Shift   bool
	Control bool
	Alt     bool
	Meta    bool
	Name    string
}

KeyboardEvent is a keyboard event

func (KeyboardEvent) IsGraphic

func (e KeyboardEvent) IsGraphic() bool

IsGraphic tests printable rune

func (KeyboardEvent) Type

func (e KeyboardEvent) Type() int

Type returns event type

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

Menu represents any menu node

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

NewItem adds a item to menu node

func (m *Menu) NewItemFunc(label string, event MenuEvent, f func())

NewItemFunc adds a item with callback func to menu node

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

NewMenu returns new submenu node

type MenuEvent struct {
	Action string
}

MenuEvent is menu action event

func NewMenuEvent added in v0.1.7

func NewMenuEvent(short string) MenuEvent

NewMenuEvent returns a menu action event

func (e MenuEvent) Type() int

Type returns event type

type Menuer interface {
	NewMenu(label string) Menuer
	NewItem(label string, action string)
}

Menuer is the interface to a menu node

type MotionEvent

type MotionEvent struct {
	Point   Point
	Shift   bool
	Control bool
	Alt     bool
	Meta    bool
}

MotionEvent is mouse motion event

func (MotionEvent) Type

func (e MotionEvent) Type() int

Type returns event type

type Painter

type Painter interface {
	Drop()
	Size(rect Rect)
	Raise()
	Clear()
	Show()
	Fill(rect Rect, color Color)
	Line(from Point, to Point, color Color)
	Image(from Point, img *Image)
	Text(text string, font *Font, from Point, color Color)
}

Painter is the interface to a window functions

type Point

type Point struct {
	X, Y int
}

A Point is an X, Y coordinate pair. The axes increase right and down.

func NewPoint

func NewPoint(x, y int) Point

NewPoint is same as Point{x, y}.

func (*Point) In

func (p *Point) In(rect Rect) bool

In returns true when point is inside rect

func (Point) Move added in v0.1.9

func (p Point) Move(add Point) Point

func (Point) MoveX added in v0.1.9

func (p Point) MoveX(x int) Point

func (Point) MoveY added in v0.1.9

func (p Point) MoveY(y int) Point

func (Point) Size added in v0.1.9

func (p Point) Size(size Size) Rect

type Rect

type Rect struct {
	Point
	Size
}

A Rect contains the upper left corner coordinates and rectangle size.

func NewRect

func NewRect(x, y, width, height int) Rect

NewRect is same as Rect{Point:Point{x,y}, Size:Size{width, height}}.

func (Rect) Move added in v0.1.9

func (r Rect) Move(add Point) Rect

type Size

type Size struct {
	Width, Height int
}

A Size is an Width and Height pair.

func NewSize

func NewSize(width, height int) Size

NewSize is same as Size{width, height}.

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 Rect, color Color)

Fill draws a rectangle with specified size and foreground color

func (*Window) Image

func (w *Window) Image(from Point, img *Image)

Image draws a CAIRO_FORMAT_RGB24 data

func (*Window) Line

func (w *Window) Line(from Point, to Point, 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

func (*Window) Size

func (w *Window) Size(rect Rect)

Size changes window size and position

func (*Window) Text

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

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

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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