Compare commits
2 Commits
30def95bb1
...
9dca822b21
Author | SHA1 | Date |
---|---|---|
Speiger | 9dca822b21 | |
Speiger | 99951a1642 |
|
@ -0,0 +1,56 @@
|
|||
package speiger.src.coreengine.rendering.newGui.layout.constraints;
|
||||
|
||||
import speiger.src.coreengine.rendering.newGui.components.base.GuiComponent;
|
||||
import speiger.src.coreengine.rendering.newGui.layout.constraints.IConstraint.Target;
|
||||
|
||||
public class ConstraintContainer {
|
||||
private static final int CONSTRAINT_LENGTH = 4;
|
||||
IConstraint[] constraints = new IConstraint[CONSTRAINT_LENGTH];
|
||||
|
||||
private ConstraintContainer() {}
|
||||
|
||||
public void apply(GuiComponent owner, GuiComponent parent) {
|
||||
for(int i = 0;i<4;i++) {
|
||||
if(constraints[i] == null) continue;
|
||||
constraints[i].apply(owner, parent, Target.by(i));
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() { return new Builder(); }
|
||||
public Builder copy() { return new Builder(this); }
|
||||
|
||||
public static class Builder {
|
||||
ConstraintContainer container = new ConstraintContainer();
|
||||
|
||||
private Builder() {}
|
||||
private Builder(ConstraintContainer container) {
|
||||
System.arraycopy(container.constraints, 0, this.container.constraints, 0, CONSTRAINT_LENGTH);
|
||||
}
|
||||
|
||||
public Builder x(IConstraint value) {
|
||||
container.constraints[Target.X.ordinal()] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder y(IConstraint value) {
|
||||
container.constraints[Target.Y.ordinal()] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder width(IConstraint value) {
|
||||
container.constraints[Target.WIDTH.ordinal()] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder height(IConstraint value) {
|
||||
container.constraints[Target.HEIGHT.ordinal()] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstraintContainer build() {
|
||||
var result = container;
|
||||
container = null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package speiger.src.coreengine.rendering.newGui.layout.constraints;
|
||||
|
||||
import speiger.src.coreengine.rendering.gui.helper.box.IGuiBox;
|
||||
import speiger.src.coreengine.rendering.newGui.layout.constraints.IConstraint.ISimpleConstraint;
|
||||
|
||||
public class Constraints {
|
||||
public static record Pixels(float value, boolean inverted) implements ISimpleConstraint {
|
||||
|
||||
public static Pixels of(float value) { return new Pixels(value, false); }
|
||||
public static Pixels inverted(float value) { return new Pixels(value, true); }
|
||||
|
||||
@Override
|
||||
public void apply(IGuiBox owner, IGuiBox parent, Target target) {
|
||||
target.set(owner, inverted ? target.asArea().get(parent) - value : value);
|
||||
}
|
||||
}
|
||||
|
||||
public static record Parent(float padding, boolean inv) implements ISimpleConstraint {
|
||||
|
||||
public static Parent of() { return new Parent(0F, false); }
|
||||
public static Parent of(float padding) { return new Parent(padding, false); }
|
||||
public static Parent inverted() { return new Parent(0F, true); }
|
||||
public static Parent inverted(float padding) { return new Parent(padding, true); }
|
||||
|
||||
@Override
|
||||
public void apply(IGuiBox owner, IGuiBox parent, Target target) {
|
||||
//TODO implement
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package speiger.src.coreengine.rendering.newGui.layout.constraints;
|
||||
|
||||
import speiger.src.coreengine.rendering.gui.helper.box.IGuiBox;
|
||||
import speiger.src.coreengine.rendering.newGui.components.base.GuiComponent;
|
||||
|
||||
public interface IConstraint {
|
||||
public void apply(GuiComponent owner, GuiComponent child, Target target);
|
||||
|
||||
public static interface ISimpleConstraint extends IConstraint {
|
||||
@Override
|
||||
default void apply(GuiComponent owner, GuiComponent parent, Target target) { apply(owner.getBox(), parent.getBox(), target); }
|
||||
public void apply(IGuiBox owner, IGuiBox parent, Target target);
|
||||
}
|
||||
|
||||
public static enum Target {
|
||||
X,
|
||||
Y,
|
||||
WIDTH,
|
||||
HEIGHT;
|
||||
|
||||
static final Target[] BY_INDEX = values();
|
||||
|
||||
public static Target by(int index) { return BY_INDEX[index & 3]; }
|
||||
public static Target pos(boolean x) { return x ? X : Y; }
|
||||
public static Target bounds(boolean x) { return x ? WIDTH : HEIGHT; }
|
||||
public boolean isPosition() { return this == X || this == Y; }
|
||||
public Target asArea() {
|
||||
return switch(this) {
|
||||
case X -> WIDTH;
|
||||
case Y -> HEIGHT;
|
||||
default -> this;
|
||||
};
|
||||
}
|
||||
|
||||
public float get(GuiComponent comp) { return get(comp.getBox()); }
|
||||
public void set(GuiComponent comp, float value) { set(comp.getBox(), value); }
|
||||
|
||||
public float get(IGuiBox box) {
|
||||
return switch(this) {
|
||||
case X -> box.getMinX();
|
||||
case Y -> box.getMinY();
|
||||
case WIDTH -> box.getBaseWidth();
|
||||
case HEIGHT -> box.getBaseHeight();
|
||||
};
|
||||
}
|
||||
|
||||
public void set(IGuiBox box, float value) {
|
||||
switch(this) {
|
||||
case X -> box.setX(value);
|
||||
case Y -> box.setY(value);
|
||||
case WIDTH -> box.setWidth(value);
|
||||
case HEIGHT -> box.setHeight(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package speiger.src.coreengine.rendering.newGui.layout.layouts;
|
||||
|
||||
import speiger.src.coreengine.rendering.newGui.components.base.GuiComponent;
|
||||
|
||||
public interface ILayout {
|
||||
public default ILayout add(GuiComponent comp) { return add(comp, null); }
|
||||
public ILayout add(GuiComponent comp, Object value);
|
||||
public ILayout remove(GuiComponent comp);
|
||||
|
||||
public void apply();
|
||||
}
|
Loading…
Reference in New Issue