Retain layout sizes by pixel axis
This commit is contained in:
1 parent
82fa6c1123
commit
b1b3eca1c0
11 files changed
+371
-69
No files matched your search
@@ -11,13 +11,15 @@ pub struct Scroll {
|
||||
|
||||
impl Widget for Scroll {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
let output_len = painter.output_size().axis(self.axis);
|
||||
let container_len = UiScalar::abs(painter.px_size().axis(self.axis));
|
||||
// Draw in the whole container to learn the content's length, then
|
||||
// place it at the scrolled offset.
|
||||
let child = painter.place(&self.inner, UiRegion::FULL).size();
|
||||
let content_len = child
|
||||
.axis(self.axis)
|
||||
let output_len = painter.output_len(self.axis);
|
||||
let container_len = UiScalar::abs(painter.px_len(self.axis));
|
||||
// Draw in the whole container only when its scrolling-axis length is
|
||||
// not already known, then place it at the scrolled offset.
|
||||
let known_len = painter.known_len(&self.inner, self.axis, UiRegion::FULL);
|
||||
let measured = known_len.is_none();
|
||||
let child = measured.then(|| painter.place(&self.inner, UiRegion::FULL).size());
|
||||
let content_len = known_len
|
||||
.unwrap_or_else(|| child.unwrap().axis(self.axis))
|
||||
.apply_rest()
|
||||
.within_len(container_len)
|
||||
.to_abs(output_len);
|
||||
@@ -31,8 +33,8 @@ impl Widget for Scroll {
|
||||
|
||||
let mut region = UiRegion::FULL.offset(Vec2::from_axis(self.axis, -self.amt, 0.0));
|
||||
region.axis_mut(self.axis).end = region.axis(self.axis).start.offset(self.content_len);
|
||||
painter.place(&self.inner, region);
|
||||
child
|
||||
let placed = painter.place(&self.inner, region).size();
|
||||
child.unwrap_or(placed)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user