impress

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2022 License: MIT Imports: 5 Imported by: 20

README

impress

Cross platform GUI Library for Go

PkgGoDev

Alpha Version

Notes:

  • The project tested on Debian 11.6 and macOS Big Sur (11.5)
  • The library may contain bugs

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 (
	"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)
	w.Text("Hello, world!", font, image.Pt(280, 210), foreground)
	w.Line(image.Pt(270, 230), image.Pt(380, 230), underline)
	w.Show()

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

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 clue of the project importance (stars, etc)
  • any advice on the library design and principles
  • help to correct grammatical and writing errors (PR or issue)
  • any contribution to project, project wiki, examples

Using

See documentation, examples folder and project wiki.

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

Stay tuned for more.

Issues

Feel free to open 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{}

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) 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) []string

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

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

Jump to

Keyboard shortcuts

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