contraption

package module
v0.0.0-...-9271c2c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 36 Imported by: 2

README

Contraption

A real-time programmable vector graphics editor and GUI framework.

Motivation

Go does not have a sane UI framework, and I need one for my heroic endeavor. Gio is incomprehensible. It is good from the "rendering technology" point of view (and soon I will use it as a browser backend), but its program interface is simply bad. You can't do a serious GUI application with it without an unlimited amount of time and sanity.

So I simply want a GUI framework that is Apparatus in form of code. Also it must be fast and be able to run in browser.

Intro

See examples/sink/main.go

Mode of operation

In the following text, wo is the value of contraption.World that you got from calling contraption.New

Since not only Gio is bad but Go itself is sometimes bad, I had to implement a DSL.

There is a compound (wo.Compound) — a generic container inside of which shapes or modifiers can be placed.

There are modifiers that specify the way its children are arranged. These modifiers are called aligners, and they are Vfollow, Hfollow or nothing, in which case the compound will use the stack layout. There are also modifiers that change the geometry of children (Halign, Valign), stroke and fill (Stroke, Strokewidth, Fill), and so on.

Shapes are exactly what you think they are. Currently there aren't many, and the Text will be replaced by a Sequence-like element in the nearest future.

Sequences. You can implement the contraption.Sequence interface to generate components from other sources. Currently it will get the every element from the Sequence to generate the tree. Receiving only those elements that could be drawn is currently only a planned feature.

Contraption uses the function call mechanics for topological sorting of components to minimize copying. This means that sometimes you should use closures to place a component correctly in a tree. If you don't do this you will get an incorrect layout. Will be obsolete in the next few weeks because I will return the pointer. Copying is simply too expensive according to profiling.

Anything that could be placed inside a compound has the type Sorm. Anything in the package contraption that returns a Sorm must be considered an element of Contraption.

Layout model

Think Subform Layout, but 100x dumber and there are actually no main and auxiliary axes are exposed to user (at least for now).

Positive size values function as pixels scaled by the applied transform. The s unit from Subform is the negative unit (-1, -2, -3 etc) in Contraption. Negative units are distributed between all children recursively, meaning that in

wo.Compound(
	wo.Vfollow(),
	wo.Rect(-1, -1),
	wo.Rect(-1, -1),
	wo.Compound(
		wo.Hfollow(),
		wo.Rect(-1, -1),
		wo.Rect(-1, -1),))

the -1 X and -1 Y in the deeper children is equal to the corresponding -1s of the children at the top. Limit can limit this behavior, thus the negative values in it break the recursion of calculations for the compound that contains it Positive values for Limit are setting the maximum avaliable amount of units that is distributed for stretching. A maximum size for a compound can not be set. Limit applies only to the stretchy components, not the fixed ones.

Cascade

For now, these things are cascaded from parent to children compounds:

  • wo.Transform transforms
  • fill and stroke paints
  • stroke width
  • font family
  • font size (but i am not sure about this one)

State

Contraption uses an unusual approach to state in components. Instead of storing an internal DOM and diffing it or updating it by signals, it stores only the latest history of the input events, the activator (focus object) stack and a tree from the previous update cycle. All the other states are external and are managed by the end user. Components can use regular expressions on events trace. It is enough for 80% of internal UI state, such as double-clicks, hover effects of static components and text field state.

However, it is a compromise. For example, you can't do a button release effect on a scrollable pane (at least not yet, since there is no scrollable pane), because an object relies on its previous position to do it. I see using this system instead of VDOM like using screen-space techniques instead of path tracing.

Events trace and regular expressions

  • Regexps are matched left to right →
  • In a trace and in regexp syntax, the last event is the left-most ←. (*World).Events.Trace[0] is also the latest event.
  • Modifiers: :in :out :before :after
  • ! negates a symbol — match anything except this.
  • * and ? work like intended, + is not there for reasons I don't remember.

Recipes

Hotkey

From the Contraption itself:

if wo.Events.Match(`!Release(Ctrl)* Press(Ctrl)`) {
	if wo.Events.Match(`!Release(Shift)* Press(Shift)`) {
		if wo.Events.Match(`Press(I)`) {09
			wo.Goggles.on = !wo.Goggles.on
		}
	}
}

This will work too, but is order-dependent:

if wo.Events.Match(`Press(I) !Release(Ctrl)* !Release(Shift)* Press(Shift) !Release(Ctrl)* Press(Ctrl)`) {
	wo.Goggles.on = !wo.Goggles.on
}

TBD

  • Documentation, examples
  • Scrolling
  • Rotations
  • Multiline text, sensible text interface
  • Refine layout model so Transform makes sense

See also the comment at the beginning of contraption.go.

Acknowledgements

The research was stolen from tonsky from his articles about his GUI framework

The idea of regexps for event maching is stolen from Proton multitouch framework and any other paper on using state machines in UI to match the user input.

Contraption was initially developed as the part of a larger project funded by Foundation for Assistance to Small Innovative Enterprises UMNIK grant № 18384ГУ/2023.

Documentation

Index

Constants

View Source
const (
	RuneDelete    = '\x7f' // ASCII Delete
	RuneBackspace = '\b'   // ASCII Backspace
	RuneLeft      = '\x11' // ASCII Device Control 1 — Left cursor key
	RuneDown      = '\x12' // ASCII Device Control 2 — Down ...
	RuneUp        = '\x13' // ASCII Device Control 3 — Up   ...
	RuneRight     = '\x14' // ASCII Device Control 4 — Right ...
)

Special values of rune.

If one needs to enter those code points, they either writing a terminal emulator and should insert such special characters using Ctrl+Shift+<Key> instead, or they are plainly doing something wrong.

Variables

This section is empty.

Functions

func AddDragEffect

func AddDragEffect[T any](wo *World, convert func(interval [2]geom.Point, drag T) Sorm)

func Bytes

func Bytes(bs []byte) io.RuneScanner

func GetSystemFont

func GetSystemFont(err error) (string, float64, error)

func Int

func Int[T constraints.Integer](i T) io.RuneScanner

func Makealine

func Makealine(vg *Context, font *Font, size float64, runes []rune) float64

func MakealineReader

func MakealineReader(vg *Context, font *Font, size float64, rd io.RuneScanner) float64

func MakealineStrict

func MakealineStrict(vg *Context, font *Font, size float64, runes []rune) float64

func Pretty

func Pretty(pretty bool) func(*rpeg) error

func Replay

func Replay(vg *Context, segs []Segment)

func Runes

func Runes(rs []rune) io.RuneScanner

func Size

func Size(size int) func(*rpeg) error

func String

func String(s string) io.RuneScanner

Types

type Activator

type Activator interface {
	Activate(events *Events) (action Symbol)
}

Activator — это любой объект, на котором может быть сконцентрирован фокус ввода. Этот объект может обрабатывать свои события внутри метода Activate. В системе есть какое-то глобальное поле, которое обозначает текущий сфокусированный объект.

Activate возвращает Silence, когда объект не среагировал на событие, Ack, когда среагировал и Deactivate, когда объект сбросил с себя фокус.

Activator временный и умирает после смены фокуса.

type ActivatorPainter

type ActivatorPainter interface {
	Activator
	Paint(wo *World) Sorm
}

ActivatorPainter — это Activator, который может рисовать себя во время Drag.

type Click

type Click int

Click is a mouse click event, representing a button number.

type Config

type Config struct {
	// Default window frame.
	// Effective if not zero.
	WindowRect image.Rectangle

	// If not nil, events are not received from user, but replayed from this reader
	// as recorded after pressing F5.
	ReplayReader io.Reader
}

type Context

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

Context is a draw list with the interface of Nanovgo.

It is interpreted by the backend to draw on screen or to do anything else. TODO All transformations must be resolved by Context, not by the backend.

func (*Context) Also

func (c *Context) Also()

func (*Context) Arc

func (c *Context) Arc(cx, cy, r, a0, a1 float64, dir nanovgo.Direction)

func (*Context) ArcTo

func (c *Context) ArcTo(x1, y1, x2, y2, radius float64)

func (*Context) BeginFrame

func (c *Context) BeginFrame(windowWidth, windowHeight int, devicePixelRatio float64)

func (*Context) BeginPath

func (c *Context) BeginPath()

func (*Context) BezierTo

func (c *Context) BezierTo(c1x, c1y, c2x, c2y, x, y float64)

func (*Context) Block

func (c *Context) Block(block func())

func (*Context) CancelFrame

func (c *Context) CancelFrame()

func (*Context) Circle

func (c *Context) Circle(cx, cy, r float64)

func (*Context) ClosePath

func (c *Context) ClosePath()

func (*Context) CreateFontFromMemory

func (c *Context) CreateFontFromMemory(name string, data []byte, freeData uint8) int

func (*Context) CreateImageFromGoImage

func (c *Context) CreateImageFromGoImage(imageFlag nanovgo.ImageFlags, img image.Image) int

func (*Context) CreateImageRGBA

func (c *Context) CreateImageRGBA(w, h int, imageFlags nanovgo.ImageFlags, data []byte) int

func (*Context) CurrentTransform

func (c *Context) CurrentTransform() nanovgo.TransformMatrix

func (*Context) DebugDumpPathCache

func (c *Context) DebugDumpPathCache()

func (*Context) Delete

func (c *Context) Delete()

func (*Context) DeleteImage

func (c *Context) DeleteImage(img int)

func (*Context) Ellipse

func (c *Context) Ellipse(cx, cy, rx, ry float64)

func (*Context) EndFrame

func (c *Context) EndFrame() (oldhash [512]byte)

func (*Context) Fill

func (c *Context) Fill()

func (*Context) FindFont

func (c *Context) FindFont(name string) int

func (*Context) FontBlur

func (c *Context) FontBlur() float64

func (*Context) FontFace

func (c *Context) FontFace() string

func (*Context) FontFaceID

func (c *Context) FontFaceID() int

func (*Context) FontSize

func (c *Context) FontSize() float64

func (*Context) GlobalAlpha

func (c *Context) GlobalAlpha() float64

func (*Context) ImageSize

func (c *Context) ImageSize(img int) (int, int, error)

func (*Context) IntersectScissor

func (c *Context) IntersectScissor(x, y, w, h float64)

func (*Context) LineCap

func (c *Context) LineCap() nanovgo.LineCap

func (*Context) LineJoin

func (c *Context) LineJoin() nanovgo.LineCap

func (*Context) LineTo

func (c *Context) LineTo(x, y float64)

func (*Context) MiterLimit

func (c *Context) MiterLimit() float64

func (*Context) MoveTo

func (c *Context) MoveTo(x, y float64)

func (*Context) PathWinding

func (c *Context) PathWinding(winding nanovgo.Winding)

func (*Context) QuadTo

func (c *Context) QuadTo(cx, cy, x, y float64)

func (*Context) Rect

func (c *Context) Rect(x, y, w, h float64)

func (*Context) Reset

func (c *Context) Reset()

func (*Context) ResetScissor

func (c *Context) ResetScissor()

func (*Context) ResetTransform

func (c *Context) ResetTransform()

func (*Context) Restore

func (c *Context) Restore()

func (*Context) Rotate

func (c *Context) Rotate(angle float64)

func (*Context) RoundedRect

func (c *Context) RoundedRect(x, y, w, h, r float64)

func (*Context) Save

func (c *Context) Save()

func (*Context) Scale

func (c *Context) Scale(x, y float64)

func (*Context) Scissor

func (c *Context) Scissor(x, y, w, h float64)

func (*Context) SetFillColor

func (c *Context) SetFillColor(color nanovgo.Color)

func (*Context) SetFillPaint

func (c *Context) SetFillPaint(paint nanovgo.Paint)

func (*Context) SetFontBlur

func (c *Context) SetFontBlur(blur float64)

func (*Context) SetFontFace

func (c *Context) SetFontFace(font string)

func (*Context) SetFontFaceID

func (c *Context) SetFontFaceID(font int)

func (*Context) SetFontSize

func (c *Context) SetFontSize(size float64)

func (*Context) SetGlobalAlpha

func (c *Context) SetGlobalAlpha(alpha float64)

func (*Context) SetLineCap

func (c *Context) SetLineCap(cap nanovgo.LineCap)

func (*Context) SetLineJoin

func (c *Context) SetLineJoin(joint nanovgo.LineCap)

func (*Context) SetMiterLimit

func (c *Context) SetMiterLimit(limit float64)

func (*Context) SetStrokeColor

func (c *Context) SetStrokeColor(color nanovgo.Color)

func (*Context) SetStrokePaint

func (c *Context) SetStrokePaint(paint nanovgo.Paint)

func (*Context) SetStrokeWidth

func (c *Context) SetStrokeWidth(width float64)

func (*Context) SetTextAlign

func (c *Context) SetTextAlign(align nanovgo.Align)

func (*Context) SetTextLetterSpacing

func (c *Context) SetTextLetterSpacing(spacing float64)

func (*Context) SetTextLineHeight

func (c *Context) SetTextLineHeight(lineHeight float64)

func (*Context) SetTransform

func (c *Context) SetTransform(t nanovgo.TransformMatrix)

func (*Context) SetTransformByValue

func (cx *Context) SetTransformByValue(a, b, c, d, e, f float64)

func (*Context) SkewX

func (c *Context) SkewX(angle float64)

func (*Context) SkewY

func (c *Context) SkewY(angle float64)

func (*Context) Stroke

func (c *Context) Stroke()

func (*Context) StrokeWidth

func (c *Context) StrokeWidth() float64

func (*Context) TextAlign

func (c *Context) TextAlign() nanovgo.Align

func (*Context) TextBounds

func (c *Context) TextBounds(x, y float64, runes []rune) (float64, geom.Rectangle)

func (*Context) TextLetterSpacing

func (c *Context) TextLetterSpacing() float64

func (*Context) TextLineHeight

func (c *Context) TextLineHeight() float64

func (*Context) TextMetrics

func (c *Context) TextMetrics() (float64, float64, float64)

func (*Context) TextRune

func (c *Context) TextRune(x, y float64, runes []rune) float64

func (*Context) Translate

func (c *Context) Translate(x, y float64)

func (*Context) UpdateImage

func (c *Context) UpdateImage(img int, data []byte) error

type Drop

type Drop struct {
	Paths []string
	// contains filtered or unexported fields
}

Drag is an event of dragged and dropped into application file.

type Eqn

type Eqn func(pt geom.Point) (dist float64)

type Equation

type Equation interface {
	Eqn(pt geom.Point) (dist float64)
	Size() geom.Point
}

type EventPoint

type EventPoint struct {
	E  interface{}
	Pt geom.Point
	T  time.Time
	// contains filtered or unexported fields
}

func (EventPoint) String

func (ev EventPoint) String() string

type EventTraceLast

type EventTraceLast struct {
	StartedAt  time.Time // Time of a first matched event.
	FirstTouch geom.Point
	Duration   time.Duration  // Duration of match.
	Freshness  time.Duration  // Difference between start of match and now.
	Box        geom.Rectangle // Total cursor position distribution of a match.
	Choked     bool
}

type Events

type Events struct {
	Trace    []EventPoint
	Last     EventTraceLast
	Now      time.Time
	Dt       time.Duration
	Viewport geom.Point

	MatchCount int

	RecordPath string
	// contains filtered or unexported fields
}

func NewEventTracer

func NewEventTracer(w *glfw.Window, replay io.Reader) *Events

func (*Events) Anywhere

func (u *Events) Anywhere() Matcher

func (*Events) In

func (u *Events) In(r geom.Rectangle) Matcher

func (*Events) Match

func (u *Events) Match(pattern string) bool

func (*Events) MatchDeadline

func (u *Events) MatchDeadline(pattern string, deadline time.Time) bool

func (*Events) MatchFreshness

func (u *Events) MatchFreshness(pattern string, freshness time.Duration) bool

func (*Events) MatchIn

func (u *Events) MatchIn(pattern string, r geom.Rectangle) bool

Hint: :in. And add MatchAllIn later, for fuck's sake.

func (*Events) MatchInDeadline

func (u *Events) MatchInDeadline(pattern string, rect geom.Rectangle, deadline time.Time) bool

func (*Events) MatchInDuration

func (u *Events) MatchInDuration(pattern string, rect geom.Rectangle, duration time.Duration) bool

func (*Events) MatchInFreshness

func (u *Events) MatchInFreshness(pattern string, rect geom.Rectangle, freshness time.Duration) bool

func (*Events) MatchInIndef

func (u *Events) MatchInIndef(pattern string, rect geom.Rectangle) bool

func (*Events) MatchInNochoke

func (u *Events) MatchInNochoke(pattern string, r geom.Rectangle) bool

func (*Events) MatchIndef

func (u *Events) MatchIndef(pattern string) bool

func (*Events) SetDeadline

func (u *Events) SetDeadline(t time.Time)

type Font

type Font struct {
	Data           []byte
	Parsed         *sfnt.Font
	FreeTypeParsed *truetype.Font
	Vgoid          int
	Name           string
	// contains filtered or unexported fields
}

Font is a multipurpose wrapper for a loaded to memory TrueType font.

func NewFont

func NewFont(vgo *Context, data []byte, name string) (*Font, error)

func (*Font) Advance

func (f *Font) Advance(r rune) float64

func (*Font) Captoem

func (f *Font) Captoem(cap float64) float64

func (*Font) CaptoemFixed

func (f *Font) CaptoemFixed(cap fixed.Int26_6) fixed.Int26_6

func (*Font) Emtocap

func (f *Font) Emtocap(em float64) float64

func (*Font) EmtocapFixed

func (f *Font) EmtocapFixed(em fixed.Int26_6) fixed.Int26_6

func (*Font) Measure

func (font *Font) Measure(cap float64, runes []rune) float64

func (*Font) MeasureReader

func (font *Font) MeasureReader(cap float64, rd io.RuneScanner) float64

func (*Font) PureAdvance

func (f *Font) PureAdvance(r rune) float64

func (*Font) Segments

func (f *Font) Segments(r rune) []Segment

func (*Font) TrueXBearing

func (f *Font) TrueXBearing(r rune) float64

func (*Font) Width

func (f *Font) Width(r rune) float64

type Hover

type Hover struct{}

type Index

type Index struct {
	I int
	O float64
}

type Key

type Key = glfw.Key

type Matcher

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

Matcher is a builder interface for regular expressions.

func (Matcher) Anywhere

func (m Matcher) Anywhere() Matcher

func (Matcher) Deadline

func (m Matcher) Deadline(t time.Time) Matcher

func (Matcher) Duration

func (m Matcher) Duration(d time.Duration) Matcher

func (Matcher) Indef

func (m Matcher) Indef() Matcher

func (Matcher) Match

func (m Matcher) Match(pattern string) bool

func (Matcher) Nochoke

func (m Matcher) Nochoke() Matcher

func (Matcher) Rect

func (m Matcher) Rect() geom.Rectangle

func (Matcher) WithZ

func (m Matcher) WithZ(z int) Matcher

func (Matcher) Z

func (m Matcher) Z() int

type NanovgoDestination

type NanovgoDestination struct {
	iconvg.Palette
	// contains filtered or unexported fields
}

func (*NanovgoDestination) AbsArcTo

func (n *NanovgoDestination) AbsArcTo(rx, ry, xAxisRotation float32, largeArc, sweep bool, x, y float32)

func (*NanovgoDestination) AbsCubeTo

func (n *NanovgoDestination) AbsCubeTo(x1, y1, x2, y2, x, y float32)

func (*NanovgoDestination) AbsHLineTo

func (n *NanovgoDestination) AbsHLineTo(x float32)

func (*NanovgoDestination) AbsLineTo

func (n *NanovgoDestination) AbsLineTo(x, y float32)

func (*NanovgoDestination) AbsQuadTo

func (n *NanovgoDestination) AbsQuadTo(x1, y1, x, y float32)

func (*NanovgoDestination) AbsSmoothCubeTo

func (n *NanovgoDestination) AbsSmoothCubeTo(x2, y2, x, y float32)

func (*NanovgoDestination) AbsSmoothQuadTo

func (n *NanovgoDestination) AbsSmoothQuadTo(x, y float32)

func (*NanovgoDestination) AbsVLineTo

func (n *NanovgoDestination) AbsVLineTo(y float32)

func (*NanovgoDestination) ClosePathAbsMoveTo

func (n *NanovgoDestination) ClosePathAbsMoveTo(x, y float32)

func (*NanovgoDestination) ClosePathEndPath

func (n *NanovgoDestination) ClosePathEndPath()

func (*NanovgoDestination) ClosePathRelMoveTo

func (n *NanovgoDestination) ClosePathRelMoveTo(x, y float32)

func (*NanovgoDestination) RelArcTo

func (n *NanovgoDestination) RelArcTo(rx, ry, xAxisRotation float32, largeArc, sweep bool, x, y float32)

func (*NanovgoDestination) RelCubeTo

func (n *NanovgoDestination) RelCubeTo(x1, y1, x2, y2, x, y float32)

func (*NanovgoDestination) RelHLineTo

func (n *NanovgoDestination) RelHLineTo(x float32)

func (*NanovgoDestination) RelLineTo

func (n *NanovgoDestination) RelLineTo(x, y float32)

func (*NanovgoDestination) RelQuadTo

func (n *NanovgoDestination) RelQuadTo(x1, y1, x, y float32)

func (*NanovgoDestination) RelSmoothCubeTo

func (n *NanovgoDestination) RelSmoothCubeTo(x2, y2, x, y float32)

func (*NanovgoDestination) RelSmoothQuadTo

func (n *NanovgoDestination) RelSmoothQuadTo(x, y float32)

func (*NanovgoDestination) RelVLineTo

func (n *NanovgoDestination) RelVLineTo(y float32)

func (*NanovgoDestination) Reset

func (n *NanovgoDestination) Reset(m iconvg.Metadata)

func (*NanovgoDestination) SetCReg

func (n *NanovgoDestination) SetCReg(adj uint8, incr bool, c iconvg.Color)

func (*NanovgoDestination) SetCSel

func (n *NanovgoDestination) SetCSel(cSel uint8)

func (*NanovgoDestination) SetLOD

func (n *NanovgoDestination) SetLOD(lod0, lod1 float32)

func (*NanovgoDestination) SetNReg

func (n *NanovgoDestination) SetNReg(adj uint8, incr bool, f float32)

func (*NanovgoDestination) SetNSel

func (n *NanovgoDestination) SetNSel(nSel uint8)

func (*NanovgoDestination) StartPath

func (n *NanovgoDestination) StartPath(adj uint8, x, y float32)

type Oscilloscope

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

type Press

type Press struct {
	Key
	Rune rune
}

Press is a keyboard key press event, representing the key code with Rune.

Rune part is not matched in regular expressions.

type Release

type Release struct {
	Key
	Rune rune
}

Release is a keyboard key release event, representing the key code with optional Rune if releasing emitted a text enter.

Rune part is not matched in regular expressions.

type Scroll

type Scroll int

Scroll is a vertical mouse scroll event. Positive values represent scrolling up, negative — scrolling down.

type Scrollptr

type Scrollptr struct {
	Index  int
	Offset float64

	Dirty bool
	// contains filtered or unexported fields
}

type Segment

type Segment struct {
	// Op is the operator.
	// 	'M' — move, one coordinate
	// 	'L' — line, one coordinate
	//	'Q' — quadratic bezier, two coordinates
	// 	'C' — cubic bezier, three coordinates
	Op byte
	// Args is up to three (x, y) coordinates. The Y axis increases down.
	Args [3]geom.Point
}

Segment is a segment of a vector path. It is based on golang.org/x/image/font/sfnt.Segment.

func ApplySegment

func ApplySegment(g geom.Geom, s Segment) Segment

func (Segment) LastComponent

func (s Segment) LastComponent() geom.Point

func (Segment) String

func (s Segment) String() string

type Sequence

type Sequence interface {
	Get(wo *World, j int, buf []Sorm) (n int)
	Length(wo *World) int
}

Sequence is the thing that can generate elements for a compound.

func AdhocSequence

func AdhocSequence(get func(i int) Sorm, length func() int) Sequence

func SliceSequence

func SliceSequence[T any](sl []T, produce func(T) Sorm) Sequence

func SliceSequence2

func SliceSequence2[T any](sl []T, produce func(int) Sorm) Sequence

func StringSeq

func StringSeq(s string, produce func(rune) Sorm) Sequence

type Sorm

type Sorm struct {
	Size point
	// contains filtered or unexported fields
}

func (Sorm) Betweener

func (s Sorm) Betweener() Sorm

func (Sorm) Cond

func (s Sorm) Cond(f func(Matcher)) Sorm

func (Sorm) CondFill

func (s Sorm) CondFill(f func(rect geom.Rectangle) nanovgo.Paint) Sorm

func (Sorm) CondFillStroke

func (s Sorm) CondFillStroke(f func(rect geom.Rectangle) (nanovgo.Paint, nanovgo.Paint)) Sorm

func (Sorm) CondStroke

func (s Sorm) CondStroke(f func(rect geom.Rectangle) nanovgo.Paint) Sorm

func (Sorm) Fill

func (s Sorm) Fill(p nanovgo.Paint) Sorm

func (Sorm) FillStroke

func (s Sorm) FillStroke(p nanovgo.Paint) Sorm

func (Sorm) Hoverride

func (s Sorm) Hoverride() Sorm

func (Sorm) Lmb

func (s Sorm) Lmb(wo *World, f func()) Sorm

func (Sorm) Override

func (s Sorm) Override() Sorm

func (Sorm) Rectangle

func (s Sorm) Rectangle() geom.Rectangle

func (Sorm) Resize

func (s Sorm) Resize(x, y float64) Sorm

func (Sorm) String

func (s Sorm) String() string

func (Sorm) Stroke

func (s Sorm) Stroke(p nanovgo.Paint) Sorm

func (Sorm) Strokewidth

func (s Sorm) Strokewidth(w float64) Sorm

func (Sorm) Voverride

func (s Sorm) Voverride() Sorm

type Sormer

type Sormer[T interface{ BaseWorld() *World }] interface {
	Sorm(T) Sorm
}

type SpriteUnit

type SpriteUnit struct {
	Hfont int
	Clip  geom.Rectangle
	Tc    geom.Rectangle
}

type Sweep

type Sweep int

Sweep is a horizontal mouse scroll event. Negative values represent scrolling left, positive — scrolling right.

type Symbol

type Symbol int
const (
	Silence Symbol = iota
	Unfocus
	Ack
)

type Unclick

type Unclick int

Unclick is a mouse button release event, representing a button number.

type Window

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

func (*Window) Rect

func (wi *Window) Rect() image.Rectangle

type World

type World struct {
	*Events

	Window       Window
	Oscilloscope Oscilloscope

	Vgo *Context

	Wwin, Hwin float64

	BeforeVgo func()
	// contains filtered or unexported fields
}

func New

func New(config Config) (wo *World)

func (*World) BaseWorld

func (wo *World) BaseWorld() *World

BaseWorld returns itself. This method allows to access base World class from user worlds.

func (*World) Between

func (wo *World) Between(f func() Sorm) (s Sorm)

Between adds a Sorm from given constructor between every other shape in a compound.

func (*World) BetweenVoid

func (wo *World) BetweenVoid(w, h complex128) (s Sorm)

BetweenVoid adds a Void between every other shape of a compound.

func (*World) Canvas

func (wo *World) Canvas(w, h complex128, run func(vgo *Context, wt geom.Geom, rect geom.Rectangle)) (s Sorm)

Canvas gives a direct access to Nanovgo for painting a vector image.

func (*World) Cat

func (wo *World) Cat(a, b []Sorm) (s Sorm)

Cat returns a Compound from two Sorm sources. Its intended usage is for defining user's own abstractions.

func (*World) Circle

func (wo *World) Circle(d float64) (s Sorm)

Circle is a circle shape.

func (*World) Compound

func (wo *World) Compound(args ...Sorm) (s Sorm)

Compound is a shape container. It combines multiple Sorms into a single shape. Every other container is just a rebranded Compound.

func (*World) Cond

func (wo *World) Cond(f func(m Matcher)) (s Sorm)

Cond adds an event callback to a compound.

func (*World) CondFill

func (wo *World) CondFill(f func(geom.Rectangle) nanovgo.Paint) (s Sorm)

CondFill adds an event callback to a Compound.

func (*World) CondStroke

func (wo *World) CondStroke(f func(geom.Rectangle) nanovgo.Paint) (s Sorm)

func (*World) Crop

func (wo *World) Crop() (s Sorm)

Crop limits the painting area of a compound to its limit.

func (*World) Develop

func (wo *World) Develop()

Develop applies the layout and renders the next frame. See package description for preferred use of Contraption.

func (*World) Equation

func (wo *World) Equation(eqn Equation) (s Sorm)

func (*World) Fill

func (wo *World) Fill(p nanovgo.Paint) (s Sorm)

Strokewidth sets the fill paint.

func (*World) Halign

func (wo *World) Halign(amt float64) (s Sorm)

Halign aligns elements horizontally.

If amt == 0, elements are aligned to the left, if 0.5 to the middle and if 1 to the right. Values between those are acceptable.

amt is clipped to the range 0 < amt < 1.

func (*World) Hfollow

func (wo *World) Hfollow() (s Sorm)

func (*World) Hscroll

func (wo *World) Hscroll(idx *Index, du float64) (s Sorm)

func (*World) Hshrink

func (wo *World) Hshrink() (s Sorm)

Hshrink shrinks the horizontal size of a stretchy compound to the size of the children with the maximum known horizontal size.

func (*World) Identity

func (wo *World) Identity(key any) (s Sorm)

Identity gives a compound the key on which it can be retrieved from the layout tree on the next event loop cycle.

func (*World) Illustration

func (wo *World) Illustration(w, h complex128, mode string, src io.Reader) (s Sorm)

Illustration is a static, unchangeable image. Src is decoded by image.Decoder. You must register codecs for every type of image you want to use with this shape.

If w or h are zero, the corresponding axis of the resulting shape will be sized as the original picture.

Negative sizes will result in a stretched image, whose size is fully controlled by the parent compound.

mode is determining how the image will be resized if the proportions of the parent compound and the proportions of the image are different.

Available modes are

  • "stretch": the image will be stretched without preserving proportions.
  • "zoom": the smallest dimension of the image will be resized to the largest available dimension.
  • "pad": the smallest dimension of the image will be resized to the smallest available dimension.

The image won't be cropped in any of those cases. Use Scissor in the parent compound to limit the size of an image.

The texture from the image may be interpolated to a smaller size. Deallocation of the texture is the subject to the two-frame policy like any other resource in Contraption.

func (*World) Key

func (wo *World) Key(k any) (v *any)

Key is a temporary key-value storage for on-screen state. The value is deleted if it had been not accessed for two frames.

func (*World) Limit

func (wo *World) Limit(w, h float64) (s Sorm)

Limit limits the maximum compound size to specified limits. If a given size is negative, it limits the corresponding size of a compound by the rules of negative units for shapes.

TODO Imaginary limits.

func (*World) NewBottomUpText

func (wo *World) NewBottomUpText(font []byte) func(size float64, str []rune) Sorm

func (*World) NewText

func (wo *World) NewText(font []byte) func(size float64, str []rune) Sorm

func (*World) NewTopDownText

func (wo *World) NewTopDownText(font []byte) func(size float64, str []rune) Sorm

func (*World) NewVectorText

func (wo *World) NewVectorText(font []byte) func(size float64, str []rune) Sorm

func (*World) NewVectorTextReader

func (wo *World) NewVectorTextReader(font []byte) func(size float64, rd io.RuneScanner) Sorm

TODO This is the main and preferred method to do vector text. TODO Pool of (Runes)

func (*World) Next

func (wo *World) Next() bool

Next prepares the Contraption for rendering the next frame. See package description for preferred use of Contraption.

func (*World) Noround

func (wo *World) Noround() (s Sorm)

func (*World) Posttransform

func (wo *World) Posttransform(x, y float64) (s Sorm)

Posttransform applies transformation that only affects objects visually. It doesn't affect object sizes for layout.

func (*World) Prevkey

func (wo *World) Prevkey(key any) Sorm

func (*World) Rectangle

func (wo *World) Rectangle(w, h complex128) (s Sorm)

Rectangle is a rectangle shape.

func (*World) ResetDragEffects

func (wo *World) ResetDragEffects()

func (*World) Root

func (wo *World) Root(s ...Sorm)

func (*World) Round

func (wo *World) Round() (s Sorm)

func (*World) Roundrect

func (wo *World) Roundrect(w, h complex128, r float64) (s Sorm)

Roundrect is a rounded rectangle shape.

func (*World) Sequence

func (wo *World) Sequence(q Sequence) (s Sorm)

Sequence transforms external data to stream of shapes.

Modifiers in Sequence right now are ignored, but can trigger a panic in future versions.

func (*World) Sink

func (wo *World) Sink(f func(drop any)) (s Sorm)

Sink marks area of current compound as a drag sink. When program receives Release(1) event with mouse cursor inside a sink, it calls given function with the drag value.

func (*World) Source

func (wo *World) Source() (s Sorm)

Source marks area of current compound as a drag source. It uses compound's identity (set with Identity modifier) as a drag value.

func (*World) Stroke

func (wo *World) Stroke(p nanovgo.Paint) (s Sorm)

Strokewidth sets the stroke paint.

func (*World) Strokewidth

func (wo *World) Strokewidth(w float64) (s Sorm)

Strokewidth sets the stroke width.

func (*World) Transform

func (wo *World) Transform(m geom.Geom) (s Sorm)

Transform applies transformation that affects objects sizes for layout.

func (*World) Valign

func (wo *World) Valign(amt float64) (s Sorm)

Valign aligns elements vertically. If amt == 0, elements are aligned to the top, if 0.5 to the center and if 1 to the bottom. Values between those are acceptable.

amt is clipped to the range 0 < amt < 1.

func (*World) Vfollow

func (wo *World) Vfollow() (s Sorm)

func (*World) Void

func (wo *World) Void(w, h complex128) (s Sorm)

func (*World) Vscroll

func (wo *World) Vscroll(idx *Index, du float64) (s Sorm)

func (*World) Vshrink

func (wo *World) Vshrink() (s Sorm)

Vshrink works exactly like Hshrink, but for vertical sizes.

func (*World) Whereis

func (wo *World) Whereis(s Sorm) Sorm

Directories

Path Synopsis
examples
keymap Module
sink Module
fontstashmini/truetype
This library processes TrueType files:
This library processes TrueType files:

Jump to

Keyboard shortcuts

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