Skip to content

Commit b4bff8e

Browse files
committed
move keepScrollBarInArea field from ListWidget to AbstractScrollWidget
1 parent 996fbba commit b4bff8e

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/main/java/com/cleanroommc/modularui/widget/AbstractScrollWidget.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
public abstract class AbstractScrollWidget<I extends IWidget, W extends AbstractScrollWidget<I, W>> extends AbstractParentWidget<I, W> implements IViewport, Interactable {
2727

2828
private final ScrollArea scroll = new ScrollArea();
29+
private boolean keepScrollBarInArea = false;
2930

3031
public AbstractScrollWidget(@Nullable HorizontalScrollData x, @Nullable VerticalScrollData y) {
3132
super();
@@ -69,9 +70,15 @@ public void getWidgetsAt(IViewportStack stack, HoveredWidgetList widgets, int x,
6970
public void onResized() {
7071
if (this.scroll.getScrollX() != null) {
7172
this.scroll.getScrollX().clamp(this.scroll);
73+
if (!this.keepScrollBarInArea) {
74+
getArea().width += this.scroll.getScrollY().getThickness();
75+
}
7276
}
7377
if (this.scroll.getScrollY() != null) {
7478
this.scroll.getScrollY().clamp(this.scroll);
79+
if (!this.keepScrollBarInArea) {
80+
getArea().height += this.scroll.getScrollX().getThickness();
81+
}
7582
}
7683
}
7784

@@ -128,4 +135,21 @@ public int getScrollX() {
128135
public int getScrollY() {
129136
return this.scroll.getScrollY() != null ? this.scroll.getScrollY().getScroll() : 0;
130137
}
138+
139+
/**
140+
* Sets whether the scroll bar should be kept inside the area of this widget, which might cause it to overlap with the content of this widget.
141+
* By setting the value to false, the size of this widget is expanded by the thickness of the scrollbars after the tree is resized.
142+
* Default: false
143+
*
144+
* @param value if the scroll bar should be kept inside the widgets area
145+
* @return this
146+
*/
147+
public W keepScrollBarInArea(boolean value) {
148+
this.keepScrollBarInArea = value;
149+
return getThis();
150+
}
151+
152+
public W keepScrollBarInArea() {
153+
return keepScrollBarInArea(true);
154+
}
131155
}

src/main/java/com/cleanroommc/modularui/widgets/ListWidget.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class ListWidget<I extends IWidget, W extends ListWidget<I, W>> extends A
2929
private ScrollData scrollData;
3030
private IIcon childSeparator;
3131
private final IntList separatorPositions = new IntArrayList();
32-
private boolean keepScrollBarInArea = false;
3332

3433
public ListWidget() {
3534
super(null, null);
@@ -42,16 +41,6 @@ public void onInit() {
4241
}
4342
}
4443

45-
@Override
46-
public void onResized() {
47-
if (this.keepScrollBarInArea) return;
48-
if (this.scrollData.isVertical()) {
49-
getArea().width += this.scrollData.getThickness();
50-
} else {
51-
getArea().height += this.scrollData.getThickness();
52-
}
53-
}
54-
5544
@Override
5645
public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
5746
if (this.childSeparator == null || this.separatorPositions.isEmpty()) return;
@@ -141,11 +130,6 @@ public W scrollDirection(ScrollData data) {
141130
return getThis();
142131
}
143132

144-
public W keepScrollBarInArea() {
145-
this.keepScrollBarInArea = true;
146-
return getThis();
147-
}
148-
149133
public W childSeparator(IIcon separator) {
150134
this.childSeparator = separator;
151135
return getThis();

0 commit comments

Comments
 (0)