aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java
diff options
context:
space:
mode:
authorMoulberry <james.jenour@student.scotch.wa.edu.au>2020-10-03 06:09:28 +1000
committerMoulberry <james.jenour@student.scotch.wa.edu.au>2020-10-03 06:09:28 +1000
commit275fe45caa8eb1048914d864aafae21f3f3a1157 (patch)
tree87fe9a8e5f996c7cbc6fc81f2f522561ceb96992 /src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java
parentbb067068aabda36f8ba74b34a68856e19139beb9 (diff)
downloadnotenoughupdates-275fe45caa8eb1048914d864aafae21f3f3a1157.tar.gz
notenoughupdates-275fe45caa8eb1048914d864aafae21f3f3a1157.tar.bz2
notenoughupdates-275fe45caa8eb1048914d864aafae21f3f3a1157.zip
1.3.3-ALPA
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java
new file mode 100644
index 00000000..77a28fd5
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupAligned.java
@@ -0,0 +1,67 @@
+package io.github.moulberry.notenoughupdates.mbgui;
+
+import org.lwjgl.util.vector.Vector2f;
+
+import java.util.Collection;
+import java.util.List;
+
+public abstract class MBGuiGroupAligned extends MBGuiGroup {
+
+ //Serialized
+ private List<MBGuiElement> children;
+ private boolean vertical;
+
+ public MBGuiGroupAligned(List<MBGuiElement> children, boolean vertical) {
+ this.children = children;
+ this.vertical = vertical;
+ recalculate();
+ }
+
+ public abstract int getPadding();
+
+ public Collection<MBGuiElement> getChildren() {
+ return children;
+ }
+
+ public void recalculate() {
+ for(MBGuiElement child : children) {
+ child.recalculate();
+ }
+
+ if(vertical) {
+ height = 0;
+ for(int i=0; i<children.size(); i++) {
+ MBGuiElement child = children.get(i);
+ childrenPosition.put(child, new Vector2f(0, height));
+ height += child.getHeight();
+ if(i != children.size()-1) height += getPadding();
+ }
+
+ width = 0;
+ for(MBGuiElement child : children) {
+ int childWidth = child.getWidth();
+ if(childWidth > width) {
+ width = childWidth;
+ }
+ }
+ } else {
+ width = 0;
+ for(int i=0; i<children.size(); i++) {
+ MBGuiElement child = children.get(i);
+ childrenPosition.put(child, new Vector2f(width, 0));
+ width += child.getWidth();
+ if(i != children.size()-1) width += getPadding();
+ }
+
+ height = 0;
+ for(MBGuiElement child : children) {
+ int childHeight = child.getHeight();
+ if(childHeight > height) {
+ height = childHeight;
+ }
+ }
+ }
+
+ }
+
+}