Interface ElementEvents

All Known Implementing Classes:
GuiButton, GuiColourPicker, GuiColourPicker.ColourPreview, GuiColourPicker.SliderBG, GuiContextMenu, GuiDialog, GuiDVD, GuiElement, GuiEnergyBar, GuiEntityRenderer, GuiEventProvider, GuiFluidTank, GuiItemStack, GuiList, GuiManipulable, GuiProgressIcon, GuiRectangle, GuiScrolling, GuiSlider, GuiSlots, GuiText, GuiTextField, GuiTextList, GuiTexture

public interface ElementEvents
This class defines the default implementation for all Screen events. Input events in Modular GUI v2 work similar to v2, events are passed to all elements recursively in a top-down order, and if any element 'consumes' the event, it will not be passed any further down the chain. However, this approach had issues in v2, because there are certain situations where an element needs to receive an event even if it has been consumed. To deal with that we now have two methods for each event, the main handler method that will always get called, and uses a 'consumed' flag to track whether the event has been consumed, as well as a simpler convenience method that will only get called if the event has not already been canceled, and does not require you to call super.

Created by brandon3055 on 09/08/2023

  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
     
    default boolean
    charTyped(char character, int modifiers)
    Override this method to implement handling for the charTyped event.
    default boolean
    charTyped(char character, int modifiers, boolean consumed)
    Root handler for charTyped event.
     
    default boolean
    keyPressed(int key, int scancode, int modifiers)
    Override this method to implement handling for the keyPressed event.
    default boolean
    keyPressed(int key, int scancode, int modifiers, boolean consumed)
    Root handler for keyPressed event.
    default boolean
    keyReleased(int key, int scancode, int modifiers)
    Override this method to implement handling for the keyReleased event.
    default boolean
    keyReleased(int key, int scancode, int modifiers, boolean consumed)
    Root handler for keyReleased event.
    default boolean
    mouseClicked(double mouseX, double mouseY, int button)
    Override this method to implement handling for the mouseClicked event.
    default boolean
    mouseClicked(double mouseX, double mouseY, int button, boolean consumed)
    Root handler for mouseClick event.
    default void
    mouseMoved(double mouseX, double mouseY)
    Called whenever the cursor position changes.
    default boolean
    mouseReleased(double mouseX, double mouseY, int button)
    Override this method to implement handling for the mouseReleased event.
    default boolean
    mouseReleased(double mouseX, double mouseY, int button, boolean consumed)
    Root handler for mouseReleased event.
    default boolean
    mouseScrolled(double mouseX, double mouseY, double scroll)
    Override this method to implement handling for the mouseScrolled event.
    default boolean
    mouseScrolled(double mouseX, double mouseY, double scroll, boolean consumed)
    Root handler for mouseScrolled event.
  • Method Details

    • getChildren

      List<GuiElement<?>> getChildren()
      Returns:
      An unmodifiable list of all assigned child elements assigned to this parent. The list should be sorted in the order they were added.
    • mouseMoved

      default void mouseMoved(double mouseX, double mouseY)
      Called whenever the cursor position changes. Vanillas mouseDragged is not passed through because it is redundant. All mouse drag functionality can be archived using available events.
      Parameters:
      mouseX - new mouse X position
      mouseY - new mouse Y position
    • mouseClicked

      default boolean mouseClicked(double mouseX, double mouseY, int button)
      Override this method to implement handling for the mouseClicked event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can override mouseClicked(double, double, int, boolean)

      Note: You do not need to call super when overriding this interface method.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      button - Mouse Button
      Returns:
      true to consume event.
    • mouseClicked

      default boolean mouseClicked(double mouseX, double mouseY, int button, boolean consumed)
      Root handler for mouseClick event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of mouseClick handling should be implemented via mouseClicked(double, double, int)

      Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      button - Mouse Button
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.
    • mouseReleased

      default boolean mouseReleased(double mouseX, double mouseY, int button)
      Override this method to implement handling for the mouseReleased event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can override mouseReleased(double, double, int, boolean)

      Note: You do not need to call super when overriding this interface method.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      button - Mouse Button
      Returns:
      true to consume event.
    • mouseReleased

      default boolean mouseReleased(double mouseX, double mouseY, int button, boolean consumed)
      Root handler for mouseReleased event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of mouseReleased handling should be implemented via mouseReleased(double, double, int)

      Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      button - Mouse Button
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.
    • mouseScrolled

      default boolean mouseScrolled(double mouseX, double mouseY, double scroll)
      Override this method to implement handling for the mouseScrolled event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can override mouseScrolled(double, double, double, boolean)

      Note: You do not need to call super when overriding this interface method.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      scroll - Scroll direction and amount
      Returns:
      true to consume event.
    • mouseScrolled

      default boolean mouseScrolled(double mouseX, double mouseY, double scroll, boolean consumed)
      Root handler for mouseScrolled event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of mouseScrolled handling should be implemented via mouseScrolled(double, double, double)

      Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.

      Parameters:
      mouseX - Mouse X position
      mouseY - Mouse Y position
      scroll - Scroll direction and amount
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.
    • blockMouseEvents

      default boolean blockMouseEvents()
      Returns:
      True to prevent mouse events from being passed to elements bellow this element.
    • keyPressed

      default boolean keyPressed(int key, int scancode, int modifiers)
      Override this method to implement handling for the keyPressed event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can override keyPressed(int, int, int, boolean)

      Note: You do not need to call super when overriding this interface method.

      Parameters:
      key - the keyboard key that was pressed.
      scancode - the system-specific scancode of the key
      modifiers - bitfield describing which modifier keys were held down.
      Returns:
      true to consume event.
    • keyPressed

      default boolean keyPressed(int key, int scancode, int modifiers, boolean consumed)
      Root handler for keyPressed event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of keyPressed handling should be implemented via keyPressed(int, int, int)

      Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.

      Parameters:
      key - the keyboard key that was pressed.
      scancode - the system-specific scancode of the key
      modifiers - bitfield describing which modifier keys were held down.
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.
    • keyReleased

      default boolean keyReleased(int key, int scancode, int modifiers)
      Override this method to implement handling for the keyReleased event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can override keyReleased(int, int, int, boolean)

      Note: You do not need to call super when overriding this interface method.

      Parameters:
      key - the keyboard key that was released.
      scancode - the system-specific scancode of the key
      modifiers - bitfield describing which modifier keys were held down.
      Returns:
      true to consume event.
    • keyReleased

      default boolean keyReleased(int key, int scancode, int modifiers, boolean consumed)
      Root handler for keyReleased event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of keyReleased handling should be implemented via keyReleased(int, int, int)

      Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.

      Parameters:
      key - the keyboard key that was released.
      scancode - the system-specific scancode of the key
      modifiers - bitfield describing which modifier keys were held down.
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.
    • charTyped

      default boolean charTyped(char character, int modifiers)
      Override this method to implement handling for the charTyped event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can override charTyped(char, int, boolean)

      Note: You do not need to call super when overriding this interface method.

      Parameters:
      character - The character typed.
      modifiers - bitfield describing which modifier keys were held down.
      Returns:
      true to consume event.
    • charTyped

      default boolean charTyped(char character, int modifiers, boolean consumed)
      Root handler for charTyped event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of charTyped handling should be implemented via charTyped(char, int)

      Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.

      Parameters:
      character - The character typed.
      modifiers - bitfield describing which modifier keys were held down.
      consumed - Will be true if this action has already been consumed.
      Returns:
      true if this event has been consumed.