Spaces:
Build error
Build error
File size: 3,458 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
package net.minecraft.client.gui.layouts;
import java.util.function.Consumer;
import net.minecraft.Util;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class LinearLayout implements Layout {
private final GridLayout wrapped;
private final LinearLayout.Orientation orientation;
private int nextChildIndex = 0;
private LinearLayout(LinearLayout.Orientation p_265341_) {
this(0, 0, p_265341_);
}
public LinearLayout(int p_265093_, int p_265502_, LinearLayout.Orientation p_265112_) {
this.wrapped = new GridLayout(p_265093_, p_265502_);
this.orientation = p_265112_;
}
public LinearLayout spacing(int p_298391_) {
this.orientation.setSpacing(this.wrapped, p_298391_);
return this;
}
public LayoutSettings newCellSettings() {
return this.wrapped.newCellSettings();
}
public LayoutSettings defaultCellSetting() {
return this.wrapped.defaultCellSetting();
}
public <T extends LayoutElement> T addChild(T p_265475_, LayoutSettings p_265684_) {
return this.orientation.addChild(this.wrapped, p_265475_, this.nextChildIndex++, p_265684_);
}
public <T extends LayoutElement> T addChild(T p_265140_) {
return this.addChild(p_265140_, this.newCellSettings());
}
public <T extends LayoutElement> T addChild(T p_300762_, Consumer<LayoutSettings> p_300497_) {
return this.orientation.addChild(this.wrapped, p_300762_, this.nextChildIndex++, Util.make(this.newCellSettings(), p_300497_));
}
@Override
public void visitChildren(Consumer<LayoutElement> p_265508_) {
this.wrapped.visitChildren(p_265508_);
}
@Override
public void arrangeElements() {
this.wrapped.arrangeElements();
}
@Override
public int getWidth() {
return this.wrapped.getWidth();
}
@Override
public int getHeight() {
return this.wrapped.getHeight();
}
@Override
public void setX(int p_297321_) {
this.wrapped.setX(p_297321_);
}
@Override
public void setY(int p_299381_) {
this.wrapped.setY(p_299381_);
}
@Override
public int getX() {
return this.wrapped.getX();
}
@Override
public int getY() {
return this.wrapped.getY();
}
public static LinearLayout vertical() {
return new LinearLayout(LinearLayout.Orientation.VERTICAL);
}
public static LinearLayout horizontal() {
return new LinearLayout(LinearLayout.Orientation.HORIZONTAL);
}
@OnlyIn(Dist.CLIENT)
public static enum Orientation {
HORIZONTAL,
VERTICAL;
void setSpacing(GridLayout p_299858_, int p_299775_) {
switch (this) {
case HORIZONTAL:
p_299858_.columnSpacing(p_299775_);
break;
case VERTICAL:
p_299858_.rowSpacing(p_299775_);
}
}
public <T extends LayoutElement> T addChild(GridLayout p_298633_, T p_297548_, int p_300692_, LayoutSettings p_298693_) {
return (T)(switch (this) {
case HORIZONTAL -> (LayoutElement)p_298633_.addChild(p_297548_, 0, p_300692_, p_298693_);
case VERTICAL -> (LayoutElement)p_298633_.addChild(p_297548_, p_300692_, 0, p_298693_);
});
}
}
} |