Some refactoring

This commit is contained in:
Frank 2022-07-17 01:21:33 +02:00
parent ef34bc9981
commit 4aed7c6285
17 changed files with 124 additions and 83 deletions

View file

@ -83,7 +83,7 @@ public class MainScreen extends LayoutScreenWithIcon {
@Override @Override
protected LayoutComponent initContent() { protected LayoutComponent initContent() {
VerticalStack content = new VerticalStack(Value.fit(), Value.fit()); VerticalStack content = new VerticalStack(Value.fit(), Value.fit()).setDebugName("content");
Configs.GENERATOR_CONFIG.getAllOptions() Configs.GENERATOR_CONFIG.getAllOptions()
.stream() .stream()
@ -101,11 +101,9 @@ public class MainScreen extends LayoutScreenWithIcon {
.forEach(o -> addRow(content, Configs.CLIENT_CONFIG, o)); .forEach(o -> addRow(content, Configs.CLIENT_CONFIG, o));
VerticalStack grid = new VerticalStack(Value.fill(), Value.fill()); VerticalStack grid = new VerticalStack(Value.fill(), Value.fill()).setDebugName("main grid");
grid.addScrollable(content); grid.addScrollable(content);
grid.addSpacer(8); grid.addSpacer(8);
HorizontalStack row = grid.addRow();
row.addFiller();
grid.addButton(Value.fit(), Value.fit(), CommonComponents.GUI_DONE, (button) -> { grid.addButton(Value.fit(), Value.fit(), CommonComponents.GUI_DONE, (button) -> {
Configs.CLIENT_CONFIG.saveChanges(); Configs.CLIENT_CONFIG.saveChanges();
Configs.GENERATOR_CONFIG.saveChanges(); Configs.GENERATOR_CONFIG.saveChanges();

View file

@ -24,7 +24,7 @@ public class TestScreen extends LayoutScreen {
} }
@Override @Override
protected LayoutComponent<?> initContent() { protected LayoutComponent<?, ?> initContent() {
VerticalStack rows = new VerticalStack(Value.fit(), Value.fitOrFill()); VerticalStack rows = new VerticalStack(Value.fit(), Value.fitOrFill());
rows.addFiller(); rows.addFiller();
@ -94,8 +94,6 @@ public class TestScreen extends LayoutScreen {
Component.literal("test"), Component.literal("test"),
(bt) -> { (bt) -> {
System.out.println("clicked test"); System.out.println("clicked test");
},
(bt, pose, x, y) -> {
} }
).centerHorizontal() ).centerHorizontal()
); );
@ -105,8 +103,6 @@ public class TestScreen extends LayoutScreen {
Component.literal("Hello World"), Component.literal("Hello World"),
(bt) -> { (bt) -> {
System.out.println("clicked hello"); System.out.println("clicked hello");
},
(bt, pose, x, y) -> {
} }
).centerHorizontal() ).centerHorizontal()
); );

View file

@ -6,6 +6,7 @@ import org.betterx.ui.layout.components.render.NullRenderer;
import org.betterx.ui.layout.values.Rectangle; import org.betterx.ui.layout.values.Rectangle;
import org.betterx.ui.layout.values.Size; import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value; import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.Slider;
import org.betterx.ui.vanilla.VanillaScrollerRenderer; import org.betterx.ui.vanilla.VanillaScrollerRenderer;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
@ -21,8 +22,8 @@ import java.util.List;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public abstract class AbstractStack<R extends ComponentRenderer, T extends AbstractStack<R, T>> extends LayoutComponent<R> implements RelativeContainerEventHandler { public abstract class AbstractStack<R extends ComponentRenderer, T extends AbstractStack<R, T>> extends LayoutComponent<R, T> implements RelativeContainerEventHandler {
protected final List<LayoutComponent<?>> components = new LinkedList<>(); protected final List<LayoutComponent<?, ?>> components = new LinkedList<>();
public AbstractStack(Value width, Value height) { public AbstractStack(Value width, Value height) {
this(width, height, null); this(width, height, null);
@ -58,12 +59,12 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
Rectangle clipRect Rectangle clipRect
) { ) {
super.renderInBounds(poseStack, mouseX, mouseY, deltaTicks, renderBounds, clipRect); super.renderInBounds(poseStack, mouseX, mouseY, deltaTicks, renderBounds, clipRect);
for (LayoutComponent<?> c : components) { for (LayoutComponent<?, ?> c : components) {
c.render(poseStack, mouseX, mouseY, deltaTicks, renderBounds, clipRect); c.render(poseStack, mouseX, mouseY, deltaTicks, renderBounds, clipRect);
} }
} }
public T add(LayoutComponent<?> c) { public T add(LayoutComponent<?, ?> c) {
this.components.add(c); this.components.add(c);
return (T) this; return (T) this;
} }
@ -144,32 +145,68 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
Component component, Component component,
net.minecraft.client.gui.components.Button.OnPress onPress net.minecraft.client.gui.components.Button.OnPress onPress
) { ) {
return addButton(width, height, component, onPress, net.minecraft.client.gui.components.Button.NO_TOOLTIP); Button b = new Button(width, height, component, onPress);
}
public Button addButton(
Value width, Value height,
Component component,
net.minecraft.client.gui.components.Button.OnPress onPress,
net.minecraft.client.gui.components.Button.OnTooltip onTooltip
) {
Button b = new Button(width, height, component, onPress, onTooltip);
add(b); add(b);
return b; return b;
} }
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent content) { public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
return addScrollable(Value.fill(), Value.fill(), content); return addScrollable(Value.fill(), Value.fill(), content);
} }
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable( public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(
Value width, Value width,
Value heihght, Value height,
LayoutComponent content LayoutComponent<?, ?> content
) { ) {
VerticalScroll<NullRenderer, VanillaScrollerRenderer> s = VerticalScroll.create(width, height, content); VerticalScroll<NullRenderer, VanillaScrollerRenderer> s = VerticalScroll.create(width, height, content);
add(s); add(s);
return s; return s;
} }
public Text addText(Value width, Value height, net.minecraft.network.chat.Component text) {
Text t = new Text(width, height, text);
add(t);
return t;
}
public MultiLineText addMultilineText(Value width, Value height, net.minecraft.network.chat.Component text) {
MultiLineText t = new MultiLineText(width, height, text);
add(t);
return t;
}
public Range<Integer> addRange(
Value width, Value height,
net.minecraft.network.chat.Component titleOrNull,
int minValue, int maxValue, int initialValue,
Slider.SliderValueChanged<Integer> onChange
) {
Range<Integer> r = new Range<>(width, height, titleOrNull, minValue, maxValue, initialValue, onChange);
add(r);
return r;
}
public Range<Float> addRange(
Value width, Value height,
net.minecraft.network.chat.Component titleOrNull,
float minValue, float maxValue, float initialValue,
Slider.SliderValueChanged<Float> onChange
) {
Range<Float> r = new Range<>(width, height, titleOrNull, minValue, maxValue, initialValue, onChange);
add(r);
return r;
}
public Range<Double> addRange(
Value width, Value height,
net.minecraft.network.chat.Component titleOrNull,
double minValue, double maxValue, double initialValue,
Slider.SliderValueChanged<Double> onChange
) {
Range<Double> r = new Range<>(width, height, titleOrNull, minValue, maxValue, initialValue, onChange);
add(r);
return r;
}
} }

View file

@ -4,7 +4,7 @@ import org.betterx.ui.layout.values.Value;
import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.AbstractWidget;
public abstract class AbstractVanillaComponent<C extends AbstractWidget, V extends AbstractVanillaComponent<C, V>> extends LayoutComponent<AbstractVanillaComponentRenderer<C, V>> { public abstract class AbstractVanillaComponent<C extends AbstractWidget, V extends AbstractVanillaComponent<C, V>> extends LayoutComponent<AbstractVanillaComponentRenderer<C, V>, V> {
protected C vanillaComponent; protected C vanillaComponent;
protected final net.minecraft.network.chat.Component component; protected final net.minecraft.network.chat.Component component;
protected float alpha = 1.0f; protected float alpha = 1.0f;

View file

@ -9,18 +9,22 @@ import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class Button extends AbstractVanillaComponent<net.minecraft.client.gui.components.Button, Button> { public class Button extends AbstractVanillaComponent<net.minecraft.client.gui.components.Button, Button> {
final net.minecraft.client.gui.components.Button.OnPress onPress; final net.minecraft.client.gui.components.Button.OnPress onPress;
final net.minecraft.client.gui.components.Button.OnTooltip onTooltip; net.minecraft.client.gui.components.Button.OnTooltip onTooltip;
public Button( public Button(
Value width, Value width,
Value height, Value height,
net.minecraft.network.chat.Component component, net.minecraft.network.chat.Component component,
net.minecraft.client.gui.components.Button.OnPress onPress, net.minecraft.client.gui.components.Button.OnPress onPress
net.minecraft.client.gui.components.Button.OnTooltip onTooltip
) { ) {
super(width, height, new ButtonRenderer(), component); super(width, height, new ButtonRenderer(), component);
this.onPress = onPress; this.onPress = onPress;
this.onTooltip = net.minecraft.client.gui.components.Button.NO_TOOLTIP;
}
public Button setOnToolTip(net.minecraft.client.gui.components.Button.OnTooltip onTooltip) {
this.onTooltip = onTooltip; this.onTooltip = onTooltip;
return this;
} }
@Override @Override

View file

@ -10,7 +10,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public abstract class CustomRenderComponent<C extends CustomRenderComponent<C>> extends LayoutComponent<CustomRenderComponent.CustomRenderRenderer<C>> { public abstract class CustomRenderComponent<C extends CustomRenderComponent<C>> extends LayoutComponent<CustomRenderComponent.CustomRenderRenderer<C>, C> {
public CustomRenderComponent( public CustomRenderComponent(
Value width, Value width,
Value height Value height

View file

@ -1,12 +1,13 @@
package org.betterx.ui.layout.components; package org.betterx.ui.layout.components;
import org.betterx.ui.layout.components.render.NullRenderer;
import org.betterx.ui.layout.values.Value; import org.betterx.ui.layout.values.Value;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class Empty extends LayoutComponent { public class Empty extends LayoutComponent<NullRenderer, Empty> {
public Empty( public Empty(
Value width, Value width,
Value height Value height

View file

@ -22,7 +22,7 @@ public class HorizontalStack extends AbstractStack<NullRenderer, HorizontalStack
int freeWidth = Math.max(0, myWidth - fixedWidth); int freeWidth = Math.max(0, myWidth - fixedWidth);
fillWidth(myWidth, freeWidth); fillWidth(myWidth, freeWidth);
for (LayoutComponent<?> c : components) { for (LayoutComponent<?, ?> c : components) {
c.updateContainerWidth(c.width.calculatedSize()); c.updateContainerWidth(c.width.calculatedSize());
} }
@ -33,7 +33,7 @@ public class HorizontalStack extends AbstractStack<NullRenderer, HorizontalStack
protected int updateContainerHeight(int containerHeight) { protected int updateContainerHeight(int containerHeight) {
int myHeight = height.calculateOrFill(containerHeight); int myHeight = height.calculateOrFill(containerHeight);
components.stream().forEach(c -> c.height.calculateOrFill(myHeight)); components.stream().forEach(c -> c.height.calculateOrFill(myHeight));
for (LayoutComponent<?> c : components) { for (LayoutComponent<?, ?> c : components) {
c.updateContainerHeight(c.height.calculatedSize()); c.updateContainerHeight(c.height.calculatedSize());
} }
return myHeight; return myHeight;
@ -45,7 +45,7 @@ public class HorizontalStack extends AbstractStack<NullRenderer, HorizontalStack
super.setRelativeBounds(left, top); super.setRelativeBounds(left, top);
int offset = 0; int offset = 0;
for (LayoutComponent<?> c : components) { for (LayoutComponent<?, ?> c : components) {
int delta = relativeBounds.height - c.height.calculatedSize(); int delta = relativeBounds.height - c.height.calculatedSize();
if (c.hAlign == Alignment.MIN) delta = 0; if (c.hAlign == Alignment.MIN) delta = 0;
else if (c.hAlign == Alignment.CENTER) delta /= 2; else if (c.hAlign == Alignment.CENTER) delta /= 2;
@ -67,11 +67,11 @@ public class HorizontalStack extends AbstractStack<NullRenderer, HorizontalStack
return components.stream().map(c -> c.height.calculateFixed()).reduce(0, Integer::max); return components.stream().map(c -> c.height.calculateFixed()).reduce(0, Integer::max);
} }
public static HorizontalStack centered(LayoutComponent<?> c) { public static HorizontalStack centered(LayoutComponent<?, ?> c) {
return new HorizontalStack(Value.fill(), Value.fill()).addFiller().add(c).addFiller(); return new HorizontalStack(Value.fill(), Value.fill()).addFiller().add(c).addFiller();
} }
public static HorizontalStack bottom(LayoutComponent<?> c) { public static HorizontalStack bottom(LayoutComponent<?, ?> c) {
return new HorizontalStack(Value.fill(), Value.fill()).add(c).addFiller(); return new HorizontalStack(Value.fill(), Value.fill()).add(c).addFiller();
} }

View file

@ -14,10 +14,11 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public abstract class LayoutComponent<R extends ComponentRenderer> implements ComponentWithBounds, GuiEventListener { public abstract class LayoutComponent<R extends ComponentRenderer, L extends LayoutComponent<R, L>> implements ComponentWithBounds, GuiEventListener {
protected final R renderer; protected final R renderer;
protected final Value width; protected final Value width;
protected final Value height; protected final Value height;
protected String debugName;
protected Rectangle relativeBounds; protected Rectangle relativeBounds;
protected Alignment vAlign = Alignment.MIN; protected Alignment vAlign = Alignment.MIN;
protected Alignment hAlign = Alignment.MIN; protected Alignment hAlign = Alignment.MIN;
@ -94,7 +95,8 @@ public abstract class LayoutComponent<R extends ComponentRenderer> implements Co
Rectangle clip = r.intersect(clipRect); Rectangle clip = r.intersect(clipRect);
poseStack.pushPose(); poseStack.pushPose();
poseStack.translate(relativeBounds.left, relativeBounds.top, 0); poseStack.translate(relativeBounds.left, relativeBounds.top, 0);
if (r.overlaps(clip)) { //if (r.overlaps(clip))
{
renderInBounds(poseStack, mouseX - relativeBounds.left, mouseY - relativeBounds.top, deltaTicks, r, clip); renderInBounds(poseStack, mouseX - relativeBounds.left, mouseY - relativeBounds.top, deltaTicks, r, clip);
} }
poseStack.popPose(); poseStack.popPose();
@ -117,36 +119,45 @@ public abstract class LayoutComponent<R extends ComponentRenderer> implements Co
@Override @Override
public String toString() { public String toString() {
return super.toString() + "(" + relativeBounds + ", " + width.calculatedSize() + "x" + height.calculatedSize() + ")"; return super.toString() + "(" +
(debugName == null ? "" : debugName + " - ") +
relativeBounds + ", " +
width.calculatedSize() + "x" + height.calculatedSize() +
")";
} }
public LayoutComponent<R> alignTop() { public L alignTop() {
vAlign = Alignment.MIN; vAlign = Alignment.MIN;
return this; return (L) this;
} }
public LayoutComponent<R> alignBottom() { public L alignBottom() {
vAlign = Alignment.MAX; vAlign = Alignment.MAX;
return this; return (L) this;
} }
public LayoutComponent<R> centerVertical() { public L centerVertical() {
vAlign = Alignment.CENTER; vAlign = Alignment.CENTER;
return this; return (L) this;
} }
public LayoutComponent<R> alignLeft() { public L alignLeft() {
hAlign = Alignment.MIN; hAlign = Alignment.MIN;
return this; return (L) this;
} }
public LayoutComponent<R> alignRight() { public L alignRight() {
hAlign = Alignment.MAX; hAlign = Alignment.MAX;
return this; return (L) this;
} }
public LayoutComponent<R> centerHorizontal() { public L centerHorizontal() {
hAlign = Alignment.CENTER; hAlign = Alignment.CENTER;
return this; return (L) this;
}
public L setDebugName(String d) {
debugName = d;
return (L) this;
} }
} }

View file

@ -10,7 +10,7 @@ import org.betterx.ui.layout.values.Value;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.MultiLineLabel; import net.minecraft.client.gui.components.MultiLineLabel;
public class MultiLineText extends LayoutComponent<MultiLineText.MultiLineTextRenderer> { public class MultiLineText extends LayoutComponent<MultiLineText.MultiLineTextRenderer, MultiLineText> {
final net.minecraft.network.chat.Component text; final net.minecraft.network.chat.Component text;
int color = ColorUtil.DEFAULT_TEXT; int color = ColorUtil.DEFAULT_TEXT;
protected MultiLineLabel multiLineLabel; protected MultiLineLabel multiLineLabel;

View file

@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class Panel implements ComponentWithBounds, RelativeContainerEventHandler, NarratableEntry, Widget { public class Panel implements ComponentWithBounds, RelativeContainerEventHandler, NarratableEntry, Widget {
protected LayoutComponent<?> child; protected LayoutComponent<?, ?> child;
List<? extends GuiEventListener> listeners = List.of(); List<? extends GuiEventListener> listeners = List.of();
public final Rectangle bounds; public final Rectangle bounds;
@ -30,7 +30,7 @@ public class Panel implements ComponentWithBounds, RelativeContainerEventHandler
bounds = new Rectangle(left, top, width, height); bounds = new Rectangle(left, top, width, height);
} }
public void setChild(LayoutComponent<?> c) { public void setChild(LayoutComponent<?, ?> c) {
this.child = c; this.child = c;
listeners = List.of(c); listeners = List.of(c);
} }

View file

@ -40,11 +40,7 @@ public class Range<N extends Number> extends AbstractVanillaComponent<Slider<N>,
N initialValue, N initialValue,
Slider.SliderValueChanged<N> onChange Slider.SliderValueChanged<N> onChange
) { ) {
super(width, height, new RangeRenderer<>(), null); this(width, height, null, minValue, maxValue, initialValue, onChange);
this.onChange = onChange;
this.minValue = minValue;
this.maxValue = maxValue;
this.initialValue = initialValue;
} }
@Override @Override

View file

@ -10,7 +10,7 @@ import org.betterx.ui.layout.values.Value;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.GuiComponent;
public class Text extends LayoutComponent<Text.TextRenderer> { public class Text extends LayoutComponent<Text.TextRenderer, Text> {
final net.minecraft.network.chat.Component text; final net.minecraft.network.chat.Component text;
int color = ColorUtil.DEFAULT_TEXT; int color = ColorUtil.DEFAULT_TEXT;
@ -18,7 +18,6 @@ public class Text extends LayoutComponent<Text.TextRenderer> {
Value width, Value width,
Value height, Value height,
net.minecraft.network.chat.Component text net.minecraft.network.chat.Component text
) { ) {
super(width, height, new TextRenderer()); super(width, height, new TextRenderer());
vAlign = Alignment.CENTER; vAlign = Alignment.CENTER;

View file

@ -14,8 +14,8 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRenderer> extends LayoutComponent<R> { public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRenderer> extends LayoutComponent<R, VerticalScroll<R, RS>> {
protected LayoutComponent<?> child; protected LayoutComponent<?, ?> child;
protected final RS scrollerRenderer; protected final RS scrollerRenderer;
protected int dist; protected int dist;
@ -33,14 +33,14 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
this.scrollerRenderer = scrollerRenderer; this.scrollerRenderer = scrollerRenderer;
} }
public static VerticalScroll<NullRenderer, VanillaScrollerRenderer> create(LayoutComponent<?> c) { public static VerticalScroll<NullRenderer, VanillaScrollerRenderer> create(LayoutComponent<?, ?> c) {
return create(Value.relative(1), Value.relative(1), c); return create(Value.relative(1), Value.relative(1), c);
} }
public static VerticalScroll<NullRenderer, VanillaScrollerRenderer> create( public static VerticalScroll<NullRenderer, VanillaScrollerRenderer> create(
Value width, Value width,
Value height, Value height,
LayoutComponent<?> c LayoutComponent<?, ?> c
) { ) {
VerticalScroll<NullRenderer, VanillaScrollerRenderer> res = new VerticalScroll<>( VerticalScroll<NullRenderer, VanillaScrollerRenderer> res = new VerticalScroll<>(
width, width,
@ -52,7 +52,7 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
return res; return res;
} }
public void setChild(LayoutComponent<?> c) { public void setChild(LayoutComponent<?, ?> c) {
this.child = c; this.child = c;
} }

View file

@ -19,7 +19,7 @@ public class VerticalStack extends AbstractStack<NullRenderer, VerticalStack> im
protected int updateContainerWidth(int containerWidth) { protected int updateContainerWidth(int containerWidth) {
int myWidth = width.calculateOrFill(containerWidth); int myWidth = width.calculateOrFill(containerWidth);
components.stream().forEach(c -> c.width.calculateOrFill(myWidth)); components.stream().forEach(c -> c.width.calculateOrFill(myWidth));
for (LayoutComponent<?> c : components) { for (LayoutComponent<?, ?> c : components) {
c.updateContainerWidth(c.width.calculatedSize()); c.updateContainerWidth(c.width.calculatedSize());
} }
return myWidth; return myWidth;
@ -33,7 +33,7 @@ public class VerticalStack extends AbstractStack<NullRenderer, VerticalStack> im
int freeHeight = Math.max(0, myHeight - fixedHeight); int freeHeight = Math.max(0, myHeight - fixedHeight);
fillHeight(myHeight, freeHeight); fillHeight(myHeight, freeHeight);
for (LayoutComponent<?> c : components) { for (LayoutComponent<?, ?> c : components) {
c.updateContainerHeight(c.height.calculatedSize()); c.updateContainerHeight(c.height.calculatedSize());
} }
@ -45,7 +45,7 @@ public class VerticalStack extends AbstractStack<NullRenderer, VerticalStack> im
super.setRelativeBounds(left, top); super.setRelativeBounds(left, top);
int offset = 0; int offset = 0;
for (LayoutComponent<?> c : components) { for (LayoutComponent<?, ?> c : components) {
int delta = relativeBounds.width - c.width.calculatedSize(); int delta = relativeBounds.width - c.width.calculatedSize();
if (c.hAlign == Alignment.MIN) delta = 0; if (c.hAlign == Alignment.MIN) delta = 0;
else if (c.hAlign == Alignment.CENTER) delta /= 2; else if (c.hAlign == Alignment.CENTER) delta /= 2;
@ -67,11 +67,11 @@ public class VerticalStack extends AbstractStack<NullRenderer, VerticalStack> im
return (int) (fixedHeight / (1 - percentage)); return (int) (fixedHeight / (1 - percentage));
} }
public static VerticalStack centered(LayoutComponent<?> c) { public static VerticalStack centered(LayoutComponent<?, ?> c) {
return new VerticalStack(Value.relative(1), Value.relative(1)).addFiller().add(c).addFiller(); return new VerticalStack(Value.relative(1), Value.relative(1)).addFiller().add(c).addFiller();
} }
public static VerticalStack bottom(LayoutComponent<?> c) { public static VerticalStack bottom(LayoutComponent<?, ?> c) {
return new VerticalStack(Value.relative(1), Value.relative(1)).add(c).addFiller(); return new VerticalStack(Value.relative(1), Value.relative(1)).add(c).addFiller();
} }

View file

@ -46,7 +46,7 @@ public abstract class LayoutScreen extends Screen {
@Nullable @Nullable
public final Screen parent; public final Screen parent;
protected abstract LayoutComponent<?> initContent(); protected abstract LayoutComponent<?, ?> initContent();
@Override @Override
protected final void init() { protected final void init() {
@ -58,14 +58,13 @@ public abstract class LayoutScreen extends Screen {
addRenderableWidget(main); addRenderableWidget(main);
} }
protected LayoutComponent<?> buildTitle() { protected LayoutComponent<?, ?> buildTitle() {
var text = new Text(Value.fill(), Value.fit(), title).centerHorizontal().setDebugName("title");
var text = new Text(Value.fill(), Value.fit(), title).centerHorizontal();
return text; return text;
} }
protected LayoutComponent<?> addTitle(LayoutComponent<?> content) { protected LayoutComponent<?, ?> addTitle(LayoutComponent<?, ?> content) {
VerticalStack rows = new VerticalStack(Value.fill(), Value.fill()); VerticalStack rows = new VerticalStack(Value.fill(), Value.fill()).setDebugName("title stack");
if (topPadding > 0) rows.addSpacer(topPadding); if (topPadding > 0) rows.addSpacer(topPadding);
rows.add(buildTitle()); rows.add(buildTitle());
@ -75,7 +74,7 @@ public abstract class LayoutScreen extends Screen {
if (sidePadding <= 0) return rows; if (sidePadding <= 0) return rows;
HorizontalStack cols = new HorizontalStack(Value.fill(), Value.fill()); HorizontalStack cols = new HorizontalStack(Value.fill(), Value.fill()).setDebugName("padded side");
cols.addSpacer(sidePadding); cols.addSpacer(sidePadding);
cols.add(rows); cols.add(rows);
cols.addSpacer(sidePadding); cols.addSpacer(sidePadding);

View file

@ -39,11 +39,11 @@ public abstract class LayoutScreenWithIcon extends LayoutScreen {
} }
@Override @Override
protected LayoutComponent<?> buildTitle() { protected LayoutComponent<?, ?> buildTitle() {
LayoutComponent<?> title = super.buildTitle(); LayoutComponent<?, ?> title = super.buildTitle();
HorizontalStack row = new HorizontalStack(Value.fill(), Value.fit()); HorizontalStack row = new HorizontalStack(Value.fill(), Value.fit()).setDebugName("title bar");
row.addFiller(); row.addFiller();
row.addIcon(icon, Size.of(512)); row.addIcon(icon, Size.of(512)).setDebugName("icon");
row.addSpacer(4); row.addSpacer(4);
row.add(title); row.add(title);
row.addFiller(); row.addFiller();