dragdrop

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 3 Imported by: ? 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 dragdrop transfers application values between views in one window. It owns gesture negotiation, target changes and cancellation, with no look: the application supplies each view and its preview, and keeps a menu or another keyboard-accessible way to perform the same operation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activation

type Activation uint8

Activation chooses how a source starts a drag, independently of device.

const (
	// AfterMove starts after the pointer moves Threshold points. It is the default.
	AfterMove Activation = iota
	// AfterLongPress first waits for View.DelayLongPress, or the normal long-press
	// delay, then for movement. A scroll may take an earlier swipe as usual.
	AfterLongPress
)

type Area

type Area struct{ Children []core.Node }

Area connects its Source and Target descendants in one window. It adds no layout container. Nested areas are independent; use one per window. The source keeps its original view while a noninteractive preview follows the pointer above the content. Escape, native cancellation or source disposal ends the drag without dropping.

func (Area) Render

func (p Area) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Event

type Event struct {
	Data         any
	Position     core.Point
	PagePosition core.Point
}

Event is a value being dragged over a target. Data is sampled once as the drag starts; it may itself be a slice of the app's selected items.

type Result

type Result struct {
	Data    any
	Dropped bool
	Target  *core.Ref
}

Result ends a source's drag. Dropped says a live accepting target received it; Target is that target's view, nil when the drag was cancelled or missed.

type Source

type Source struct {
	View core.View
	// Data is sampled once when the drag starts. A nil function disables dragging.
	// Copy mutable data here when the drag must retain a snapshot.
	Data func() any
	// Preview supplies a label or picture. Without it View.Label/LabelFunc is used.
	Preview    func(data any) core.Node
	Activation Activation
	// Threshold is movement in points, 4 when zero or negative.
	Threshold core.Points
	OnStart   func(data any)
	OnEnd     func(Result)
}

Source makes View draggable within its Area. View retains its press, keyboard, accessibility and styling props; its Responder is owned by Source and must be unset. Put a button or another existing control in View.Children when it owns the normal action. A movement below Threshold leaves that action intact.

func (Source) Render

func (p Source) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Target

type Target struct {
	View                             core.View
	Accept                           func(data any) bool
	OnEnter, OnMove, OnLeave, OnDrop func(Event)
}

Target receives values on View. Accept may reject a value, allowing an accepting ancestor target to take it. OnEnter/OnLeave let the application draw the target state; no hover or press appearance is added. OnDrop must be set for the target to accept a drop. View.Ref is retained when supplied.

func (Target) Render

func (p Target) Render(cx *core.Scope) core.Node

Render implements core.Node.

Jump to

Keyboard shortcuts

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