Say when a drawing cannot be taken out of its box, rather than guessing
`lerp_inv` returns `Option`. Inverting a lerp over a range of zero length has no one answer, and `div_or`'s fallback picked one: the start of the range. Measured, that is not a wrong number so much as a plausible one -- taking a part out of a box fixed at the top of the window hands back exactly what went in, and out of a box fixed at the middle hands back the parent's own `rel` of 0.5 as if it were the child's fraction. Either way the caller cannot tell that nothing was recovered, which is the defect; the previous commit's claim that it "returns a rel of 0" is right only for the first case. `UiScalar::outside` and `UiSpan::outside` follow it to `Option`, and `Remap` is the answer at the region level: `new` says whether a drawing in one box can be put in another and `apply` then cannot fail, so `try_reuse` asks once for a whole subtree and `reusable` goes back to reporting only what the widget claims. That replaces the predicate the last commit put in `reusable`, which stated the same rule in a second place. `DivOr` existed only for the fallback and is gone, along with `UiRegion::outside` and `UiVec2::outside`, which had no callers once `Remap` owned the operation. `UiRegion::axis` took `&mut self` to return a shared reference; `Remap::new` needs it on a shared one. This does not redraw less. `Remap::new` refuses exactly what the predicate refused; what it buys is one statement of the rule and a remap that cannot half-apply. Counted on a resize, with the old wipe-everything for comparison: 20 padded rows, 101 widgets 101 draws -> 0 the `tabs` example 73 draws -> 0 the `text` example 49 draws -> 48 So the saving is whole where a resize does not change any widget's size, and nil in `text`, where both paragraphs rewrap to a different height and the relayout that forces reaches the root. The last commit's message oversold that case. Checked: fmt, clippy and 35 tests. `tabs` (with the image replay), `view` and `minimal` still byte-identical to `upstream/main`, `text` unchanged, and the live sway resize round trip still matches a cold start at each size.
This commit is contained in:
1 parent
984f482a7f
commit
53e61289f5
5 files changed
+106
-77
No files matched your search
@@ -0,0 +1,27 @@
|
||||
//! What a drawing can be taken out of, and what it cannot.
|
||||
|
||||
use iris::core::{Remap, UiRegion, UiScalar, UiSpan};
|
||||
|
||||
/// A box `size` tall whose top is `rel` of the way down the window.
|
||||
fn fixed(rel: f32, size: f32) -> UiRegion {
|
||||
UiRegion::new(
|
||||
UiSpan::FULL,
|
||||
UiSpan::new(UiScalar { rel, abs: 0.0 }, UiScalar { rel, abs: size }),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fixed_box_can_be_carried_but_not_stretched() {
|
||||
let from = fixed(0.0, 164.0);
|
||||
assert!(Remap::new(from, UiRegion::FULL).is_none());
|
||||
assert!(Remap::new(from, fixed(0.5, 164.0)).is_some());
|
||||
assert!(Remap::new(from, fixed(0.0, 98.0)).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_relative_box_can_be_stretched_to_any_other() {
|
||||
let remap = Remap::new(UiRegion::FULL, fixed(0.0, 98.0)).expect("relative boxes remap");
|
||||
// A part that filled the window keeps filling what replaced it, which is
|
||||
// exactly what `outside` could not say for a box of a fixed length.
|
||||
assert_eq!(remap.apply(UiRegion::FULL), fixed(0.0, 98.0));
|
||||
}
|
||||
Reference in new issue
Block a user