AbstractLayout .java

net.minecraft.client.gui.layouts.AbstractLayout (class): members: AbstractChildWrapper, setX, setY, getY, getX, getWidth, getHeight, width, height.

net.minecraft.client.gui.layoutsclass92 linesclient2.3 KB

Implements

API Surface (10)

void setX(final int x)
void setY(final int y)
int getX()
int getY()
int getWidth()
int getHeight()
int getHeight()
int getWidth()
void setX(final int x, final int availableSpace)
void setY(final int y, final int availableSpace)

Fields & Constants (4)

x
y
width
height

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

AbstractLayout.java92 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.layouts;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.util.Mth;
6
7
@Environment(EnvType.CLIENT)
8
public abstract class AbstractLayout implements Layout {
9
	private int x;
10
	private int y;
11
	protected int width;
12
	protected int height;
13
14
	public AbstractLayout(final int x, final int y, final int width, final int height) {
15
		this.x = x;
16
		this.y = y;
17
		this.width = width;
18
		this.height = height;
19
	}
20
21
	@Override
22
	public void setX(final int x) {
23
		this.visitChildren(child -> {
24
			int newChildX = child.getX() + (x - this.getX());
25
			child.setX(newChildX);
26
		});
27
		this.x = x;
28
	}
29
30
	@Override
31
	public void setY(final int y) {
32
		this.visitChildren(child -> {
33
			int newChildY = child.getY() + (y - this.getY());
34
			child.setY(newChildY);
35
		});
36
		this.y = y;
37
	}
38
39
	@Override
40
	public int getX() {
41
		return this.x;
42
	}
43
44
	@Override
45
	public int getY() {
46
		return this.y;
47
	}
48
49
	@Override
50
	public int getWidth() {
51
		return this.width;
52
	}
53
54
	@Override
55
	public int getHeight() {
56
		return this.height;
57
	}
58
59
	@Environment(EnvType.CLIENT)
60
	protected abstract static class AbstractChildWrapper {
61
		public final LayoutElement child;
62
		public final LayoutSettings.LayoutSettingsImpl layoutSettings;
63
64
		protected AbstractChildWrapper(final LayoutElement child, final LayoutSettings layoutSettings) {
65
			this.child = child;
66
			this.layoutSettings = layoutSettings.getExposed();
67
		}
68
69
		public int getHeight() {
70
			return this.child.getHeight() + this.layoutSettings.paddingTop + this.layoutSettings.paddingBottom;
71
		}
72
73
		public int getWidth() {
74
			return this.child.getWidth() + this.layoutSettings.paddingLeft + this.layoutSettings.paddingRight;
75
		}
76
77
		public void setX(final int x, final int availableSpace) {
78
			float leastOffset = this.layoutSettings.paddingLeft;
79
			float mostOffset = availableSpace - this.child.getWidth() - this.layoutSettings.paddingRight;
80
			int offset = (int)Mth.lerp(this.layoutSettings.xAlignment, leastOffset, mostOffset);
81
			this.child.setX(offset + x);
82
		}
83
84
		public void setY(final int y, final int availableSpace) {
85
			float leastOffset = this.layoutSettings.paddingTop;
86
			float mostOffset = availableSpace - this.child.getHeight() - this.layoutSettings.paddingBottom;
87
			int offset = Math.round(Mth.lerp(this.layoutSettings.yAlignment, leastOffset, mostOffset));
88
			this.child.setY(offset + y);
89
		}
90
	}
91
}
92

Decompiled Minecraft 26.3 source of AbstractLayout (net/minecraft/client/gui/layouts/AbstractLayout.java) with Mojang official mappings, stored verbatim on the site.