Make alignment a widget property
This commit is contained in:
1 parent
8220a78d4a
commit
d3b0ebf90c
21 files changed
+823
-300
No files matched your search
@@ -14,13 +14,9 @@ impl Widget for Scroll {
|
||||
let container_len = painter.px_len(self.axis);
|
||||
// Draw in the whole container only when its scrolling-axis length is
|
||||
// not already known, then draw it at the scrolled offset.
|
||||
let (answer_len, measured) = match painter.known_len(&self.inner, self.axis, UiRegion::FULL)
|
||||
{
|
||||
Some(len) => (len, None),
|
||||
None => {
|
||||
let size = painter.widget_within(&self.inner, UiRegion::FULL).size();
|
||||
(size.axis(self.axis), Some(size))
|
||||
}
|
||||
let answer_len = match painter.known_len(&self.inner, self.axis, UiRegion::FULL) {
|
||||
Some(len) => len,
|
||||
None => painter.widget(&self.inner).size().axis(self.axis),
|
||||
};
|
||||
let content = answer_len.apply_leftover();
|
||||
self.container_len = container_len;
|
||||
@@ -30,21 +26,33 @@ impl Widget for Scroll {
|
||||
self.amt = self.content_len - self.container_len;
|
||||
}
|
||||
self.update_amt();
|
||||
// Content of a fixed length that fits sits at the start of any box
|
||||
// it fits in; one scrolled part way sits where it is until the box
|
||||
// shrinks past what is left of it. Kept to the end, it moves with
|
||||
// every length.
|
||||
if content.rel == 0.0 && self.content_len <= self.container_len {
|
||||
let align = painter.alignment().axis(self.axis);
|
||||
// Content of a fixed length that fits sits at the start of any box it
|
||||
// fits in -- but only anchored there. Anywhere else it is a part of
|
||||
// the room left over, so it moves with every length the box takes and
|
||||
// the drawing holds for that length alone. One scrolled part way sits
|
||||
// where it is until the box shrinks past what is left of it. Kept to
|
||||
// the end, it moves with every length.
|
||||
if content.rel == 0.0 && self.content_len <= self.container_len && align == AxisAlign::NEG {
|
||||
painter.holds(self.axis, self.content_len..=f32::INFINITY);
|
||||
} else if content.rel == 0.0 && !self.snap_end {
|
||||
let left = self.content_len - self.amt;
|
||||
painter.holds(self.axis, f32::NEG_INFINITY..=left);
|
||||
}
|
||||
|
||||
let mut region = UiRegion::FULL.offset(Vec2::from_axis(self.axis, -self.amt, 0.0));
|
||||
// Content shorter than the viewport has room to sit in, and where it
|
||||
// sits is this widget's own alignment -- the same property that would
|
||||
// have placed the whole scroll in a box longer than it.
|
||||
let slack = (self.container_len - self.content_len).max(0.0);
|
||||
let anchor = slack * align.rel();
|
||||
let mut region = UiRegion::FULL.offset(Vec2::from_axis(self.axis, anchor - self.amt, 0.0));
|
||||
region.axis_mut(self.axis).end = region.axis(self.axis).start.offset(self.content_len);
|
||||
let placed = painter.widget_within(&self.inner, region).size();
|
||||
measured.unwrap_or_else(|| Size::from_axis(self.axis, answer_len, placed.axis(!self.axis)))
|
||||
painter.widget_aligned(&self.inner, region, RegionAlign::NEAR);
|
||||
// What it occupies is its box, on both axes: it clips its content to
|
||||
// that box, so it can neither take less of one nor honestly ask for
|
||||
// more. The content's length is what it scrolls through, not what it
|
||||
// is.
|
||||
Size::LEFTOVER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user