[Fix] Odd scroll/focus interaction
This commit is contained in:
parent
8c0372e4bc
commit
20c89735ce
6 changed files with 25 additions and 16 deletions
|
@ -117,6 +117,7 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
|
||||||
public void setFocused(@Nullable GuiEventListener guiEventListener) {
|
public void setFocused(@Nullable GuiEventListener guiEventListener) {
|
||||||
focused = guiEventListener;
|
focused = guiEventListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Image addIcon(ResourceLocation location, Size resourceSize) {
|
public Image addIcon(ResourceLocation location, Size resourceSize) {
|
||||||
Image i = new Image(Value.fixed(24), Value.fixed(24), location, resourceSize);
|
Image i = new Image(Value.fixed(24), Value.fixed(24), location, resourceSize);
|
||||||
|
@ -222,5 +223,16 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
|
||||||
add(c);
|
add(c);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ColorPicker addColorPicker(
|
||||||
|
Value width,
|
||||||
|
Value height,
|
||||||
|
net.minecraft.network.chat.Component titleOrNull,
|
||||||
|
int color
|
||||||
|
) {
|
||||||
|
ColorPicker c = new ColorPicker(width, height, titleOrNull, color);
|
||||||
|
add(c);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ public abstract class AbstractVanillaComponent<C extends AbstractWidget, V exten
|
||||||
@Override
|
@Override
|
||||||
public boolean isMouseOver(double x, double y) {
|
public boolean isMouseOver(double x, double y) {
|
||||||
if (vanillaComponent != null && enabled)
|
if (vanillaComponent != null && enabled)
|
||||||
return vanillaComponent.isMouseOver(x, y);
|
return vanillaComponent.isMouseOver(x - relativeBounds.left, y - relativeBounds.top);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,4 +88,9 @@ public class Input extends AbstractVanillaComponent<EditBox, Input> {
|
||||||
public boolean changeFocus(boolean bl) {
|
public boolean changeFocus(boolean bl) {
|
||||||
return super.changeFocus(bl);
|
return super.changeFocus(bl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(double x, double y, int button) {
|
||||||
|
return super.mouseClicked(x, y, button);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,15 +100,6 @@ public class Panel implements ComponentWithBounds, RelativeContainerEventHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMouseOver(double x, double y) {
|
|
||||||
if (child != null) {
|
|
||||||
if (child.isMouseOver(x - bounds.left, y - bounds.top))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return bounds.contains(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public void mouseMoved(double x, double y) {
|
// public void mouseMoved(double x, double y) {
|
||||||
// if (child != null)
|
// if (child != null)
|
||||||
|
|
|
@ -255,13 +255,14 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!didCapture) {
|
if (!didCapture) {
|
||||||
scrollerY = scrollerY + delta;
|
scrollerY = Math.max(0, Math.min(travel, scrollerY)) + delta;
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
System.out.println("Child did capture scroll");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GuiEventListener focused;
|
GuiEventListener focused;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -283,7 +284,6 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
||||||
dragging = bl;
|
dragging = bl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMouseOver(double x, double y) {
|
public boolean isMouseOver(double x, double y) {
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
|
@ -292,6 +292,4 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
||||||
}
|
}
|
||||||
return relativeBounds.contains(x, y);
|
return relativeBounds.contains(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,13 @@ public interface RelativeContainerEventHandler extends ContainerEventHandler {
|
||||||
|
|
||||||
default Optional<GuiEventListener> getChildAt(double d, double e) {
|
default Optional<GuiEventListener> getChildAt(double d, double e) {
|
||||||
Rectangle r = getInputBounds();
|
Rectangle r = getInputBounds();
|
||||||
return ContainerEventHandler.super.getChildAt(d - r.left, e - r.top);
|
return ContainerEventHandler.super.getChildAt(d, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean mouseClicked(double d, double e, int i) {
|
default boolean mouseClicked(double d, double e, int i) {
|
||||||
|
if (getFocused() != null) {
|
||||||
|
getFocused().mouseClicked(d, e, i);
|
||||||
|
}
|
||||||
Rectangle r = getInputBounds();
|
Rectangle r = getInputBounds();
|
||||||
return ContainerEventHandler.super.mouseClicked(d - r.left, e - r.top, i);
|
return ContainerEventHandler.super.mouseClicked(d - r.left, e - r.top, i);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue