Skip to content

Commit

Permalink
A couple minor gui fixes.
Browse files Browse the repository at this point in the history
- Fixed first tick gui element position glitch with some elements.
- Fixed inability to manipulate opaque manipulable elements.
  • Loading branch information
brandon3055 committed May 31, 2024
1 parent 3bf35a1 commit 0bf9da4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ protected void applyQueuedChildUpdates() {

if (!addedQueue.isEmpty()) {
childElements.addAll(addedQueue);
addedQueue.forEach(ConstrainedGeometry::clearGeometryCache);
addedQueue.clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class GuiManipulable extends GuiElement<GuiManipulable> implements Conten

public GuiManipulable(@NotNull GuiParent<?> parent) {
super(parent);
this.contentElement = new GuiElement<>(this)
this.contentElement = new ContentElement(this)
.constrain(LEFT, Constraint.dynamic(() -> (double) xMin))
.constrain(RIGHT, Constraint.dynamic(() -> (double) xMax))
.constrain(TOP, Constraint.dynamic(() -> (double) yMin))
Expand Down Expand Up @@ -335,34 +335,6 @@ public void startDragging() {
dragPos = true;
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) return true;

boolean posFlag = moveHandle != null && moveHandle.isMouseOver();
boolean topFlag = topHandle != null && topHandle.isMouseOver();
boolean leftFlag = leftHandle != null && leftHandle.isMouseOver();
boolean bottomFlag = bottomHandle != null && bottomHandle.isMouseOver();
boolean rightFlag = rightHandle != null && rightHandle.isMouseOver();

if (posFlag || topFlag || leftFlag || bottomFlag || rightFlag) {
dragXOffset = (int) (mouseX - xMin);
dragYOffset = (int) (mouseY - yMin);
isDragging = true;
if (posFlag) {
dragPos = true;
} else {
dragTop = topFlag;
dragLeft = leftFlag;
dragBottom = bottomFlag;
dragRight = rightFlag;
}
return true;
}

return false;
}

@Override
public void mouseMoved(double mouseX, double mouseY) {
if (isDragging) {
Expand Down Expand Up @@ -454,4 +426,39 @@ public boolean isResizing() {
public interface PositionRestraint {
void restrainPosition(GuiManipulable draggable);
}

private class ContentElement extends GuiElement<ContentElement> {

public ContentElement(@NotNull GuiParent<?> parent) {
super(parent);
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (super.mouseClicked(mouseX, mouseY, button)) return true;

boolean posFlag = moveHandle != null && moveHandle.isMouseOver();
boolean topFlag = topHandle != null && topHandle.isMouseOver();
boolean leftFlag = leftHandle != null && leftHandle.isMouseOver();
boolean bottomFlag = bottomHandle != null && bottomHandle.isMouseOver();
boolean rightFlag = rightHandle != null && rightHandle.isMouseOver();

if (posFlag || topFlag || leftFlag || bottomFlag || rightFlag) {
dragXOffset = (int) (mouseX - xMin);
dragYOffset = (int) (mouseY - yMin);
isDragging = true;
if (posFlag) {
dragPos = true;
} else {
dragTop = topFlag;
dragLeft = leftFlag;
dragBottom = bottomFlag;
dragRight = rightFlag;
}
return true;
}

return false;
}
}
}

0 comments on commit 0bf9da4

Please sign in to comment.