diff --git a/src/widget/scroll_view.rs b/src/widget/scroll_view.rs index 20edb9f7f..7978ea3a5 100644 --- a/src/widget/scroll_view.rs +++ b/src/widget/scroll_view.rs @@ -116,11 +116,24 @@ impl Widget for ScrollView { height: f64::INFINITY, }, ); - let size = self.child.layout(cx, &cbc); - Size { - width: size.width.min(bc.max().width), - height: size.height.min(bc.max().height), + let child_size = self.child.layout(cx, &cbc); + let size = Size { + width: child_size.width.min(bc.max().width), + height: child_size.height.min(bc.max().height), + }; + + // Ensure that scroll offset is within bounds + let max_offset = (child_size.height - size.height).max(0.0); + if max_offset < self.offset { + self.offset = max_offset; + let new_origin = Point { + x: 0.0, + y: -self.offset, + }; + self.child.set_origin(cx.widget_state, new_origin); } + + size } fn paint(&mut self, cx: &mut PaintCx, builder: &mut SceneBuilder) {