Documentation
¶
Overview ¶
This package provides support for rich UI layers with input handling, rendering, layouting and declarative UI.
Index ¶
- func Viewport(create func(t *scaff.Tracker, props *ViewportProps)) scaff.NodeBuilder
- type AcceptChild
- type AcceptChildren
- type AcceptNoChild
- type Node
- type NodeBuilder
- type StandardCreate
- type StandardMethods
- type StandardNode
- func (s *StandardNode[P]) Child() (Node, bool)
- func (s *StandardNode[P]) Children() []Node
- func (s *StandardNode[P]) Constraints() scath.Constraints
- func (s *StandardNode[P]) Context() *scaff.BuildContext
- func (s *StandardNode[P]) Draw(position scath.Vec, renderer paint.Painter)
- func (s *StandardNode[P]) HandleEvent(c *scaff.Context, event scaff.Event) scaff.TracedError
- func (s *StandardNode[P]) ID() string
- func (s *StandardNode[P]) Layout() (scath.Vec, error)
- func (s *StandardNode[P]) LayoutChildren() (scath.Vec, error)
- func (s *StandardNode[P]) Load(parent Node)
- func (s *StandardNode[P]) Parent() Node
- func (s *StandardNode[P]) Props() P
- func (s *StandardNode[P]) PropsChanged(new P)
- func (s *StandardNode[P]) SetConstraints(c scath.Constraints)
- func (s *StandardNode[P]) Size() scath.Vec
- func (s *StandardNode[P]) Tracker() *scaff.Tracker
- func (s *StandardNode[P]) Unload()
- func (s *StandardNode[P]) Update() (UpdateResult, scaff.TracedError)
- func (s *StandardNode[P]) WantedConstraints(parent scath.Constraints) scath.Constraints
- type UpdateResult
- type ViewportProps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Viewport ¶
func Viewport(create func(t *scaff.Tracker, props *ViewportProps)) scaff.NodeBuilder
Viewport creates a viewport node that can be used to essentially mount a
Types ¶
type AcceptChild ¶
type AcceptChild = scaff.AcceptChildTemplate[NodeBuilder]
func EmptyChild ¶
func EmptyChild() *AcceptChild
func WithChild ¶
func WithChild(builder NodeBuilder) *AcceptChild
type AcceptChildren ¶
type AcceptChildren = scaff.AcceptChildrenTemplate[NodeBuilder]
func EmptyChildren ¶
func EmptyChildren() *AcceptChildren
func WithChildren ¶
func WithChildren(builders []NodeBuilder) *AcceptChildren
type AcceptNoChild ¶
type AcceptNoChild = scaff.AcceptNoChildTemplate[NodeBuilder]
func EmptyNoChild ¶
func EmptyNoChild() AcceptNoChild
type Node ¶
type Node interface {
scaff.Tracking
scaff.Identifiable
scaff.Loadable[Node]
// Get the parent node of the current Node
Parent() Node
// Get all children nodes of the current Node
Children() []Node
// Should return the current size of the node
Size() scath.Vec
// Should return the constraints wanted by this Node
WantedConstraints(parent scath.Constraints) scath.Constraints
// Should return the current constraints (that were last set)
Constraints() scath.Constraints
// Set the constraints of the node (should be used for layouting)
SetConstraints(c scath.Constraints)
// Should layout the node and return the size within the (previously set) constraints
Layout() (scath.Vec, error)
// Called to see if a draw is needed based on changed props, etc.
Update() (UpdateResult, scaff.TracedError)
// Draw the thing onto the screen at a specified position (next step is getting this to work)
Draw(position scath.Vec, painter paint.Painter)
// Handle events from scaff (you do not have to handle any, but should always push them along to children at least)
HandleEvent(c *scaff.Context, event scaff.Event) scaff.TracedError
}
type NodeBuilder ¶
type NodeBuilder func(*scaff.BuildContext) Node
func Standard ¶
func Standard[P scaff.ChildProps[NodeBuilder]](create StandardCreate[P]) NodeBuilder
Standard lets you create a node with multiple children. Simply implement the ChildProps interface on the props you want to have for your node.
type StandardCreate ¶
type StandardCreate[P scaff.ChildProps[NodeBuilder]] struct { ID string DefaultProps P PropsCreator func(t *scaff.Tracker, props *P) Create func(methods *StandardMethods[P]) }
Struct for defining a standard node.
ID should be a unique id for the node, but also probably be readable as it shows up in error messages.
DefaultProps are the props as they are by default. Make sure to also specify any embedded struct pointers.
PropsCreator should be the function passed in by users of your node (as in it should probably be an argument of the function creating your node).
Create is the function actually specifying your node. You can overwrite all of the functions of the node interface there, with some exceptions that we implement for you.
type StandardMethods ¶
type StandardMethods[P scaff.ChildProps[NodeBuilder]] struct { OnLoad func(node *StandardNode[P]) OnPropsChanged func(node *StandardNode[P]) OnUnload func(node *StandardNode[P]) OnWantedConstraints func(node *StandardNode[P], parent scath.Constraints) scath.Constraints OnLayout func(node *StandardNode[P]) (scath.Vec, error) OnHandleEvent func(node *StandardNode[P], c *scaff.Context, event scaff.Event) error OnDraw func(node *StandardNode[P], position scath.Vec, renderer paint.Painter) }
type StandardNode ¶
type StandardNode[P scaff.ChildProps[NodeBuilder]] struct { // contains filtered or unexported fields }
func (*StandardNode[P]) Child ¶
func (s *StandardNode[P]) Child() (Node, bool)
Get the first child, this is just a helper function for nodes that have one child.
func (*StandardNode[P]) Children ¶
func (s *StandardNode[P]) Children() []Node
func (*StandardNode[P]) Constraints ¶
func (s *StandardNode[P]) Constraints() scath.Constraints
func (*StandardNode[P]) Context ¶
func (s *StandardNode[P]) Context() *scaff.BuildContext
func (*StandardNode[P]) Draw ¶
func (s *StandardNode[P]) Draw(position scath.Vec, renderer paint.Painter)
func (*StandardNode[P]) HandleEvent ¶
func (s *StandardNode[P]) HandleEvent(c *scaff.Context, event scaff.Event) scaff.TracedError
func (*StandardNode[P]) ID ¶
func (s *StandardNode[P]) ID() string
func (*StandardNode[P]) LayoutChildren ¶
func (s *StandardNode[P]) LayoutChildren() (scath.Vec, error)
Default implementation of layout
func (*StandardNode[P]) Load ¶
func (s *StandardNode[P]) Load(parent Node)
func (*StandardNode[P]) Parent ¶
func (s *StandardNode[P]) Parent() Node
func (*StandardNode[P]) Props ¶
func (s *StandardNode[P]) Props() P
func (*StandardNode[P]) PropsChanged ¶
func (s *StandardNode[P]) PropsChanged(new P)
func (*StandardNode[P]) SetConstraints ¶
func (s *StandardNode[P]) SetConstraints(c scath.Constraints)
func (*StandardNode[P]) Size ¶
func (s *StandardNode[P]) Size() scath.Vec
func (*StandardNode[P]) Tracker ¶
func (s *StandardNode[P]) Tracker() *scaff.Tracker
func (*StandardNode[P]) Unload ¶
func (s *StandardNode[P]) Unload()
func (*StandardNode[P]) Update ¶
func (s *StandardNode[P]) Update() (UpdateResult, scaff.TracedError)
func (*StandardNode[P]) WantedConstraints ¶
func (s *StandardNode[P]) WantedConstraints(parent scath.Constraints) scath.Constraints
type UpdateResult ¶
type UpdateResult struct {
SizeChanged bool // The size of the current node changed due to updates, re-layouting is needed
AnythingChanged bool // If any of the children changed, but no more re-layouting is needed
}
func LayoutChanged ¶
func LayoutChanged() UpdateResult
Wen you did re-layouting, but your size didn't change
func SizeChanged ¶
func SizeChanged() UpdateResult
When your size changed, return this to signal a change in size
func (*UpdateResult) Stack ¶
func (ur *UpdateResult) Stack(ur2 UpdateResult)
Stack a UpdateResult with a different one, will keep everything true that was before and sort of combine every boolean using or.
type ViewportProps ¶
type ViewportProps struct {
*scaff.AcceptNoChild
// contains filtered or unexported fields
}
func (ViewportProps) Child ¶
func (vp ViewportProps) Child(builder NodeBuilder)