Skip to content

Commit ec60aed

Browse files
X-C-0Wide-Cat
authored andcommitted
Fix scrolling for view-in-view scenario
1 parent 3933027 commit ec60aed

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/main/java/meteordevelopment/meteorclient/gui/screens/settings/FontFaceSettingScreen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public void initWidgets() {
6161
};
6262

6363
WView view = add(theme.view()).expandX().widget();
64+
// Prevents double scrolling for view-in-view scenario
65+
view.maxHeight = window.view.maxHeight - 128;
6466
view.scrollOnlyWhenMouseOver = false;
67+
6568
table = view.add(theme.table()).expandX().widget();
6669

6770
initTable();

src/main/java/meteordevelopment/meteorclient/gui/themes/meteor/widgets/WMeteorView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class WMeteorView extends WView implements MeteorWidget {
1313
@Override
1414
protected void onRender(GuiRenderer renderer, double mouseX, double mouseY, double delta) {
1515
if (canScroll && hasScrollBar) {
16-
renderer.quad(handleX(), handleY(), handleWidth(), handleHeight(), theme().scrollbarColor.get(handlePressed, handleMouseOver));
16+
renderer.quad(handleX(), handleY(), handleWidth(), handleHeight(), theme().scrollbarColor.get(focused, handleMouseOver));
1717
}
1818
}
1919
}

src/main/java/meteordevelopment/meteorclient/gui/widgets/containers/WContainer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ public void moveCells(double deltaX, double deltaY) {
6464

6565
@Override
6666
public boolean isFocused() {
67-
for (Cell<?> cell : cells) if (cell.widget().isFocused()) return true;
67+
if (focused) return true;
68+
69+
for (Cell<?> cell : cells) {
70+
if (cell.widget().isFocused())
71+
return true;
72+
}
73+
6874
return false;
6975
}
7076

src/main/java/meteordevelopment/meteorclient/gui/widgets/containers/WView.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public abstract class WView extends WVerticalList {
2626
private boolean moveAfterPositionWidgets;
2727

2828
protected boolean handleMouseOver;
29-
protected boolean handlePressed;
3029

3130
@Override
3231
public void init() {
@@ -77,7 +76,7 @@ protected void onCalculateWidgetPositions() {
7776
@Override
7877
public boolean onMouseClicked(Click click, boolean doubled) {
7978
if (handleMouseOver && click.button() == GLFW_MOUSE_BUTTON_LEFT && !doubled) {
80-
handlePressed = true;
79+
setFocused(true);
8180
return true;
8281
}
8382

@@ -86,7 +85,7 @@ public boolean onMouseClicked(Click click, boolean doubled) {
8685

8786
@Override
8887
public boolean onMouseReleased(Click click) {
89-
if (handlePressed) handlePressed = false;
88+
if (focused) setFocused(false);
9089

9190
return false;
9291
}
@@ -104,7 +103,7 @@ public void onMouseMoved(double mouseX, double mouseY, double lastMouseX, double
104103
}
105104
}
106105

107-
if (handlePressed) {
106+
if (focused) {
108107
double preScroll = scroll;
109108
double mouseDelta = mouseY - lastMouseY;
110109

@@ -123,9 +122,13 @@ public void onMouseMoved(double mouseX, double mouseY, double lastMouseX, double
123122
@Override
124123
public boolean onMouseScrolled(double amount) {
125124
if (!scrollOnlyWhenMouseOver || mouseOver) {
125+
double max = actualHeight - height;
126+
126127
targetScroll -= Math.round(theme.scale(amount * 40));
127-
targetScroll = MathHelper.clamp(targetScroll, 0, actualHeight - height);
128-
return true;
128+
targetScroll = MathHelper.clamp(targetScroll, 0, max);
129+
130+
// Only consume the event if the view actually scrolled, otherwise propagate to parent.
131+
return targetScroll > 0 && targetScroll < max;
129132
}
130133

131134
return false;
@@ -164,7 +167,13 @@ else if (targetScroll < scroll) {
164167

165168
@Override
166169
protected boolean propagateEvents(WWidget widget) {
167-
return (mouseOver && isWidgetInView(widget)) || widget.isFocused();
170+
if (widget.isFocused()) return true;
171+
172+
// Propagate to any visible view, to allow inputs even when not hovered
173+
if (widget instanceof WView) return isWidgetInView(widget);
174+
175+
// Propagate to any visible widget while the view is hovered
176+
return mouseOver && isWidgetInView(widget);
168177
}
169178

170179
protected double handleWidth() {

0 commit comments

Comments
 (0)