Documentation ¶
Overview ¶
Package app contains an API for working with a native application window and relevant input / output that goes with it.
Index ¶
- Constants
- type Controller
- type Cursor
- type CursorDefinition
- type FilepathPayload
- type GamepadState
- type KeyCode
- type KeyModifier
- type KeyModifierSet
- type KeyboardEvent
- type KeyboardEventType
- type LayeredController
- func (c *LayeredController) OnCloseRequested(window Window)
- func (c *LayeredController) OnCreate(window Window)
- func (c *LayeredController) OnDestroy(window Window)
- func (c *LayeredController) OnFramebufferResize(window Window, width, height int)
- func (c *LayeredController) OnKeyboardEvent(window Window, event KeyboardEvent) bool
- func (c *LayeredController) OnMouseEvent(window Window, event MouseEvent) bool
- func (c *LayeredController) OnRender(window Window)
- func (c *LayeredController) OnResize(window Window, width, height int)
- type MouseButton
- type MouseEvent
- type MouseEventType
- type NopController
- func (NopController) OnCloseRequested(window Window)
- func (NopController) OnCreate(window Window)
- func (NopController) OnDestroy(window Window)
- func (NopController) OnFramebufferResize(window Window, width, height int)
- func (NopController) OnKeyboardEvent(window Window, event KeyboardEvent) bool
- func (NopController) OnMouseEvent(window Window, event MouseEvent) bool
- func (NopController) OnRender(window Window)
- func (NopController) OnResize(window Window, width, height int)
- type Window
Constants ¶
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 // especially the case on devices with high DPI setting. OnFramebufferResize(window Window, width, height int) // OnKeyboardEvent is called whenever a keyboard event has occurred. OnKeyboardEvent(window Window, event KeyboardEvent) bool // OnMouseEvent is called whenever a mouse event has occurred. 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 whenever the window is about to close. 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 specified otherwise.
type Cursor ¶
type Cursor interface {
// Delete releases all resources allocated for this cursor.
Delete()
}
Cursor represents the visual aspect of a pointer on the screen.
type CursorDefinition ¶
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 GamepadState ¶
type GamepadState struct { // LeftStickX indicates the amount that the left stick has been // moved along the X axis. LeftStickX float32 // LeftStickY indicates the amount that the left stick has been // moved along the Y axis. LeftStickY float32 // RightStickX indicates the amount that the right stick has been // moved along the X axis. RightStickX float32 // RightStickY indicates the amount that the right stick has been // moved along the Y axis. RightStickY float32 // LeftTrigger indicates the amount that the left trigger has been // pressed. LeftTrigger float32 // RightTrigger indicates the amount that the right trigger has been // pressed. RightTrigger float32 // LeftBumper indicates whether the left bumper has been pressed. LeftBumper bool // RightBumper indicates whether the right bumper has been pressed. RightBumper bool // TriangleButton indicates whether the triangle button has been pressed. TriangleButton bool // SquareButton indicates whether the square button has been pressed. SquareButton bool // CrossButton indicates whether the cross button has been pressed. CrossButton bool // CircleButton indicates whether the circle button has been pressed. CircleButton bool }
GamepadState represents a snapshot state of a gamepad controller.
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 )
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 a certain order, mostly favouring layers with higher index.
func NewLayeredController ¶
func NewLayeredController(layers ...Controller) *LayeredController
NewLayeredController returns a new LayeredController that has the specified 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) // GamepadState returns the state of the specified gamepad and // whether a gamepad at the specified index is at all connected. GamepadState(index int) (GamepadState, bool) // Schedule queues a function to be called on the main thread // when possible. There are no guarantees that that will necessarily // be on the next frame iteration. Schedule(fn func() error) // Invalidate causes this window to be redrawn. 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) // Close disposes of this window. Close() }
Window represents a native application window.
All methods must be invoked on the UI thread (UI goroutine), unless specified otherwise.