Package de.gurkenlabs.litiengine.gui
Class Menu
java.lang.Object
de.gurkenlabs.litiengine.gui.GuiComponent
de.gurkenlabs.litiengine.gui.ImageComponentList
de.gurkenlabs.litiengine.gui.Menu
- All Implemented Interfaces:
IRenderable,Tweenable,MouseListener,MouseMotionListener,MouseWheelListener,EventListener
Represents a menu component that extends the ImageComponentList. This class provides functionality to create a menu with selectable items.
-
Field Summary
Fields inherited from class de.gurkenlabs.litiengine.gui.GuiComponent
ICON_FONT -
Constructor Summary
ConstructorsConstructorDescriptionMenu(double x, double y, double width, double height, Spritesheet background, Orientation orientation, String... items) Constructs a new Menu with the specified position, size, background, and orientation.Menu(double x, double y, double width, double height, Orientation orientation, String... items) Constructs a new Menu with the specified position, size, and orientation.Constructs a new Menu with the specified position, size, and items. -
Method Summary
Modifier and TypeMethodDescriptionintGets the current selection index of the menu.Gets the orientation of the menu.voidonChange(IntConsumer cons) Adds a consumer that will be notified when the selection of the menu changes.voidprepare()Prepares the menu by setting the text of the menu buttons and adding the click listeners.voidsetCurrentSelection(int newSelection) Sets the current selection index of the menu and updates the selection state of the menu items.Methods inherited from class de.gurkenlabs.litiengine.gui.ImageComponentList
createNewEntry, getBackground, getCellComponents, getColumns, getColumnWidth, getImages, getRowHeight, getRows, setColumnWidth, setRowHeight, setXOffset, setYOffsetMethods inherited from class de.gurkenlabs.litiengine.gui.GuiComponent
addRenderedListener, addRenderListener, getAppearance, getAppearanceDisabled, getAppearanceHovered, getBoundingBox, getCenterX, getCenterY, getClickConsumer, getComponentId, getComponents, getCurrentAppearance, getFont, getHeight, getHoverConsumer, getHoverSound, getLocation, getMouseDraggedConsumer, getMouseEnterConsumer, getMouseLeaveConsumer, getMouseMovedConsumer, getMousePressedConsumer, getMouseReleasedConsumer, getMouseWheelConsumer, getName, getShape, getTag, getText, getTextAlign, getTextAngle, getTextShadowColor, getTextShadowRadius, getTextToRender, getTextValign, getTextX, getTextY, getTweenValues, getWidth, getX, getY, hasAutomaticLineBreaks, hasTextAntialiasing, hasTextShadow, initializeComponents, isEnabled, isForwardMouseEvents, isHovered, isPressed, isSelected, isSuspended, isVisible, mouseClicked, mouseDragged, mouseEntered, mouseEventShouldBeForwarded, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, onClicked, onHovered, onMouseDragged, onMouseEnter, onMouseLeave, onMouseMoved, onMousePressed, onMouseReleased, onMouseWheelScrolled, onTextChanged, removeListener, removeListener, render, setAutomaticLineBreaks, setDimension, setEnabled, setFont, setFontSize, setForwardMouseEvents, setHeight, setHovered, setHoverSound, setLocation, setLocation, setName, setSelected, setTag, setText, setTextAlign, setTextAngle, setTextAntialiasing, setTextShadow, setTextShadowColor, setTextShadowRadius, setTextValign, setTextX, setTextY, setTweenValues, setVisible, setWidth, setX, setY, suspend, toggleSelection, toggleSuspension
-
Constructor Details
-
Menu
public Menu(double x, double y, double width, double height, Orientation orientation, String... items) Constructs a new Menu with the specified position, size, and orientation.- Parameters:
x- The x-coordinate of the menu.y- The y-coordinate of the menu.width- The width of the menu.height- The height of the menu.orientation- The orientation of the menu (horizontal or vertical).items- The items to be displayed in the menu.
-
Menu
Constructs a new Menu with the specified position, size, and items.- Parameters:
x- The x-coordinate of the menu.y- The y-coordinate of the menu.width- The width of the menu.height- The height of the menu.items- The items to be displayed in the menu.
-
Menu
public Menu(double x, double y, double width, double height, Spritesheet background, Orientation orientation, String... items) Constructs a new Menu with the specified position, size, background, and orientation.- Parameters:
x- The x-coordinate of the menu.y- The y-coordinate of the menu.width- The width of the menu.height- The height of the menu.background- The background of the menu.orientation- The orientation of the menu (horizontal or vertical).items- The items to be displayed in the menu.
-
-
Method Details
-
getCurrentSelection
public int getCurrentSelection()Gets the current selection index of the menu.- Returns:
- The current selection index of the menu.
-
getOrientation
Gets the orientation of the menu.- Returns:
- The orientation of the menu.
-
onChange
Adds a consumer that will be notified when the selection of the menu changes.- Parameters:
cons- The consumer that will be notified when the selection of the menu changes.
-
prepare
public void prepare()Prepares the menu by setting the text of the menu buttons and adding the click listeners.- Overrides:
preparein classImageComponentList
-
setCurrentSelection
public void setCurrentSelection(int newSelection) Sets the current selection index of the menu and updates the selection state of the menu items.- Parameters:
newSelection- The index of the item to be selected.
-