diff --git a/arc-core/src/arc/math/Mathf.java b/arc-core/src/arc/math/Mathf.java index a2213484..65e84a26 100644 --- a/arc-core/src/arc/math/Mathf.java +++ b/arc-core/src/arc/math/Mathf.java @@ -395,7 +395,7 @@ public static float clamp(float value, float min, float max){ /** Clamps to [0, 1]. */ public static float clamp(float value){ - return clamp(value, 0f, 1f); + return Math.max(Math.min(value, 1f), 0f); } public static double clamp(double value, double min, double max){ diff --git a/arc-core/src/arc/scene/ui/layout/Spacer.java b/arc-core/src/arc/scene/ui/layout/Spacer.java new file mode 100644 index 00000000..d6aa0484 --- /dev/null +++ b/arc-core/src/arc/scene/ui/layout/Spacer.java @@ -0,0 +1,38 @@ +package arc.scene.ui.layout; + +import arc.func.*; +import arc.scene.*; + +public class Spacer extends Element{ + Floatp widthFunc, heightFunc; + + public Spacer(Floatp widthFunc, Floatp heightFunc){ + this.widthFunc = widthFunc; + this.heightFunc = heightFunc; + + width = Scl.scl(widthFunc.get()); + height = Scl.scl(heightFunc.get()); + } + + @Override + public void act(float delta){ + super.act(delta); + + float w = Scl.scl(widthFunc.get()), h = Scl.scl(heightFunc.get()); + if(w != width || h != height){ + width = w; + height = h; + invalidateHierarchy(); + } + } + + @Override + public float getPrefHeight(){ + return Scl.scl(heightFunc.get()); + } + + @Override + public float getPrefWidth(){ + return Scl.scl(widthFunc.get()); + } +} diff --git a/arc-core/src/arc/scene/ui/layout/Table.java b/arc-core/src/arc/scene/ui/layout/Table.java index d794218d..c867cc82 100644 --- a/arc-core/src/arc/scene/ui/layout/Table.java +++ b/arc-core/src/arc/scene/ui/layout/Table.java @@ -366,6 +366,18 @@ public Cell stack(Element... elements){ return add(stack); } + public Cell spacer(Floatp width, Floatp height){ + return add(new Spacer(width, height)); + } + + public Cell spacerX(Floatp width){ + return add(new Spacer(width, () -> 0f)); + } + + public Cell spacerY(Floatp height){ + return add(new Spacer(() -> 0f, height)); + } + public Cell image(Prov reg){ return add(new Image(reg.get())).update(i -> { ((TextureRegionDrawable)i.getDrawable()).setRegion(reg.get()); diff --git a/arc-core/src/arc/struct/IntSeq.java b/arc-core/src/arc/struct/IntSeq.java index 1bbd9fae..44740906 100644 --- a/arc-core/src/arc/struct/IntSeq.java +++ b/arc-core/src/arc/struct/IntSeq.java @@ -125,6 +125,13 @@ public int sum(){ return sum; } + public void chunked(int chunkSize, Cons iterator){ + for(int i = 0; i < size; i += chunkSize){ + int[] slice = Arrays.copyOfRange(items, i, Math.min(i + chunkSize, size)); + iterator.get(slice); + } + } + /** * Adds a value if it was already not in this sequence. * @return whether this value was not present in this sequence.