impress

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 6 Imported by: 20

README

impress. Go GUI cross-platform library

PkgGoDev

See project site for a technical details and a library overview.

Some usage examples are in the examples folder.

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"
)

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

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

    w := app.NewWindow(image.Rect(0, 0, 480, 240), color.RGBA{255, 255, 255, 255})
    defer w.Drop()

    w.Text("Hello, world!", font, image.Pt(200, 100), color.RGBA{0, 0, 0, 255})
    w.Line(image.Pt(200, 120), image.Pt(300, 120), color.RGBA{255, 0, 0, 255})
    w.Show()
    app.Sync()

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

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

To run this example on Debian/ Ubuntu:
  1. Install gcc, make, pkg-config if you don't have them installed.

  2. Install GTK+ 3 libraries if you don't have them installed:

sudo apt-get install libgtk-3-dev
  1. Build impress terminal from source:
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/

Steps 0-2 are needed to build a impress terminal binary. See impress terminal page for other options for downloading or building impress terminal app.

Technical details

Basic Principles of Library Design:

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

The main idea is to stay away from the event driven programming paradigm. See "What's wrong with event-driven programming" page.

The library uses a separate application (GTK+ 3 terminal) for drawing instead of binding low-level library to a Golang.

Project State

  • The project is currently in its beta stage. It is highly suitable for the development of in-house applications.
  • The project was tested on Debian 12.8 and macOS 15.1.
  • While the API remains stable, please note that the specific details may be subject to change.

The project roadmap includes both short-term and long-term project stages.

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

Up to 2 ms from the moment you press the key, the mind-map application window is redrawn. Measured on a computer with an N200 processor without a video card.

Contributing

First, welcome:

  • Any like to the project (star, post, link, etc.).
  • Any recommendations about library design principles.
  • Contribution to project, documentation, examples.
  • Bug report, open issue.
  • Or any help to fix grammatical or writing errors (PR or issue).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewApplication = func(rect image.Rectangle, title string) *Application {
	log.Fatalf("GUI driver must be registered. Add GTK driver to use by default:\nimport _ \"github.com/codeation/impress/duo\"")
	return nil
}

NewApplication creates main application window for default GUI driver. Consider using MakeApplication func instead

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

NewFont return a font selection struct for default GUI driver.

Deprecated: Use *Application.NewFont func instead.

View Source
var NewImage func(img image.Image) *Image

NewImage returns a image resources struct for default GUI driver.

Deprecated: Use *Application.NewImage func instead.

Functions

func Register

func Register(d 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 MakeApplication added in v0.5.0

func MakeApplication(d driver.Driver, rect image.Rectangle, title string) *Application

MakeApplication creates a top application window for specified GUI driver

func (*Application) Chan added in v0.1.10

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

Chan returns event channel

func (*Application) ClipboardGet added in v0.4.0

func (app *Application) ClipboardGet(typeID int)

ClipboardGet requests event with clipboard content

func (*Application) ClipboardPut added in v0.4.0

func (app *Application) ClipboardPut(c clipboard.Clipboarder)

ClipboardPut set content to OS clipboard

func (*Application) Close

func (app *Application) Close()

Close destroys application resources

func (*Application) NewFont added in v0.5.0

func (app *Application) 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 (*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) NewImage added in v0.5.0

func (app *Application) NewImage(img image.Image) *Image

NewImage returns a image resources struct

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
	LineHeight int
	Baseline   int
	Ascent     int
	Descent    int
	Attributes map[string]string
	// contains filtered or unexported fields
}

Font represents a font selection

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 (*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)

Image draws a image into specified rectangle. Specify a different rectangle size to scale the image

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
Package to register WebAssembly driver as default impress driver
Package to register WebAssembly driver as default impress driver
canvasdriver
Package to connect to WebAssembly driver
Package to connect to WebAssembly driver
duo
Package to register GTK driver as default impress driver
Package to register GTK driver as default impress driver
duodriver
Package to connect to GTK driver
Package to connect to GTK driver
examples
geo
joint
bus
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.
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.
drawwait
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.
eventrecv
Package implements an internal mechanism to communicate with an impress terminal.
Package implements an internal mechanism to communicate with an impress terminal.
eventsend
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.
lazy
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.
serversocket
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