Skip to content

Commit

Permalink
Dynamic spacer class
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Oct 3, 2024
1 parent 66ae776 commit bf2ab4d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
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 heightFunc.get();
}

@Override
public float getPrefWidth(){
return 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

0 comments on commit bf2ab4d

Please sign in to comment.