drag

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Start      = Type("Start")
	Move       = Type("Move")
	End        = Type("End")
	EndInertia = Type("EndInertia")
)

Variables

View Source
var DefaultInertialMotion = InertialMotion{
	InertiaExtinction: 0.1,
	SmoothingTimeout:  300 * time.Millisecond,
	InertiaDelay:      30 * time.Millisecond,
}

Functions

This section is empty.

Types

type Drag

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

func DragWith

func DragWith(options ...Option) *Drag

func (*Drag) Handle

func (d *Drag) Handle(e Event)

func (*Drag) Notify

func (d *Drag) Notify(e Event)

func (*Drag) On

func (d *Drag) On(handler Handler)

type Dragger

type Dragger interface {
	On(handler Handler)
}

type Event

type Event struct {
	Type Type
	X    float64
	Y    float64
	T    time.Duration
	Dx   float64
	Dy   float64
	Dt   time.Duration
}

type Handler

type Handler func(Event)

type InertialMotion

type InertialMotion struct {
	// InertiaExtinction is the amount taken off the remaining internal motion on every
	// call to the Damp() method. A value of e.g. 0.1 means that 10% is taken off.
	InertiaExtinction float64

	// SmoothingTimeout is the duration of the smoothing low pass filter.
	SmoothingTimeout time.Duration

	// InertiaDelay is the expected time between calls to Get to retrieve the
	// remaining inertial motion.
	InertiaDelay time.Duration
	// contains filtered or unexported fields
}

func (*InertialMotion) Damp

func (i *InertialMotion) Damp() *InertialMotion

Apply damping to slow the motion once the user has stopped dragging.

func (*InertialMotion) Get

func (i *InertialMotion) Get() (dx, dy float64)

Get returns the residual inertial motion that occured in a period of duration InertiaMsecDelay. So it is expected to be called every InertiaMsecDelay milliseconds.

func (*InertialMotion) Reset

func (i *InertialMotion) Reset()

Reset zeroes the residual inertial motion.

func (*InertialMotion) Update

func (i *InertialMotion) Update(dx, dy float64, dt time.Duration)

Update will update the current rate of motion dx,dy in x and y. The dt value is expected to be in milliseconds and it specifies the duration of the period in which dx,dy were accrued.

type Option

type Option func(*Drag)

func Inertia

func Inertia(value bool) Option

type Type

type Type string

Jump to

Keyboard shortcuts

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