Skip to content

Interaction

coding.jackalope edited this page Jan 9, 2021 · 6 revisions
Table of Contents

Overview

Slab offers functions to query the user's input on a given frame. There are also functions to query for input on the most recently declared control. This can allow the implementation to use custom logic for controls to create custom behaviors.

Slab.BeginWindow('Interaction', {Title = "Interaction"})

Slab.Button("Button")
if Slab.IsControlHovered() then
	Slab.Text("Hovered")
else
	Slab.Text("Not Hovered")
end

Slab.EndWindow()

API

Below is a list of functions that queries for user input.

IsMouseDown

Determines if a given mouse button is down.

Parameter Type Description
Button Number The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
Return Description
Boolean True if the given button is down. False otherwise.

IsMouseClicked

Determines if a given mouse button changes state from up to down this frame.

Parameter Type Description
Button Number The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
Return Description
Boolean True if the given button changes state from up to down. False otherwise.

IsMouseReleased

Determines if a given mouse button changes state from down to up this frame.

Parameter Type Description
Button Number The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
Return Description
Boolean True if the given button changes state from down to up. False otherwise.

IsMouseDoubleClicked

Determines if a given mouse button has been clicked twice within a given time frame.

Parameter Type Description
Button Number The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
Return Description
Boolean True if the given button was double clicked. False otherwise.

IsMouseDragging

Determines if a given mouse button is down and there has been movement.

Parameter Type Description
Button Number The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
Return Description
Boolean True if the button is held down and is moving. False otherwise.

GetMousePosition

Retrieves the current mouse position in the viewport.

Return Description
Number, Number The X and Y coordinates of the mouse position.

GetMousePositionWindow

Retrieves the current mouse position within the current window. This position will include any transformations added to the window such as scrolling.

Return Description
Number, Number The X and Y coordinates of the mouse position within the window.

GetMouseDelta

Retrieves the change in mouse coordinates from the last frame.

Return Description
Number, Number The X and Y coordinates of the delta from the last frame.

SetCustomMouseCursor

Overrides a system mouse cursor of the given type to render a custom image instead.

Parameter Type Description
Type String The system cursor type to replace. This can be one of the following values: 'arrow', 'sizewe', 'sizens', 'sizenesw', 'sizenwse', 'ibeam', 'hand'.
Image Table An 'Image' object created from love.graphics.newImage. If this is nil, then an empty image is created and is drawn when the system cursor is activated.
Quad Table A 'Quad' object created from love.graphics.newQuad. This allows support for setting UVs of an image to render.

ClearCustomMouseCursor

Removes any override of a system mouse cursor with the given type and defaults to the OS specific mouse cursor.

Parameter Type Description
Type String The system cursor type to remove. This can be one of the following values: 'arrow', 'sizewe', 'sizens', 'sizenesw', 'sizenwse', 'ibeam', 'hand'.

IsControlHovered

Checks to see if the last control added to the window is hovered by the mouse.

Return Description
Boolean True if the last control is hovered, false otherwise.

IsControlClicked

Checks to see if the previous control is hovered and clicked.

Parameter Type Description
Button Number The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
Return Description
Boolean True if the previous control is hovered and clicked. False otherwise.

GetControlSize

Retrieves the last declared control's size.

Return Description
Number, Number The width and height of the last control declared.

IsVoidHovered

Checks to see if any non-Slab area of the viewport is hovered.

Return Description
Boolean True if any non-Slab area of the viewport is hovered. False otherwise.

IsVoidClicked

Checks to see if any non-Slab area of the viewport is clicked.

Parameter Type Description
Button Number The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
Return Description
Boolean True if any non-Slab area of the viewport is clicked. False otherwise.

IsKeyDown

Checks to see if a specific key is held down. The key should be one of the love defined Scancode which the list can be found here.

Parameter Type Description
Key String A love defined scancode.
Return Description
Boolean True if the key is held down. False otherwise.

IsKeyPressed

Checks to see if a specific key state went from up to down this frame. The key should be one of the love defined Scancode which the list can be found here.

Parameter Type Description
Key String A love defined scancode.
Return Description
Boolean True if the key state went from up to down this frame. False otherwise.

IsKeyReleased

Checks to see if a specific key state went from down to up this frame. The key should be one of the love defined Scancode which the list can be found here.

Parameter Type Description
Key String A love defined scancode.
Return Description
Boolean True if the key state went from down to up this frame. False otherwise.
Clone this wiki locally