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
- Variables
- func AddLayer(l *Layer)
- func AfterDraw(screen *ebiten.Image)
- func AnyKeyPressed() bool
- func CursorPosition() (int, int)
- func Draw(screen *ebiten.Image)
- func GetWindowSize() image.Point
- func InputChars() []rune
- func KeyPressed(k ebiten.Key) bool
- func MouseButtonJustPressed(b ebiten.MouseButton) bool
- func MouseButtonJustPressedLayer(b ebiten.MouseButton, l *Layer) bool
- func MouseButtonPressed(b ebiten.MouseButton) bool
- func MouseButtonPressedLayer(b ebiten.MouseButton, l *Layer) bool
- func SetCursorImage(name string, cursorImage *ebiten.Image)
- func SetCursorImageWithOffset(name string, cursorImage *ebiten.Image, offset image.Point)
- func SetCursorShape(name string)
- func SetCursorUpdater(cursorUpdater CursorUpdater)
- func SetupInputLayersWithDeferred(ls []Layerer)
- func Update()
- func Wheel() (float64, float64)
- func WheelLayer(l *Layer) (float64, float64)
- type CursorUpdater
- type DeferredSetupInputLayerFunc
- type Layer
- type LayerEventType
- type LayerRectFunc
- type Layerer
- type SetupInputLayerFunc
Constants ¶
const ( CURSOR_DEFAULT = "Cursor_Default" CURSOR_EWRESIZE = "Cursor_EWResize" CURSOR_NSRESIZE = "Cursor_NSResize" CURSOR_POINTER = "Cursor_Pointer" CURSOR_TEXT = "Cursor_Text" CURSOR_CROSSHAIR = "Cursor_Crosshair" CURSOR_NONE = "Cursor_None" )
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)) )
const ( // LayerEventTypeAny is used for ActiveFor to indicate no special event types. LayerEventTypeAny = LayerEventType(0) )
Variables ¶
var CursorManagementEnabled = true
This flag allows you to disable ebitenui's cursor management
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.
var UIHovered = false
This variable indicates if the UI has currently being hovered over
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 ¶
CursorPosition returns the current cursor position.
func GetWindowSize ¶
This method returns the drawable screen size whether it is fullscreen or not.
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 ¶
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 ¶
MouseButtonPressedLayer returns whether mouse button b is currently pressed if input layer l is eligible to handle it.
func SetCursorImage ¶
func SetCursorImage(name string, cursorImage *ebiten.Image)
func SetCursorShape ¶
func SetCursorShape(name string)
func SetCursorUpdater ¶
func SetCursorUpdater(cursorUpdater CursorUpdater)
If the system cannot find a cursor image, it will revert to the system defaults. If cursorUpdater is nil the system will revert to the standard InputHandler system
EbitenUI by default will look for the following cursors:
CURSOR_EWRESIZE : "Cursor_EWResize" CURSOR_NSRESIZE : "Cursor_NSResize" CURSOR_DEFAULT : "Cursor_Default" CURSOR_POINTER : "Cursor_Pointer" CURSOR_TEXT : "Cursor_Text" CURSOR_CROSSHAIR : "Cursor_Crosshair"
func SetupInputLayersWithDeferred ¶
func SetupInputLayersWithDeferred(ls []Layerer)
SetupInputLayersWithDeferred calls ls to set up input layers. This function is called by the UI.
func WheelLayer ¶
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 CursorUpdater ¶
type CursorUpdater interface { // Called every Update call from Ebiten // Note that before this is called the current cursor shape is reset to DEFAULT every cycle Update() // Called at the beginning of every Draw call. Draw(screen *ebiten.Image) // Called at the end of every Draw call AfterDraw(screen *ebiten.Image) // MouseButtonPressed returns whether mouse button b is currently pressed. MouseButtonPressed(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. MouseButtonJustPressed(b ebiten.MouseButton) bool // CursorPosition returns the current cursor position. // If you define a CursorPosition that doesn't align with a system cursor you will need to // set the CursorDrawMode to Custom. This is because ebiten doesn't have a way to set the // cursor location manually CursorPosition() (int, int) // Returns the image to use as the cursor // EbitenUI by default will look for the following cursors: // "EWResize" // "NSResize" // "Default" GetCursorImage(name string) *ebiten.Image // Returns how far from the CursorPosition to offset the cursor image. // This is best used with cursors such as resizing. GetCursorOffset(name string) image.Point }
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.
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 ¶
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.