impress

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 6 Imported by: 20

README

impress. Go GUI cross-platform library

PkgGoDev

See the project site for 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 the 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 an impress terminal binary. See the impress terminal page for other options for downloading or building the impress terminal.

Technical details

Basic Principles of Library Design:

  • Performance of the application as well as native applications.
  • Simple and clean application code.
  • Creating a GUI application without a form designer or hard-coded widgets.

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

The library uses a separate application (GTK+ 3 terminal) for drawing instead of binding a low-level library to 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.9 and macOS 15.3.
  • 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.

Contributing

First, welcome:

  • Any clue to keep the project going (star, post, link, etc.).
  • Any recommendations about library design principles.
  • Contributions to the project, documentation, examples.
  • Bug report, open an 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 the main application window for the default GUI driver. Consider using the MakeApplication function instead.

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

NewFont returns a Font struct for the default GUI driver.

Deprecated: Use the *Application.NewFont function instead.

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

NewImage returns an Image struct containing the image resources for the default GUI driver.

Deprecated: Use the *Application.NewImage function 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 the top-level window of the application.

func MakeApplication added in v0.5.0

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

MakeApplication creates the top application window for the specified GUI driver.

func (*Application) Chan added in v0.1.10

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

Chan returns the event channel.

func (*Application) ClipboardGet added in v0.4.0

func (app *Application) ClipboardGet(typeID int)

ClipboardGet requests an event with the clipboard content.

func (*Application) ClipboardPut added in v0.4.0

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

ClipboardPut sets the content to the 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 returns a Font struct representing a font selection. Note that "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 creates a new inner frame with the specified size.

func (*Application) NewImage added in v0.5.0

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

NewImage returns an Image struct containing the image resources.

func (*Application) NewMenu added in v0.1.7

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

NewMenu returns a new top-level menu node with the specified label.

func (*Application) NewWindow

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

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

func (*Application) Size

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

Size sets the application window size.

func (*Application) Sync added in v0.2.3

func (app *Application) Sync()

Sync flushes the graphics content to the screen driver.

func (*Application) Title

func (app *Application) Title(title string)

Title sets the 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 the font selection. Note that a closed font can no longer be used.

func (*Font) Size

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

Size returns the width and height of the drawing area for the given text.

func (*Font) Split

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

Split breaks the text into lines that fit within the specified width. The indent parameter specifies the width to indent the first line.

type Frame added in v0.2.4

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

Frame represents a GUI frame.

func (*Frame) Drop added in v0.2.4

func (f *Frame) Drop()

Drop deletes the 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 creates a new child frame with the specified size.

func (*Frame) NewWindow added in v0.2.4

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

NewWindow creates a 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 the frame size and position.

type Image

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

Image represents a drawable image.

func (*Image) Close

func (i *Image) Close()

Close destroys the image resources. Note that a closed image can no longer be used.

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

Menu represents any menu node.

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

NewItem adds an item to the menu node with the specified label and event.

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

NewMenu returns a new submenu node with the specified label.

type Window

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

Window represents an inner window.

func (*Window) Clear

func (w *Window) Clear()

Clear clears the current window.

func (*Window) Drop

func (w *Window) Drop()

Drop deletes the 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 the specified size and foreground color.

func (*Window) Image

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

Image draws an image into the 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 colored 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 drawings are not visible until Show is called.

func (*Window) Size

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

Size changes the window size and position.

func (*Window) Text

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

Text draws text at the specified location using the 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
Package event defines various types of GUI events
Package event defines various types of GUI events
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.
idcycle
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