Documentation
¶
Index ¶
- Variables
- func ComputeLocalTransform(n *Node) [6]float64
- func DefaultDebugCheckChildCount(n *Node)
- func DefaultDebugCheckDisposed(n *Node, op string)
- func DefaultDebugCheckTreeDepth(n *Node)
- func InvertAffine(m [6]float64) [6]float64
- func IsAncestor(candidate, node *Node) bool
- func MarkSubtreeDirty(n *Node)
- func MatchPattern(s, inner string, mode WildMode) bool
- func MultiplyAffine(p, c [6]float64) [6]float64
- func TransformPoint(m [6]float64, x, y float64) (float64, float64)
- func UpdateWorldTransform(n *Node, parentTransform [6]float64, parentAlpha float64, ...)
- type ClickContext
- type DragContext
- type EmitFn
- type MeshData
- type Node
- func (n *Node) AddChild(child *Node)
- func (n *Node) AddChildAt(child *Node, index int)
- func (n *Node) Alpha() float64
- func (n *Node) BlendMode() types.BlendMode
- func (n *Node) ChildAt(index int) *Node
- func (n *Node) Children() []*Node
- func (n *Node) ClearMask()
- func (n *Node) Color() types.Color
- func (n *Node) CustomImage() *ebiten.Image
- func (n *Node) Dispose()
- func (n *Node) EnsureCallbacks() *NodeCallbacks
- func (n *Node) EnsureMesh() *MeshData
- func (n *Node) FindChild(pattern string) *Node
- func (n *Node) FindDescendant(pattern string) *Node
- func (n *Node) GetMask() *Node
- func (n *Node) GetOnClick() func(ClickContext)
- func (n *Node) GetOnDrag() func(DragContext)
- func (n *Node) GetOnDragEnd() func(DragContext)
- func (n *Node) GetOnDragStart() func(DragContext)
- func (n *Node) GetOnPinch() func(PinchContext)
- func (n *Node) GetOnPointerDown() func(PointerContext)
- func (n *Node) GetOnPointerEnter() func(PointerContext)
- func (n *Node) GetOnPointerLeave() func(PointerContext)
- func (n *Node) GetOnPointerMove() func(PointerContext)
- func (n *Node) GetOnPointerUp() func(PointerContext)
- func (n *Node) HasOnClick() bool
- func (n *Node) HasOnDrag() bool
- func (n *Node) HasOnDragEnd() bool
- func (n *Node) HasOnDragStart() bool
- func (n *Node) HasOnPinch() bool
- func (n *Node) HasOnPointerDown() bool
- func (n *Node) HasOnPointerEnter() bool
- func (n *Node) HasOnPointerLeave() bool
- func (n *Node) HasOnPointerMove() bool
- func (n *Node) HasOnPointerUp() bool
- func (n *Node) Height() float64
- func (n *Node) Invalidate()
- func (n *Node) InvalidateCache()
- func (n *Node) InvalidateCacheTree()
- func (n *Node) InvalidateMeshAABB()
- func (n *Node) IsCacheAsTreeEnabled() bool
- func (n *Node) IsCacheEnabled() bool
- func (n *Node) IsDisposed() bool
- func (n *Node) LocalToWorld(lx, ly float64) (wx, wy float64)
- func (n *Node) MeshImage() *ebiten.Image
- func (n *Node) MeshIndices() []uint16
- func (n *Node) MeshVertices() []ebiten.Vertex
- func (n *Node) NumChildren() int
- func (n *Node) OnClick(fn func(ClickContext))
- func (n *Node) OnDrag(fn func(DragContext))
- func (n *Node) OnDragEnd(fn func(DragContext))
- func (n *Node) OnDragStart(fn func(DragContext))
- func (n *Node) OnPinch(fn func(PinchContext))
- func (n *Node) OnPointerDown(fn func(PointerContext))
- func (n *Node) OnPointerEnter(fn func(PointerContext))
- func (n *Node) OnPointerLeave(fn func(PointerContext))
- func (n *Node) OnPointerMove(fn func(PointerContext))
- func (n *Node) OnPointerUp(fn func(PointerContext))
- func (n *Node) PivotX() float64
- func (n *Node) PivotY() float64
- func (n *Node) RemoveChild(child *Node)
- func (n *Node) RemoveChildAt(index int) *Node
- func (n *Node) RemoveChildren()
- func (n *Node) RemoveFromParent()
- func (n *Node) Renderable() bool
- func (n *Node) Rotation() float64
- func (n *Node) ScaleX() float64
- func (n *Node) ScaleY() float64
- func (n *Node) Scene() any
- func (n *Node) SetAlign(a types.TextAlign)
- func (n *Node) SetAlpha(a float64)
- func (n *Node) SetBlendMode(b types.BlendMode)
- func (n *Node) SetCacheAsTexture(enabled bool)
- func (n *Node) SetCacheAsTree(enabled bool, mode ...types.CacheTreeMode)
- func (n *Node) SetChildIndex(child *Node, index int)
- func (n *Node) SetColor(c types.Color)
- func (n *Node) SetContent(s string)
- func (n *Node) SetCustomImage(img *ebiten.Image)
- func (n *Node) SetFont(f interface{ ... })
- func (n *Node) SetFontSize(size float64)
- func (n *Node) SetGlobalOrder(o int)
- func (n *Node) SetLineHeight(h float64)
- func (n *Node) SetMask(maskNode *Node)
- func (n *Node) SetMeshData(vertices []ebiten.Vertex, indices []uint16, img *ebiten.Image)
- func (n *Node) SetMeshImage(img *ebiten.Image)
- func (n *Node) SetMeshIndices(indices []uint16)
- func (n *Node) SetMeshVertices(vertices []ebiten.Vertex)
- func (n *Node) SetPivot(px, py float64)
- func (n *Node) SetPosition(x, y float64)
- func (n *Node) SetRenderLayer(l uint8)
- func (n *Node) SetRenderable(r bool)
- func (n *Node) SetRotation(r float64)
- func (n *Node) SetScale(sx, sy float64)
- func (n *Node) SetSize(w, h float64)
- func (n *Node) SetSkew(sx, sy float64)
- func (n *Node) SetTextColor(c types.Color)
- func (n *Node) SetTextEffects(e *text.TextEffects)
- func (n *Node) SetTextureRegion(r types.TextureRegion)
- func (n *Node) SetVisible(v bool)
- func (n *Node) SetWrapWidth(w float64)
- func (n *Node) SetX(x float64)
- func (n *Node) SetY(y float64)
- func (n *Node) SetZIndex(z int)
- func (n *Node) SkewX() float64
- func (n *Node) SkewY() float64
- func (n *Node) TextureRegion() types.TextureRegion
- func (n *Node) Visible() bool
- func (n *Node) Width() float64
- func (n *Node) WorldToLocal(wx, wy float64) (lx, ly float64)
- func (n *Node) X() float64
- func (n *Node) Y() float64
- func (n *Node) ZIndex() int
- type NodeCallbacks
- type NodeIndex
- func (idx *NodeIndex) Add(node *Node, tags ...string)
- func (idx *NodeIndex) CountByTag(tag string) int
- func (idx *NodeIndex) Each(fn func(n *Node) bool)
- func (idx *NodeIndex) EachByTag(tag string, fn func(n *Node) bool)
- func (idx *NodeIndex) FindAllByName(pattern string) []*Node
- func (idx *NodeIndex) FindByName(pattern string) *Node
- func (idx *NodeIndex) FindByTag(pattern string) []*Node
- func (idx *NodeIndex) FindByTags(tags ...string) []*Node
- func (idx *NodeIndex) Remove(node *Node, tags ...string)
- type PinchContext
- type PointerContext
- type WildMode
Constants ¶
This section is empty.
Variables ¶
var ( // Debug enables debug checks on tree operations. Debug bool // DebugCheckDisposed panics if a disposed node is used. DebugCheckDisposed func(n *Node, op string) // DebugCheckTreeDepth warns if tree depth exceeds a threshold. DebugCheckTreeDepth func(n *Node) // DebugCheckChildCount warns if a node has too many children. DebugCheckChildCount func(n *Node) // WhitePixelImage is the 1x1 white pixel used for solid color sprites. WhitePixelImage *ebiten.Image // InvalidateAncestorCacheFn walks up from n to the nearest cached ancestor // and marks it dirty (auto mode only). Wired by render/. InvalidateAncestorCacheFn func(n *Node) // RegisterAnimatedInCacheFn registers a node's cached command as animated // so replay reads the live TextureRegion. Wired by render/. RegisterAnimatedInCacheFn func(n *Node) // SetCacheAsTreeFn enables/disables subtree command caching. Wired by core/. SetCacheAsTreeFn func(n *Node, enabled bool, mode ...types.CacheTreeMode) // InvalidateCacheTreeFn marks a node's cache as stale. Wired by core/. InvalidateCacheTreeFn func(n *Node) // IsCacheAsTreeEnabledFn reports whether cache is enabled. Wired by core/. IsCacheAsTreeEnabledFn func(n *Node) bool // PropagatSceneFn recursively sets the scene back-pointer. Wired by core/. PropagateSceneFn func(n *Node, scene any) )
var AnyTransformDirty bool
AnyTransformDirty is set when any node's transform or alpha is dirtied. The scene resets this after the first UpdateWorldTransform pass and checks it before the second pass to skip a redundant full tree walk.
var IdentityTransform = [6]float64{1, 0, 0, 1, 0, 0}
IdentityTransform is the identity affine matrix.
Functions ¶
func ComputeLocalTransform ¶
ComputeLocalTransform computes the local affine matrix from the node's transform properties. Returns [a, b, c, d, tx, ty].
func DefaultDebugCheckChildCount ¶
func DefaultDebugCheckChildCount(n *Node)
DefaultDebugCheckChildCount warns on stderr if a node has more than 1000 children.
func DefaultDebugCheckDisposed ¶
DefaultDebugCheckDisposed panics if a disposed node is used in a tree operation.
func DefaultDebugCheckTreeDepth ¶
func DefaultDebugCheckTreeDepth(n *Node)
DefaultDebugCheckTreeDepth warns on stderr if tree depth exceeds threshold.
func InvertAffine ¶
InvertAffine computes the inverse of a 2D affine matrix.
func IsAncestor ¶
IsAncestor reports whether candidate is an ancestor of node.
func MarkSubtreeDirty ¶
func MarkSubtreeDirty(n *Node)
MarkSubtreeDirty marks a node as needing transform and alpha recomputation.
func MatchPattern ¶
MatchPattern tests s against a parsed pattern.
func MultiplyAffine ¶
MultiplyAffine multiplies two 2D affine matrices: result = parent * child.
func TransformPoint ¶
TransformPoint applies an affine matrix to a point.
Types ¶
type ClickContext ¶
type ClickContext struct {
Node *Node // the clicked node
EntityID uint32 // the clicked node's EntityID (for ECS bridging)
UserData any // the clicked node's UserData
GlobalX float64 // click X in world coordinates
GlobalY float64 // click Y in world coordinates
LocalX float64 // click X in the node's local coordinates
LocalY float64 // click Y in the node's local coordinates
Button types.MouseButton // which mouse button was clicked
PointerID int // 0 = mouse, 1-9 = touch contacts
Modifiers types.KeyModifiers // keyboard modifier keys held during the click
}
ClickContext carries click event data passed to click callbacks.
type DragContext ¶
type DragContext struct {
Node *Node // the node being dragged
EntityID uint32 // the dragged node's EntityID (for ECS bridging)
UserData any // the dragged node's UserData
GlobalX float64 // current pointer X in world coordinates
GlobalY float64 // current pointer Y in world coordinates
LocalX float64 // current pointer X in the node's local coordinates
LocalY float64 // current pointer Y in the node's local coordinates
StartX float64 // world X where the drag began
StartY float64 // world Y where the drag began
DeltaX float64 // X movement since the previous drag event
DeltaY float64 // Y movement since the previous drag event
ScreenDeltaX float64 // X movement in screen pixels since the previous drag event
ScreenDeltaY float64 // Y movement in screen pixels since the previous drag event
Button types.MouseButton // which mouse button initiated the drag
PointerID int // 0 = mouse, 1-9 = touch contacts
Modifiers types.KeyModifiers // keyboard modifier keys held during the drag
}
DragContext carries drag event data passed to drag callbacks.
type EmitFn ¶
EmitFn is the type for render emission functions stored on Node. The `any` parameter is an opaque *Scene — node/ never inspects it.
type MeshData ¶
type MeshData struct {
Vertices []ebiten.Vertex
Indices []uint16
Image *ebiten.Image
TransformedVerts []ebiten.Vertex // preallocated transform buffer
Aabb types.Rect // cached local-space AABB
AabbDirty bool // recompute AABB when true
}
MeshData holds mesh-specific fields for NodeTypeMesh nodes. Allocated by NewMesh. Only mesh nodes carry this data.
type Node ¶
type Node struct {
// ---- HOT: traverse flags (cache line 0) ----
Visible_ bool
Renderable_ bool
TransformDirty bool
AlphaDirty bool
ChildrenSorted bool
Type types.NodeType
RenderLayer uint8
BlendMode_ types.BlendMode
// ---- HOT: computed world state ----
WorldAlpha float64
Alpha_ float64
WorldTransform [6]float64
// ---- HOT: children for iteration ----
Children_ []*Node
SortedChildren []*Node
// ---- HOT: render command fields ----
CustomImage_ *ebiten.Image
CacheData any // opaque *render.CacheTreeData — node/ never inspects
GlobalOrder int
TextureRegion_ types.TextureRegion
Color_ types.Color
// ---- WARM: local transform ----
X_, Y_ float64
ScaleX_ float64
ScaleY_ float64
Rotation_ float64
SkewX_, SkewY_ float64
PivotX_ float64
PivotY_ float64
// ---- COLD: hierarchy, identity, metadata ----
Parent *Node
Scene_ any // opaque *Scene — node/ never inspects
Name string
UserData any
// ---- COLD: pointers ----
Mesh *MeshData
Emitter *particle.Emitter
TextBlock *text.TextBlock
Callbacks *NodeCallbacks
MaskNode *Node
CacheTexture *ebiten.Image
// ---- COLD: interfaces and slices ----
HitShape types.HitShape
Filters []any // opaque []filter.Filter — node/ never inspects
// ---- COLD: functions ----
OnUpdate func(dt float64)
CustomEmit func(s any, treeOrder *int)
EmitFn EmitFn
// ---- COLD: int-sized ----
ZIndex_ int
ID uint32
EntityID uint32
// ---- COLD: bools (packed) ----
Interactable bool
Draggable bool
Pinchable bool
CacheEnabled bool
CacheDirty bool
Disposed bool
}
Node is the fundamental scene graph element. A single flat struct is used for all node types to avoid interface dispatch on the hot path.
func (*Node) AddChild ¶
AddChild appends child to this node's children. If child already has a parent, it is removed from that parent first.
func (*Node) AddChildAt ¶
AddChildAt inserts child at the given index.
func (*Node) CustomImage ¶
func (*Node) EnsureCallbacks ¶
func (n *Node) EnsureCallbacks() *NodeCallbacks
EnsureCallbacks lazily allocates the callback struct.
func (*Node) EnsureMesh ¶
func (*Node) FindChild ¶
FindChild returns the first direct child matching the name pattern, or nil.
func (*Node) FindDescendant ¶
FindDescendant returns the first descendant (depth-first) matching the name pattern.
func (*Node) GetOnClick ¶
func (n *Node) GetOnClick() func(ClickContext)
func (*Node) GetOnDrag ¶
func (n *Node) GetOnDrag() func(DragContext)
func (*Node) GetOnDragEnd ¶
func (n *Node) GetOnDragEnd() func(DragContext)
func (*Node) GetOnDragStart ¶
func (n *Node) GetOnDragStart() func(DragContext)
func (*Node) GetOnPinch ¶
func (n *Node) GetOnPinch() func(PinchContext)
func (*Node) GetOnPointerDown ¶
func (n *Node) GetOnPointerDown() func(PointerContext)
func (*Node) GetOnPointerEnter ¶
func (n *Node) GetOnPointerEnter() func(PointerContext)
func (*Node) GetOnPointerLeave ¶
func (n *Node) GetOnPointerLeave() func(PointerContext)
func (*Node) GetOnPointerMove ¶
func (n *Node) GetOnPointerMove() func(PointerContext)
func (*Node) GetOnPointerUp ¶
func (n *Node) GetOnPointerUp() func(PointerContext)
func (*Node) HasOnClick ¶
HasOnClick reports whether a click callback is registered.
func (*Node) HasOnDragEnd ¶
HasOnDragEnd reports whether a drag-end callback is registered.
func (*Node) HasOnDragStart ¶
HasOnDragStart reports whether a drag-start callback is registered.
func (*Node) HasOnPinch ¶
HasOnPinch reports whether a pinch callback is registered.
func (*Node) HasOnPointerDown ¶
HasOnPointerDown reports whether a pointer-down callback is registered.
func (*Node) HasOnPointerEnter ¶
HasOnPointerEnter reports whether a pointer-enter callback is registered.
func (*Node) HasOnPointerLeave ¶
HasOnPointerLeave reports whether a pointer-leave callback is registered.
func (*Node) HasOnPointerMove ¶
HasOnPointerMove reports whether a pointer-move callback is registered.
func (*Node) HasOnPointerUp ¶
HasOnPointerUp reports whether a pointer-up callback is registered.
func (*Node) Invalidate ¶
func (n *Node) Invalidate()
Invalidate marks the node's transform and alpha as dirty.
func (*Node) InvalidateCache ¶
func (n *Node) InvalidateCache()
func (*Node) InvalidateCacheTree ¶
func (n *Node) InvalidateCacheTree()
func (*Node) InvalidateMeshAABB ¶
func (n *Node) InvalidateMeshAABB()
func (*Node) IsCacheAsTreeEnabled ¶
func (*Node) IsCacheEnabled ¶
func (*Node) IsDisposed ¶
func (*Node) LocalToWorld ¶
func (*Node) MeshIndices ¶
func (*Node) MeshVertices ¶
func (*Node) NumChildren ¶
NumChildren returns the number of children.
func (*Node) OnClick ¶
func (n *Node) OnClick(fn func(ClickContext))
func (*Node) OnDrag ¶
func (n *Node) OnDrag(fn func(DragContext))
func (*Node) OnDragEnd ¶
func (n *Node) OnDragEnd(fn func(DragContext))
func (*Node) OnDragStart ¶
func (n *Node) OnDragStart(fn func(DragContext))
func (*Node) OnPinch ¶
func (n *Node) OnPinch(fn func(PinchContext))
func (*Node) OnPointerDown ¶
func (n *Node) OnPointerDown(fn func(PointerContext))
func (*Node) OnPointerEnter ¶
func (n *Node) OnPointerEnter(fn func(PointerContext))
func (*Node) OnPointerLeave ¶
func (n *Node) OnPointerLeave(fn func(PointerContext))
func (*Node) OnPointerMove ¶
func (n *Node) OnPointerMove(fn func(PointerContext))
func (*Node) OnPointerUp ¶
func (n *Node) OnPointerUp(fn func(PointerContext))
func (*Node) RemoveChild ¶
RemoveChild detaches child from this node.
func (*Node) RemoveChildAt ¶
RemoveChildAt removes and returns the child at the given index.
func (*Node) RemoveChildren ¶
func (n *Node) RemoveChildren()
RemoveChildren detaches all children from this node.
func (*Node) RemoveFromParent ¶
func (n *Node) RemoveFromParent()
RemoveFromParent detaches this node from its parent.
func (*Node) Renderable ¶
func (*Node) Scene ¶
Scene returns the Scene this node belongs to, or nil if not in a scene graph. Returns any because node/ cannot import the root package. Callers in root should type-assert to *Scene.
func (*Node) SetBlendMode ¶
func (*Node) SetCacheAsTexture ¶
func (*Node) SetCacheAsTree ¶
func (n *Node) SetCacheAsTree(enabled bool, mode ...types.CacheTreeMode)
func (*Node) SetChildIndex ¶
SetChildIndex moves child to a new index among its siblings.
func (*Node) SetContent ¶
func (*Node) SetCustomImage ¶
func (*Node) SetFontSize ¶
func (*Node) SetGlobalOrder ¶
func (*Node) SetLineHeight ¶
func (*Node) SetMeshData ¶
func (*Node) SetMeshImage ¶
func (*Node) SetMeshIndices ¶
func (*Node) SetMeshVertices ¶
func (*Node) SetPosition ¶
func (*Node) SetRenderLayer ¶
func (*Node) SetRenderable ¶
func (*Node) SetRotation ¶
func (*Node) SetTextColor ¶
func (*Node) SetTextEffects ¶
func (n *Node) SetTextEffects(e *text.TextEffects)
func (*Node) SetTextureRegion ¶
func (n *Node) SetTextureRegion(r types.TextureRegion)
func (*Node) SetVisible ¶
func (*Node) SetWrapWidth ¶
func (*Node) TextureRegion ¶
func (n *Node) TextureRegion() types.TextureRegion
func (*Node) WorldToLocal ¶
type NodeCallbacks ¶
type NodeCallbacks struct {
OnPointerDown func(PointerContext)
OnPointerUp func(PointerContext)
OnPointerMove func(PointerContext)
OnClick func(ClickContext)
OnDragStart func(DragContext)
OnDrag func(DragContext)
OnDragEnd func(DragContext)
OnPinch func(PinchContext)
OnPointerEnter func(PointerContext)
OnPointerLeave func(PointerContext)
}
NodeCallbacks holds per-node event handler functions. Allocated on first callback setter call. Most nodes never receive callbacks.
type NodeIndex ¶
type NodeIndex struct {
// contains filtered or unexported fields
}
NodeIndex is an opt-in registry for looking up nodes by name or tag.
func (*NodeIndex) CountByTag ¶
CountByTag returns the number of nodes with the given tag.
func (*NodeIndex) FindAllByName ¶
FindAllByName returns all registered nodes matching the name pattern.
func (*NodeIndex) FindByName ¶
FindByName returns the first registered node matching the name pattern.
func (*NodeIndex) FindByTags ¶
FindByTags returns all nodes that have every one of the given tags.
type PinchContext ¶
type PinchContext struct {
CenterX, CenterY float64 // midpoint between the two touch points in world coordinates
Scale, ScaleDelta float64 // cumulative scale factor and frame-to-frame change
Rotation, RotDelta float64 // cumulative rotation (radians) and frame-to-frame change
}
PinchContext carries two-finger pinch/rotate gesture data.
type PointerContext ¶
type PointerContext struct {
Node *Node // the node under the pointer, or nil if none
EntityID uint32 // the hit node's EntityID (for ECS bridging)
UserData any // the hit node's UserData
GlobalX float64 // pointer X in world coordinates
GlobalY float64 // pointer Y in world coordinates
LocalX float64 // pointer X in the hit node's local coordinates
LocalY float64 // pointer Y in the hit node's local coordinates
Button types.MouseButton // which mouse button is involved
PointerID int // 0 = mouse, 1-9 = touch contacts
Modifiers types.KeyModifiers // keyboard modifier keys held during the event
}
PointerContext carries pointer event data passed to pointer callbacks.
type WildMode ¶
type WildMode byte
WildMode describes the type of % wildcard match.
func ParsePattern ¶
ParsePattern checks for % wildcards at the start/end of pattern.