Skip to content

Commit

Permalink
Merge branch 'master' into be
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Oct 9, 2024
2 parents 5ed3082 + a39155a commit 29dfdda
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arc-core/src/arc/math/Mathf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
38 changes: 38 additions & 0 deletions arc-core/src/arc/scene/ui/layout/Spacer.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
12 changes: 12 additions & 0 deletions arc-core/src/arc/scene/ui/layout/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ public Cell<Stack> stack(Element... elements){
return add(stack);
}

public Cell<Spacer> spacer(Floatp width, Floatp height){
return add(new Spacer(width, height));
}

public Cell<Spacer> spacerX(Floatp width){
return add(new Spacer(width, () -> 0f));
}

public Cell<Spacer> spacerY(Floatp height){
return add(new Spacer(() -> 0f, height));
}

public Cell<Image> image(Prov<TextureRegion> reg){
return add(new Image(reg.get())).update(i -> {
((TextureRegionDrawable)i.getDrawable()).setRegion(reg.get());
Expand Down
7 changes: 7 additions & 0 deletions arc-core/src/arc/struct/IntSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public int sum(){
return sum;
}

public void chunked(int chunkSize, Cons<int[]> 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.
Expand Down

0 comments on commit 29dfdda

Please sign in to comment.