MyGo
Native UI

Native UI

Native UI

A window can show a user interface that MyGo draws itself instead of a web page. You write it in Go with package ui: there is no HTML, no JavaScript and no frontend build, and the window starts no webview, so it opens at once and uses little memory. MyGo draws it on the GPU, with Metal on macOS, Direct3D 11 on Windows and OpenGL on Linux.

package main

import (
	"fmt"
	"log"

	"github.com/egoist/mygo"
	"github.com/egoist/mygo/ui"
)

// counter is the app's state.
type counter struct{ n int }

// view builds the window's interface from the state, for every frame.
func (app *counter) view(c *ui.Context) {
	ui.Column(c).Fill().Center().Gap(12).Children(func() {
		ui.Text(c, fmt.Sprint(app.n)).FontSize(40).Bold()
		if ui.PrimaryButton(c, "Increment").Clicked() {
			app.n++
		}
	})
}

func main() {
	app := &counter{}
	mygo.App.WhenReady(func() {
		mygo.NewWindow(mygo.WindowOptions{
			Title:   "Counter",
			Width:   320,
			Height:  240,
			Content: ui.View(app.view),
		})
	})
	if err := mygo.App.Run(); err != nil {
		log.Fatal(err)
	}
}

Reading the examples. The examples in these guides are parts of a view such as counter.view: c is the view's *ui.Context, and app its receiver, the value of your own type that holds the state. A field such as app.volume or a method such as app.save() is one you declare on that type, as counter declares n; Views says more.

mygo init -template native my-app starts a native UI project (see the CLI). The counter example includes a view test, and the gallery shows the controls and layouts.

One app can have windows of both kinds. Native UI suits tools, settings, inspectors and utilities, and apps that must start instantly; a web page suits rich documents, existing web code and anything that needs what only a browser has. Screen readers and other assistive technology read native UI as they read other apps (see Accessibility).

Guides

ViewsBuild lifetimes, event queries and callbacks, keys, and changing the state from other goroutines.LayoutRows and columns, sizes, spacing, alignment and positioning.TextText and its style, rich text, links within sentences, and fonts.Styling and themesBackgrounds, borders, shadows and gradients, and the theme that follows the desktop.InputThe pointer, the keyboard focus, shortcuts, the keys held, input methods, dropped files, and widgets that take every key.Drag and dropValues dragged within the window, and rows reordered by dragging.Pages and navigationA router of pages with a history, layouts, transitions, and going back and forward.OverlaysWhat dialogs, popovers and the layer above the window share: the focus, Escape, and what is behind them.AccessibilityWhat screen readers see, naming elements, roles, descriptions and announcements.Right to leftInterfaces laid out from the right for Arabic and Hebrew, logical edges, and what mirrors.LanguagesThe window's language and regional formats, numbers and dates written in them, and the controls' own strings.Drawing and animationPainting on elements, shaping text, and values that ease to their targets.ShadersPixels computed on the GPU by shaders written in Go's syntax, with values and images the app passes them.TransitionsElements that move, resize, recolor and shade smoothly as the layout changes, and come and go.MotionSprings that keep their velocity, curves, delays, values thrown by the pointer, keyframes, timelines that play several tweens on one playhead, and knowing when they are done.TransformsVisual translation, scaling and rotation of any element, which the pointer, text input and accessibility follow.Custom widgetsThe widgets without a look that every widget is built on, and widgets of your own.Windows with native UIWindow options, title bars drawn by the view, zooming the content, and vibrancy.TestingRunning a view without a window, as fast as a unit test.InspectorThe elements of a window, their boxes and styles, and the time frames take, beside the content.RenderingHow MyGo draws, on the GPU or the CPU.BrowsersThe same app in a page, compiled to WebAssembly and drawn with WebGL 2.MigrationElement values, persistent handles, focus bindings and source migration.PerformanceMeasured frame costs and retained memory.

Actions

Choices

Text input

Code

Documents

Dates and colors

Collections

Containers

Dialogs and messages

Status

Charts

Images