Class ScrollGutters
ScrollView,
ListView and TextArea all hold one, and so should anything else
that scrolls.
// in onLayout, where `content` re-measures into a viewport:
Size size = gutters.resolve(width(), height(), vBar, hBar,
(viewW, viewH) -> child.measure(Constraints.loose(viewW, viewH)));
float viewW = gutters.viewportWidth(width());
The class exists because three widgets needed the same three paragraphs of reasoning, and a rule copied three times is a rule that will differ three ways within a year. What is genuinely per-widget (how content is measured, where rows are placed, what gets clipped) stays with the widget; what is identical (when a strip is reserved and how wide) lives here.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHow the content is measured for a candidate viewport.static enumWhether a bar floats over the content or takes a strip out of it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatHeight taken by the horizontal bar, likewise.layout()Whether the bars overlay the content or reserve a gutter beside it.resolve(float boxWidth, float boxHeight, ScrollBar vBar, ScrollBar hBar, ScrollGutters.Content content) Settles the strips for a box and returns the content's size in the viewport they leave.voidsetLayout(ScrollGutters.Layout newLayout) Sets the mode (defaultScrollGutters.Layout.OVERLAY); the host asks for the relayout.floatWidth taken by the vertical bar, or0when it floats or is not needed.floatviewportHeight(float boxHeight) Height left for content, the full box when the bars overlay it.floatviewportWidth(float boxWidth) Width left for content, the full box when the bars overlay it.
-
Constructor Details
-
ScrollGutters
public ScrollGutters()
-
-
Method Details
-
setLayout
Sets the mode (defaultScrollGutters.Layout.OVERLAY); the host asks for the relayout. -
layout
Whether the bars overlay the content or reserve a gutter beside it. -
verticalStrip
public float verticalStrip()Width taken by the vertical bar, or0when it floats or is not needed. -
horizontalStrip
public float horizontalStrip()Height taken by the horizontal bar, likewise. -
viewportWidth
public float viewportWidth(float boxWidth) Width left for content, the full box when the bars overlay it. -
viewportHeight
public float viewportHeight(float boxHeight) Height left for content, the full box when the bars overlay it. -
resolve
public Size resolve(float boxWidth, float boxHeight, ScrollBar vBar, ScrollBar hBar, ScrollGutters.Content content) Settles the strips for a box and returns the content's size in the viewport they leave. Passnullfor an axis the widget does not scroll.Two passes, and it refuses a third. Reserving a strip narrows the content, which can make it taller (wrapped text is the everyday case) and turn an axis that fitted into one that overflows; the second pass sees that. A third is where content whose two axes disagree about which bar they need would oscillate forever, and one bar more than strictly necessary is a better outcome than a layout that never settles.
The strips key on overflow, not on whether a bar is currently drawn. Under the fading policies a bar comes and goes constantly, and reserving by visibility would rewrap the content under the pointer every time it did.
-