Padding settings
This commit is contained in:
parent
67d21f3fba
commit
51da03f3c8
4 changed files with 37 additions and 9 deletions
|
@ -26,12 +26,12 @@ public class TestScreen extends LayoutScreen {
|
|||
|
||||
rows.addFiller();
|
||||
rows.add(new Text(
|
||||
DynamicSize.fitOrFill(), DynamicSize.fit(),
|
||||
DynamicSize.fitOrFill(), DynamicSize.fixed(20),
|
||||
Component.literal("Some Text")
|
||||
).alignRight()
|
||||
);
|
||||
rows.add(new Text(
|
||||
DynamicSize.fitOrFill(), DynamicSize.fit(),
|
||||
DynamicSize.fitOrFill(), DynamicSize.fixed(20),
|
||||
Component.literal("Some other, longer Text")
|
||||
).centerHorizontal()
|
||||
);
|
||||
|
|
|
@ -48,6 +48,10 @@ public class Text extends Component<Text.TextRenderer> {
|
|||
return getFont().width(c.getVisualOrderText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(net.minecraft.network.chat.Component c) {
|
||||
return TextProvider.super.getLineHeight(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInBounds(PoseStack stack, int x, int y, float a, Rectangle bounds, Rectangle clipRect) {
|
||||
|
|
|
@ -26,10 +26,6 @@ public class Rectangle {
|
|||
return top + height;
|
||||
}
|
||||
|
||||
public Size size() {
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
public Rectangle movedBy(int left, int top) {
|
||||
return new Rectangle(this.left + left, this.top + top, this.width, this.height);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue