Documentation
¶
Overview ¶
Package dirhook lets code that lays objects out outside a layout walk — a Refresh from a timer, an animation or a binding, a Container's Add, a widget resized by hand — run that layout in the direction the object sits in (#749). The lookup lives in internal/driver, which the root package cannot import, so the root package and the widget bases reach it through the hook installed here. It imports only core, so every package can use it.
While no direction other than the process-wide one can apply anywhere (no container.DirectionScope has been rendered, no canvas has its own direction), InUse is false and callers run their layout directly: an atomic load is the whole cost for an app without scopes.
Index ¶
- func Added(parent, obj core.CanvasObject)
- func Changed()
- func Enter(obj core.CanvasObject) bool
- func Epoch() uint64
- func Exit(pushed bool)
- func InUse() bool
- func Note()
- func Refreshed(obj core.CanvasObject)
- func Removed(parent, obj core.CanvasObject)
- func Run(obj core.CanvasObject, f func())
- func SetEnter(enterF func(obj core.CanvasObject) bool, exitF func())
- func SetMoved(f func(parent, obj core.CanvasObject, added bool))
- func SetRefreshed(f func(obj core.CanvasObject))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Added ¶
func Added(parent, obj core.CanvasObject)
Added records that obj was added to parent's children (a Container's Add), so it may now be inside a direction scope. The driver's direction cache takes obj's subtree in where it stands rather than being rebuilt, so a loop of Adds costs a walk of what it adds, not of every scope each time.
func Changed ¶
func Changed()
Changed records a change that can move an object into or out of a direction scope (an object removed from a container, a canvas' content or overlays changed, a scope's direction changed), and a frame boundary. The driver's direction cache is rebuilt after it.
func Enter ¶
func Enter(obj core.CanvasObject) bool
Enter makes obj's layout direction the ambient one, when InUse and a hook is installed, until the matching Exit; it reports whether it pushed one. Pair them with a defer, so a panic in between unwinds the push:
defer dirhook.Exit(dirhook.Enter(obj))
Unlike Run it takes no closure, so a hot path such as a widget's Refresh allocates nothing for it (#772).
func InUse ¶
func InUse() bool
InUse reports whether Note has been called. Until it has, every object is in the process-wide direction and Run has nothing to push.
func Note ¶
func Note()
Note records that a direction other than the process-wide one may now apply somewhere: a direction scope was rendered, a canvas was given its own direction, or an overlay inherited its opener's. It stays set.
func Refreshed ¶
func Refreshed(obj core.CanvasObject)
Refreshed records that obj was refreshed: a widget's renderer, or code that assigned a Container's Objects, may have given it children no Added reported. The driver's direction cache takes them in where obj stands, so a lookup before the next frame finds them (#773).
func Removed ¶
func Removed(parent, obj core.CanvasObject)
Removed records that obj left parent's children (a Container's Remove or RemoveAll), so it may have left a direction scope; see Added.
func Run ¶
func Run(obj core.CanvasObject, f func())
Run runs f with obj's layout direction as the ambient one, when InUse and a hook is installed; otherwise it just runs f. Callers on hot paths test InUse first, so the closure they pass is only built when it is needed, or use Enter and Exit, which take none.
func SetEnter ¶
func SetEnter(enterF func(obj core.CanvasObject) bool, exitF func())
SetEnter installs enterF as the function Enter delegates to, and exitF as the one Exit calls to undo a push. internal/driver installs them at init.
func SetMoved ¶
func SetMoved(f func(parent, obj core.CanvasObject, added bool))
SetMoved installs f as the function Added and Removed report to. internal/driver installs it at init.
func SetRefreshed ¶
func SetRefreshed(f func(obj core.CanvasObject))
SetRefreshed installs f as the function Refreshed reports to. internal/driver installs it at init.
Types ¶
This section is empty.