Padding settings

This commit is contained in:
Frank 2022-07-15 15:02:34 +02:00
parent 67d21f3fba
commit 51da03f3c8
4 changed files with 37 additions and 9 deletions

View file

@ -1,5 +1,6 @@
package org.betterx.ui.vanilla;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.Panel;
import org.betterx.ui.layout.components.Text;
import org.betterx.ui.layout.components.VerticalStack;
@ -16,13 +17,30 @@ import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public abstract class LayoutScreen extends Screen {
protected final int topPadding;
protected final int bottomPadding;
protected final int sidePadding;
public LayoutScreen(Component component) {
this(null, component);
this(null, component, 20, 10, 20);
}
public LayoutScreen(@Nullable Screen parent, Component component) {
this(parent, component, 20, 10, 20);
}
public LayoutScreen(
@Nullable Screen parent,
Component component,
int topPadding,
int bottomPadding,
int sidePadding
) {
super(component);
this.parent = parent;
this.topPadding = topPadding;
this.bottomPadding = topPadding;
this.sidePadding = sidePadding;
}
@Nullable
@ -44,12 +62,22 @@ public abstract class LayoutScreen extends Screen {
}
protected org.betterx.ui.layout.components.Component<?> addTitle(org.betterx.ui.layout.components.Component<?> content) {
VerticalStack rows = new VerticalStack(DynamicSize.relative(1), DynamicSize.relative(1));
VerticalStack rows = new VerticalStack(DynamicSize.fill(), DynamicSize.fill());
if (topPadding > 0) rows.addSpacer(topPadding);
rows.add(new Text(DynamicSize.fill(), DynamicSize.fit(), title).centerHorizontal());
rows.addSpacer(15);
rows.add(content);
return rows;
if (bottomPadding > 0) rows.addSpacer(bottomPadding);
if (sidePadding <= 0) return rows;
HorizontalStack cols = new HorizontalStack(DynamicSize.fill(), DynamicSize.fill());
cols.addSpacer(sidePadding);
cols.add(rows);
cols.addSpacer(sidePadding);
return cols;
}
protected void renderBackground(PoseStack poseStack, int i, int j, float f) {