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

@ -2,9 +2,11 @@ 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.Rectangle;
import org.betterx.ui.layout.values.Size;
import org.betterx.ui.layout.values.Value;
import org.betterx.ui.vanilla.VanillaScrollerRenderer;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.events.GuiEventListener;
@ -155,5 +157,19 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
add(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();
}
public boolean contains(double x, double y) {
return x >= left && x <= right() && y >= top && y <= bottom();
}
public Rectangle intersect(Rectangle r) {
if (!overlaps(r)) return ZERO;
int left = Math.max(this.left, r.left);