|
26 | 26 | public abstract class AbstractScrollWidget<I extends IWidget, W extends AbstractScrollWidget<I, W>> extends AbstractParentWidget<I, W> implements IViewport, Interactable { |
27 | 27 |
|
28 | 28 | private final ScrollArea scroll = new ScrollArea(); |
| 29 | + private boolean keepScrollBarInArea = false; |
29 | 30 |
|
30 | 31 | public AbstractScrollWidget(@Nullable HorizontalScrollData x, @Nullable VerticalScrollData y) { |
31 | 32 | super(); |
@@ -69,9 +70,15 @@ public void getWidgetsAt(IViewportStack stack, HoveredWidgetList widgets, int x, |
69 | 70 | public void onResized() { |
70 | 71 | if (this.scroll.getScrollX() != null) { |
71 | 72 | this.scroll.getScrollX().clamp(this.scroll); |
| 73 | + if (!this.keepScrollBarInArea) { |
| 74 | + getArea().width += this.scroll.getScrollY().getThickness(); |
| 75 | + } |
72 | 76 | } |
73 | 77 | if (this.scroll.getScrollY() != null) { |
74 | 78 | this.scroll.getScrollY().clamp(this.scroll); |
| 79 | + if (!this.keepScrollBarInArea) { |
| 80 | + getArea().height += this.scroll.getScrollX().getThickness(); |
| 81 | + } |
75 | 82 | } |
76 | 83 | } |
77 | 84 |
|
@@ -128,4 +135,21 @@ public int getScrollX() { |
128 | 135 | public int getScrollY() { |
129 | 136 | return this.scroll.getScrollY() != null ? this.scroll.getScrollY().getScroll() : 0; |
130 | 137 | } |
| 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 | + } |
131 | 155 | } |
0 commit comments