Fixed Hover Rendering
This commit is contained in:
parent
399d9820d4
commit
ca81b5a720
9 changed files with 117 additions and 34 deletions
|
@ -21,14 +21,14 @@ class ButtonRenderer implements ComponentRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight(net.minecraft.network.chat.Component c) {
|
public int getHeight(net.minecraft.network.chat.Component c) {
|
||||||
return getFont().lineHeight + 12;
|
return getFont().lineHeight + 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderInBounds(PoseStack poseStack, Rectangle bounds, Rectangle clipRect) {
|
public void renderInBounds(PoseStack poseStack, int x, int y, float a, Rectangle bounds, Rectangle clipRect) {
|
||||||
if (linkedButton != null) {
|
if (linkedButton != null) {
|
||||||
if (linkedButton.vanillaButton != null) {
|
if (linkedButton.vanillaButton != null) {
|
||||||
linkedButton.vanillaButton.render(poseStack, linkedButton.mouseX, linkedButton.mouseY, 1);
|
linkedButton.vanillaButton.render(poseStack, x, y, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,8 @@ public class Button extends Component<ButtonRenderer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(double x, double y) {
|
public void mouseMoved(double x, double y) {
|
||||||
|
mouseX = (int) x;
|
||||||
|
mouseY = (int) y;
|
||||||
if (vanillaButton != null)
|
if (vanillaButton != null)
|
||||||
vanillaButton.mouseMoved(x - relativeBounds.left, y - relativeBounds.top);
|
vanillaButton.mouseMoved(x - relativeBounds.left, y - relativeBounds.top);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,20 +62,27 @@ public abstract class Component<R extends ComponentRenderer> implements Componen
|
||||||
return height.calculatedSize();
|
return height.calculatedSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(PoseStack poseStack, Rectangle parentBounds, Rectangle clipRect) {
|
public void render(PoseStack poseStack, int x, int y, float a, Rectangle parentBounds, Rectangle clipRect) {
|
||||||
Rectangle r = relativeBounds.movedBy(parentBounds.left, parentBounds.top);
|
Rectangle r = relativeBounds.movedBy(parentBounds.left, parentBounds.top);
|
||||||
Rectangle clip = r.intersect(clipRect);
|
Rectangle clip = r.intersect(clipRect);
|
||||||
poseStack.pushPose();
|
poseStack.pushPose();
|
||||||
poseStack.translate(relativeBounds.left, relativeBounds.top, 0);
|
poseStack.translate(relativeBounds.left, relativeBounds.top, 0);
|
||||||
if (r.overlaps(clip)) {
|
if (r.overlaps(clip)) {
|
||||||
renderInBounds(poseStack, r, clip);
|
renderInBounds(poseStack, x - relativeBounds.left, y - relativeBounds.top, a, r, clip);
|
||||||
}
|
}
|
||||||
poseStack.popPose();
|
poseStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void renderInBounds(PoseStack poseStack, Rectangle renderBounds, Rectangle clipRect) {
|
protected void renderInBounds(
|
||||||
|
PoseStack poseStack,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
float a,
|
||||||
|
Rectangle renderBounds,
|
||||||
|
Rectangle clipRect
|
||||||
|
) {
|
||||||
if (renderer != null) {
|
if (renderer != null) {
|
||||||
renderer.renderInBounds(poseStack, renderBounds, clipRect);
|
renderer.renderInBounds(poseStack, x, y, a, renderBounds, clipRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
package org.betterx.ui.layout.components;
|
package org.betterx.ui.layout.components;
|
||||||
|
|
||||||
import org.betterx.ui.layout.components.input.MouseEvent;
|
import org.betterx.ui.layout.components.input.MouseEvent;
|
||||||
|
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.values.Alignment;
|
import org.betterx.ui.layout.values.Alignment;
|
||||||
import org.betterx.ui.layout.values.DynamicSize;
|
import org.betterx.ui.layout.values.DynamicSize;
|
||||||
import org.betterx.ui.layout.values.Rectangle;
|
import org.betterx.ui.layout.values.Rectangle;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.gui.components.events.ContainerEventHandler;
|
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class HorizontalStack<R extends ComponentRenderer> extends Component<R> implements ContainerEventHandler {
|
public class HorizontalStack<R extends ComponentRenderer> extends Component<R> implements RelativeContainerEventHandler {
|
||||||
protected final List<Component<?>> components = new LinkedList<>();
|
protected final List<Component<?>> components = new LinkedList<>();
|
||||||
|
|
||||||
public HorizontalStack(DynamicSize width, DynamicSize height) {
|
public HorizontalStack(DynamicSize width, DynamicSize height) {
|
||||||
|
@ -100,10 +100,17 @@ public class HorizontalStack<R extends ComponentRenderer> extends Component<R> i
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderInBounds(PoseStack poseStack, Rectangle renderBounds, Rectangle clipRect) {
|
protected void renderInBounds(
|
||||||
super.renderInBounds(poseStack, renderBounds, clipRect);
|
PoseStack poseStack,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
float a,
|
||||||
|
Rectangle renderBounds,
|
||||||
|
Rectangle clipRect
|
||||||
|
) {
|
||||||
|
super.renderInBounds(poseStack, x, y, a, renderBounds, clipRect);
|
||||||
for (Component<?> c : components) {
|
for (Component<?> c : components) {
|
||||||
c.render(poseStack, renderBounds, clipRect);
|
c.render(poseStack, x, y, a, renderBounds, clipRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +160,11 @@ public class HorizontalStack<R extends ComponentRenderer> extends Component<R> i
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rectangle getInputBounds() {
|
||||||
|
return relativeBounds;
|
||||||
|
}
|
||||||
|
|
||||||
boolean dragging;
|
boolean dragging;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,11 +2,11 @@ package org.betterx.ui.layout.components;
|
||||||
|
|
||||||
|
|
||||||
import org.betterx.ui.layout.components.input.MouseEvent;
|
import org.betterx.ui.layout.components.input.MouseEvent;
|
||||||
|
import org.betterx.ui.layout.components.input.RelativeContainerEventHandler;
|
||||||
import org.betterx.ui.layout.values.Rectangle;
|
import org.betterx.ui.layout.values.Rectangle;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.gui.components.Widget;
|
import net.minecraft.client.gui.components.Widget;
|
||||||
import net.minecraft.client.gui.components.events.ContainerEventHandler;
|
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
|
@ -14,7 +14,7 @@ import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class Panel implements ComponentWithBounds, ContainerEventHandler, NarratableEntry, Widget {
|
public class Panel implements ComponentWithBounds, RelativeContainerEventHandler, NarratableEntry, Widget {
|
||||||
protected Component<?> child;
|
protected Component<?> child;
|
||||||
List<? extends GuiEventListener> listeners = List.of();
|
List<? extends GuiEventListener> listeners = List.of();
|
||||||
public final Rectangle bounds;
|
public final Rectangle bounds;
|
||||||
|
@ -43,12 +43,6 @@ public class Panel implements ComponentWithBounds, ContainerEventHandler, Narrat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(PoseStack poseStack) {
|
|
||||||
if (child != null) {
|
|
||||||
child.render(poseStack, bounds, bounds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rectangle getRelativeBounds() {
|
public Rectangle getRelativeBounds() {
|
||||||
return bounds;
|
return bounds;
|
||||||
|
@ -59,6 +53,11 @@ public class Panel implements ComponentWithBounds, ContainerEventHandler, Narrat
|
||||||
return listeners;
|
return listeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rectangle getInputBounds() {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
boolean dragging = false;
|
boolean dragging = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,8 +94,10 @@ public class Panel implements ComponentWithBounds, ContainerEventHandler, Narrat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(PoseStack poseStack, int i, int j, float f) {
|
public void render(PoseStack poseStack, int x, int y, float a) {
|
||||||
render(poseStack);
|
if (child != null) {
|
||||||
|
child.render(poseStack, x - bounds.left, y - bounds.top, a, bounds, bounds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// @Override
|
// @Override
|
||||||
// public void mouseMoved(double x, double y) {
|
// public void mouseMoved(double x, double y) {
|
||||||
|
|
|
@ -83,13 +83,20 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderInBounds(PoseStack poseStack, Rectangle renderBounds, Rectangle clipRect) {
|
protected void renderInBounds(
|
||||||
super.renderInBounds(poseStack, renderBounds, clipRect);
|
PoseStack poseStack,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
float a,
|
||||||
|
Rectangle renderBounds,
|
||||||
|
Rectangle clipRect
|
||||||
|
) {
|
||||||
|
super.renderInBounds(poseStack, x, y, a, renderBounds, clipRect);
|
||||||
|
|
||||||
if (showScrollBar()) {
|
if (showScrollBar()) {
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
child.render(
|
child.render(
|
||||||
poseStack,
|
poseStack, x, y, a,
|
||||||
renderBounds.movedBy(0, scrollerOffset(), scrollerRenderer.scrollerWidth(), 0),
|
renderBounds.movedBy(0, scrollerOffset(), scrollerRenderer.scrollerWidth(), 0),
|
||||||
clipRect
|
clipRect
|
||||||
);
|
);
|
||||||
|
@ -97,7 +104,7 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
||||||
scrollerRenderer.renderScrollBar(renderBounds, saveScrollerY(), scrollerHeight);
|
scrollerRenderer.renderScrollBar(renderBounds, saveScrollerY(), scrollerHeight);
|
||||||
} else {
|
} else {
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
child.render(poseStack, renderBounds, clipRect);
|
child.render(poseStack, x, y, a, renderBounds, clipRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,20 @@ package org.betterx.ui.layout.components;
|
||||||
|
|
||||||
|
|
||||||
import org.betterx.ui.layout.components.input.MouseEvent;
|
import org.betterx.ui.layout.components.input.MouseEvent;
|
||||||
|
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.values.Alignment;
|
import org.betterx.ui.layout.values.Alignment;
|
||||||
import org.betterx.ui.layout.values.DynamicSize;
|
import org.betterx.ui.layout.values.DynamicSize;
|
||||||
import org.betterx.ui.layout.values.Rectangle;
|
import org.betterx.ui.layout.values.Rectangle;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.gui.components.events.ContainerEventHandler;
|
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class VerticalStack<R extends ComponentRenderer> extends Component<R> implements ContainerEventHandler {
|
public class VerticalStack<R extends ComponentRenderer> extends Component<R> implements RelativeContainerEventHandler {
|
||||||
protected final List<Component<?>> components = new LinkedList<>();
|
protected final List<Component<?>> components = new LinkedList<>();
|
||||||
|
|
||||||
public VerticalStack(DynamicSize width, DynamicSize height) {
|
public VerticalStack(DynamicSize width, DynamicSize height) {
|
||||||
|
@ -99,10 +99,17 @@ public class VerticalStack<R extends ComponentRenderer> extends Component<R> imp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderInBounds(PoseStack poseStack, Rectangle renderBounds, Rectangle clipRect) {
|
protected void renderInBounds(
|
||||||
super.renderInBounds(poseStack, renderBounds, clipRect);
|
PoseStack poseStack,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
float a,
|
||||||
|
Rectangle renderBounds,
|
||||||
|
Rectangle clipRect
|
||||||
|
) {
|
||||||
|
super.renderInBounds(poseStack, x, y, a, renderBounds, clipRect);
|
||||||
for (Component<?> c : components) {
|
for (Component<?> c : components) {
|
||||||
c.render(poseStack, renderBounds, clipRect);
|
c.render(poseStack, x, y, a, renderBounds, clipRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +159,11 @@ public class VerticalStack<R extends ComponentRenderer> extends Component<R> imp
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rectangle getInputBounds() {
|
||||||
|
return relativeBounds;
|
||||||
|
}
|
||||||
|
|
||||||
boolean dragging;
|
boolean dragging;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -177,7 +189,7 @@ public class VerticalStack<R extends ComponentRenderer> extends Component<R> imp
|
||||||
focused = guiEventListener;
|
focused = guiEventListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public void mouseMoved(double x, double y) {
|
// public void mouseMoved(double x, double y) {
|
||||||
// for (Component<?> c : components) {
|
// for (Component<?> c : components) {
|
||||||
// c.mouseMoved(x - relativeBounds.left, y - relativeBounds.top);
|
// c.mouseMoved(x - relativeBounds.left, y - relativeBounds.top);
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package org.betterx.ui.layout.components.input;
|
||||||
|
|
||||||
|
import org.betterx.ui.layout.values.Rectangle;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.components.events.ContainerEventHandler;
|
||||||
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
|
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public interface RelativeContainerEventHandler extends ContainerEventHandler {
|
||||||
|
Rectangle getInputBounds();
|
||||||
|
|
||||||
|
default Optional<GuiEventListener> getChildAt(double d, double e) {
|
||||||
|
Rectangle r = getInputBounds();
|
||||||
|
return ContainerEventHandler.super.getChildAt(d - r.left, e - r.top);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean mouseClicked(double d, double e, int i) {
|
||||||
|
Rectangle r = getInputBounds();
|
||||||
|
return ContainerEventHandler.super.mouseClicked(d - r.left, e - r.top, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean mouseReleased(double d, double e, int i) {
|
||||||
|
Rectangle r = getInputBounds();
|
||||||
|
return ContainerEventHandler.super.mouseReleased(d - r.left, e - r.top, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean mouseDragged(double d, double e, int i, double f, double g) {
|
||||||
|
Rectangle r = getInputBounds();
|
||||||
|
return ContainerEventHandler.super.mouseDragged(d - r.left, e - r.top, i, f - r.left, g - r.top);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean mouseScrolled(double d, double e, double f) {
|
||||||
|
Rectangle r = getInputBounds();
|
||||||
|
return ContainerEventHandler.super.mouseScrolled(d - r.left, e - r.top, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,5 +5,5 @@ import org.betterx.ui.layout.values.Rectangle;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
public interface ComponentRenderer {
|
public interface ComponentRenderer {
|
||||||
void renderInBounds(PoseStack stack, Rectangle bounds, Rectangle clipRect);
|
void renderInBounds(PoseStack stack, int x, int y, float a, Rectangle bounds, Rectangle clipRect);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue