input

package
v0.0.0-...-7ac4638 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package input deals with user input such as mouse button clicks, scroll wheel movement etc. It also provides access to the input layer stack to handle staggered input.

Widget implementations should always use this package to handle user input rather than using Ebiten functions directly.

Index

Constants

View Source
const (
	// LayerEventTypeMouseButton indicates an interest in mouse button events.
	LayerEventTypeMouseButton = LayerEventType(1 << iota)

	// LayerEventTypeWheel indicates an interest in mouse wheel events.
	LayerEventTypeWheel

	// LayerEventTypeAll indicates an interest in all event types.
	LayerEventTypeAll = LayerEventType(^uint16(0))
)
View Source
const (
	// LayerEventTypeAny is used for ActiveFor to indicate no special event types.
	LayerEventTypeAny = LayerEventType(0)
)

Variables

View Source
var DefaultLayer = Layer{
	DebugLabel: "default",
	EventTypes: LayerEventTypeAll,
	BlockLower: true,
	FullScreen: true,
}

DefaultLayer is the bottom-most input layer. It is a full screen layer that is eligible for all event types.

Functions

func AddLayer

func AddLayer(l *Layer)

AddLayer adds l at the top of the layer stack.

Layers are only valid for the duration of a frame. Layers are removed automatically for the next frame.

func AnyKeyPressed

func AnyKeyPressed() bool

AnyKeyPressed returns whether any key is currently pressed.

func CursorPosition

func CursorPosition() (int, int)

CursorPosition returns the current cursor position.

func InputChars

func InputChars() []rune

InputChars returns user keyboard input.

func KeyPressed

func KeyPressed(k ebiten.Key) bool

KeyPressed returns whether key k is currently pressed.

func MouseButtonJustPressed

func MouseButtonJustPressed(b ebiten.MouseButton) bool

MouseButtonJustPressed returns whether mouse button b has just been pressed. It only returns true during the first frame that the button is pressed.

func MouseButtonJustPressedLayer

func MouseButtonJustPressedLayer(b ebiten.MouseButton, l *Layer) bool

MouseButtonJustPressedLayer returns whether mouse button b has just been pressed if input layer l is eligible to handle it. It only returns true during the first frame that the button is pressed.

func MouseButtonPressed

func MouseButtonPressed(b ebiten.MouseButton) bool

MouseButtonPressed returns whether mouse button b is currently pressed.

func MouseButtonPressedLayer

func MouseButtonPressedLayer(b ebiten.MouseButton, l *Layer) bool

MouseButtonPressedLayer returns whether mouse button b is currently pressed if input layer l is eligible to handle it.

func SetupInputLayersWithDeferred

func SetupInputLayersWithDeferred(ls []Layerer)

SetupInputLayersWithDeferred calls ls to set up input layers. This function is called by the UI.

func Wheel

func Wheel() (float64, float64)

Wheel returns current mouse wheel movement.

func WheelLayer

func WheelLayer(l *Layer) (float64, float64)

WheelLayer returns current mouse wheel movement if input layer l is eligible to handle it. If l is not eligible, it returns 0, 0.

Types

type DeferredSetupInputLayerFunc

type DeferredSetupInputLayerFunc func(s SetupInputLayerFunc)

DeferredSetupInputLayerFunc is a function that stores s for deferred execution.

type Layer

type Layer struct {
	// DebugLabel is a label used in debugging to distinguish input layers. It is not used in any other way.
	DebugLabel string

	// EventTypes is a bit mask that specifies the types of events the input layer is eligible for.
	EventTypes LayerEventType

	// BlockLower specifies if events will be passed on to lower input layers even if the current layer
	// is eligible to handle them.
	BlockLower bool

	// FullScreen specifies if the input layer covers the full screen.
	FullScreen bool

	// RectFunc is a function that returns the input layer's screen area of interest. This function is only
	// called if FullScreen is false.
	RectFunc LayerRectFunc
	// contains filtered or unexported fields
}

A Layer is an input layer that can be used to block user input from lower layers of the user interface. For example, if two clickable areas overlap each other, clicking on the overlapping part should only result in a click event sent to the upper area instead of both. Input layers can be used to achieve this.

Input layers are stacked: Lower layers may be eligible to handle an event if upper layers are not, or if upper layers specify to pass events on to lower layers regardless.

Input layers may specify a screen Rectangle as their area of interest, or they may specify to cover the full screen.

func (*Layer) ActiveFor

func (l *Layer) ActiveFor(x int, y int, eventType LayerEventType) bool

ActiveFor returns whether l is eligible for an event of type eventType, according to l.EventTypes. It returns false if l is not a fullscreen layer and does not contain the position x,y.

func (*Layer) Valid

func (l *Layer) Valid() bool

Valid returns whether l is still valid, that is, it has not been added to the layer stack in previous frames.

type LayerEventType

type LayerEventType uint16

LayerEventType is a type of input event, such as mouse button press or release, wheel click, and so on.

type LayerRectFunc

type LayerRectFunc func() image.Rectangle

LayerRectFunc is a function that returns a Layer's screen area of interest.

type Layerer

type Layerer interface {
	// SetupInputLayer sets up input layers. def may be called to defer additional input layer setup.
	SetupInputLayer(def DeferredSetupInputLayerFunc)
}

Layerer may be implemented by widgets that need to set up input layers by calling AddLayer.

type SetupInputLayerFunc

type SetupInputLayerFunc func(def DeferredSetupInputLayerFunc)

SetupInputLayerFunc is a function that sets up input layers by calling AddLayer. def may be called to defer additional input layer setup.

Jump to

Keyboard shortcuts

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