Documentation
¶
Index ¶
- Constants
- Variables
- func BuiltinKeyboardShortcut(key event.KeyName, clip bellui.Clipboard) core.Shortcut
- func CanvasForObject(obj core.CanvasObject) core.Canvas
- func ClampRegionToCanvas(pos geo.Position, sz geo.Size, size geo.Size) (geo.Position, geo.Size)
- func CullOffClip(obj core.CanvasObject, pos, clipPos geo.Position, clipSize geo.Size) bool
- func DragDecay(delta geo.Delta) geo.Delta
- func InDirtyRegion(pos geo.Position, size geo.Size, rPos geo.Position, rSize geo.Size) bool
- func PaintClips(node *RenderCacheNode) driver.Clips
- func PaintExtent(obj core.CanvasObject) (geo.Position, geo.Size)
- func RectsOverlap(aPos geo.Position, aSize geo.Size, bPos geo.Position, bSize geo.Size) bool
- func RegionCoversCanvas(region, canvas geo.Size) bool
- type BoundaryGeometry
- type BoundaryPhase
- type Canvas
- func (c *Canvas) AddShortcut(shortcut core.Shortcut, handler func(shortcut core.Shortcut))
- func (c *Canvas) CheckDirtyAndClear() bool
- func (c *Canvas) CullOffClip(obj core.CanvasObject, pos, clipPos geo.Position, clipSize geo.Size) 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) MarkDirtyRect(pos geo.Position, size geo.Size)
- func (c *Canvas) MarkFullRepaint()
- func (c *Canvas) MarkMinSizeDirty(obj core.CanvasObject)
- func (c *Canvas) MarkPlacementDirty(obj core.CanvasObject)
- func (c *Canvas) MinSizeVisits() int
- 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) RegionVisits() int
- 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) WalkContentTreesCulled(cull driver.CullFunc, 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
- func (r *RenderCacheNode) BoundaryRenderedAt(phase BoundaryPhase) bool
- func (r *RenderCacheNode) IsBoundary() bool
- func (r *RenderCacheNode) Obj() core.CanvasObject
- func (r *RenderCacheNode) Parent() *RenderCacheNode
- func (r *RenderCacheNode) SetBoundaryRenderedAt(phase BoundaryPhase)
- func (r *RenderCacheNode) WorldTransform() geo.Matrix
- 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 ClampRegionToCanvas ¶ added in v1.2.0
ClampRegionToCanvas intersects a dirty region with the canvas [0,0]-(size) box, returning a zero-size region when it falls entirely outside.
func CullOffClip ¶ added in v1.2.0
CullOffClip is the paint walk's CullFunc: it culls a clip-owner (a scroll, a ClipToBounds container, a rounded clip such as a Card) whose bounds, widened by cullMargin and by its own shadow, miss the clip. A clip-owner's descendants draw inside its bounds, so nothing of the subtree can show. An object that owns no clip may draw outside its bounds, and is never culled.
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 InDirtyRegion ¶ added in v1.2.0
InDirtyRegion reports whether the rect (pos, size) needs repainting under a partial repaint of the region (rPos, rSize). An empty region, a frame with nothing dirty, holds nothing. By overlap alone, a rect reaching across the empty region at (0, 0) would count as inside it and be painted unclipped, over pixels nothing else repainted (#605).
func PaintClips ¶ added in v1.2.0
func PaintClips(node *RenderCacheNode) driver.Clips
PaintClips is the clips a paint walk sets up for node's object: none for a clip-owner whose children the walk culled, as they would constrain nothing (#481). Each one costs the painter a stencil or scissor change.
func PaintExtent ¶ added in v1.2.0
PaintExtent returns the box obj's painters draw in, relative to its position: its bounds, grown to what the painters draw past them. A text is drawn at its MinSize whatever its own size, so one positioned but never resized still draws its glyphs (#602), on the side its alignment puts them; a stroke, an italic lean or a path reaching outside its size overflows by the painters' VectorPad; a box shadow's blur spreads around its offset box.
Partial repaint decides from this box whether an object needs repainting, and records it as where the object was painted, so pixels an object draws outside it would be cleared and never redrawn.
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 BoundaryGeometry ¶ added in v1.2.0
type BoundaryGeometry struct {
// Origin is the texture's top-left corner, where it is blitted: the
// boundary's position snapped down to a device pixel, less the margin.
Origin geo.Position
// PixW and PixH are the texture's size in device pixels, covering the
// boundary and the margin around it.
PixW, PixH int
// Size is the texture's size in canvas units.
Size geo.Size
// Phase is how far the boundary's content sits from the pixel grid.
Phase BoundaryPhase
}
BoundaryGeometry is where a RepaintBoundary is rendered and drawn.
func BoundaryGeometryFor ¶ added in v1.2.0
BoundaryGeometryFor places a RepaintBoundary at pos with size, on a canvas of pxPerUnit device pixels per unit. Rendering its content at pos - Origin keeps the sub-pixel offset it would have drawn directly, and blitting the texture at Origin is a copy, pixel for pixel. A texture placed at pos instead drew its content on another sub-pixel grid and resampled it, so edges came out differently from drawing in place (#570).
type BoundaryPhase ¶ added in v1.2.0
type BoundaryPhase struct{ X, Y int32 }
BoundaryPhase is the sub-pixel offset, in 1/boundaryPhaseSteps of a device pixel, of a RepaintBoundary's content from the pixel grid.
type Canvas ¶
type Canvas struct {
OnFocus func(obj event.Focusable)
OnUnfocus func()
// FixedSize is set by drivers whose window cannot grow to fit its content
// (the browser, where the window is the page's viewport). Content larger
// than the canvas is then clipped instead of the canvas growing past the
// window: a canvas laid out wider than the viewport was drawn squeezed
// into it until the next window resize (#387).
FixedSize bool
// 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. Call it on the main goroutine only: the flag has no lock.
func (*Canvas) CullOffClip ¶ added in v1.2.0
func (c *Canvas) CullOffClip(obj core.CanvasObject, pos, clipPos geo.Position, clipSize geo.Size) bool
CullOffClip is the package's CullOffClip for a walk's CullFunc. For the object the walk is about to visit it answers from that object's node, which remembers its clip and shadow reach (#599); for any other object it asks the renderer, as CullOffClip does.
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. Call it on the main goroutine only. 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) MarkDirtyRect ¶ added in v1.2.0
MarkDirtyRect adds a rect to the next PartialDirtyRegion. A driver that paints something no canvas object stands for, such as the mobile screen-reader focus ring, marks where it was and where it will be, so the region clears the one and redraws the content under the other (#551).
func (*Canvas) MarkFullRepaint ¶ added in v1.2.0
func (c *Canvas) MarkFullRepaint()
MarkFullRepaint tells PartialDirtyRegion that the frame being painted is a full repaint that did not ask it for a region, so the bounds it recorded are no longer those on screen.
func (*Canvas) MarkMinSizeDirty ¶ added in v1.2.0
func (c *Canvas) MarkMinSizeDirty(obj core.CanvasObject)
MarkMinSizeDirty records that obj may report a different min size, so the next EnsureMinSize asks it again (#464). Refresh calls it; BaseWidget.Refresh calls it for the widget itself, whose renderer may refresh only its parts. Safe from any goroutine.
func (*Canvas) MarkPlacementDirty ¶ added in v1.2.0
func (c *Canvas) MarkPlacementDirty(obj core.CanvasObject)
MarkPlacementDirty records that obj may have moved, been resized or been hidden, so the next partial-repaint region walks from its node. An object with no node is not drawn, or is under one a walk reaches anyway: a new object is added through a container or widget that reports, and a shown one through paintgen. Safe from any goroutine.
func (*Canvas) MinSizeVisits ¶ added in v1.2.0
MinSizeVisits reports how many nodes the last EnsureMinSize visited.
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.
When the refreshed objects' previous bounds alone cover most of the canvas, the region would too, so it returns the whole canvas without walking; the first later call that cannot skip walks to record the bounds again, and also returns the whole canvas (#496). So does the call after a full repaint the caller did without asking for a region (MarkFullRepaint).
It walks from the nodes reported moved, resized, hidden or refreshed since the last call, not from the roots, unless something no node can report changed (region.go, #599).
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) RegionVisits ¶ added in v1.2.0
RegionVisits reports how many nodes the last PartialDirtyRegion visited.
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) SetDirty ¶
func (c *Canvas) SetDirty()
SetDirty marks the canvas as needing a paint. Call it on the main goroutine only: the flag has no lock.
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) WalkContentTreesCulled ¶ added in v1.2.0
func (c *Canvas) WalkContentTreesCulled( cull driver.CullFunc, beforeChildren func(*RenderCacheNode, geo.Position), afterChildren func(*RenderCacheNode, geo.Position), )
WalkContentTreesCulled walks the content trees as WalkContentTrees does, visiting an object cull reports as drawing nothing visible without its children (driver.WalkVisibleObjectTreeCulled). The paint walk passes CullOffClip, so content scrolled out of view costs one visit per clip-owner instead of its whole subtree (#464). Walks that must reach every object (layout, hit testing, accessibility) pass nil.
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) BoundaryRenderedAt ¶ added in v1.2.0
func (r *RenderCacheNode) BoundaryRenderedAt(phase BoundaryPhase) bool
BoundaryRenderedAt reports whether node's RepaintBoundary texture was rendered at phase. A clean texture rendered at another phase holds its content on another sub-pixel grid, so it must be rendered again.
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) SetBoundaryRenderedAt ¶ added in v1.2.0
func (r *RenderCacheNode) SetBoundaryRenderedAt(phase BoundaryPhase)
SetBoundaryRenderedAt records the phase node's RepaintBoundary texture was rendered at.
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 lists the [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.
Each entry is stored once, in entries; a cell holds int32 indices into it, all cells packed into one items slice (cell i is items[cellStart[i]: cellStart[i+1]]). Copying the entry into every cell it overlapped made a full-window background ~510 entry copies, and with the slices regrown from zero each paint the rebuild was 81% of a static frame's allocation (#435). The slices are reused by reset, so a canvas rebuilding every paint allocates only when the scene outgrows them.
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). It also carries two-finger pans
// (pinch.go, #398). Where the Scroll is itself Draggable (the mobile
// driver, #402) a one-finger drag latches the Scroll first, so setting this
// there only adds the two-finger pan. A driver that leaves it nil gets
// neither, and two fingers over a Pinchable always pinch.
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).