LinearLayout .java

net.minecraft.client.gui.layouts.LinearLayout (class): members: nextChildIndex, defaultCellSetting, newCellSettings, Orientation, vertical, spacing, setX.

net.minecraft.client.gui.layoutsclass125 linesclient3.1 KB

Implements

API Surface (18)

LinearLayout spacing(final int spacing)
LayoutSettings newCellSettings()
LayoutSettings defaultCellSetting()
<T extends LayoutElement> T addChild(final T child, final LayoutSettings cellSettings)
<T extends LayoutElement> T addChild(final T child)
<T extends LayoutElement> T addChild(final T child, final Consumer<LayoutSettings> layoutSettingsAdjustments)
void visitChildren(final Consumer<LayoutElement> layoutElementVisitor)
void removeChildren()
void arrangeElements()
int getWidth()
int getHeight()
void setX(final int x)
void setY(final int y)
int getX()
int getY()
LinearLayout vertical()
LinearLayout horizontal()
<T extends LayoutElement> T addChild(final GridLayout gridLayout, final T child, final int index, final LayoutSettings cellSettings)

Fields & Constants (3)

wrapped
orientation
nextChildIndex

Code Graph: Dependencies (6)

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

Full Source

LinearLayout.java125 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.layouts;
2
3
import java.util.function.Consumer;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.util.Util;
7
8
@Environment(EnvType.CLIENT)
9
public class LinearLayout implements Layout {
10
	private final GridLayout wrapped;
11
	private final LinearLayout.Orientation orientation;
12
	private int nextChildIndex = 0;
13
14
	private LinearLayout(final LinearLayout.Orientation orientation) {
15
		this(0, 0, orientation);
16
	}
17
18
	public LinearLayout(final int x, final int y, final LinearLayout.Orientation orientation) {
19
		this.wrapped = new GridLayout(x, y);
20
		this.orientation = orientation;
21
	}
22
23
	public LinearLayout spacing(final int spacing) {
24
		this.orientation.setSpacing(this.wrapped, spacing);
25
		return this;
26
	}
27
28
	public LayoutSettings newCellSettings() {
29
		return this.wrapped.newCellSettings();
30
	}
31
32
	public LayoutSettings defaultCellSetting() {
33
		return this.wrapped.defaultCellSetting();
34
	}
35
36
	public <T extends LayoutElement> T addChild(final T child, final LayoutSettings cellSettings) {
37
		return this.orientation.addChild(this.wrapped, child, this.nextChildIndex++, cellSettings);
38
	}
39
40
	public <T extends LayoutElement> T addChild(final T child) {
41
		return this.addChild(child, this.newCellSettings());
42
	}
43
44
	public <T extends LayoutElement> T addChild(final T child, final Consumer<LayoutSettings> layoutSettingsAdjustments) {
45
		return this.orientation.addChild(this.wrapped, child, this.nextChildIndex++, Util.make(this.newCellSettings(), layoutSettingsAdjustments));
46
	}
47
48
	@Override
49
	public void visitChildren(final Consumer<LayoutElement> layoutElementVisitor) {
50
		this.wrapped.visitChildren(layoutElementVisitor);
51
	}
52
53
	@Override
54
	public void removeChildren() {
55
		this.wrapped.removeChildren();
56
		this.nextChildIndex = 0;
57
	}
58
59
	@Override
60
	public void arrangeElements() {
61
		this.wrapped.arrangeElements();
62
	}
63
64
	@Override
65
	public int getWidth() {
66
		return this.wrapped.getWidth();
67
	}
68
69
	@Override
70
	public int getHeight() {
71
		return this.wrapped.getHeight();
72
	}
73
74
	@Override
75
	public void setX(final int x) {
76
		this.wrapped.setX(x);
77
	}
78
79
	@Override
80
	public void setY(final int y) {
81
		this.wrapped.setY(y);
82
	}
83
84
	@Override
85
	public int getX() {
86
		return this.wrapped.getX();
87
	}
88
89
	@Override
90
	public int getY() {
91
		return this.wrapped.getY();
92
	}
93
94
	public static LinearLayout vertical() {
95
		return new LinearLayout(LinearLayout.Orientation.VERTICAL);
96
	}
97
98
	public static LinearLayout horizontal() {
99
		return new LinearLayout(LinearLayout.Orientation.HORIZONTAL);
100
	}
101
102
	@Environment(EnvType.CLIENT)
103
	public enum Orientation {
104
		HORIZONTAL,
105
		VERTICAL;
106
107
		private void setSpacing(final GridLayout gridLayout, final int spacing) {
108
			switch (this) {
109
				case HORIZONTAL:
110
					gridLayout.columnSpacing(spacing);
111
					break;
112
				case VERTICAL:
113
					gridLayout.rowSpacing(spacing);
114
			}
115
		}
116
117
		public <T extends LayoutElement> T addChild(final GridLayout gridLayout, final T child, final int index, final LayoutSettings cellSettings) {
118
			return (T)(switch (this) {
119
				case HORIZONTAL -> gridLayout.addChild(child, 0, index, cellSettings);
120
				case VERTICAL -> gridLayout.addChild(child, index, 0, cellSettings);
121
			});
122
		}
123
	}
124
}
125

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