-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an IPlaceable interface for GUI elements that can have their posi…
…tion set
- Loading branch information
Showing
29 changed files
with
497 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
CommonApi/src/main/java/mezz/jei/api/gui/placement/HorizontalAlignment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package mezz.jei.api.gui.placement; | ||
|
||
/** | ||
* Represents a horizontal alignment of an element inside a larger area. | ||
* @since 19.19.1 | ||
*/ | ||
public enum HorizontalAlignment { | ||
LEFT { | ||
@Override | ||
public int getXPos(int availableWidth, int elementWidth) { | ||
return 0; | ||
} | ||
}, | ||
CENTER { | ||
@Override | ||
public int getXPos(int availableWidth, int elementWidth) { | ||
return Math.round((availableWidth - elementWidth) / 2f); | ||
} | ||
}, | ||
RIGHT { | ||
@Override | ||
public int getXPos(int availableWidth, int elementWidth) { | ||
return availableWidth - elementWidth; | ||
} | ||
}; | ||
|
||
/** | ||
* Calculate the x position needed to align an element with the given width inside the availableArea. | ||
* @since 19.19.1 | ||
*/ | ||
public abstract int getXPos(int availableWidth, int elementWidth); | ||
} |
37 changes: 37 additions & 0 deletions
37
CommonApi/src/main/java/mezz/jei/api/gui/placement/IPlaceable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package mezz.jei.api.gui.placement; | ||
|
||
/** | ||
* Interface for things that can have their position set, and be aligned vertically and horizontally in an area. | ||
* | ||
* @since 19.19.1 | ||
*/ | ||
public interface IPlaceable<THIS extends IPlaceable<THIS>> { | ||
/** | ||
* Place this element at the given position. | ||
* @since 19.19.1 | ||
*/ | ||
THIS setPosition(int xPos, int yPos); | ||
|
||
/** | ||
* Place this element inside the given area, with the given alignment. | ||
* | ||
* @since 19.19.1 | ||
*/ | ||
default THIS setPosition(int areaX, int areaY, int areaWidth, int areaHeight, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { | ||
int x = areaX + horizontalAlignment.getXPos(areaWidth, getWidth()); | ||
int y = areaY + verticalAlignment.getYPos(areaHeight, getHeight()); | ||
return setPosition(x, y); | ||
} | ||
|
||
/** | ||
* Get the width of this element. | ||
* @since 19.19.1 | ||
*/ | ||
int getWidth(); | ||
|
||
/** | ||
* Get the height of this element. | ||
* @since 19.19.1 | ||
*/ | ||
int getHeight(); | ||
} |
Oops, something went wrong.