common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: BSD-3-Clause Imports: 23 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

Index

Constants

View Source
const (
	TapMoveDecay        = 0.92                   // scroll continue decay per frame
	TapMoveEndThreshold = 2.0                    // offset threshold to stop decay
	TapMoveThreshold    = 4.0                    // movement before drag begins
	TapSecondaryDelay   = 300 * time.Millisecond // long-press for secondary tap
	TapDoubleDelay      = 500 * time.Millisecond // max gap between double-tap
)

Tap handling constants shared by mobile and embedded drivers.

Variables

View Source
var DonePool = async.Pool[chan struct{}]{
	New: func() chan struct{} {
		return make(chan struct{})
	},
}

Functions

func BuiltinKeyboardShortcut

func BuiltinKeyboardShortcut(key event.KeyName, clip bellui.Clipboard) core.Shortcut

BuiltinKeyboardShortcut returns the standard editing shortcut bound to a key pressed with the platform shortcut modifier held (Control, or Super on macOS), or nil when the key is not one of the built-ins. Clipboard shortcuts (Copy/Cut/Paste) are given clip. Shared by the desktop (glfw) and mobile drivers so both map the same keys to the same shortcuts (#1077).

func CanvasForObject

func CanvasForObject(obj core.CanvasObject) core.Canvas

CanvasForObject returns the canvas for the specified object.

func DragDecay

func DragDecay(delta geo.Delta) geo.Delta

DragDecay implements momentum-based scroll decay after a drag ends. Call this from a ticker/animation callback, passing the last drag delta. Returns the decayed delta, or zero if below threshold.

func RectsOverlap

func RectsOverlap(aPos geo.Position, aSize geo.Size, bPos geo.Position, bSize geo.Size) bool

RectsOverlap reports whether two axis-aligned rectangles intersect. Used by the drivers to cull objects that fall outside the partial-repaint region.

func RegionCoversCanvas

func RegionCoversCanvas(region, canvas geo.Size) bool

RegionCoversCanvas reports whether a dirty region is large enough that a partial repaint saves little, so a plain full clear is preferable.

Types

type Canvas

type Canvas struct {
	OnFocus   func(obj event.Focusable)
	OnUnfocus func()
	// contains filtered or unexported fields
}

Canvas defines common canvas implementation.

func (*Canvas) AddShortcut

func (c *Canvas) AddShortcut(shortcut core.Shortcut, handler func(shortcut core.Shortcut))

AddShortcut adds a shortcut to the canvas.

func (*Canvas) CheckDirtyAndClear

func (c *Canvas) CheckDirtyAndClear() bool

CheckDirtyAndClear returns true if the canvas is dirty and clears the dirty state atomically.

func (*Canvas) Direction

func (c *Canvas) Direction() bellui.Direction

Direction returns the per-canvas user-interface direction set by Canvas.SetDirection. The default github.com/belluikit/bellui.DirectionAuto defers to the process-global github.com/belluikit/bellui.SetLayoutDirection.

func (*Canvas) DirtyRegion

func (c *Canvas) DirtyRegion() (pos geo.Position, size geo.Size, set bool)

DirtyRegion returns the accumulated dirty region from the last FreeDirtyTextures call. If set is false, the region is undefined and a full repaint is needed.

func (*Canvas) DrawDebugOverlay

func (c *Canvas) DrawDebugOverlay(obj core.CanvasObject, pos geo.Position, size geo.Size)

func (*Canvas) EnsureMinSize

func (c *Canvas) EnsureMinSize() bool

EnsureMinSize ensure canvas min size.

This function uses lock.

func (*Canvas) Focus

func (c *Canvas) Focus(obj event.Focusable)

Focus makes the provided item focused.

func (*Canvas) FocusGained

func (c *Canvas) FocusGained()

FocusGained signals to the manager that its content got focus. Valid only on Desktop.

func (*Canvas) FocusLost

func (c *Canvas) FocusLost()

FocusLost signals to the manager that its content lost focus. Valid only on Desktop.

func (*Canvas) FocusNext

func (c *Canvas) FocusNext()

FocusNext focuses the next focusable item.

func (*Canvas) FocusPrevious

func (c *Canvas) FocusPrevious()

FocusPrevious focuses the previous focusable item.

func (*Canvas) Focused

func (c *Canvas) Focused() event.Focusable

Focused returns the current focused object.

func (*Canvas) FreeDirtyTextures

func (c *Canvas) FreeDirtyTextures() uint64

FreeDirtyTextures frees dirty textures and returns the number of freed textures.

func (*Canvas) Initialize

func (c *Canvas) Initialize(impl SizeableCanvas, onOverlayChanged func())

Initialize initializes the canvas.

func (*Canvas) IsDirty

func (c *Canvas) IsDirty() bool

IsDirty reports whether the canvas has changes that have not been painted yet, without clearing the flag. While it is true the spatial index has not been rebuilt since the last change, so hit testing must not rely on it.

func (*Canvas) NodeFor

func (c *Canvas) NodeFor(obj core.CanvasObject) (*RenderCacheNode, bool)

NodeFor returns the RenderCacheNode for the given object, if it exists.

func (*Canvas) ObjectTrees

func (c *Canvas) ObjectTrees() []core.CanvasObject

ObjectTrees return canvas object trees.

This function uses lock.

func (*Canvas) Overlays

func (c *Canvas) Overlays() core.OverlayStack

Overlays returns the overlay stack.

func (*Canvas) Painter

func (c *Canvas) Painter() gpu.Painter

Painter returns the canvas painter.

func (*Canvas) PartialDirtyRegion

func (c *Canvas) PartialDirtyRegion() (pos geo.Position, size geo.Size, set bool)

PartialDirtyRegion runs a draw-free walk that recomputes world transforms and returns the region of the canvas that must be cleared and redrawn this frame: the union, over every object that was refreshed or has moved/resized since the previous paint, of both its previous and its current world-space bounds (so a move clears where it left as well as where it lands), padded for anti-aliased edges. Refreshed objects additionally contribute their whole subtree so overflow children (shadows, ripples, focus rings) are covered. Each node's recorded bounds are advanced to the current frame. set is false when nothing changed, in which case the caller can skip the redraw entirely.

Only meaningful under the partialrepaint build tag; the per-node bookkeeping it relies on is otherwise never populated.

func (*Canvas) RebuildSpatialIndex

func (c *Canvas) RebuildSpatialIndex()

RebuildSpatialIndex walks the render cache trees and populates a new SpatialIndex from the cached world transforms and clip bounds.

func (*Canvas) Refresh

func (c *Canvas) Refresh(obj core.CanvasObject)

Refresh refreshes a canvas object.

func (*Canvas) RemoveShortcut

func (c *Canvas) RemoveShortcut(shortcut core.Shortcut)

RemoveShortcut removes a shortcut from the canvas.

func (*Canvas) SetContentTreeAndFocusMgr

func (c *Canvas) SetContentTreeAndFocusMgr(content core.CanvasObject)

SetContentTreeAndFocusMgr sets content tree and focus manager.

This function does not use the canvas lock.

func (*Canvas) SetDirection

func (c *Canvas) SetDirection(d bellui.Direction)

SetDirection overrides the user-interface direction for this canvas' whole content, regardless of the process-global setting, so one window can flow left-to-right inside a right-to-left application (or vice versa). Passing github.com/belluikit/bellui.DirectionAuto restores the global setting. The content is re-laid-out and repainted to apply the change.

func (*Canvas) SetDirty

func (c *Canvas) SetDirty()

SetDirty sets canvas dirty flag atomically.

func (*Canvas) SetMenuTreeAndFocusMgr

func (c *Canvas) SetMenuTreeAndFocusMgr(menu core.CanvasObject)

SetMenuTreeAndFocusMgr sets menu tree and focus manager.

This function does not use the canvas lock.

func (*Canvas) SetMobileWindowHeadTree

func (c *Canvas) SetMobileWindowHeadTree(head core.CanvasObject)

SetMobileWindowHeadTree sets window head tree.

This function does not use the canvas lock.

func (*Canvas) SetPainter

func (c *Canvas) SetPainter(p gpu.Painter)

SetPainter sets the canvas painter.

func (*Canvas) SpatialIndex

func (c *Canvas) SpatialIndex() *SpatialIndex

SpatialIndex returns the current spatial index for broadphase hit testing. May return nil if the index has not been built yet.

func (*Canvas) TypedShortcut

func (c *Canvas) TypedShortcut(shortcut core.Shortcut)

TypedShortcut handle the registered shortcut.

func (*Canvas) Unfocus

func (c *Canvas) Unfocus()

Unfocus unfocuses all the objects in the canvas.

func (*Canvas) WalkContentTrees

func (c *Canvas) WalkContentTrees(
	beforeChildren func(*RenderCacheNode, geo.Position),
	afterChildren func(*RenderCacheNode, geo.Position),
)

WalkContentTrees walks content, window head, and menu trees (not overlays).

func (*Canvas) WalkOverlayTrees

func (c *Canvas) WalkOverlayTrees(
	beforeChildren func(*RenderCacheNode, geo.Position),
	afterChildren func(*RenderCacheNode, geo.Position),
)

WalkOverlayTrees walks overlay trees only.

func (*Canvas) WalkTrees

func (c *Canvas) WalkTrees(
	beforeChildren func(*RenderCacheNode, geo.Position),
	afterChildren func(*RenderCacheNode, geo.Position),
)

WalkTrees walks over all trees (content, menu, overlays) and rebuilds the spatial index.

type ObjectFinder

type ObjectFinder interface {
	FindObjectAtPositionMatching(pos geo.Position, test func(core.CanvasObject) bool) (core.CanvasObject, geo.Position, int)
	CanvasForTouch() core.Canvas
}

ObjectFinder locates objects at a position on a canvas. This abstracts the difference between mobile (uses overlay stack) and embedded (uses FindObjectAtPositionMatching directly).

type RenderCacheNode

type RenderCacheNode struct {
	// contains filtered or unexported fields
}

RenderCacheNode represents a node in a render cache tree.

func (*RenderCacheNode) IsBoundary

func (r *RenderCacheNode) IsBoundary() bool

IsBoundary returns true if this node is a RepaintBoundary.

func (*RenderCacheNode) Obj

Obj returns the node object.

func (*RenderCacheNode) Parent

func (r *RenderCacheNode) Parent() *RenderCacheNode

Parent returns the parent node, or nil for root nodes.

func (*RenderCacheNode) WorldTransform

func (r *RenderCacheNode) WorldTransform() geo.Matrix

WorldTransform returns the composed affine transform from root to this node. It incorporates all ancestor transforms plus this node's local transform.

type SizeableCanvas

type SizeableCanvas interface {
	core.Canvas
	Resize(geo.Size)
	MinSize() geo.Size
}

SizeableCanvas defines a canvas with size related functions.

type SpatialIndex

type SpatialIndex struct {
	// contains filtered or unexported fields
}

SpatialIndex provides O(1) broadphase hit testing via a uniform grid.

The canvas is divided into cells of fixed size. Each cell contains a list of [spatialEntry] values whose screen-space AABB overlaps that cell. Entries are inserted in DFS order during the tree walk so that within each cell the last matching entry is the deepest (innermost) object — matching the existing "last match wins" semantics.

The index is immutable once built and safe for concurrent reads.

func (*SpatialIndex) FindAllObjectsAtPositionMatching

func (idx *SpatialIndex) FindAllObjectsAtPositionMatching(
	mouse geo.Position,
	matches func(core.CanvasObject) bool,
) []driver.ObjectAtPosition

FindAllObjectsAtPositionMatching returns all matching objects at mouse, ordered from deepest (innermost) to shallowest (outermost). This is used for scroll event propagation.

func (*SpatialIndex) FindObjectAtPositionMatching

func (idx *SpatialIndex) FindObjectAtPositionMatching(
	mouse geo.Position,
	matches func(core.CanvasObject) bool,
) (core.CanvasObject, geo.Position, bool)

FindObjectAtPositionMatching finds the deepest object at mouse whose screen-space AABB and clip bounds contain the point, that passes the narrowphase inverse-transform test, and for which matches returns true.

The return values mirror driver.FindObjectAtPositionMatching: the matched object, the mouse position in object-local coordinates, and a boolean indicating whether a match was found.

type TouchHandler

type TouchHandler struct {
	Finder ObjectFinder

	LastTapDown    map[int]time.Time
	LastTapDownPos map[int]geo.Position
	LastTapDelta   map[int]geo.Delta

	DragOffset geo.Position
	DragStart  geo.Position
	Dragging   event.Draggable

	Touched         map[int]mobile.Touchable
	TouchCancelFunc context.CancelFunc
	TouchCancelLock sync.Mutex
	TouchLastTapped core.CanvasObject
	TouchTapCount   int

	// OnTapUp is an optional hook called at the start of TapUp, before
	// tap/drag processing. If it returns true, tap processing is skipped
	// (the hook handled the event). Used by mobile for menu dismissal.
	OnTapUp func(pos geo.Position) bool

	// ScrollCallback, when set by the driver, enables touch flick-scrolling of
	// scrollable content (#291): a move past the tap slop that latches no
	// Draggable but began over an event.Scrollable becomes a scroll gesture —
	// every move calls this with the gesture origin and the move's delta, and
	// the driver turns it into a touch-sourced ScrollEvent (which buys nested
	// propagation from its scroll dispatch). Drivers whose Scroll is itself
	// Draggable (mobile) leave this nil and nothing changes for them.
	ScrollCallback func(origin geo.Position, delta geo.Delta)
	// ScrollEndCallback is called when a scroll gesture's contact lifts, with
	// the last move's delta as the momentum seed. A system cancel ends the
	// gesture without it — momentum from a contact the system took over would
	// keep content moving after a palm rejection.
	ScrollEndCallback func(origin geo.Position, delta geo.Delta)

	// LongPressCallback, when set by the driver, enables hold-fire long-press
	// (#758): a stationary touch dispatches LongPressed at TapSecondaryDelay
	// while the finger is still down — native mobile behavior — instead of on
	// release. The release of a hold-fired touch then dispatches
	// SecondaryTappable, so a widget implementing both gets "select on hold,
	// menu on lift". Targets that are not LongPressable keep the release-time
	// handling in TapUp unchanged.
	LongPressCallback func(event.LongPressable, *event.PointEvent)
	// contains filtered or unexported fields
}

TouchHandler implements tap, drag, and double-tap event handling logic shared between mobile and embedded drivers. Embed this struct and provide an ObjectFinder.

func (*TouchHandler) InitTouchHandler

func (h *TouchHandler) InitTouchHandler(finder ObjectFinder)

InitTouchHandler initializes the maps. Call from the canvas constructor.

func (*TouchHandler) TapCancel

func (h *TouchHandler) TapCancel(pos geo.Position, tapID int)

TapCancel handles a system-cancelled touch sequence (the desktop driver's glfw TouchCancel, #266): the system took the contact over — e.g. a palm rejection or an edge gesture — so the gesture must end without dispatching any tap. A pending hold-fire and tooltip are cancelled, a Touchable gets TouchCancel, and a drag this contact latched gets DragEnd (the drag's effect so far stands; there is no undo protocol for Draggable) — a drag some other contact owns is left alone, which is the point of a palm rejection arriving mid-drag. pos is the last known contact position — it may be zero where the platform does not report one, so it is used for the cancel event only, never for hit testing.

func (*TouchHandler) TapDown

func (h *TouchHandler) TapDown(pos geo.Position, tapID int)

TapDown handles a pointer-down event.

func (*TouchHandler) TapMove

func (h *TouchHandler) TapMove(pos geo.Position, tapID int,
	dragCallback func(event.Draggable, *event.DragEvent),
)

TapMove handles a pointer-move event (potential drag).

func (*TouchHandler) TapUp

func (h *TouchHandler) TapUp(pos geo.Position, tapID int,
	tapCallback func(event.Tappable, *event.PointEvent),
	tapAltCallback func(event.SecondaryTappable, *event.PointEvent),
	longPressCallback func(event.LongPressable, *event.PointEvent),
	doubleTapCallback func(event.DoubleTappable, *event.PointEvent),
	dragCallback func(event.Draggable, *event.DragEvent),
)

TapUp handles a pointer-up event (tap, secondary tap, long-press, or drag end).

Jump to

Keyboard shortcuts

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