AbstractLayout.java
net.minecraft.client.gui.layouts.AbstractLayout
信息
- 全限定名:net.minecraft.client.gui.layouts.AbstractLayout
- 类型:public abstract class
- 包:net.minecraft.client.gui.layouts
- 源码路径:src/main/java/net/minecraft/client/gui/layouts/AbstractLayout.java
- 起始行号:L8
- 实现:Layout
- 职责:
TODO
字段/常量
-
x- 类型:
int - 修饰符:
private - 源码定位:
L9 - 说明:
TODO
- 类型:
-
y- 类型:
int - 修饰符:
private - 源码定位:
L10 - 说明:
TODO
- 类型:
-
width- 类型:
int - 修饰符:
protected - 源码定位:
L11 - 说明:
TODO
- 类型:
-
height- 类型:
int - 修饰符:
protected - 源码定位:
L12 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.gui.layouts.AbstractLayout.AbstractChildWrapper- 类型:
class - 修饰符:
protected abstract static - 源码定位:
L60 - 说明:
TODO
- 类型:
构造器
public AbstractLayout(int x, int y, int width, int height) @ L14
- 构造器名:AbstractLayout
- 源码定位:L14
- 修饰符:public
参数:
- x: int
- y: int
- width: int
- height: int
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void setX(int x) @ L21
- 方法名:setX
- 源码定位:L21
- 返回类型:void
- 修饰符:public
参数:
- x: int
说明:
TODO
public void setY(int y) @ L30
- 方法名:setY
- 源码定位:L30
- 返回类型:void
- 修饰符:public
参数:
- y: int
说明:
TODO
public int getX() @ L39
- 方法名:getX
- 源码定位:L39
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int getY() @ L44
- 方法名:getY
- 源码定位:L44
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int getWidth() @ L49
- 方法名:getWidth
- 源码定位:L49
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int getHeight() @ L54
- 方法名:getHeight
- 源码定位:L54
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public abstract class AbstractLayout implements Layout {
private int x;
private int y;
protected int width;
protected int height;
public AbstractLayout(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
@Override
public void setX(int x) {
this.visitChildren(child -> {
int newChildX = child.getX() + (x - this.getX());
child.setX(newChildX);
});
this.x = x;
}
@Override
public void setY(int y) {
this.visitChildren(child -> {
int newChildY = child.getY() + (y - this.getY());
child.setY(newChildY);
});
this.y = y;
}
@Override
public int getX() {
return this.x;
}
@Override
public int getY() {
return this.y;
}
@Override
public int getWidth() {
return this.width;
}
@Override
public int getHeight() {
return this.height;
}
@OnlyIn(Dist.CLIENT)
protected abstract static class AbstractChildWrapper {
public final LayoutElement child;
public final LayoutSettings.LayoutSettingsImpl layoutSettings;
protected AbstractChildWrapper(LayoutElement child, LayoutSettings layoutSettings) {
this.child = child;
this.layoutSettings = layoutSettings.getExposed();
}
public int getHeight() {
return this.child.getHeight() + this.layoutSettings.paddingTop + this.layoutSettings.paddingBottom;
}
public int getWidth() {
return this.child.getWidth() + this.layoutSettings.paddingLeft + this.layoutSettings.paddingRight;
}
public void setX(int x, int availableSpace) {
float leastOffset = this.layoutSettings.paddingLeft;
float mostOffset = availableSpace - this.child.getWidth() - this.layoutSettings.paddingRight;
int offset = (int)Mth.lerp(this.layoutSettings.xAlignment, leastOffset, mostOffset);
this.child.setX(offset + x);
}
public void setY(int y, int availableSpace) {
float leastOffset = this.layoutSettings.paddingTop;
float mostOffset = availableSpace - this.child.getHeight() - this.layoutSettings.paddingBottom;
int offset = Math.round(Mth.lerp(this.layoutSettings.yAlignment, leastOffset, mostOffset));
this.child.setY(offset + y);
}
}
}