Skip to content
Maxence Charriere edited this page Nov 27, 2016 · 37 revisions

app

Package to build multiplatform apps with Go, HTML and CSS.

How it works?

app

Component

A component is a struct that represents a graphic element. It implements the app.Componer interface.

type Componer interface {
	Render() string
}

The Render method returns an HTML markup that describes the graphic interface.

Components can be encapsulated to make complex UIs.

They are displayed by being mounted into contexts.

Context

A context is an application element which display a graphical user interface. It can be a window, a menu, a dock, etc...

It implements the interface app.Contexter which defines their available interactions.

type Contexter interface {
	// Mounts the component and renders it in the context.
	Mount(c Componer)

	// If applicable, returns the position of the context.
	Position() (x float64, y float64)

	// If applicable, moves the context.
	Move(x float64, y float64)

	// If applicable, returns the size of the context.
	Size() (width float64, height float64)

	// If applicable, resizes the context.
	Resize(width float64, height float64)

	// If applicable, set the icon targeted by path.
	SetIcon(path string)

	// If applicable, set the badge with v.
	SetBadge(v interface{})

	// If applicable, closes the context.
	Close()

    // ...
}

Example

// Component.
type Hello struct {
	Placeholder bool
}

func (h *Hello) Render() string {
	return `<div>Hello World</div>`
}

// Create a window and mounts the Hello Component.
func main() {
	app.OnLaunch = func() {
		win := app.NewWindow(app.Window{
			Title:          "Hello World",
			Width:          1280,
			Height:         720,
		})

		hello := &Hello{}
		win.Mount(hello)
	}

	app.Run()
}
Clone this wiki locally