Skip to content

Commit 90af741

Browse files
Rename StackContainer to StackLayout and introduce UIContainer
Renamed `StackContainer` to `StackLayout` for consistency and clarity. Added a new `UIContainer` class to serve as a base for containers, simplifying child management by centralizing common logic. Adjusted references in `TestScreen` and related files to use the updated naming and structure.
1 parent 4c1ac89 commit 90af741

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

common-testmod/src/main/java/me/pandamods/test/client/screen/TestScreen.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
import me.pandamods.pandalib.client.screen.BasePLScreen;
1616
import me.pandamods.pandalib.client.screen.components.TextUIComponent;
1717
import me.pandamods.pandalib.client.screen.components.VanillaUIComponent;
18-
import me.pandamods.pandalib.client.screen.layouts.StackContainer;
18+
import me.pandamods.pandalib.client.screen.containers.StackLayout;
1919
import net.minecraft.client.Minecraft;
2020
import net.minecraft.client.gui.components.Button;
2121
import net.minecraft.client.gui.components.EditBox;
2222
import net.minecraft.network.chat.Component;
2323

24-
public class TestScreen extends BasePLScreen<StackContainer> {
24+
public class TestScreen extends BasePLScreen<StackLayout> {
2525
public TestScreen() {
2626
super(() -> {
27-
StackContainer stack = StackContainer.createVerticalLayout();
27+
StackLayout stack = StackLayout.createVerticalLayout();
2828
stack.setGapSize(4);
2929
return stack;
3030
});
3131
}
3232

3333
@Override
34-
protected void build(StackContainer rootComponent) {
34+
protected void build(StackLayout rootComponent) {
3535
VanillaUIComponent vanillaTestButton = VanillaUIComponent.of(Button.builder(Component.literal("Test Vanilla Button"),
3636
button -> System.out.println("Test click"))
3737
.width(200)

common/src/main/java/me/pandamods/pandalib/client/screen/layouts/StackContainer.java renamed to common/src/main/java/me/pandamods/pandalib/client/screen/containers/StackLayout.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1111
*/
1212

13-
package me.pandamods.pandalib.client.screen.layouts;
13+
package me.pandamods.pandalib.client.screen.containers;
1414

15-
import me.pandamods.pandalib.client.screen.BaseParentUIComponent;
1615
import me.pandamods.pandalib.client.screen.core.UIComponent;
1716

1817
import java.util.ArrayList;
@@ -22,49 +21,31 @@
2221
import java.util.function.Consumer;
2322
import java.util.function.Supplier;
2423

25-
public class StackContainer extends BaseParentUIComponent {
26-
private final List<UIComponent> children = new ArrayList<>();
27-
private final List<UIComponent> viewChildren = Collections.unmodifiableList(children);
28-
24+
public class StackLayout extends UIContainer {
2925
protected Direction direction;
3026
protected int gapSize = 0;
3127

3228
private int contentWidth = 0;
3329
private int contentHeight = 0;
3430

35-
public static StackContainer createHorizontalLayout() {
36-
return new StackContainer(Direction.HORIZONTAL);
31+
public static StackLayout createHorizontalLayout() {
32+
return new StackLayout(Direction.HORIZONTAL);
3733
}
3834

39-
public static StackContainer createVerticalLayout() {
40-
return new StackContainer(Direction.VERTICAL);
35+
public static StackLayout createVerticalLayout() {
36+
return new StackLayout(Direction.VERTICAL);
4137
}
4238

43-
public StackContainer(Direction direction) {
39+
public StackLayout(Direction direction) {
4440
this.direction = direction;
4541
}
46-
47-
@Override
48-
public List<UIComponent> getChildren() {
49-
return viewChildren;
50-
}
51-
42+
5243
@Override
5344
public void updateChildState(UIComponent uiComponent) {
5445
super.updateChildState(uiComponent);
5546
align();
5647
}
5748

58-
@Override
59-
protected void addChild(UIComponent UIComponent) {
60-
children.add(UIComponent);
61-
}
62-
63-
@Override
64-
protected void removeChild(UIComponent UIComponent) {
65-
children.remove(UIComponent);
66-
}
67-
6849
public void setDirection(Direction direction) {
6950
this.direction = direction;
7051
this.align();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2024 Oliver Froberg (The Panda Oliver)
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* any later version.
8+
*
9+
* You should have received a copy of the GNU Lesser General Public License
10+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
11+
*/
12+
13+
package me.pandamods.pandalib.client.screen.containers;
14+
15+
import me.pandamods.pandalib.client.screen.BaseParentUIComponent;
16+
import me.pandamods.pandalib.client.screen.core.UIComponent;
17+
18+
import java.util.ArrayList;
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
public class UIContainer extends BaseParentUIComponent {
23+
protected final List<UIComponent> children = new ArrayList<>();
24+
protected final List<UIComponent> viewChildren = Collections.unmodifiableList(children);
25+
26+
@Override
27+
public List<UIComponent> getChildren() {
28+
return viewChildren;
29+
}
30+
31+
@Override
32+
protected void addChild(UIComponent UIComponent) {
33+
children.add(UIComponent);
34+
}
35+
36+
@Override
37+
protected void removeChild(UIComponent UIComponent) {
38+
children.remove(UIComponent);
39+
}
40+
}

0 commit comments

Comments
 (0)