Documentation
¶
Overview ¶
Package flow draws a directed diagram, such as a workflow, a dependency graph or a plan of tasks, and lays it out automatically: nodes fall into ranks along the edges' direction, ranks are ordered to avoid crossings and edges run between them as orthogonal lines. Applications build each node's content and own selection and what opening a node means; the view owns layout, routing and the camera.
Index ¶
- type Data
- type Direction
- type Edge
- type Look
- type Node
- type State
- func (s *State) Bounds(id string) (core.Bounds, bool)
- func (s *State) Hover(p core.Point, over bool)
- func (s *State) Hovered() string
- func (s *State) NodeAt(p core.Point) string
- func (s *State) Position(id string) (x, y float32, ok bool)
- func (s *State) Press(p core.Point, e core.PressEvent) bool
- func (s *State) Ready() bool
- func (s *State) Reveal(id string)
- func (s *State) Size() core.Size
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Edge ¶
type Edge struct {
Source, Target string
Label string
Dashed bool
Color core.Color
Width core.Points
}
Edge points from Source to Target. Edges to unknown nodes and self-loops are ignored; edges closing a cycle are drawn against the layout's direction. Label, when set, sits on the line. A zero Color takes the look's line and a zero Width 1.5 points.
type Look ¶
Look colors what the view draws itself. Line is an edge's color and Emphasis that of the edges of the hovered or selected node; Label, LabelBackground and LabelBorder color an edge's label. Zero fields take the text color the view has, as core.CurrentColor does, with lines, labels and the label's border faded, and a label with no background clears the edges under it; base reads no theme, and a styled form such as ui/flow sets its own look.
type Node ¶
Node is one card of the diagram. ID must be nonempty, unique and stable across changes; later duplicates are ignored. Label is its accessible name, the ID when empty.
Content is the node's face, made when its ID first appears and kept while the ID stays, following the signals it reads. Positive Width and Height fix the node's size; otherwise the layout measures Content, laying the diagram out again when that size changes. Muted fades the node and its edges, as for skipped or inactive steps.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State retains measured sizes and the layout between mounts, and takes the pointer for the view showing it. Its zero value is ready to use; keep one per diagram. Its methods run on the UI's goroutine and do nothing while no view shows it.
func (*State) Bounds ¶
Bounds is the frame of the node with id in diagram coordinates, false when it is not laid out.
func (*State) Hover ¶
Hover moves the pointer to a point of the diagram, emphasizing the edges of the node there, or off it when over is false.
func (*State) Hovered ¶
Hovered is the node the pointer is over, "" for none, which a caller reading it follows, such as to show the arrow over nodes.
func (*State) Position ¶
Position returns the top left corner of the node with id in diagram coordinates, and false if it is not laid out.
func (*State) Press ¶
Press presses the diagram at a point of it, as a camera hands it on: the node there is selected, and opened on a double press, or empty space selects "". It says a node took the press.
type View ¶
type View struct {
Data func() Data
// Direction is the way edges point, read as a signal; nil is top to
// bottom.
Direction func() Direction
// NodeGap separates nodes within a rank (40 when 0) and RankGap the
// ranks (72 when 0).
NodeGap, RankGap core.Points
// Selected is the application's selected node, which the view rings
// and whose edges it emphasizes.
Selected func() string
OnSelect func(id string)
OnOpen func(id string)
// State holds measured sizes and the layout between mounts and takes
// the pointer; nil keeps one of the view's own.
State *State
// Camera is the camera showing the diagram, which reveals the node the
// keyboard focuses; the diagram's origin is the content's unless
// Origin says where in it the diagram is.
Camera *camera.State
Origin func() core.Point
// Empty replaces the diagram while it has no nodes, an em dash when
// nil.
Empty core.Node
// Label describes the diagram for assistive technology, its count of
// nodes and edges when empty.
Label string
LabelFunc func() string
LookFunc func() Look
// NodeClass, NodeStyle and NodeStyleFunc are each node's box, around
// its Content, such as its focus ring; RingClass, RingStyle and
// RingStyleFunc the ring around the selected node, 3 points outside
// it, 2 points wide in the text's color unless they say otherwise.
NodeClass string
NodeStyle core.Style
NodeStyleFunc func() core.Style
RingClass string
RingStyle core.Style
RingStyleFunc func() core.Style
Class string
Style core.Style
TestID string
}
View is the diagram, laid out at the size its layout takes, again when Data, read as a signal, changes; put it on a camera.View to pan and zoom it, as several diagrams can share one. Nodes take the keyboard focus in data order when the application can select or open them, and Camera, when set, follows the focused node.
A press on a node selects it (OnSelect) and a double press opens it (OnOpen). Platforms hit-test views without a camera's transform, so on a camera the application hands the pointer to State's Press and Hover at points of the diagram, which find the node there themselves, and a press on empty space selects "".