dirhook

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 Epoch

func Epoch() uint64

Epoch returns the count Changed raises.

func Exit

func Exit(pushed bool)

Exit undoes the push of the Enter that returned pushed.

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.

Jump to

Keyboard shortcuts

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