Some helpers

This commit is contained in:
Frank 2022-07-16 14:01:44 +02:00
parent e33fa75716
commit ef34bc9981
3 changed files with 25 additions and 2 deletions

View file

@ -6,7 +6,10 @@ import org.betterx.bclib.config.Configs;
import org.betterx.bclib.config.NamedPathConfig; import org.betterx.bclib.config.NamedPathConfig;
import org.betterx.bclib.config.NamedPathConfig.ConfigTokenDescription; import org.betterx.bclib.config.NamedPathConfig.ConfigTokenDescription;
import org.betterx.bclib.config.NamedPathConfig.DependendConfigToken; import org.betterx.bclib.config.NamedPathConfig.DependendConfigToken;
import org.betterx.ui.layout.components.*; import org.betterx.ui.layout.components.Checkbox;
import org.betterx.ui.layout.components.HorizontalStack;
import org.betterx.ui.layout.components.LayoutComponent;
import org.betterx.ui.layout.components.VerticalStack;
import org.betterx.ui.layout.values.Value; import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.LayoutScreenWithIcon; import org.betterx.ui.vanilla.LayoutScreenWithIcon;
@ -99,7 +102,7 @@ public class MainScreen extends LayoutScreenWithIcon {
VerticalStack grid = new VerticalStack(Value.fill(), Value.fill()); VerticalStack grid = new VerticalStack(Value.fill(), Value.fill());
grid.add(VerticalScroll.create(Value.fill(), Value.fill(), content)); grid.addScrollable(content);
grid.addSpacer(8); grid.addSpacer(8);
HorizontalStack row = grid.addRow(); HorizontalStack row = grid.addRow();
row.addFiller(); row.addFiller();

View file

@ -2,9 +2,11 @@ package org.betterx.ui.layout.components;
import org.betterx.ui.layout.components.input.RelativeContainerEventHandler; import org.betterx.ui.layout.components.input.RelativeContainerEventHandler;
import org.betterx.ui.layout.components.render.ComponentRenderer; import org.betterx.ui.layout.components.render.ComponentRenderer;
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.VanillaScrollerRenderer;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.components.events.GuiEventListener;
@ -155,5 +157,19 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
add(b); add(b);
return b; return b;
} }
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent content) {
return addScrollable(Value.fill(), Value.fill(), content);
}
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(
Value width,
Value heihght,
LayoutComponent content
) {
VerticalScroll<NullRenderer, VanillaScrollerRenderer> s = VerticalScroll.create(width, height, content);
add(s);
return s;
}
} }

View file

@ -43,6 +43,10 @@ public class Rectangle {
return x >= left && x <= right() && y >= top && y <= bottom(); return x >= left && x <= right() && y >= top && y <= bottom();
} }
public boolean contains(double x, double y) {
return x >= left && x <= right() && y >= top && y <= bottom();
}
public Rectangle intersect(Rectangle r) { public Rectangle intersect(Rectangle r) {
if (!overlaps(r)) return ZERO; if (!overlaps(r)) return ZERO;
int left = Math.max(this.left, r.left); int left = Math.max(this.left, r.left);