Skip to content

Input System

GNamimates edited this page Jan 20, 2025 · 2 revisions

this section will cover everything there is to know about the input system of GNUI.

Why does Canvas exist

canvas serves as the root container handling all the input events and cursor movement for the entire tree, having every box do that would be a waste of resources. (actually thats how it used to work, but it made things alot messier)

Now, lets imagine our senario is the image bellow

img

first lets differenciate between each Input event in GNUI.

Input Events

Box.INPUT

  • each box has its own INPUT event. and the event has its first parameter as an InputEvent

  • every key press on your keyboard and mouse clicks and scrolls are handled by the InputEvent class.

  • only gets called if the cursor is on top of the box in question, so in the image above, this will only trigger for the blue box. because the cursor is on top of it.

  • returning true will stop the event from being handled. example of this being used is with the TextInput element, clicking on it will make the every input event not trigger except for itself. unless you click away or confirm its input.

Canvas.INPUT

  • this is the same as Box.INPUT but it will trigger regardles of where the cursor is. as long as its in the canvas.

Canvas.UNHANDLED

  • this is the same as Box.INPUTbut will trigger when no box is on top of the cursor. and input events are triggered.
  • useful when you want to for example do something when the cursor is not on top of any UI elements.

Box.MOUSE_MOVED

  • this event is triggered when the mouse moves within the confines of the box.
  • its first parameter is a InputEventMouseMotion

Box.MOUSE_ENTERED and Box.MOUSE_EXITED

  • these events are triggered when the cursor enters and exits the confines of the box.

Box.MOUSE_PRESSENCE_CHANGED

  • this event is triggered when the state of the mouse to box interaction changes, arguments include: (hovering: boolean, pressed: boolean)

Clone this wiki locally