app

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 5 Imported by: 7

Documentation

Overview

Package app contains an API for working with an application window and the relevant input / output mechanisms that go with it.

Index

Constants

View Source
const (
	// MouseButtonLeft specifies the left mouse button.
	MouseButtonLeft = 1 + iota

	// MouseButtonMiddle specifies the middle mouse button.
	MouseButtonMiddle

	// MouseButtonRight specifies the right mouse button.
	MouseButtonRight
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller interface {

	// OnCreate is called when the window has been created and is
	// ready to be used.
	OnCreate(window Window)

	// OnResize is called when the window's content area has been
	// resized.
	OnResize(window Window, width, height int)

	// OnFramebufferResize is called when the window's framebuffer has
	// been resized.
	// Note that the framebuffer need not match the content size. This
	// is mostly the case on devices with high DPI setting.
	OnFramebufferResize(window Window, width, height int)

	// OnKeyboardEvent is called whenever a keyboard event has occurred.
	//
	// Return true to indicate that the event has been consumed and should
	// not be propagated to other potential receivers, otherwise return false.
	OnKeyboardEvent(window Window, event KeyboardEvent) bool

	// OnMouseEvent is called whenever a mouse event has occurred.
	//
	// Return true to indicate that the event has been consumed and should
	// not be propagated to other potential receivers, otherwise return false.
	OnMouseEvent(window Window, event MouseEvent) bool

	// OnRender is called whenever the window would like to be redrawn.
	OnRender(window Window)

	// OnCloseRequested is called whenever the end-user has requested
	// that the application be closed through the native OS means
	// (e.g. pressing the close button or ALT+F4).
	//
	// It is up to the controller implementation to call Close on the
	// window if they accept the end-user's request (e.g. games might
	// decide to show a prompt and not want the close to occur).
	OnCloseRequested(window Window)

	// OnDestroy is called before the window is closed.
	OnDestroy(window Window)
}

Controller is a mechanism through which the user code can be notified of changes to the application window.

All methods will be invoked on the UI thread (UI goroutine), unless otherwise specified.

type Cursor

type Cursor interface {

	// Destroy releases all resources allocated for this cursor.
	Destroy()
}

Cursor represents the visual aspect of a pointer on the screen.

type CursorDefinition

type CursorDefinition struct {

	// Path specifies the location of the image resource.
	Path string

	// HotspotX specifies the X click position within the cursor image.
	HotspotX int

	// HotspotY specifies the Y click position within the cursor image.
	HotspotY int
}

CursorDefinition can be used to describe a new cursor.

type FilepathPayload added in v0.3.0

type FilepathPayload struct {

	// Paths contains file paths to the dropped resources.
	Paths []string
}

FilepathPayload is a type of Payload that occurs when files have been dragged and dropped into the window.

type Gamepad added in v0.10.0

type Gamepad interface {

	// Connected returns whether this Gamepad is still connected. This is
	// useful for when a Gamepad instance is kept by the user code.
	Connected() bool

	// Supported returns whether the connected device can be mapped to the
	// standard layout:
	// https://w3c.github.io/gamepad/#remapping
	//
	// Devices that are not supported will return zero values for buttons
	// and axes.
	Supported() bool

	// StickDeadzone returns the range around 0.0 that will not be considered
	// valid for stick motion.
	StickDeadzone() float64

	// SetStickDeadzone changes the deadzone range for sticks.
	SetStickDeadzone(deadzone float64)

	// TriggerDeadzone returns the range around 0.0 that will not be considered
	// valid for trigger motion.
	TriggerDeadzone() float64

	// SetTriggerDeadzone changes the deadzone range for triggers.
	SetTriggerDeadzone(deadzone float64)

	// LeftStickX returns the horizontal axis of the left stick.
	LeftStickX() float64

	// LeftStickY returns the vertical axis of the left stick.
	LeftStickY() float64

	// LeftStickButton returns the button represented by pressing
	// on the left stick.
	LeftStickButton() bool

	// RightStickX returns the horizontal axis of the right stick.
	RightStickX() float64

	// RightStickY returns the horizontal axis of the right stick.
	RightStickY() float64

	// RightStickButton returns the button represented by pressing
	// on the right stick.
	RightStickButton() bool

	// LeftTrigger returns the left trigger button.
	LeftTrigger() float64

	// RightTrigger returns the right trigger button.
	RightTrigger() float64

	// LeftBumper returns the left bumper button.
	LeftBumper() bool

	// RightBumper returns the right bumper button.
	RightBumper() bool

	// DpadUpButton returns the up button of the left cluster.
	DpadUpButton() bool

	// DpadDownButton returns the down button of the left cluster.
	DpadDownButton() bool

	// DpadLeftButton returns the left button of the left cluster.
	DpadLeftButton() bool

	// DpadRightButton returns the right button of the left cluster.
	DpadRightButton() bool

	// ActionTopButton returns the up button of the right cluster.
	ActionUpButton() bool

	// ActionDownButton returns the down button of the right cluster.
	ActionDownButton() bool

	// ActionLeftButton returns the left button of the right cluster.
	ActionLeftButton() bool

	// ActionRightButton returns the right button of the right cluster.
	ActionRightButton() bool

	// ForwardButton represents the right button of the center cluster.
	ForwardButton() bool

	// BackButton represents the left button of the center cluster.
	BackButton() bool

	// Pulse causes the Gamepad controller to vibrate with the specified
	// intensity (0.0 to 1.0) for the specified duration.
	//
	// If the device does not have haptic feedback then this method does nothing.
	Pulse(intensity float64, duration time.Duration)
}

Gamepad represents a gamepad type joystick. Only input devides that can be mapped according to standard layout will work and have any axis and button output.

type KeyCode

type KeyCode int

KeyCode represents a keyboard key.

const (
	KeyCodeEscape KeyCode = 1 + iota
	KeyCodeEnter
	KeyCodeSpace
	KeyCodeTab
	KeyCodeCaps
	KeyCodeLeftShift
	KeyCodeRightShift
	KeyCodeLeftControl
	KeyCodeRightControl
	KeyCodeLeftAlt
	KeyCodeRightAlt
	KeyCodeBackspace
	KeyCodeInsert
	KeyCodeDelete
	KeyCodeHome
	KeyCodeEnd
	KeyCodePageUp
	KeyCodePageDown
	KeyCodeArrowLeft
	KeyCodeArrowRight
	KeyCodeArrowUp
	KeyCodeArrowDown
	KeyCodeMinus
	KeyCodeEqual
	KeyCodeLeftBracket
	KeyCodeRightBracket
	KeyCodeSemicolon
	KeyCodeComma
	KeyCodePeriod
	KeyCodeSlash
	KeyCodeBackslash
	KeyCodeApostrophe
	KeyCodeGraveAccent
	KeyCodeA
	KeyCodeB
	KeyCodeC
	KeyCodeD
	KeyCodeE
	KeyCodeF
	KeyCodeG
	KeyCodeH
	KeyCodeI
	KeyCodeJ
	KeyCodeK
	KeyCodeL
	KeyCodeM
	KeyCodeN
	KeyCodeO
	KeyCodeP
	KeyCodeQ
	KeyCodeR
	KeyCodeS
	KeyCodeT
	KeyCodeU
	KeyCodeV
	KeyCodeW
	KeyCodeX
	KeyCodeY
	KeyCodeZ
	KeyCode0
	KeyCode1
	KeyCode2
	KeyCode3
	KeyCode4
	KeyCode5
	KeyCode6
	KeyCode7
	KeyCode8
	KeyCode9
	KeyCodeF1
	KeyCodeF2
	KeyCodeF3
	KeyCodeF4
	KeyCodeF5
	KeyCodeF6
	KeyCodeF7
	KeyCodeF8
	KeyCodeF9
	KeyCodeF10
	KeyCodeF11
	KeyCodeF12
)

func (KeyCode) String added in v0.12.0

func (c KeyCode) String() string

String returns a string representation of this key code.

type KeyModifier

type KeyModifier int

KeyModifier represents a modifier key.

const (
	KeyModifierControl KeyModifier = 1 << (iota + 1)
	KeyModifierShift
	KeyModifierAlt
	KeyModifierCapsLock
)

func (KeyModifier) String

func (m KeyModifier) String() string

String returns a string representation of this key modifier.

type KeyModifierSet

type KeyModifierSet int

KeyModifierSet is used to indicate which modifier keys were active at the event occurrence.

func (KeyModifierSet) Contains

func (s KeyModifierSet) Contains(modifier KeyModifier) bool

Contains returns whether the set contains the specified modifier

func (KeyModifierSet) String

func (s KeyModifierSet) String() string

String returns a string representation of this key modifier set.

type KeyboardEvent

type KeyboardEvent struct {

	// Type specifies the keyboard event type.
	Type KeyboardEventType

	// Code returns the code of the keyboard key.
	Code KeyCode

	// Rune returns the character that was typed in case
	// of an KeyboardEventTypeType event.
	Rune rune

	// Modifiers contains a set of modifier keys that were
	// pressed during the event.
	Modifiers KeyModifierSet
}

KeyboardEvent is used to propagate events related to keyboard actions.

type KeyboardEventType

type KeyboardEventType int

KeyboardEventType is used to specify the type of keyboard action that occurred.

const (
	// KeyboardEventTypeKeyDown indicates that a keyboard key
	// was pressed.
	KeyboardEventTypeKeyDown KeyboardEventType = 1 + iota

	// KeyboardEventTypeKeyUp indicates that a keyboard key was
	// released.
	KeyboardEventTypeKeyUp

	// keyboardEventTypeType indicates that a keyboard key is
	// being pressed continuously.
	KeyboardEventTypeRepeat

	// KeyboardEventTypeType indicates that a character is typed
	// with the keyboard.
	// Such events would be duplicates to KeyboardEventTypeDown
	// or KeyboardEventTypeRepeat but allow for the character
	// rune to be read after all modifiers have been applied so that
	// one does not have to implement that on their own.
	KeyboardEventTypeType
)

func (KeyboardEventType) String

func (t KeyboardEventType) String() string

String returns a string representation of this event type,

type LayeredController

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

LayeredController is an implementation of Controller that invokes the specified controller layers in an order emulating multiple overlays of a window.

func NewLayeredController

func NewLayeredController(layers ...Controller) *LayeredController

NewLayeredController returns a new LayeredController that has the specified controller layers configured.

func (*LayeredController) OnCloseRequested

func (c *LayeredController) OnCloseRequested(window Window)

func (*LayeredController) OnCreate

func (c *LayeredController) OnCreate(window Window)

func (*LayeredController) OnDestroy

func (c *LayeredController) OnDestroy(window Window)

func (*LayeredController) OnFramebufferResize

func (c *LayeredController) OnFramebufferResize(window Window, width, height int)

func (*LayeredController) OnKeyboardEvent

func (c *LayeredController) OnKeyboardEvent(window Window, event KeyboardEvent) bool

func (*LayeredController) OnMouseEvent

func (c *LayeredController) OnMouseEvent(window Window, event MouseEvent) bool

func (*LayeredController) OnRender

func (c *LayeredController) OnRender(window Window)

func (*LayeredController) OnResize

func (c *LayeredController) OnResize(window Window, width, height int)

type MouseButton

type MouseButton int

MouseButton represents the mouse button.

func (MouseButton) String

func (b MouseButton) String() string

String returns a string representation of this button.

type MouseEvent

type MouseEvent struct {

	// Index indicates which mouse triggered the event. By default
	// the index for a the primary mouse is 0.
	// This is applicable for devices with multiple pointers
	// (mobile) or in case a second mouse is emulated
	// (e.g. with a game controller).
	Index int

	// X specifies the horizontal position of the mouse.
	X int

	// Y specifies the vertical position of the mouse.
	Y int

	// Type specifies the mouse event type.
	Type MouseEventType

	// Button specifies the button for which the event is
	// applicable.
	Button MouseButton

	// ScrollX determines the amount of horizontal scroll.
	ScrollX float64

	// ScrollY determines the amount of vertical scroll.
	ScrollY float64

	// Payload contains the data that was dropped in case of
	// a MouseEventTypeDrop event.
	Payload interface{}
}

MouseEvent represents an event related to a mouse action.

func (MouseEvent) String

func (e MouseEvent) String() string

String returns a string representation of this event.

type MouseEventType

type MouseEventType int

MouseEventType represents the type of mouse event.

const (
	// MouseEventTypeDown indicates that a mouse button
	// was pressed down over the receiver control.
	MouseEventTypeDown MouseEventType = 1 + iota

	// MouseEventTypeUp indicates that a mouse button
	// was released over the receiver control.
	MouseEventTypeUp

	// MouseEventTypeMove indicates that the mouse was
	// moved over the receiver control.
	MouseEventTypeMove

	// MouseEventTypeDrag indicates that the mouse that
	// was previously pressed within the receiver control
	// is being moved.
	// The even could be received for a motion outside the
	// bounds of the control.
	MouseEventTypeDrag

	// MouseEventTypeDrop indicates that some content was dropped
	// within the receiver.
	MouseEventTypeDrop

	// MouseEventTypeDragCancel indicates that a drag operation
	// was cancelled by the parent control (other control might
	// have taken over).
	MouseEventTypeDragCancel

	// MouseEventTypeEnter indicates that the mouse has
	// entered the bounds of the control.
	MouseEventTypeEnter

	// MouseEventTypeLeave indicates that the mouse has
	// left the bounds of the control.
	// If the mouse was being dragged, the control may
	// receive further events.
	MouseEventTypeLeave

	// MouseEventTypeScroll indicates that the mouse wheel
	// was scrolled. The X and Y values of the event indicate the
	// offset.
	MouseEventTypeScroll
)

func (MouseEventType) String

func (t MouseEventType) String() string

String returns a string representation of this event type.

type NopController

type NopController struct{}

NopController is a no-op implementation of a Controller.

func (NopController) OnCloseRequested

func (NopController) OnCloseRequested(window Window)

func (NopController) OnCreate

func (NopController) OnCreate(window Window)

func (NopController) OnDestroy

func (NopController) OnDestroy(window Window)

func (NopController) OnFramebufferResize

func (NopController) OnFramebufferResize(window Window, width, height int)

func (NopController) OnKeyboardEvent

func (NopController) OnKeyboardEvent(window Window, event KeyboardEvent) bool

func (NopController) OnMouseEvent

func (NopController) OnMouseEvent(window Window, event MouseEvent) bool

func (NopController) OnRender

func (NopController) OnRender(window Window)

func (NopController) OnResize

func (NopController) OnResize(window Window, width, height int)

type Window

type Window interface {

	// Title returns this window's title.
	Title() string

	// SetTitle changes the title of this window.
	SetTitle(title string)

	// Size returns the content area of this window.
	Size() (int, int)

	// SetSize changes the content area of this window.
	SetSize(width, height int)

	// FramebufferSize returns the texel size of the underlying framebuffer.
	// This would normally be used as reference when using graphics libraries
	// to draw on the screen as the framebuffer size may differ from the
	// window size.
	FramebufferSize() (int, int)

	// Gamepads returns an array of potentially available gamepad
	// controllers.
	//
	// Use the Connected and Supported methods on the Gamepad object to check
	// whether it is connected and can be used.
	//
	// This API supports up to 4 connected devices.
	Gamepads() [4]Gamepad

	// Schedule queues a function to be called on the main thread
	// when possible. There are no guarantees that it will necessarily
	// be on the next frame iteration.
	Schedule(fn func())

	// Invalidate causes this window to be redrawn when possible.
	Invalidate()

	// CreateCursor creates a new cursor object based on the specified
	// definition.
	CreateCursor(definition CursorDefinition) Cursor

	// UseCursor changes the currently displayed cursor on the screen.
	// Specifying nil returns the default cursor.
	UseCursor(cursor Cursor)

	// CursorVisible returns whether a cursor is to be displayed on the
	// screen. This is determined based on the visibility and lock settings
	// of the cursor
	CursorVisible() bool

	// SetCursorVisible changes whether a cursor is displayed on the
	// screen.
	SetCursorVisible(visible bool)

	// SetCursorLocked traps the cursor within the boundaries of the window
	// and reports relative motion events. This method also hides the cursor.
	SetCursorLocked(locked bool)

	// RenderAPI provides access to a usable Render API based on the current
	// window's screen.
	//
	// If the implementation of this API does not support graphics, then this
	// method returns nil.
	RenderAPI() render.API

	// AudioAPI provides access to a usable Audio API based on the current
	// window.
	//
	// If the implementation of this API does not support graphics, then this
	// method returns nil.
	AudioAPI() audio.API

	// Close disposes of this window.
	Close()
}

Window represents a native application window.

All methods must be invoked on the UI thread (UI goroutine), unless otherwise specified.

Jump to

Keyboard shortcuts

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