uidir

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 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 Current is a single read of the top.

An entry also carries a text direction (Scope): a scope given bellui.TextDirectionFirstStrong leaves layout as it is and makes the text drawn inside it, whose own direction is automatic, take its direction from its letters (#1733). A pushed entry is combined with the one below it, so the top holds both directions in effect and Text is a single read too.

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 Layout added in v1.10.0

func Layout(d bellui.Direction) bellui.Direction

Layout returns d as a layout direction: bellui.TextDirectionFirstStrong, which a direction setting shares a type with but which is a text direction only, is bellui.DirectionAuto.

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 PopScope added in v1.10.0

func PopScope(s Scope)

PopScope removes what the matching PushScope installed.

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 Scope, 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 PushScope added in v1.10.0

func PushScope(s Scope)

PushScope is Push for both directions of a scope: s combined with the directions already in effect, until the matching PopScope.

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 Scope,
)

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

func Text added in v1.10.0

func Text() bellui.Direction

Text returns the ambient text direction on the calling goroutine: bellui.TextDirectionFirstStrong inside a scope that makes text take its direction from its letters, else DirectionAuto (#1733).

Types

type Scope added in v1.10.0

type Scope struct {
	Dir, Text bellui.Direction
}

Scope is what a direction scope applies to its subtree: a layout direction, and a text direction for the text drawn inside whose own direction is automatic. Dir is LTR, RTL or DirectionAuto, the enclosing one; Text is bellui.TextDirectionFirstStrong or DirectionAuto, the enclosing one (#1733).

func Ambient added in v1.10.0

func Ambient() (Scope, bool)

Ambient returns the directions in effect on the calling goroutine, combined from every scope pushed; ok is false when nothing is pushed.

func Inherited added in v1.3.0

func Inherited(obj core.CanvasObject) (Scope, bool)

Inherited returns the directions 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 ScopeOf added in v1.10.0

func ScopeOf(d bellui.Direction) Scope

ScopeOf is the Scope a direction setting d gives: bellui.TextDirectionFirstStrong is a text direction only, any other d a layout direction.

func (Scope) IsZero added in v1.10.0

func (s Scope) IsZero() bool

IsZero reports whether s applies nothing: both directions automatic.

func (Scope) Key added in v1.10.0

func (s Scope) Key() uint8

Key is s as one byte, for a cache key: a cache of drawn or shaped text keys on the directions in effect where it is drawn, and a wider key costs every lookup its hash (#1733).

func (Scope) Within added in v1.10.0

func (s Scope) Within(outer Scope) Scope

Within is s inside outer: each direction s leaves automatic is outer's.

Jump to

Keyboard shortcuts

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