Skip to content

Commit

Permalink
Ensure that scroll offset is in bounds after layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Nov 17, 2023
1 parent 0c8d42b commit 9f8aacc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/widget/scroll_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9f8aacc

Please sign in to comment.