Alignment
source
Description & Properties
The Alignment
enum class is used to define the alignment of GUI elements within a GUI. It provides a set of predefined alignment options that can be used to position elements such as buttons, text, and images within a GUI layout. The enum class has the following properties and methods:
TOP_LEFT
: Aligns elements to the top left corner of the GUI.TOP_CENTER
: Aligns elements to the top center of the GUI.TOP_RIGHT
: Aligns elements to the top right corner of the GUI.CENTER_LEFT
: Aligns elements to the center left of the GUI.CENTER
: Aligns elements to the center of the GUI.CENTER_RIGHT
: Aligns elements to the center right of the GUI.BOTTOM_LEFT
: Aligns elements to the bottom left corner of the GUI.BOTTOM_CENTER
: Aligns elements to the bottom center of the GUI.BOTTOM_RIGHT
: Aligns elements to the bottom right corner of the GUI.getIndex(alignment: Alignment, rows: Int)
: A static method that calculates the index of the slot corresponding to the specified alignment and number of rows in the GUI.
The getIndex
method takes an Alignment
value and the number of rows in the GUI as input and returns the index of the slot that represents the specified alignment within the GUI layout.
Example
You can use the Alignment
enum class to position elements within a GUI by calculating the slot index based on the desired alignment. The getIndex
method provides a convenient way to determine the slot index for a specific alignment and number of rows in the GUI.
Here is an example of how to use the Alignment
enum class in Kotlin:
or
In this example, we create an Alignment
enum value representing the top center alignment and specify the number of rows in the GUI. We then use the getIndex
method to calculate the slot index corresponding to the specified alignment within the GUI layout. This slot index can be used to position elements such as buttons or items within the GUI at the desired alignment.
By leveraging the Alignment
enum class and its getIndex
method, you can easily align elements within your GUI layouts and create visually appealing and organized interfaces for players to interact with in Minecraft.
Summary
The Alignment
enum class provides a flexible way to define and calculate the alignment of elements within a GUI layout. By using the predefined alignment options and the getIndex
method, you can position elements accurately within the GUI based on the desired alignment and number of rows. This allows you to create visually appealing and user-friendly GUIs that enhance the player experience in your Minecraft plugin or mod.