synth

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: EPL-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package synth builds a synthetic UI-mockup / diagram document for gfx benchmarks: rounded boxes with border, shadow and two text lines, joined by cubic connectors with arrowheads, every third one dashed.

Index

Examples

Constants

View Source
const (
	ScreenW = 1920.0
	ScreenH = 1080.0
	// Gap between neighbouring screens on the grid.
	ScreenGap = 160.0
)

Mock screens: 1920 x 1080 application windows made of an app rail, a sidebar of icon and label rows, a header with tabs, and a body that is a form, a list of rows or a board of cards, with text on nearly every node. The node counts match what the real design screens of a task tracker give (about 150 to 540 nodes and 40 to 150 text lines per screen, a third of the nodes vector icons); the colors and strings are made up.

View Source
const (
	CellW = 200.0 // grid pitch of the box layout
	CellH = 130.0
)

CellW and CellH are the pitch of the box grid.

Variables

This section is empty.

Functions

func Curve

func Curve(a, b *Box, vert bool) *gfx.Path

Curve returns the connector path between the anchor points of two boxes.

func Grid

func Grid(n int, w, h float64) (cols, rows int)

Grid returns the grid for n screens of w x h with the gap between them, wider than tall.

Types

type Box

type Box struct {
	Node  *gfx.Node
	X, Y  float64
	W, H  float64
	Conns []*Conn
}

Box is a rounded rectangle node with its position and the connectors that touch it.

type Conn

type Conn struct {
	Node   *gfx.Node
	Shape  *gfx.Path
	A, B   *Box
	Vert   bool // bottom-to-top instead of right-to-left
	Dashed bool
}

Conn is a connector node between two boxes.

type Doc

type Doc struct {
	Scene *gfx.Scene
	Boxes []*Box
	Conns []*Conn
	Cols  int
	Rows  int
}

Doc is a synthetic document: boxes on a grid and the connectors added with Link.

func New

func New(n int, seed int64) *Doc

New lays out n boxes in a wide grid with right and down connectors.

Example

A document of boxes on a grid for benchmarks and demos; Link adds a connector between two boxes.

package main

import (
	"fmt"

	"github.com/haiodo/gowt/gfx/synth"
)

func main() {
	doc := synth.New(100, 1)
	n := len(doc.Conns) // New already links neighbours
	doc.Link(doc.Boxes[0], doc.Boxes[5], false)
	doc.Scene.Commit()
	fmt.Println(len(doc.Boxes), len(doc.Conns)-n)
}
Output:
100 1
func (d *Doc) Link(a, b *Box, vert bool) *Conn

Link adds a connector from a to b.

func (*Doc) Move

func (d *Doc) Move(tx *gfx.Tx, b *Box, x, y float64)

Move records in tx the move of b to (x, y) and the new pictures of its connectors.

func (*Doc) MoveBox

func (d *Doc) MoveBox(b *Box, x, y float64) gfx.Rect

MoveBox moves b to (x, y), rebuilds its connectors and returns the area that went stale.

type Mock

type Mock struct {
	Scene      *gfx.Scene
	Screens    []*Screen
	Cols, Rows int
}

Mock is a scene of mockup screens on a grid.

func NewMock

func NewMock(n int, seed int64) *Mock

NewMock builds n screens on a grid. Kinds alternate between form, list and board.

type Screen

type Screen struct {
	Root          *gfx.Node
	X, Y          float64
	Kind          string
	Nodes, Texts  int
	Paths, Frames int
}

Screen is one mockup screen: a subtree of the scene.

func BuildScreen

func BuildScreen(tx *gfx.Tx, parent *gfx.Node, ids *int, rng *rand.Rand, kind int) *Screen

BuildScreen adds one screen under parent (the scene root when nil) with ids counted from *ids, of kind 0 (form), 1 (list) or 2 (board). The root sits at the origin.

Jump to

Keyboard shortcuts

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