Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public boolean onMouseClicked(Click click, boolean doubled) {

if (mouseOver) {
dragging = true;
setFocused(true);

handleX = lastMouseX - x;
handleY = lastMouseY - y;
Expand All @@ -298,6 +299,7 @@ public boolean onMouseClicked(Click click, boolean doubled) {
public boolean onMouseReleased(Click click) {
if (dragging) {
dragging = false;
setFocused(false);
}

return false;
Expand Down Expand Up @@ -555,6 +557,7 @@ public boolean onMouseClicked(Click click, boolean doubled) {

if (mouseOver) {
dragging = true;
setFocused(true);

handleX = lastMouseX - x;
calculateHueAngleFromHandleX();
Expand All @@ -570,6 +573,7 @@ public boolean onMouseClicked(Click click, boolean doubled) {
public boolean onMouseReleased(Click click) {
if (dragging) {
dragging = false;
setFocused(false);
}

return mouseOver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public abstract class WWidget implements BaseWidget {
public String tooltip;

public boolean mouseOver;
public boolean focused;
protected boolean instantTooltips;
protected double mouseOverTimer;

Expand Down Expand Up @@ -143,11 +144,19 @@ protected WWidget getRoot() {
return parent != null ? parent.getRoot() : (this instanceof WRoot ? this : null);
}

protected WView getView() {
public WView getView() {
return this instanceof WView ? (WView) this : (parent != null ? parent.getView() : null);
}

public boolean isOver(double x, double y) {
return x >= this.x && x <= this.x + width && y >= this.y && y <= this.y + height;
}

public boolean isFocused() {
return focused;
}

public void setFocused(boolean focused) {
if (this.focused != focused) this.focused = focused;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public void moveCells(double deltaX, double deltaY) {
}
}

@Override
public boolean isFocused() {
for (Cell<?> cell : cells) if (cell.widget().isFocused()) return true;
return false;
}

// Layout

@Override
Expand Down Expand Up @@ -107,13 +113,15 @@ public boolean render(GuiRenderer renderer, double mouseX, double mouseY, double
if (super.render(renderer, mouseX, mouseY, delta)) return true;

WView view = getView();
double windowHeight = getWindowHeight();

for (Cell<?> cell : cells) {
double y = cell.widget().y;
if (y > getWindowHeight()) break;
if (view != null && !view.isWidgetInView(cell.widget())) continue;
WWidget widget = cell.widget();

if (widget.y > windowHeight) break;
if (widget.y + widget.height <= 0) continue;

if (y + cell.widget().height > 0) renderWidget(cell.widget(), renderer, mouseX, mouseY, delta);
if (shouldRenderWidget(widget, view)) renderWidget(widget, renderer, mouseX, mouseY, delta);
}

return false;
Expand All @@ -123,6 +131,17 @@ protected void renderWidget(WWidget widget, GuiRenderer renderer, double mouseX,
widget.render(renderer, mouseX, mouseY, delta);
}

private boolean shouldRenderWidget(WWidget widget, WView view) {
if (view == null) return true;
if (!view.isWidgetInView(widget)) return false;

if (widget.mouseOver && !view.mouseOver) {
widget.mouseOver = false;
}

return true;
}

// Events

protected boolean propagateEvents(WWidget widget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ else if (targetScroll < scroll) {

@Override
protected boolean propagateEvents(WWidget widget) {
return ((widget.y >= y && widget.y <= y + height) || (widget.y + widget.height >= y && widget.y + widget.height <= y + height)) || ((y >= widget.y && y <= widget.y + widget.height) || (y + height >= widget.y && y + height <= widget.y + widget.height));
}

protected boolean isWidgetInView(WWidget widget) {
return widget.y < y + height && widget.y + widget.height > y;
return (mouseOver && isWidgetInView(widget)) || widget.isFocused();
}

protected double handleWidth() {
Expand All @@ -186,4 +182,8 @@ protected double handleX() {
protected double handleY() {
return y + (height - handleHeight()) * (scroll / (actualHeight - height));
}

public boolean isWidgetInView(WWidget widget) {
return widget.y < y + height && widget.y + widget.height > y;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import meteordevelopment.meteorclient.gui.utils.Cell;
import meteordevelopment.meteorclient.gui.widgets.WRoot;
import meteordevelopment.meteorclient.gui.widgets.containers.WVerticalList;
import meteordevelopment.meteorclient.gui.widgets.containers.WView;
import meteordevelopment.meteorclient.gui.widgets.pressable.WPressable;
import net.minecraft.client.gui.Click;
import net.minecraft.client.input.CharInput;
Expand Down Expand Up @@ -84,6 +85,8 @@ protected void onCalculateWidgetPositions() {
@Override
protected void onPressed(int button) {
expanded = !expanded;
root.setFocused(expanded);
setFocused(expanded);
}

public T get() {
Expand All @@ -108,7 +111,10 @@ public boolean render(GuiRenderer renderer, double mouseX, double mouseY, double
animProgress += (expanded ? 1 : -1) * delta * 14;
animProgress = MathHelper.clamp(animProgress, 0, 1);

if (!render && animProgress > 0) {
WView view = getView();
boolean rootInView = view == null || view.isWidgetInView(root);

if (!render && animProgress > 0 && rootInView) {
renderer.absolutePost(() -> {
renderer.scissorStart(x, y + height, width, root.height * animProgress);
root.render(renderer, mouseX, mouseY, delta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public boolean onMouseClicked(Click click, boolean doubled) {
if (action != null) action.run();

dragging = true;
setFocused(true);
return true;
}

Expand Down Expand Up @@ -112,6 +113,7 @@ public boolean onMouseReleased(Click click) {
}

dragging = false;
setFocused(false);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public abstract class WTextBox extends WWidget {

protected final Renderer renderer;

protected boolean focused;
protected DoubleList textWidths = new DoubleArrayList();

protected int cursor;
Expand Down Expand Up @@ -669,10 +668,7 @@ public void set(String text) {
cursorChanged();
}

public boolean isFocused() {
return focused;
}

@Override
public void setFocused(boolean focused) {
if (this.focused && !focused && actionOnUnfocused != null) actionOnUnfocused.run();

Expand Down