Documentation
¶
Index ¶
- Constants
- Variables
- func BuiltinKeyboardShortcut(key event.KeyName, clip bellui.Clipboard) core.Shortcut
- func CanvasForObject(obj core.CanvasObject) core.Canvas
- func DragDecay(delta geo.Delta) geo.Delta
- func RectsOverlap(aPos geo.Position, aSize geo.Size, bPos geo.Position, bSize geo.Size) bool
- func RegionCoversCanvas(region, canvas geo.Size) bool
- type Canvas
- func (c *Canvas) AddShortcut(shortcut core.Shortcut, handler func(shortcut core.Shortcut))
- func (c *Canvas) CheckDirtyAndClear() bool
- func (c *Canvas) Direction() bellui.Direction
- func (c *Canvas) DirtyRegion() (pos geo.Position, size geo.Size, set bool)
- func (c *Canvas) DrawDebugOverlay(obj core.CanvasObject, pos geo.Position, size geo.Size)
- func (c *Canvas) EnsureMinSize() bool
- func (c *Canvas) Focus(obj event.Focusable)
- func (c *Canvas) FocusGained()
- func (c *Canvas) FocusLost()
- func (c *Canvas) FocusNext()
- func (c *Canvas) FocusPrevious()
- func (c *Canvas) Focused() event.Focusable
- func (c *Canvas) FreeDirtyTextures() uint64
- func (c *Canvas) Initialize(impl SizeableCanvas, onOverlayChanged func())
- func (c *Canvas) IsDirty() bool
- func (c *Canvas) NodeFor(obj core.CanvasObject) (*RenderCacheNode, bool)
- func (c *Canvas) ObjectTrees() []core.CanvasObject
- func (c *Canvas) Overlays() core.OverlayStack
- func (c *Canvas) Painter() gpu.Painter
- func (c *Canvas) PartialDirtyRegion() (pos geo.Position, size geo.Size, set bool)
- func (c *Canvas) RebuildSpatialIndex()
- func (c *Canvas) Refresh(obj core.CanvasObject)
- func (c *Canvas) RemoveShortcut(shortcut core.Shortcut)
- func (c *Canvas) SetContentTreeAndFocusMgr(content core.CanvasObject)
- func (c *Canvas) SetDirection(d bellui.Direction)
- func (c *Canvas) SetDirty()
- func (c *Canvas) SetMenuTreeAndFocusMgr(menu core.CanvasObject)
- func (c *Canvas) SetMobileWindowHeadTree(head core.CanvasObject)
- func (c *Canvas) SetPainter(p gpu.Painter)
- func (c *Canvas) SpatialIndex() *SpatialIndex
- func (c *Canvas) TypedShortcut(shortcut core.Shortcut)
- func (c *Canvas) Unfocus()
- func (c *Canvas) WalkContentTrees(beforeChildren func(*RenderCacheNode, geo.Position), ...)
- func (c *Canvas) WalkOverlayTrees(beforeChildren func(*RenderCacheNode, geo.Position), ...)
- func (c *Canvas) WalkTrees(beforeChildren func(*RenderCacheNode, geo.Position), ...)
- type ObjectFinder
- type RenderCacheNode
- type SizeableCanvas
- type SpatialIndex
- type TouchHandler
- func (h *TouchHandler) CancelPendingTap()
- func (h *TouchHandler) InitTouchHandler(finder ObjectFinder)
- func (h *TouchHandler) TapCancel(pos geo.Position, tapID int)
- func (h *TouchHandler) TapDown(pos geo.Position, tapID int)
- func (h *TouchHandler) TapMove(pos geo.Position, tapID int, ...)
- func (h *TouchHandler) TapUp(pos geo.Position, tapID int, ...)
Constants ¶
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 ¶
var DonePool = async.Pool[chan struct{}]{ New: func() chan struct{} { return make(chan struct{}) }, }
Functions ¶
func BuiltinKeyboardShortcut ¶
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 (pre-rebrand tracker #1077).
func CanvasForObject ¶
func CanvasForObject(obj core.CanvasObject) core.Canvas
CanvasForObject returns the canvas for the specified object.
func DragDecay ¶
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 ¶
RectsOverlap reports whether two axis-aligned rectangles intersect. Used by the drivers to cull objects that fall outside the partial-repaint region.
func RegionCoversCanvas ¶
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 ¶
AddShortcut adds a shortcut to the canvas.
func (*Canvas) CheckDirtyAndClear ¶
CheckDirtyAndClear returns true if the canvas is dirty and clears the dirty state atomically.
func (*Canvas) 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 ¶
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 (*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) FocusPrevious ¶
func (c *Canvas) FocusPrevious()
FocusPrevious focuses the previous focusable item.
func (*Canvas) FreeDirtyTextures ¶
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 ¶
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) PartialDirtyRegion ¶
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 ¶
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 ¶
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) 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 ¶
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 ¶
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 ¶
func (r *RenderCacheNode) Obj() core.CanvasObject
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 ¶
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
// (pre-rebrand tracker #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) CancelPendingTap ¶ added in v1.1.0
func (h *TouchHandler) CancelPendingTap()
CancelPendingTap abandons a double-tap wait that has not fired yet. Call it when the canvas those taps were dispatched against goes away — a window closing, a driver shutting down.
Cancelling the context alone is not enough and never was: that is how a SECOND tap tells the waiter to fire early as a double tap, so it makes the dispatch happen rather than preventing it. The generation bump is what distinguishes "fire now" from "do not fire at all".
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).