Skip to content
GNamimates edited this page Oct 30, 2024 · 4 revisions

Class Name: GNUI.Canvas

A special type of container that handles all the inputs

Note

Canvas.new() is meant for people who want to create their own custom UI screens. if you want to a canvas for the screen, use GNUI.getScreenCanvas() instead.

Properties

Type Field Description
boolean captureCursorMovement true when the canvas should capture mouse movement, stopping the vanilla mouse movement, not the cursor itself
boolean captureInputs true when the canvas should capture the inputs
boolean hasCustomCursorSetter true when the setCursor is called, while false, the canvas will use the screen cursor.
GNUI.any? HoveredElement the element the mouse is currently hovering over
Vector2 MousePosition the position of the mouse
GNUI.Box? PassiveHoveredElement the last hovering element.
GNUI.any[]? PressedElements the last pressed element, used to unpress buttons that have been unhovered.
boolean reciveInputs EventLibs whether the canvas could capture input events

Events

Event Description
HOVERING_ELEMENT_CHANGED triggered when the hovering element changes
INPUT serves as the handler for all inputs within the boundaries of the canvas. called with the first argument being an input event
MOUSE_POSITION_CHANGED called when the mouse position changes
PASSIVE_HOVERING_ELEMENT_CHANGED Just like the HOVERING_BOX_CHANGED, but will never be nil if there is nothing being hovered.
UNHANDLED_INPUT triggers when an input is not handled by the children of the canvas.

Methods

Returns Methods
GNUI.Canvas Canvas.new(autoScreenInputs : boolean?)
self Canvas:setMousePos(x : number|Vector2, y : number?)
Canvas:parseInputEvent(key : GNUI.keyCode, state : Event.Press.state, ctrl : boolean?, alt : boolean?, shift : boolean?, strength : number?, char : string?)
Canvas:getChildFromPos(pos : Vector2)
Canvas:pos2HoveringChild(pos : Vector2)
GNUI.Canvas Canvas:setHoveringChild(box : GNUI.Box)
GNUI.any Canvas:getHoveredElement()
self Canvas:setCaptureMouseMovement(toggle : boolean)
self Canvas:setCaptureInputs(toggle : boolean)

Canvas.new(autoScreenInputs)

Creates a new canvas.
if autoScreenInputs is true, the canvas will capture input events

Arguments

  • boolean? autoScreenInputs
    • if true, the canvas will capture input events

Returns GNUI.Canvas

Canvas:setMousePos(x, y)

Sets the Mouse position relative to the canvas. meaning in canvas local space.

Arguments

  • number|Vector2 x

  • number? y

Returns self

Canvas:parseInputEvent(key, state, ctrl, alt, shift, strength, char)

Simulates a boolean key event into the canvas.

Arguments

  • GNUI.keyCode key

  • Event.Press.state state

  • boolean? ctrl

  • boolean? alt

  • boolean? shift

  • number? strength

  • string? char

Canvas:getChildFromPos(pos)

Returns the child that the point at the given position is on top of.

Arguments

  • Vector2 pos

Canvas:pos2HoveringChild(pos)

Sets the child that the point at the given position is on top of.

Arguments

  • Vector2 pos

Canvas:setHoveringChild(box)

Sets the child being hovered.

Arguments

  • GNUI.Box box

Returns GNUI.Canvas

Canvas:getHoveredElement()

Returns which element the mouse cursor is on top of.

Returns GNUI.any

Canvas:setCaptureMouseMovement(toggle)

Sets whether the canvas should capture the mouse movement, making it not possible to move the mouse outside of the canvas.

Arguments

  • boolean toggle

Returns self

Canvas:setCaptureInputs(toggle)

Sets whether the canvas should capture input from the user.

Arguments

  • boolean toggle

Returns self

Clone this wiki locally