More Welcome Options
This commit is contained in:
parent
a7efcd25ba
commit
bcd64b87b7
15 changed files with 254 additions and 67 deletions
|
@ -255,4 +255,14 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Container create(LayoutComponent<?, ?> content) {
|
||||
return create(Value.fit(), Value.fit(), content);
|
||||
}
|
||||
|
||||
public static Container create(Value width, Value height, LayoutComponent<?, ?> content) {
|
||||
Container c = new Container(width, height);
|
||||
c.addChild(content);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package org.betterx.ui.layout.components;
|
||||
|
||||
import org.betterx.ui.layout.components.render.RenderHelper;
|
||||
import org.betterx.ui.layout.values.Rectangle;
|
||||
import org.betterx.ui.layout.values.Size;
|
||||
import org.betterx.ui.layout.values.Value;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
@ -82,35 +79,7 @@ public class Image extends CustomRenderComponent {
|
|||
Rectangle bounds,
|
||||
Rectangle clipRect
|
||||
) {
|
||||
renderImage(stack, bounds, location, uvRect, resourceSize, alpha);
|
||||
}
|
||||
|
||||
protected static void renderImage(
|
||||
PoseStack stack,
|
||||
Rectangle bounds,
|
||||
ResourceLocation location,
|
||||
Rectangle uvRect,
|
||||
Size size,
|
||||
float alpha
|
||||
) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, location);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(
|
||||
GlStateManager.SourceFactor.SRC_ALPHA,
|
||||
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA
|
||||
);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
|
||||
GuiComponent.blit(
|
||||
stack,
|
||||
0, 0, bounds.width, bounds.height,
|
||||
uvRect.left,
|
||||
uvRect.top,
|
||||
uvRect.width,
|
||||
uvRect.height,
|
||||
size.width(),
|
||||
size.height()
|
||||
);
|
||||
RenderHelper.renderImage(stack, bounds.width, bounds.height, location, uvRect, resourceSize, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,11 +28,14 @@ public class VerticalScroll<RS extends ScrollerRenderer> extends LayoutComponent
|
|||
protected int travel;
|
||||
protected int topOffset;
|
||||
|
||||
protected int scrollerPadding;
|
||||
|
||||
protected boolean keepSpaceForScrollbar = true;
|
||||
|
||||
public VerticalScroll(Value width, Value height, RS scrollerRenderer) {
|
||||
super(width, height, new NullRenderer());
|
||||
this.scrollerRenderer = scrollerRenderer;
|
||||
this.scrollerPadding = scrollerRenderer.scrollerPadding();
|
||||
}
|
||||
|
||||
public static VerticalScroll<VanillaScrollerRenderer> create(LayoutComponent<?, ?> c) {
|
||||
|
@ -61,6 +64,11 @@ public class VerticalScroll<RS extends ScrollerRenderer> extends LayoutComponent
|
|||
return this;
|
||||
}
|
||||
|
||||
public VerticalScroll<RS> setScrollerPadding(int pad) {
|
||||
this.scrollerPadding = pad;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerticalScroll<RS> setKeepSpaceForScrollbar(boolean value) {
|
||||
keepSpaceForScrollbar = value;
|
||||
return this;
|
||||
|
@ -87,7 +95,7 @@ public class VerticalScroll<RS extends ScrollerRenderer> extends LayoutComponent
|
|||
}
|
||||
|
||||
protected int scrollerWidth() {
|
||||
return scrollerRenderer.scrollerWidth() + scrollerRenderer.scrollerPadding();
|
||||
return scrollerRenderer.scrollerWidth() + scrollerPadding;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package org.betterx.ui.layout.components.render;
|
||||
|
||||
import org.betterx.ui.ColorUtil;
|
||||
import org.betterx.ui.layout.values.Rectangle;
|
||||
import org.betterx.ui.layout.values.Size;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class RenderHelper {
|
||||
public static void outline(PoseStack poseStack, int x0, int y0, int x1, int y1, int color) {
|
||||
|
@ -79,4 +84,32 @@ public class RenderHelper {
|
|||
RenderSystem.enableTexture();
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
public static void renderImage(
|
||||
PoseStack stack,
|
||||
int width, int height,
|
||||
ResourceLocation location,
|
||||
Rectangle uvRect,
|
||||
Size resourceSize,
|
||||
float alpha
|
||||
) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, location);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(
|
||||
GlStateManager.SourceFactor.SRC_ALPHA,
|
||||
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA
|
||||
);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
|
||||
GuiComponent.blit(
|
||||
stack,
|
||||
0, 0, width, height,
|
||||
uvRect.left,
|
||||
uvRect.top,
|
||||
uvRect.width,
|
||||
uvRect.height,
|
||||
resourceSize.width(),
|
||||
resourceSize.height()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,26 @@ public class Rectangle {
|
|||
this.height = height;
|
||||
}
|
||||
|
||||
public float aspect() {
|
||||
return (float) width / height;
|
||||
}
|
||||
|
||||
public Size sizeFromWidth(int width) {
|
||||
return new Size(width, (int) (width / aspect()));
|
||||
}
|
||||
|
||||
public Size sizeFromHeight(int height) {
|
||||
return new Size((int) (height * aspect()), height);
|
||||
}
|
||||
|
||||
public Size size(float scale) {
|
||||
return new Size((int) (width * scale), (int) (height * scale));
|
||||
}
|
||||
|
||||
public Size size() {
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
public int right() {
|
||||
return left + width;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue