Files
gio-patched/ui/pointer/pointer.go
T
Elias Naur a8bb3c2f14 all: make pointer.Area an interface
With an interface instead of anonymous functions, amending an
area's parameters can be done even after adding it to an OpHandler.

This will be useful when we switch to serialized op lists.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-04-25 10:02:14 +02:00

110 lines
1.4 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
package pointer
import (
"time"
"gioui.org/ui/f32"
)
type Event struct {
Type Type
Source Source
PointerID ID
Priority Priority
Time time.Duration
Hit bool
Position f32.Point
Scroll f32.Point
}
type OpHandler struct {
Key Key
Area Area
Grab bool
}
type Area interface {
Hit(pos f32.Point) HitResult
}
type Key interface{}
type Events interface {
For(k Key) []Event
}
type HitResult uint8
const (
HitNone HitResult = iota
HitTransparent
HitOpaque
)
type ID uint16
type Type uint8
type Priority uint8
type Source uint8
const (
Cancel Type = iota
Press
Release
Move
)
const (
Mouse Source = iota
Touch
)
const (
Shared Priority = iota
Foremost
Grabbed
)
func (t Type) String() string {
switch t {
case Press:
return "Press"
case Release:
return "Release"
case Cancel:
return "Cancel"
case Move:
return "Move"
default:
panic("unknown Type")
}
}
func (p Priority) String() string {
switch p {
case Shared:
return "Shared"
case Foremost:
return "Foremost"
case Grabbed:
return "Grabbed"
default:
panic("unknown priority")
}
}
func (s Source) String() string {
switch s {
case Mouse:
return "Mouse"
case Touch:
return "Touch"
default:
panic("unknown source")
}
}
func (OpHandler) ImplementsOp() {}
func (Event) ImplementsEvent() {}