From 7bc5996cf95623dd4683fc4ebbda69bfd8a4349c Mon Sep 17 00:00:00 2001 From: Ivory Date: Sun, 29 Jan 2023 23:25:44 -0500 Subject: [PATCH] vertical layout & better management --- .../valnet/engine/graphics/ImmediateUI.java | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/valnet/engine/graphics/ImmediateUI.java b/src/main/java/xyz/valnet/engine/graphics/ImmediateUI.java index 5c0b9ae..bbacda5 100644 --- a/src/main/java/xyz/valnet/engine/graphics/ImmediateUI.java +++ b/src/main/java/xyz/valnet/engine/graphics/ImmediateUI.java @@ -9,6 +9,7 @@ import java.util.Set; import java.util.Stack; import xyz.valnet.engine.math.Box; +import xyz.valnet.engine.math.Vector2i; import xyz.valnet.engine.math.Vector4f; import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.scenegraph.GameObject; @@ -120,12 +121,34 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre ); } + private void setBoxWidth(float width) { + context = new StackingContext( + context.fixedSize, + new Box(context.box.x, context.box.y, width, context.box.h), + context.occlusionBox, + context.hasRegisteredGuiArea, + context.horizontal + ); + } + + private void setBoxHeight(float height) { + context = new StackingContext( + context.fixedSize, + new Box(context.box.x, context.box.y, context.box.w, height), + context.occlusionBox, + context.hasRegisteredGuiArea, + context.horizontal + ); + } + private void adjustBox(float w, float h) { if(context.vertical()) { if(context.fixedSize) { modifyBox(0, h, 0, -h); } else { modifyBox(0, 0, 0, h); + if (w - context.box.w > 0) + modifyBox(0, 0, w - context.box.w, 0); } } else { if(context.fixedSize) { @@ -158,6 +181,19 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre return getLayer() + contextStack.size() * 0.001f; } + // PLEASE PLEASE INLINE THIS DOGWATER CALL + private final Vector2i getNextBoxLocation() { + if(context.fixedSize) { + return context.box.a.asInt(); + } else { + if(context.horizontal) { + return new Vector2i((int) context.box.x2, (int) context.box.y); + } else { + return new Vector2i((int) context.box.x, (int) context.box.y2); + } + } + } + // === ELEMENTS === // @@ -342,7 +378,7 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre contextStack.push(context); context = new StackingContext( false, - new Box(context.box.x, context.box.y, 0, 0), + new Box(getNextBoxLocation(), 0, 0), context.occlusionBox, context.hasRegisteredGuiArea, true @@ -354,6 +390,22 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre adjustBox(w, h); } + protected void vertical(RenderCallback cb) { + contextStack.push(context); + context = new StackingContext( + false, + new Box(getNextBoxLocation(), 0, 0), + context.occlusionBox, + context.hasRegisteredGuiArea, + false + ); + cb.apply(); + float w = context.box.w; + float h = context.box.h; + context = contextStack.pop(); + adjustBox(w, h); + } + protected void space(int space) { if(context.horizontal) adjustBox(space, 1);