Compare commits
2
Commits
a30971e4c5
...
a888717ee9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a888717ee9 | ||
|
|
e8a5792dcb |
No files matched your search
@@ -541,7 +541,7 @@ impl PrimitiveLike for &TextureHandle {
|
||||
/// method's `impl` block is where a `Painter`'s own boxes are, so it takes
|
||||
/// only what the child was asked with.
|
||||
impl Painter<'_> {
|
||||
/// Frame ranges are already ranges on the window and combine directly.
|
||||
/// Window ranges are already about the one unit and combine directly.
|
||||
/// A frame pin becomes this widget's own frame wherever a length of it
|
||||
/// is what reached the child; where only pixels did, no length of this
|
||||
/// frame can change the child's and the pin stops here.
|
||||
@@ -563,8 +563,8 @@ impl Painter<'_> {
|
||||
let mut result = LayoutHolds::ANY;
|
||||
for axis in AXES {
|
||||
let n = axis as usize;
|
||||
// Every frame range is already a range on the window: the
|
||||
// widget's own read converted through its frame exactly once.
|
||||
// Every read became pixels against the window, so a range on
|
||||
// it is already in this widget's terms.
|
||||
result.window[n] = holds.window[n];
|
||||
let reaches = narrow[n].is_none()
|
||||
&& !matches!(place[n].part(), Part::Sized(_))
|
||||
@@ -596,10 +596,10 @@ impl Painter<'_> {
|
||||
_ => self.extent.axis(axis).len(),
|
||||
});
|
||||
}
|
||||
// Its box is a part of this widget's frame, or a length of
|
||||
// it decided here: a length of the frame is all that reaches
|
||||
// it, so what it holds for is a range on the frame and none
|
||||
// of it on this widget's own box.
|
||||
// Its box is a length this widget decided, from its own
|
||||
// frame or from a sibling's answer: no length of this
|
||||
// widget's box reaches it, so what it holds for is a range
|
||||
// on the window and none of it on that box.
|
||||
_ => {
|
||||
result.window[n] =
|
||||
result.window[n].and(holds.extent[n].through(extent.axis(axis).len()));
|
||||
|
||||
@@ -5,14 +5,16 @@ use crate::{AxisAlign, Len, PrimitiveHandle, UiRegion, UiSpan};
|
||||
pub enum Part {
|
||||
/// The whole of it.
|
||||
All,
|
||||
/// Frame lengths from where the box starts, which is what a container
|
||||
/// dividing room among its children speaks: a child's report is a length
|
||||
/// of the frame, so the cursor that sums those reports is one too. A
|
||||
/// moved box re-places every child by re-adding its start, exactly.
|
||||
/// Window lengths from where the box starts, which is what a container
|
||||
/// dividing room among its children speaks: a child's report is a window
|
||||
/// length, so the cursor that sums those reports is one too. A moved box
|
||||
/// re-places every child by re-adding its start, exactly. A fraction
|
||||
/// here is a fraction of the window and not of the box -- the whole of a
|
||||
/// box is [`Self::All`], not a `rel(1.0)` span.
|
||||
From(UiSpan),
|
||||
/// A part of the box in its own coordinates, which is what a container
|
||||
/// that insets one speaks: taking eleven pixels off the end needs no
|
||||
/// length, where saying the same thing in frame lengths would make the
|
||||
/// length, where saying the same thing in window lengths would make the
|
||||
/// container read its own box -- and a box chosen from its own answer
|
||||
/// then feeds back into the answer.
|
||||
Of(UiSpan),
|
||||
|
||||
@@ -44,7 +44,6 @@ impl Widget for Scroll {
|
||||
// have placed the whole scroll in a box longer than it.
|
||||
let slack = (self.container_len - self.content_len).max(Px::ZERO);
|
||||
let anchor = slack.mul(align.rel());
|
||||
let mut content = UiSpan::FULL;
|
||||
// Content that fills the viewport and has not been scrolled is the
|
||||
// viewport, and is handed back as it came. Writing the same box as
|
||||
// its own length in pixels is the same box in another form, and the
|
||||
@@ -52,18 +51,20 @@ impl Widget for Scroll {
|
||||
// one centred in `px 900`, since halving a difference is not halving
|
||||
// each part of it.
|
||||
let moved = anchor != Px::ZERO || self.amt != Px::ZERO;
|
||||
if moved || self.content_len != self.container_len {
|
||||
let start = Len::from_parts(Rel::ZERO, anchor - self.amt);
|
||||
content = UiSpan::new(start, start.offset(self.content_len));
|
||||
}
|
||||
let content = match moved || self.content_len != self.container_len {
|
||||
true => {
|
||||
let start = Len::from_parts(Rel::ZERO, anchor - self.amt);
|
||||
Part::From(UiSpan::new(start, start.offset(self.content_len)))
|
||||
}
|
||||
false => Part::All,
|
||||
};
|
||||
// The viewport is the inner's frame, so a fraction it declares or
|
||||
// reports is a fraction of what is on screen rather than of the
|
||||
// content box its own answer decided. Where it goes is the content
|
||||
// box, scrolled: its drawing moved there, not made again there.
|
||||
painter.place_at(
|
||||
&self.inner,
|
||||
self.axis
|
||||
.pair(Place::Fill(Part::From(content)), Place::Fill(Part::All)),
|
||||
self.axis.pair(Place::Fill(content), Place::Fill(Part::All)),
|
||||
);
|
||||
// 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
|
||||
|
||||
@@ -145,3 +145,19 @@ fn a_clipping_widget_reporting_more_than_its_box_is_caught() {
|
||||
h.set_root(clipper);
|
||||
h.frame();
|
||||
}
|
||||
|
||||
/// Content that fits sits in the viewport, not in a box of the window's
|
||||
/// length anchored at the viewport's start. `Part::From` takes window
|
||||
/// lengths, so a `rel(1.0)` span in one is the window, and only a scroll
|
||||
/// filling the window would land right.
|
||||
#[test]
|
||||
fn content_that_fits_is_placed_in_the_viewport_and_not_in_the_window() {
|
||||
let mut h = Harness::new((400, 400));
|
||||
let head = rect(Color::RED).height(100).add(&mut h.rsc);
|
||||
let inner = rect(Color::BLUE).height(50).add(&mut h.rsc);
|
||||
let scroll = Scroll::new(inner.add_strong(&mut h.rsc), Axis::Y).add(&mut h.rsc);
|
||||
h.set_root((head, scroll).span(Dir::DOWN));
|
||||
|
||||
assert_corners!(h, scroll, (0, 100), (400, 400));
|
||||
assert_corners!(h, inner, (0, 225), (400, 275));
|
||||
}
|
||||
Reference in new issue
Block a user