added NullRenderer
This commit is contained in:
parent
06d7848e30
commit
ecb6ca1586
5 changed files with 101 additions and 24 deletions
|
@ -22,8 +22,7 @@ public class TestScreen extends Screen {
|
|||
protected void init() {
|
||||
super.init();
|
||||
main = new Panel(this.width, this.height);
|
||||
HorizontalStack<?> columns = new HorizontalStack<>(DynamicSize.relative(1), DynamicSize.relative(1));
|
||||
VerticalStack<?> rows = new VerticalStack<>(DynamicSize.fit(), DynamicSize.relative(1));
|
||||
VerticalStack rows = new VerticalStack(DynamicSize.fit(), DynamicSize.relative(1));
|
||||
|
||||
rows.addFiller();
|
||||
rows.add(new Range<>(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.betterx.ui.layout.components;
|
||||
|
||||
import org.betterx.ui.layout.components.input.RelativeContainerEventHandler;
|
||||
import org.betterx.ui.layout.components.render.ComponentRenderer;
|
||||
import org.betterx.ui.layout.components.render.NullRenderer;
|
||||
import org.betterx.ui.layout.values.Alignment;
|
||||
import org.betterx.ui.layout.values.DynamicSize;
|
||||
|
||||
|
@ -9,15 +9,11 @@ import net.fabricmc.api.EnvType;
|
|||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class HorizontalStack<R extends ComponentRenderer> extends AbstractStack<R, HorizontalStack<R>> implements RelativeContainerEventHandler {
|
||||
public class HorizontalStack extends AbstractStack<NullRenderer, HorizontalStack> implements RelativeContainerEventHandler {
|
||||
public HorizontalStack(DynamicSize width, DynamicSize height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
public HorizontalStack(DynamicSize width, DynamicSize height, R renderer) {
|
||||
super(width, height, renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateContainerWidth(int containerWidth) {
|
||||
int myWidth = width.calculateOrFill(containerWidth);
|
||||
|
@ -71,15 +67,15 @@ public class HorizontalStack<R extends ComponentRenderer> extends AbstractStack<
|
|||
return components.stream().map(c -> c.height.calculateFixed()).reduce(0, Integer::max);
|
||||
}
|
||||
|
||||
public static HorizontalStack<?> centered(Component<?> c) {
|
||||
return new HorizontalStack<>(DynamicSize.relative(1), DynamicSize.relative(1)).addFiller().add(c).addFiller();
|
||||
public static HorizontalStack centered(Component<?> c) {
|
||||
return new HorizontalStack(DynamicSize.relative(1), DynamicSize.relative(1)).addFiller().add(c).addFiller();
|
||||
}
|
||||
|
||||
public static HorizontalStack<?> bottom(Component<?> c) {
|
||||
return new HorizontalStack<>(DynamicSize.relative(1), DynamicSize.relative(1)).add(c).addFiller();
|
||||
public static HorizontalStack bottom(Component<?> c) {
|
||||
return new HorizontalStack(DynamicSize.relative(1), DynamicSize.relative(1)).add(c).addFiller();
|
||||
}
|
||||
|
||||
protected HorizontalStack<R> addEmpty(DynamicSize size) {
|
||||
protected HorizontalStack addEmpty(DynamicSize size) {
|
||||
this.components.add(new Empty(size, DynamicSize.fixed(0)));
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.betterx.ui.layout.components;
|
|||
|
||||
|
||||
import org.betterx.ui.layout.components.input.RelativeContainerEventHandler;
|
||||
import org.betterx.ui.layout.components.render.ComponentRenderer;
|
||||
import org.betterx.ui.layout.components.render.NullRenderer;
|
||||
import org.betterx.ui.layout.values.Alignment;
|
||||
import org.betterx.ui.layout.values.DynamicSize;
|
||||
|
||||
|
@ -10,15 +10,11 @@ import net.fabricmc.api.EnvType;
|
|||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class VerticalStack<R extends ComponentRenderer> extends AbstractStack<R, VerticalStack<R>> implements RelativeContainerEventHandler {
|
||||
public class VerticalStack extends AbstractStack<NullRenderer, VerticalStack> implements RelativeContainerEventHandler {
|
||||
public VerticalStack(DynamicSize width, DynamicSize height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
public VerticalStack(DynamicSize width, DynamicSize height, R renderer) {
|
||||
super(width, height, renderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int updateContainerWidth(int containerWidth) {
|
||||
int myWidth = width.calculateOrFill(containerWidth);
|
||||
|
@ -71,15 +67,15 @@ public class VerticalStack<R extends ComponentRenderer> extends AbstractStack<R,
|
|||
return (int) (fixedHeight / (1 - percentage));
|
||||
}
|
||||
|
||||
public static VerticalStack<?> centered(Component<?> c) {
|
||||
return new VerticalStack<>(DynamicSize.relative(1), DynamicSize.relative(1)).addFiller().add(c).addFiller();
|
||||
public static VerticalStack centered(Component<?> c) {
|
||||
return new VerticalStack(DynamicSize.relative(1), DynamicSize.relative(1)).addFiller().add(c).addFiller();
|
||||
}
|
||||
|
||||
public static VerticalStack<?> bottom(Component<?> c) {
|
||||
return new VerticalStack<>(DynamicSize.relative(1), DynamicSize.relative(1)).add(c).addFiller();
|
||||
public static VerticalStack bottom(Component<?> c) {
|
||||
return new VerticalStack(DynamicSize.relative(1), DynamicSize.relative(1)).add(c).addFiller();
|
||||
}
|
||||
|
||||
protected VerticalStack<R> addEmpty(DynamicSize size) {
|
||||
protected VerticalStack addEmpty(DynamicSize size) {
|
||||
this.components.add(new Empty(DynamicSize.fixed(0), size));
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.betterx.ui.layout.components.render;
|
||||
|
||||
import org.betterx.ui.layout.values.Rectangle;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class NullRenderer implements ComponentRenderer {
|
||||
@Override
|
||||
public void renderInBounds(PoseStack stack, int x, int y, float a, Rectangle bounds, Rectangle clipRect) {
|
||||
|
||||
}
|
||||
}
|
70
src/main/java/org/betterx/ui/vanilla/LayoutScreen.java
Normal file
70
src/main/java/org/betterx/ui/vanilla/LayoutScreen.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package org.betterx.ui.vanilla;
|
||||
|
||||
import org.betterx.ui.layout.components.Panel;
|
||||
import org.betterx.ui.layout.components.VerticalStack;
|
||||
import org.betterx.ui.layout.values.DynamicSize;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public abstract class LayoutScreen extends Screen {
|
||||
public LayoutScreen(Component component) {
|
||||
this(null, component);
|
||||
}
|
||||
|
||||
public LayoutScreen(@Nullable Screen parent, Component component) {
|
||||
super(component);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Panel main;
|
||||
|
||||
@Nullable
|
||||
public final Screen parent;
|
||||
|
||||
protected abstract org.betterx.ui.layout.components.Component<?> initContent();
|
||||
|
||||
@Override
|
||||
protected final void init() {
|
||||
super.init();
|
||||
main = new Panel(this.width, this.height);
|
||||
main.setChild(addTitle(initContent()));
|
||||
|
||||
main.calculateLayout();
|
||||
addRenderableWidget(main);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
//rows.add(this.title, GridLayout.Alignment.CENTER, this);
|
||||
rows.addSpacer(15);
|
||||
rows.add(content);
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(PoseStack poseStack, int i, int j, float f) {
|
||||
renderDirtBackground(i);
|
||||
super.render(poseStack, i, j, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
this.minecraft.setScreen(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPauseScreen() {
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue