view

package
v0.0.2-0...-a5fe278 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package view implements the client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func C

func C(p Pointer) complex128

C translates any Pointer into a complex128.

func Setup

func Setup(doc dom.Document, gc GraphController)

Setup connects to elements in the DOM.

Types

type Channel

type Channel struct {
	Group // Container for all the channel elements.

	// Cache of raw Pin objects which are connected.
	Pins map[*Pin]*Route
	// contains filtered or unexported fields
}

Channel is the view's model of a channel.

func (*Channel) MakeElements

func (c *Channel) MakeElements(doc dom.Document, parent dom.Element)

MakeElements recreates elements for this channel and adds them to the parent.

func (*Channel) Pt

func (c *Channel) Pt() Point

Pt implements Pointer.

type ChannelController

type ChannelController interface {
	Name() string
	Pins(func(PinController)) // input called for all currently attached pins

	Attach(PinController)
	Detach(PinController)
	GainFocus()

	Commit(ctx context.Context) error
	Delete(ctx context.Context) error
}

ChannelController is implemented by the controller of a channel.

type Graph

type Graph struct {
	Group // container for all graph elements

	Nodes    map[string]*Node
	Channels map[string]*Channel
	// contains filtered or unexported fields
}

Graph is the view-model of a graph.

func (*Graph) MakeElements

func (g *Graph) MakeElements(doc dom.Document, parent dom.Element)

MakeElements drops any existing elements, and then loads new ones from the graph controller.

type GraphController

type GraphController interface {
	GainFocus()

	// Sub-controllers
	Nodes(func(NodeController)) // input called for all nodes
	NumNodes() int

	Channels(func(ChannelController)) // input called for all channels
	NumChannels() int

	CreateChannel(pcs ...PinController) (ChannelController, error)
	CreateNode(ctx context.Context, partType string) (NodeController, error)

	// Send properties to server
	Commit(ctx context.Context) error

	// Action links
	Save(ctx context.Context) error
	Revert(ctx context.Context) error
	Generate(ctx context.Context) error
	Build(ctx context.Context) error
	Install(ctx context.Context) error
	Run(ctx context.Context) error
	PreviewGo()
	PreviewRawGo()
	PreviewJSON()

	// Misc
	HelpLicenses()
	HelpAbout()
}

GraphController is implemented by the controller of a whole graph.

type Group

type Group struct {
	dom.Element
}

Group includes handy methods for using SVG groups.

func NewGroup

func NewGroup(doc dom.Document, parent dom.Element) Group

NewGroup creates an SVG group in the given document.

func (Group) AddTo

func (g Group) AddTo(parent dom.Element) Group

AddTo adds the group to the given parent element.

func (Group) BringToFront

func (g Group) BringToFront()

BringToFront re-adds the group to the parent.

func (Group) MoveTo

func (g Group) MoveTo(p Point) Group

MoveTo moves the group to have the topleft corner at x, y.

func (Group) Remove

func (g Group) Remove()

Remove removes the group from the parent, if set.

type Node

type Node struct {
	Group
	TextBox *TextBox
	Inputs  []*Pin
	Outputs []*Pin
	AllPins []*Pin
	// contains filtered or unexported fields
}

Node is the view's model of a node.

func (*Node) MakeElements

func (n *Node) MakeElements(doc dom.Document, parent dom.Element) *Node

MakeElements makes the elements that are part of this node.

func (*Node) MoveTo

func (n *Node) MoveTo(p Point) *Node

MoveTo moves the textbox to have the topleft corner at x, y.

type NodeController

type NodeController interface {
	Name() string
	Position() (x, y float64)

	Pins(func(pc PinController, channel string)) // input called for all pins on this node

	GainFocus()
	ShowMetadataSubpanel()
	ShowPartSubpanel(name string)

	Commit(ctx context.Context) error
	Delete(ctx context.Context) error
	SetPosition(ctx context.Context, x, y float64) error
}

NodeController is implemented by the controller of a node.

type Pin

type Pin struct {
	Group             // Container for all the pin elements.
	Shape dom.Element // The pin itself.
	// contains filtered or unexported fields
}

Pin represents a node pin visually, and has enough information to know if it is validly connected.

func (*Pin) MakeElements

func (p *Pin) MakeElements(doc dom.Document, parent dom.Element) *Pin

MakeElements recreates elements associated with this pin.

func (*Pin) MoveTo

func (p *Pin) MoveTo(rel Point)

MoveTo moves the pin (relatively).

func (*Pin) Pt

func (p *Pin) Pt() Point

Pt returns the diagram coordinate of the pin, for nearest-neighbor purposes.

func (*Pin) String

func (p *Pin) String() string

type PinController

type PinController interface {
	Name() string
	Type() string
	IsInput() bool
	NodeName() string
}

PinController is implemented by the controller for a pin.

type Point

type Point complex128

Point is a basic implementation of Point.

func Pt

func Pt(x, y float64) Point

Pt translates any x and y into a Point.

func (Point) Pt

func (p Point) Pt() Point

Pt implements Pointer.

type Pointer

type Pointer interface {
	Pt() Point
}

Pointer is anything that has a position on the canvas.

type Route

type Route struct {
	Group
	// contains filtered or unexported fields
}

Route is the visual connection between two points

func NewRoute

func NewRoute(doc dom.Document, parent Group, src, dst Pointer) *Route

NewRoute creates a route connecting a channel and a pin, and adds it as a child of the channel's group.

func (*Route) Reroute

func (r *Route) Reroute()

Reroute repositions the route. Call after moving either the channel or the pin.

type TextBox

type TextBox struct {
	// Children Rectangle and Text, and Text has child TextNode.
	Group
	Rect     dom.Element
	Text     dom.Element
	TextNode dom.Element

	MinWidth float64
	Margin   float64
	// contains filtered or unexported fields
}

TextBox is an SVG group containing a filled rectangle and text.

func (*TextBox) CurrentText

func (b *TextBox) CurrentText() string

CurrentText returns the last string passed to SetText.

func (*TextBox) MakeElements

func (b *TextBox) MakeElements(doc dom.Document, parent dom.Element) *TextBox

MakeElements creates the DOM elements, organises them, and sets default attributes. The return is the main group.

func (*TextBox) RecomputeWidth

func (b *TextBox) RecomputeWidth() *TextBox

RecomputeWidth resizes the textbox to fit all text (plus a margin).

func (*TextBox) SetHeight

func (b *TextBox) SetHeight(height float64) *TextBox

SetHeight sets the textbox height.

func (*TextBox) SetText

func (b *TextBox) SetText(text string) *TextBox

SetText sets te text in the textbox.

func (*TextBox) SetWidth

func (b *TextBox) SetWidth(w float64) *TextBox

SetWidth sets the width of the textbox, unless the width is less than the MinWidth, in which case MinWidth is used instead.

func (*TextBox) Width

func (b *TextBox) Width() float64

Width returns the current width.

type View

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

View caches the top-level objects for managing the UI.

Jump to

Keyboard shortcuts

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