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) {
|
||||
return getFont().lineHeight + 12;
|
||||
return getFont().lineHeight + 11;
|
||||
}
|
||||
|
||||
@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.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
|
||||
public void mouseMoved(double x, double y) {
|
||||
mouseX = (int) x;
|
||||
mouseY = (int) y;
|
||||
if (vanillaButton != null)
|
||||
vanillaButton.mouseMoved(x - relativeBounds.left, y - relativeBounds.top);
|
||||
}
|
||||
|
|
|
@ -62,20 +62,27 @@ public abstract class Component<R extends ComponentRenderer> implements Componen
|
|||
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 clip = r.intersect(clipRect);
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(relativeBounds.left, relativeBounds.top, 0);
|
||||
if (r.overlaps(clip)) {
|
||||
renderInBounds(poseStack, r, clip);
|
||||
renderInBounds(poseStack, x - relativeBounds.left, y - relativeBounds.top, a, r, clip);
|
||||
}
|
||||
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) {
|
||||
renderer.renderInBounds(poseStack, renderBounds, clipRect);
|
||||
renderer.renderInBounds(poseStack, x, y, a, renderBounds, clipRect);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package org.betterx.ui.layout.components;
|
||||
|
||||
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.values.Alignment;
|
||||
import org.betterx.ui.layout.values.DynamicSize;
|
||||
import org.betterx.ui.layout.values.Rectangle;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.events.ContainerEventHandler;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
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<>();
|
||||
|
||||
public HorizontalStack(DynamicSize width, DynamicSize height) {
|
||||
|
@ -100,10 +100,17 @@ public class HorizontalStack<R extends ComponentRenderer> extends Component<R> i
|
|||
// }
|
||||
|
||||
@Override
|
||||
protected void renderInBounds(PoseStack poseStack, Rectangle renderBounds, Rectangle clipRect) {
|
||||
super.renderInBounds(poseStack, renderBounds, clipRect);
|
||||
protected void renderInBounds(
|
||||
PoseStack poseStack,
|
||||
int x,
|
||||
int y,
|
||||
float a,
|
||||
Rectangle renderBounds,
|
||||
Rectangle clipRect
|
||||
) {
|
||||
super.renderInBounds(poseStack, x, y, a, renderBounds, clipRect);
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getInputBounds() {
|
||||
return relativeBounds;
|
||||
}
|
||||
|
||||
boolean dragging;
|
||||
|
||||
@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.RelativeContainerEventHandler;
|
||||
import org.betterx.ui.layout.values.Rectangle;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
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.narration.NarratableEntry;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.client.gui.narration.NarrationElementOutput;
|
|||
import java.util.List;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Panel implements ComponentWithBounds, ContainerEventHandler, NarratableEntry, Widget {
|
||||
public class Panel implements ComponentWithBounds, RelativeContainerEventHandler, NarratableEntry, Widget {
|
||||
protected Component<?> child;
|
||||
List<? extends GuiEventListener> listeners = List.of();
|
||||
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
|
||||
public Rectangle getRelativeBounds() {
|
||||
return bounds;
|
||||
|
@ -59,6 +53,11 @@ public class Panel implements ComponentWithBounds, ContainerEventHandler, Narrat
|
|||
return listeners;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getInputBounds() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
boolean dragging = false;
|
||||
|
||||
@Override
|
||||
|
@ -95,8 +94,10 @@ public class Panel implements ComponentWithBounds, ContainerEventHandler, Narrat
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack poseStack, int i, int j, float f) {
|
||||
render(poseStack);
|
||||
public void render(PoseStack poseStack, int x, int y, float a) {
|
||||
if (child != null) {
|
||||
child.render(poseStack, x - bounds.left, y - bounds.top, a, bounds, bounds);
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public void mouseMoved(double x, double y) {
|
||||
|
|
|
@ -83,13 +83,20 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void renderInBounds(PoseStack poseStack, Rectangle renderBounds, Rectangle clipRect) {
|
||||
super.renderInBounds(poseStack, renderBounds, clipRect);
|
||||
protected void renderInBounds(
|
||||
PoseStack poseStack,
|
||||
int x,
|
||||
int y,
|
||||
float a,
|
||||
Rectangle renderBounds,
|
||||
Rectangle clipRect
|
||||
) {
|
||||
super.renderInBounds(poseStack, x, y, a, renderBounds, clipRect);
|
||||
|
||||
if (showScrollBar()) {
|
||||
if (child != null) {
|
||||
child.render(
|
||||
poseStack,
|
||||
poseStack, x, y, a,
|
||||
renderBounds.movedBy(0, scrollerOffset(), scrollerRenderer.scrollerWidth(), 0),
|
||||
clipRect
|
||||
);
|
||||
|
@ -97,7 +104,7 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
|||
scrollerRenderer.renderScrollBar(renderBounds, saveScrollerY(), scrollerHeight);
|
||||
} else {
|
||||
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.RelativeContainerEventHandler;
|
||||
import org.betterx.ui.layout.components.render.ComponentRenderer;
|
||||
import org.betterx.ui.layout.values.Alignment;
|
||||
import org.betterx.ui.layout.values.DynamicSize;
|
||||
import org.betterx.ui.layout.values.Rectangle;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.events.ContainerEventHandler;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
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<>();
|
||||
|
||||
public VerticalStack(DynamicSize width, DynamicSize height) {
|
||||
|
@ -99,10 +99,17 @@ public class VerticalStack<R extends ComponentRenderer> extends Component<R> imp
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void renderInBounds(PoseStack poseStack, Rectangle renderBounds, Rectangle clipRect) {
|
||||
super.renderInBounds(poseStack, renderBounds, clipRect);
|
||||
protected void renderInBounds(
|
||||
PoseStack poseStack,
|
||||
int x,
|
||||
int y,
|
||||
float a,
|
||||
Rectangle renderBounds,
|
||||
Rectangle clipRect
|
||||
) {
|
||||
super.renderInBounds(poseStack, x, y, a, renderBounds, clipRect);
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getInputBounds() {
|
||||
return relativeBounds;
|
||||
}
|
||||
|
||||
boolean dragging;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
|
||||
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