EqualSpacingLayout.java
net.minecraft.client.gui.layouts.EqualSpacingLayout
信息
- 全限定名:net.minecraft.client.gui.layouts.EqualSpacingLayout
- 类型:public class
- 包:net.minecraft.client.gui.layouts
- 源码路径:src/main/java/net/minecraft/client/gui/layouts/EqualSpacingLayout.java
- 起始行号:L13
- 继承:AbstractLayout
- 职责:
TODO
字段/常量
-
orientation- 类型:
EqualSpacingLayout.Orientation - 修饰符:
private final - 源码定位:
L14 - 说明:
TODO
- 类型:
-
children- 类型:
List<EqualSpacingLayout.ChildContainer> - 修饰符:
private final - 源码定位:
L15 - 说明:
TODO
- 类型:
-
defaultChildLayoutSettings- 类型:
LayoutSettings - 修饰符:
private final - 源码定位:
L16 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.layouts.EqualSpacingLayout.ChildContainer- 类型:
class - 修饰符:
private static - 源码定位:
L99 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.layouts.EqualSpacingLayout.Orientation- 类型:
enum - 修饰符:
public static - 源码定位:
L106 - 说明:
TODO
- 类型:
构造器
public EqualSpacingLayout(int width, int height, EqualSpacingLayout.Orientation orientation) @ L18
- 构造器名:EqualSpacingLayout
- 源码定位:L18
- 修饰符:public
参数:
- width: int
- height: int
- orientation: EqualSpacingLayout.Orientation
说明:
TODO
public EqualSpacingLayout(int x, int y, int width, int height, EqualSpacingLayout.Orientation orientation) @ L22
- 构造器名:EqualSpacingLayout
- 源码定位:L22
- 修饰符:public
参数:
- x: int
- y: int
- width: int
- height: int
- orientation: EqualSpacingLayout.Orientation
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void arrangeElements() @ L27
- 方法名:arrangeElements
- 源码定位:L27
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void visitChildren(Consumer<LayoutElement> layoutElementVisitor) @ L72
- 方法名:visitChildren
- 源码定位:L72
- 返回类型:void
- 修饰符:public
参数:
- layoutElementVisitor: Consumer
说明:
TODO
public LayoutSettings newChildLayoutSettings() @ L77
- 方法名:newChildLayoutSettings
- 源码定位:L77
- 返回类型:LayoutSettings
- 修饰符:public
参数:
- 无
说明:
TODO
public LayoutSettings defaultChildLayoutSetting() @ L81
- 方法名:defaultChildLayoutSetting
- 源码定位:L81
- 返回类型:LayoutSettings
- 修饰符:public
参数:
- 无
说明:
TODO
public <T extends LayoutElement> T addChild(T child) @ L85
- 方法名:addChild
- 源码定位:L85
- 返回类型:
T - 修饰符:public
参数:
- child: T
说明:
TODO
public <T extends LayoutElement> T addChild(T child, LayoutSettings layoutSettings) @ L89
- 方法名:addChild
- 源码定位:L89
- 返回类型:
T - 修饰符:public
参数:
- child: T
- layoutSettings: LayoutSettings
说明:
TODO
public <T extends LayoutElement> T addChild(T child, Consumer<LayoutSettings> layoutSettingsAdjustments) @ L94
- 方法名:addChild
- 源码定位:L94
- 返回类型:
T - 修饰符:public
参数:
- child: T
- layoutSettingsAdjustments: Consumer
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class EqualSpacingLayout extends AbstractLayout {
private final EqualSpacingLayout.Orientation orientation;
private final List<EqualSpacingLayout.ChildContainer> children = new ArrayList<>();
private final LayoutSettings defaultChildLayoutSettings = LayoutSettings.defaults();
public EqualSpacingLayout(int width, int height, EqualSpacingLayout.Orientation orientation) {
this(0, 0, width, height, orientation);
}
public EqualSpacingLayout(int x, int y, int width, int height, EqualSpacingLayout.Orientation orientation) {
super(x, y, width, height);
this.orientation = orientation;
}
@Override
public void arrangeElements() {
super.arrangeElements();
if (!this.children.isEmpty()) {
int totalChildPrimaryLength = 0;
int maxChildSecondaryLength = this.orientation.getSecondaryLength(this);
for (EqualSpacingLayout.ChildContainer child : this.children) {
totalChildPrimaryLength += this.orientation.getPrimaryLength(child);
maxChildSecondaryLength = Math.max(maxChildSecondaryLength, this.orientation.getSecondaryLength(child));
}
int remainingSpace = this.orientation.getPrimaryLength(this) - totalChildPrimaryLength;
int position = this.orientation.getPrimaryPosition(this);
Iterator<EqualSpacingLayout.ChildContainer> childIterator = this.children.iterator();
EqualSpacingLayout.ChildContainer firstChild = childIterator.next();
this.orientation.setPrimaryPosition(firstChild, position);
position += this.orientation.getPrimaryLength(firstChild);
if (this.children.size() >= 2) {
Divisor divisor = new Divisor(remainingSpace, this.children.size() - 1);
while (divisor.hasNext()) {
position += divisor.nextInt();
EqualSpacingLayout.ChildContainer child = childIterator.next();
this.orientation.setPrimaryPosition(child, position);
position += this.orientation.getPrimaryLength(child);
}
}
int thisSecondaryPosition = this.orientation.getSecondaryPosition(this);
for (EqualSpacingLayout.ChildContainer child : this.children) {
this.orientation.setSecondaryPosition(child, thisSecondaryPosition, maxChildSecondaryLength);
}
switch (this.orientation) {
case HORIZONTAL:
this.height = maxChildSecondaryLength;
break;
case VERTICAL:
this.width = maxChildSecondaryLength;
}
}
}
@Override
public void visitChildren(Consumer<LayoutElement> layoutElementVisitor) {
this.children.forEach(wrapper -> layoutElementVisitor.accept(wrapper.child));
}
public LayoutSettings newChildLayoutSettings() {
return this.defaultChildLayoutSettings.copy();
}
public LayoutSettings defaultChildLayoutSetting() {
return this.defaultChildLayoutSettings;
}
public <T extends LayoutElement> T addChild(T child) {
return this.addChild(child, this.newChildLayoutSettings());
}
public <T extends LayoutElement> T addChild(T child, LayoutSettings layoutSettings) {
this.children.add(new EqualSpacingLayout.ChildContainer(child, layoutSettings));
return child;
}
public <T extends LayoutElement> T addChild(T child, Consumer<LayoutSettings> layoutSettingsAdjustments) {
return this.addChild(child, Util.make(this.newChildLayoutSettings(), layoutSettingsAdjustments));
}
@OnlyIn(Dist.CLIENT)
private static class ChildContainer extends AbstractLayout.AbstractChildWrapper {
protected ChildContainer(LayoutElement child, LayoutSettings layoutSettings) {
super(child, layoutSettings);
}
}
@OnlyIn(Dist.CLIENT)
public static enum Orientation {
HORIZONTAL,
VERTICAL;
private int getPrimaryLength(LayoutElement widget) {
return switch (this) {
case HORIZONTAL -> widget.getWidth();
case VERTICAL -> widget.getHeight();
};
}
private int getPrimaryLength(EqualSpacingLayout.ChildContainer childContainer) {
return switch (this) {
case HORIZONTAL -> childContainer.getWidth();
case VERTICAL -> childContainer.getHeight();
};
}
private int getSecondaryLength(LayoutElement widget) {
return switch (this) {
case HORIZONTAL -> widget.getHeight();
case VERTICAL -> widget.getWidth();
};
}
private int getSecondaryLength(EqualSpacingLayout.ChildContainer childContainer) {
return switch (this) {
case HORIZONTAL -> childContainer.getHeight();
case VERTICAL -> childContainer.getWidth();
};
}
private void setPrimaryPosition(EqualSpacingLayout.ChildContainer childContainer, int position) {
switch (this) {
case HORIZONTAL:
childContainer.setX(position, childContainer.getWidth());
break;
case VERTICAL:
childContainer.setY(position, childContainer.getHeight());
}
}
private void setSecondaryPosition(EqualSpacingLayout.ChildContainer childContainer, int position, int availableSpace) {
switch (this) {
case HORIZONTAL:
childContainer.setY(position, availableSpace);
break;
case VERTICAL:
childContainer.setX(position, availableSpace);
}
}
private int getPrimaryPosition(LayoutElement widget) {
return switch (this) {
case HORIZONTAL -> widget.getX();
case VERTICAL -> widget.getY();
};
}
private int getSecondaryPosition(LayoutElement widget) {
return switch (this) {
case HORIZONTAL -> widget.getY();
case VERTICAL -> widget.getX();
};
}
}
}引用的其他类
-
- 引用位置:
构造调用 - 关联成员:
Divisor()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
LayoutSettings.defaults()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.make()
- 引用位置: