uidir

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 7 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 uidir holds an ambient, per-goroutine user-interface direction override. It is the layout-direction analogue of the per-goroutine theme stack in internal/theme: a github.com/belluikit/bellui/container.DirectionScope (or a direction-scoped window canvas) pushes its direction while it lays out and paints its subtree, so the canvas-free layout, measurement and shaping code that resolves direction through lang.IsRTLDirection picks up the scoped value instead of the process-global one.

Callers push only concrete directions (LTR or RTL); a DirectionAuto scope is a no-op that defers to the enclosing scope or the global setting, so the stack never contains DirectionAuto and Current is a single read of the top.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Current

func Current() (bellui.Direction, bool)

Current returns the ambient direction override in effect on the calling goroutine, if any. The bool is false when no scope is active, in which case callers fall back to the process-global direction. The returned direction is always concrete (LTR or RTL); see the package comment.

func ForgetInherited added in v1.3.0

func ForgetInherited(overlay core.CanvasObject)

ForgetInherited drops overlay's inherited direction, if it has one.

func Inherited added in v1.3.0

func Inherited(obj core.CanvasObject) (bellui.Direction, bool)

Inherited returns the direction obj, an overlay, took from its opener; ok is false when it took none. It is a single atomic load while no overlay has one, and takes no lock otherwise.

func Mark

func Mark() int

Mark returns the calling goroutine's current direction-stack depth. Pair it with Restore (typically via defer) around a tree walk that does per-node Push/Pop in separate visitor callbacks: if a draw or layout panic unwinds past the matching Pops, Restore discards the orphaned entries so the per-goroutine stack does not leak and corrupt later direction resolution.

func NoteDirectedCanvas added in v1.3.0

func NoteDirectedCanvas()

NoteDirectedCanvas records that a canvas was given a direction of its own (Canvas.SetDirection), so re-layout outside a walk must ask for an object's direction from now on (internal/dirhook). Unlike NoteScope it does not make a lookup walk for scopes.

func NoteScope added in v1.3.0

func NoteScope()

NoteScope records that a direction scope exists. A scope calls it when its renderer is created, which precedes it having any laid-out content.

func Pop

func Pop(d bellui.Direction)

Pop removes the direction installed by the matching Push. A Pop balancing a bellui.DirectionAuto Push (which pushed nothing) is a no-op.

func PopOwned added in v1.3.0

func PopOwned(owner core.CanvasObject, mayBeScope bool)

PopOwned removes the direction owner pushed with PushOwned, if it pushed one: the top entry, when owner is its owner. mayBeScope is false for an object that is not a direction scope, which can only have pushed as an overlay: while no overlay has pushed, that is a single atomic load.

func PopTop added in v1.3.0

func PopTop()

PopTop removes the calling goroutine's top direction, whatever pushed it: the pop for a push the caller knows it made with a concrete direction.

func Push

func Push(d bellui.Direction)

Push installs d as the ambient direction for the calling goroutine until the matching Pop. It is called by a direction scope around the layout and paint of its subtree. Pushing bellui.DirectionAuto is a no-op so that an automatic scope transparently inherits the enclosing direction.

func PushOwned added in v1.3.0

func PushOwned(d bellui.Direction, owner core.CanvasObject, overlay bool)

PushOwned pushes d for owner, an object a walk visits, until the matching PopOwned for owner. A walk pairs them in its before- and after-children callbacks: the pop removes what owner pushed, if anything, even when owner's direction changed in between (#749). overlay marks an overlay that pushes a direction it inherited (see SetInherited).

func RegisterScope added in v1.3.0

func RegisterScope(get func() core.CanvasObject)

RegisterScope records a rendered direction scope; get returns it, or nil once it is gone (a weak reference, so the registry keeps nothing alive).

func Restore

func Restore(depth int)

Restore truncates the calling goroutine's direction stack back to the depth returned by an earlier Mark. On the normal balanced-Pop path the stack is already at that depth, so Restore is a no-op; it only acts when a panic left entries pushed after the Mark.

func Scopes added in v1.3.0

func Scopes() []core.CanvasObject

Scopes returns the registered scopes still alive, and the overlays that inherited a direction, dropping the scopes that are gone.

func ScopesInUse added in v1.3.0

func ScopesInUse() bool

ScopesInUse reports whether any direction scope has been rendered, or an overlay inherited a direction, in this process; see NoteScope.

func SetInherited added in v1.3.0

func SetInherited[T any, P interface {
	*T
	core.CanvasObject
}](overlay P, d bellui.Direction,
)

SetInherited makes overlay lay out and paint its subtree in d, as a direction scope around it would. A DirectionAuto d forgets overlay.

Types

This section is empty.

Jump to

Keyboard shortcuts

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