Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62a16b5608 |
No files matched your search
@@ -32,6 +32,7 @@ pub(crate) enum Counter {
|
|||||||
SizeReads,
|
SizeReads,
|
||||||
HintHits,
|
HintHits,
|
||||||
HintMisses,
|
HintMisses,
|
||||||
|
RetainedSizeHits,
|
||||||
ReuseAttempts,
|
ReuseAttempts,
|
||||||
ReuseExact,
|
ReuseExact,
|
||||||
ReuseMoved,
|
ReuseMoved,
|
||||||
@@ -41,6 +42,7 @@ pub(crate) enum Counter {
|
|||||||
ReuseOutside,
|
ReuseOutside,
|
||||||
ReuseWrongLayer,
|
ReuseWrongLayer,
|
||||||
ReuseWrongNode,
|
ReuseWrongNode,
|
||||||
|
PlaceRedraws,
|
||||||
QueuePops,
|
QueuePops,
|
||||||
DepthReads,
|
DepthReads,
|
||||||
LocalRedraws,
|
LocalRedraws,
|
||||||
@@ -52,7 +54,7 @@ pub(crate) enum Counter {
|
|||||||
TextShapes,
|
TextShapes,
|
||||||
TextBreaks,
|
TextBreaks,
|
||||||
GlyphPlacements,
|
GlyphPlacements,
|
||||||
OutsidePinnedLen,
|
OutsidePlacement,
|
||||||
OutsideFrame,
|
OutsideFrame,
|
||||||
OutsideExtent,
|
OutsideExtent,
|
||||||
}
|
}
|
||||||
@@ -68,6 +70,7 @@ impl Counter {
|
|||||||
"draw-result size reads",
|
"draw-result size reads",
|
||||||
"hint hits",
|
"hint hits",
|
||||||
"hint misses",
|
"hint misses",
|
||||||
|
"retained size hits",
|
||||||
"reuse attempts",
|
"reuse attempts",
|
||||||
"reuse exact",
|
"reuse exact",
|
||||||
"reuse moved",
|
"reuse moved",
|
||||||
@@ -77,6 +80,7 @@ impl Counter {
|
|||||||
"reuse: outside what it holds for",
|
"reuse: outside what it holds for",
|
||||||
"reuse: another layer",
|
"reuse: another layer",
|
||||||
"reuse: region-node choice changed",
|
"reuse: region-node choice changed",
|
||||||
|
"placed by redrawing",
|
||||||
"redraw queue pops",
|
"redraw queue pops",
|
||||||
"depth reads",
|
"depth reads",
|
||||||
"local redraws",
|
"local redraws",
|
||||||
@@ -88,7 +92,7 @@ impl Counter {
|
|||||||
"text shapes",
|
"text shapes",
|
||||||
"text line breaks",
|
"text line breaks",
|
||||||
"glyph placements",
|
"glyph placements",
|
||||||
"reuse outside: the length it was pinned to",
|
"reuse outside: the placement it was pinned to",
|
||||||
"reuse outside: a frame length",
|
"reuse outside: a frame length",
|
||||||
"reuse outside: an extent length",
|
"reuse outside: an extent length",
|
||||||
];
|
];
|
||||||
|
|||||||
+65
-41
@@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
LayerId, LayoutHolds, LayoutLen, Len, MaskIdx, MoveIdx, Place, RegionAlign, RetainedPrimitive,
|
DrawRegion, LayerId, LayoutHolds, LayoutLen, MaskIdx, MoveIdx, RegionAlign, RetainedPrimitive,
|
||||||
Size, TextureHandle, UiRegion, UiVec2, WidgetId,
|
Size, TextureHandle, UiRegion, UiVec2, WidgetId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -9,39 +9,31 @@ use crate::{
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ActiveData {
|
pub struct ActiveData {
|
||||||
pub id: WidgetId,
|
pub id: WidgetId,
|
||||||
/// Where its drawing goes, in its region node's coordinates.
|
/// The box its parent gave it, in `parent_move`'s coordinates: what it
|
||||||
pub extent: UiRegion,
|
/// was asked about, and what a fraction under it is a fraction of. A
|
||||||
/// What a fraction declared or reported under this widget is a fraction
|
/// local redraw asks here.
|
||||||
/// of, as a length of the window.
|
pub region: UiRegion,
|
||||||
pub frame: UiVec2,
|
/// Where its drawing sits inside that box, in the box's own coordinates.
|
||||||
/// A frame its parent decided for it on each axis -- a row's slot, or
|
pub placement: UiRegion,
|
||||||
/// padding's frame less its pixels -- as a length of the window. `None`
|
/// The original frame in its parent widget's coordinates. Recomposition
|
||||||
/// forwards the parent's frame. What it declared is kept separately in
|
/// and pixel-length evaluation both follow this chain.
|
||||||
/// `declared` and is a fraction of whichever of the two reached it.
|
pub given_region: UiRegion,
|
||||||
pub narrow: [Option<Len>; 2],
|
/// The frame it was first asked in, in the same coordinates: the offer's
|
||||||
/// Where its drawing was put, and where it was asked, each as a part of
|
/// frame, which its parent's placing draw may since have narrowed.
|
||||||
/// its parent's box. The two differ where a container asks in one place
|
pub offer_region: UiRegion,
|
||||||
/// and puts the answer in another -- a row measures from its cursor and
|
/// The lengths of the box its parent first asked about it in, as
|
||||||
/// puts the child in its slot. A part is a length from the box's start,
|
/// lengths of the box the parent was itself offered. Any later box it
|
||||||
/// so a box that moved re-places every child by re-adding that start.
|
/// was given was decided knowing its answer, so this is the question
|
||||||
pub placed: [Place; 2],
|
/// asked again -- and a chain of fractions has no frame in it, which is
|
||||||
pub asked: [Place; 2],
|
/// why a region node between two widgets cannot break it.
|
||||||
/// The box it was asked in, in the parent's region-node coordinates: the
|
pub offer_len: UiVec2,
|
||||||
/// box its drawing was made in and the one its contract is about. Its
|
pub offer_placement: [Option<crate::UiSpan>; 2],
|
||||||
/// drawing is placed elsewhere by re-expression, never by asking again.
|
|
||||||
pub part: UiRegion,
|
|
||||||
/// The measured answer and its dependencies. A hint-only dependency or
|
/// The measured answer and its dependencies. A hint-only dependency or
|
||||||
/// a widget first encountered during placement has no measurement yet.
|
/// a widget first encountered during placement has no measurement yet.
|
||||||
pub answer: Option<(Size, LayoutHolds)>,
|
pub answer: Option<(Size, LayoutHolds)>,
|
||||||
/// Asked more than once in its parent's last draw -- measured in one box
|
/// What the widget said it used of its box, the last time it drew.
|
||||||
/// and then asked in the one the parent decided. The parent's layout
|
|
||||||
/// rests on the first answer and its drawing on the last, so only the
|
|
||||||
/// parent can ask either again.
|
|
||||||
pub re_asked: bool,
|
|
||||||
/// What the widget reported, in window-unit lengths.
|
|
||||||
pub size: Size,
|
pub size: Size,
|
||||||
/// The window and extent reads that this drawing holds for, and the
|
/// The frame, extent and explicit placement reads that this drawing holds for.
|
||||||
/// frame and box it pinned.
|
|
||||||
pub holds: LayoutHolds,
|
pub holds: LayoutHolds,
|
||||||
pub drawn: bool,
|
pub drawn: bool,
|
||||||
pub parent: Option<WidgetId>,
|
pub parent: Option<WidgetId>,
|
||||||
@@ -50,25 +42,30 @@ pub struct ActiveData {
|
|||||||
/// widget a frame visits and cannot drift while one is being drawn.
|
/// widget a frame visits and cannot drift while one is being drawn.
|
||||||
pub depth: usize,
|
pub depth: usize,
|
||||||
pub textures: Vec<TextureHandle>,
|
pub textures: Vec<TextureHandle>,
|
||||||
/// Its primitives, each keeping the box it was written in -- in this
|
|
||||||
/// widget's extent coordinates, which is what a move recomposes from.
|
|
||||||
pub primitives: Vec<RetainedPrimitive>,
|
pub primitives: Vec<RetainedPrimitive>,
|
||||||
pub mask_region: Option<UiRegion>,
|
pub mask_region: Option<DrawRegion>,
|
||||||
|
/// The children whose box is a part of this widget's extent rather than
|
||||||
|
/// of its frame, and which part each was given. Moving the extent
|
||||||
|
/// re-places them through that part, so the drawing need not depend on
|
||||||
|
/// where it sits.
|
||||||
|
pub(crate) extent_children: Vec<(WidgetId, ExtentPlacement)>,
|
||||||
pub children: Vec<WidgetId>,
|
pub children: Vec<WidgetId>,
|
||||||
/// The children whose size this widget read while drawing.
|
/// The children whose size this widget read while drawing.
|
||||||
pub size_deps: Vec<WidgetId>,
|
pub size_deps: Vec<WidgetId>,
|
||||||
/// The movable region its primitives are positioned through: its own when
|
/// The movable region its primitives are positioned through: its own when
|
||||||
/// opted in, otherwise the nearest ancestor's.
|
/// opted in, otherwise the nearest ancestor's.
|
||||||
pub move_idx: MoveIdx,
|
pub move_idx: MoveIdx,
|
||||||
/// The declared lengths whoever drew this widget resolved into its frame.
|
/// The declared lengths whoever drew this widget resolved into its box.
|
||||||
/// A change to one moves a box this widget cannot fix by drawing again,
|
/// A change to one moves a box this widget cannot fix by drawing again,
|
||||||
/// and comparing them is what says so.
|
/// and comparing them is what says so.
|
||||||
pub declared: [Option<LayoutLen>; 2],
|
pub declared: [Option<LayoutLen>; 2],
|
||||||
|
/// The axes along which its parent chose its box from its own answer,
|
||||||
|
/// so a local redraw asks the question its parent asked.
|
||||||
|
pub decided: [bool; 2],
|
||||||
/// Its alignment when it was last drawn, which a change to the property
|
/// Its alignment when it was last drawn, which a change to the property
|
||||||
/// is found against.
|
/// is found against.
|
||||||
pub own_align: RegionAlign,
|
pub own_align: RegionAlign,
|
||||||
/// The movable region whose coordinates `extent` uses when this widget
|
/// The movable region whose coordinates `region` uses.
|
||||||
/// does not own a region node.
|
|
||||||
pub parent_move: MoveIdx,
|
pub parent_move: MoveIdx,
|
||||||
/// The mask its drawing is clipped to: one it set itself, or the one it
|
/// The mask its drawing is clipped to: one it set itself, or the one it
|
||||||
/// inherited from whoever drew it.
|
/// inherited from whoever drew it.
|
||||||
@@ -82,10 +79,37 @@ pub struct ActiveData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveData {
|
impl ActiveData {
|
||||||
/// What it answered when its parent asked, where it has been asked at
|
/// Whether what it answered still stands for a box of these pixel
|
||||||
/// all. Not `size`, which is what its last drawing reported: a drawing
|
/// lengths -- the box it was asked in, where `holds` is about the box its
|
||||||
/// re-expressed in the box that answer chose is not a second answer.
|
/// answer then chose.
|
||||||
pub fn measured(&self) -> Option<Size> {
|
pub fn answers_at(&self, px: crate::PxVec2) -> bool {
|
||||||
self.answer.map(|(size, _)| size)
|
self.answer.is_some_and(|(_, holds)| {
|
||||||
|
holds.contains(
|
||||||
|
px,
|
||||||
|
UiRegion {
|
||||||
|
x: self.offer_placement[0].unwrap_or(crate::UiSpan::FULL),
|
||||||
|
y: self.offer_placement[1].unwrap_or(crate::UiSpan::FULL),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What of a container's extent a child was given: the whole of it, for a
|
||||||
|
/// wrapper whose box is its child's, or a part of it.
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
pub(crate) enum ExtentPlacement {
|
||||||
|
Inherit,
|
||||||
|
Within(UiRegion),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ExtentPlacement {
|
||||||
|
/// The child's frame in the container's frame coordinates, and the slot
|
||||||
|
/// the container chose within it.
|
||||||
|
pub fn resolve(self, extent: UiRegion) -> (UiRegion, [Option<crate::UiSpan>; 2]) {
|
||||||
|
match self {
|
||||||
|
Self::Inherit => (UiRegion::FULL, [Some(extent.x), Some(extent.y)]),
|
||||||
|
Self::Within(part) => (part.within(&extent), [None; 2]),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
use crate::{PrimitiveHandle, UiRegion};
|
||||||
|
|
||||||
|
/// Retains which box geometry follows when only the extent changes.
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub enum DrawRegion {
|
||||||
|
Frame(UiRegion),
|
||||||
|
Extent(UiRegion),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DrawRegion {
|
||||||
|
pub(crate) fn resolve(self, frame: UiRegion, extent: UiRegion) -> UiRegion {
|
||||||
|
match self {
|
||||||
|
Self::Frame(local) => local.within(&frame),
|
||||||
|
Self::Extent(local) => local.within(&extent).within(&frame),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn map(self, f: impl FnOnce(UiRegion) -> UiRegion) -> Self {
|
||||||
|
match self {
|
||||||
|
Self::Frame(local) => Self::Frame(f(local)),
|
||||||
|
Self::Extent(local) => Self::Extent(f(local)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<UiRegion> for DrawRegion {
|
||||||
|
fn from(region: UiRegion) -> Self {
|
||||||
|
Self::Frame(region)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct RetainedPrimitive {
|
||||||
|
pub handle: PrimitiveHandle,
|
||||||
|
pub region: DrawRegion,
|
||||||
|
}
|
||||||
+37
-53
@@ -1,79 +1,63 @@
|
|||||||
use crate::{Axis, Holds, Len, PxVec2, UiRegion, UiVec2};
|
use crate::{Axis, Holds, PxVec2, UiRegion};
|
||||||
|
|
||||||
const AXES: [Axis; 2] = [Axis::X, Axis::Y];
|
/// Dependencies of one evaluation, before the frame and extent are composed.
|
||||||
|
|
||||||
/// What one evaluation of a widget depends on: the window lengths its reads
|
|
||||||
/// hold for, the pixel lengths of its own box, and the symbolic lengths of
|
|
||||||
/// that box and of its frame where either one is what it was expressed in.
|
|
||||||
///
|
|
||||||
/// The symbolic lengths are pins rather than ranges: a container places its
|
|
||||||
/// children as lengths of its frame measured from where its own box starts,
|
|
||||||
/// so what it draws turns on that box's length and on nothing about where it
|
|
||||||
/// is. A box pin reaches the parent only where the box it pinned is the
|
|
||||||
/// parent's own; anywhere else the parent chose that length itself, and a
|
|
||||||
/// widget pinned this way is checked when it is re-placed.
|
|
||||||
///
|
|
||||||
/// A frame pin says the answer or the drawing is a fraction of the frame,
|
|
||||||
/// which is a different length wherever the frame is a different one -- at
|
|
||||||
/// the same window size, so no range of window pixels can say it. A length
|
|
||||||
/// of the frame that is only pixels is not one: it is that many pixels
|
|
||||||
/// whatever the frame turns out to be.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub struct LayoutHolds {
|
pub struct LayoutHolds {
|
||||||
pub window: [Holds; 2],
|
pub frame: [Holds; 2],
|
||||||
pub frame_len: [Option<Len>; 2],
|
|
||||||
pub extent: [Holds; 2],
|
pub extent: [Holds; 2],
|
||||||
pub extent_len: [Option<Len>; 2],
|
pub placement: Option<UiRegion>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutHolds {
|
impl LayoutHolds {
|
||||||
pub const ANY: Self = Self {
|
pub const ANY: Self = Self {
|
||||||
window: [Holds::ANY; 2],
|
frame: [Holds::ANY; 2],
|
||||||
frame_len: [None; 2],
|
|
||||||
extent: [Holds::ANY; 2],
|
extent: [Holds::ANY; 2],
|
||||||
extent_len: [None; 2],
|
placement: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn and(self, other: Self) -> Self {
|
pub fn and(self, other: Self) -> Self {
|
||||||
let mut result = Self::ANY;
|
|
||||||
for n in 0..2 {
|
|
||||||
result.window[n] = self.window[n].and(other.window[n]);
|
|
||||||
result.extent[n] = self.extent[n].and(other.extent[n]);
|
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
self.extent_len[n].is_none()
|
self.placement.is_none()
|
||||||
|| other.extent_len[n].is_none()
|
|| other.placement.is_none()
|
||||||
|| self.extent_len[n] == other.extent_len[n]
|
|| self.placement == other.placement
|
||||||
);
|
);
|
||||||
debug_assert!(
|
Self {
|
||||||
self.frame_len[n].is_none()
|
frame: [
|
||||||
|| other.frame_len[n].is_none()
|
self.frame[0].and(other.frame[0]),
|
||||||
|| self.frame_len[n] == other.frame_len[n]
|
self.frame[1].and(other.frame[1]),
|
||||||
);
|
],
|
||||||
result.extent_len[n] = self.extent_len[n].or(other.extent_len[n]);
|
extent: [
|
||||||
result.frame_len[n] = self.frame_len[n].or(other.frame_len[n]);
|
self.extent[0].and(other.extent[0]),
|
||||||
|
self.extent[1].and(other.extent[1]),
|
||||||
|
],
|
||||||
|
placement: self.placement.or(other.placement),
|
||||||
}
|
}
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn covers(self, other: Self) -> bool {
|
pub fn covers(self, other: Self) -> bool {
|
||||||
(0..2).all(|n| {
|
self.placement
|
||||||
self.window[n].lo <= other.window[n].lo
|
.is_none_or(|placement| other.placement == Some(placement))
|
||||||
&& self.window[n].hi >= other.window[n].hi
|
&& [0, 1].into_iter().all(|n| {
|
||||||
|
self.frame[n].lo <= other.frame[n].lo
|
||||||
|
&& self.frame[n].hi >= other.frame[n].hi
|
||||||
&& self.extent[n].lo <= other.extent[n].lo
|
&& self.extent[n].lo <= other.extent[n].lo
|
||||||
&& self.extent[n].hi >= other.extent[n].hi
|
&& self.extent[n].hi >= other.extent[n].hi
|
||||||
&& self.extent_len[n].is_none_or(|len| other.extent_len[n] == Some(len))
|
|
||||||
&& self.frame_len[n].is_none_or(|len| other.frame_len[n] == Some(len))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains(self, window: PxVec2, frame: UiVec2, extent: UiRegion) -> bool {
|
pub fn contains(self, px: PxVec2, placement: UiRegion) -> bool {
|
||||||
AXES.into_iter().all(|axis| {
|
self.placement.is_none_or(|old| old == placement)
|
||||||
let n = axis as usize;
|
&& [Axis::X, Axis::Y].into_iter().all(|axis| {
|
||||||
let len = extent.axis(axis).len();
|
self.frame[axis as usize].contains(px.axis(axis))
|
||||||
self.window[n].contains(window.axis(axis))
|
&& self.extent[axis as usize]
|
||||||
&& self.frame_len[n].is_none_or(|pinned| pinned == frame.axis(axis))
|
.contains(placement.axis(axis).len().to_px(px.axis(axis)))
|
||||||
&& self.extent[n].contains(len.to_px(window.axis(axis)))
|
})
|
||||||
&& self.extent_len[n].is_none_or(|pinned| pinned == len)
|
}
|
||||||
|
|
||||||
|
pub fn in_frame(self, placement: UiRegion) -> [Holds; 2] {
|
||||||
|
[Axis::X, Axis::Y].map(|axis| {
|
||||||
|
self.frame[axis as usize]
|
||||||
|
.and(self.extent[axis as usize].through(placement.axis(axis).len()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -10,17 +10,17 @@ use crate::{
|
|||||||
pub const CHAIN_LIMIT: u32 = 64;
|
pub const CHAIN_LIMIT: u32 = 64;
|
||||||
|
|
||||||
mod active;
|
mod active;
|
||||||
|
mod draw_region;
|
||||||
mod holds;
|
mod holds;
|
||||||
mod layout_holds;
|
mod layout_holds;
|
||||||
mod painter;
|
mod painter;
|
||||||
mod place;
|
|
||||||
mod render_state;
|
mod render_state;
|
||||||
|
|
||||||
pub use active::*;
|
pub use active::*;
|
||||||
|
pub use draw_region::*;
|
||||||
pub use holds::*;
|
pub use holds::*;
|
||||||
pub use layout_holds::*;
|
pub use layout_holds::*;
|
||||||
pub use painter::{Painter, PrimitiveLike};
|
pub use painter::{Painter, PrimitiveLike};
|
||||||
pub use place::*;
|
|
||||||
pub use render_state::*;
|
pub use render_state::*;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|||||||
+433
-336
@@ -1,14 +1,14 @@
|
|||||||
#[cfg(feature = "layout-diagnostics")]
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
use crate::layout_diagnostics::{self as diag, Counter};
|
use crate::layout_diagnostics::{self as diag, Counter};
|
||||||
use crate::{
|
use crate::{
|
||||||
Axis, Holds, LayoutHolds, LayoutLen, Len, Part, Place, Px, PxVec2, RegionAlign, Rel,
|
Axis, DrawRegion, ExtentPlacement, Holds, LayoutHolds, LayoutLen, Len, Px, PxVec2, RegionAlign,
|
||||||
RenderedText, RetainedPrimitive, Size, StrongWidget, TextAttrs, TextBuffer, TextData,
|
RenderedText, RetainedPrimitive, Size, StrongWidget, TextAttrs, TextBuffer, TextData,
|
||||||
TextureHandle, UiRegion, UiRenderState, UiRsc, UiSpan, UiVec2, Weight, WidgetId, Widgets,
|
TextureHandle, UiRegion, UiRenderState, UiRsc, UiSpan, UiVec2, Weight, WidgetId, Widgets,
|
||||||
render::{
|
render::{
|
||||||
GlyphPrimitive, Mask, MaskIdx, MoveIdx, Primitive, PrimitiveInst, PrimitiveKind,
|
GlyphPrimitive, Mask, MaskIdx, MoveIdx, Primitive, PrimitiveInst, PrimitiveKind,
|
||||||
TexturePrimitive,
|
TexturePrimitive,
|
||||||
},
|
},
|
||||||
ui::render_state::{DrawInfo, Placing},
|
ui::render_state::DrawInfo,
|
||||||
};
|
};
|
||||||
const AXES: [Axis; 2] = [Axis::X, Axis::Y];
|
const AXES: [Axis; 2] = [Axis::X, Axis::Y];
|
||||||
|
|
||||||
@@ -17,40 +17,51 @@ pub struct Painter<'a> {
|
|||||||
pub(super) state: &'a mut UiRenderState,
|
pub(super) state: &'a mut UiRenderState,
|
||||||
pub(super) rsc: &'a mut dyn UiRsc,
|
pub(super) rsc: &'a mut dyn UiRsc,
|
||||||
|
|
||||||
/// This widget's frame, per axis: a length of the window, and what a
|
/// The box its parent gave it, in the coordinates of `move_idx`: what a
|
||||||
/// fraction it or anything under it declares or reports is a fraction
|
/// fraction of this widget's area is a fraction of, and what every region
|
||||||
/// of. A length rather than a box, so padding can take from both the
|
/// it writes composes within. The same box on the ask that measures and
|
||||||
/// frame and the box without either becoming the other.
|
/// the ask that places, which is what keeps a fraction under it from
|
||||||
pub(super) frame: UiVec2,
|
/// being resolved twice.
|
||||||
/// Where this widget's drawing goes, in its region node's coordinates.
|
pub(super) region: UiRegion,
|
||||||
pub(super) extent: UiRegion,
|
/// Where this widget's drawing sits inside that box, in the box's own
|
||||||
/// The extent's symbolic length where this draw read it, which makes the
|
/// coordinates: `FULL` while its answer is not yet known, and the box
|
||||||
/// drawing one that holds for that length alone -- the way reading a
|
/// its answer or its parent chose once one of them has.
|
||||||
/// length in pixels makes it hold for that number of pixels.
|
pub(super) placement: UiRegion,
|
||||||
pub(super) extent_len: [Option<Len>; 2],
|
/// Whether this draw read its placement, which makes the drawing one
|
||||||
/// The window in pixels. Frames and boxes become pixels against this one
|
/// that holds for that placement alone -- the way reading a length in
|
||||||
/// unit, regardless of region-node boundaries.
|
/// pixels makes it hold for that length.
|
||||||
pub(super) window: PxVec2,
|
pub(super) reads_placement: bool,
|
||||||
|
/// That box in pixels, which its children's are a length of: threaded
|
||||||
|
/// down from the box this widget was given rather than composed back up
|
||||||
|
/// the chain, so every length in layout is one multiply from its
|
||||||
|
/// parent's and [`Holds::through`] inverts exactly that.
|
||||||
|
pub(super) px: PxVec2,
|
||||||
pub(super) mask: MaskIdx,
|
pub(super) mask: MaskIdx,
|
||||||
pub(super) textures: Vec<TextureHandle>,
|
pub(super) textures: Vec<TextureHandle>,
|
||||||
pub(super) primitives: Vec<RetainedPrimitive>,
|
pub(super) primitives: Vec<RetainedPrimitive>,
|
||||||
pub(super) mask_region: Option<UiRegion>,
|
pub(super) mask_region: Option<DrawRegion>,
|
||||||
|
pub(super) extent_children: Vec<(WidgetId, ExtentPlacement)>,
|
||||||
|
pub(super) extent_own: [Holds; 2],
|
||||||
/// Only children whose answers were read constrain this widget's answer.
|
/// Only children whose answers were read constrain this widget's answer.
|
||||||
pub(super) answer_under: LayoutHolds,
|
pub(super) answer_under: LayoutHolds,
|
||||||
pub(super) children: Vec<WidgetId>,
|
pub(super) children: Vec<WidgetId>,
|
||||||
|
/// The children asked about so far, so the first box each was asked in
|
||||||
|
/// is the one recorded as its offer.
|
||||||
|
pub(super) offered: Vec<WidgetId>,
|
||||||
|
/// The lengths of the box this widget was first asked about in, in
|
||||||
|
/// pixels. Its children's offers are a fraction of it.
|
||||||
|
pub(super) offered_px: PxVec2,
|
||||||
|
/// Whether this draw is in a box of those lengths, which makes the
|
||||||
|
/// questions it asks the ones a cold layout asks and their answers the
|
||||||
|
/// ones to keep.
|
||||||
|
pub(super) at_offer: bool,
|
||||||
/// The children whose size this widget read while drawing.
|
/// The children whose size this widget read while drawing.
|
||||||
pub(super) size_deps: Vec<WidgetId>,
|
pub(super) size_deps: Vec<WidgetId>,
|
||||||
/// What this draw itself read of the window in pixels, per axis: every
|
/// What this draw itself read of its box in pixels, per axis: every
|
||||||
/// window until it reads one, then that one, unless it says otherwise.
|
/// length until it reads one, then that one, unless it says otherwise.
|
||||||
pub(super) window_own: [Holds; 2],
|
pub(super) own: [Holds; 2],
|
||||||
/// Its frame's symbolic length where this draw read it, which makes the
|
/// Dependencies of every child drawing, including unmeasured overlays.
|
||||||
/// drawing one that holds for that frame alone.
|
pub(super) under: LayoutHolds,
|
||||||
pub(super) frame_own_len: [Option<Len>; 2],
|
|
||||||
/// The window reads' equivalent for its own box.
|
|
||||||
pub(super) extent_own: [Holds; 2],
|
|
||||||
/// What each child's drawing depends on. Asking a child again replaces
|
|
||||||
/// its drawing, so it replaces this too rather than narrowing it.
|
|
||||||
pub(super) under: Vec<(WidgetId, LayoutHolds)>,
|
|
||||||
/// The movable region this widget's primitives are positioned through:
|
/// The movable region this widget's primitives are positioned through:
|
||||||
/// its own when opted in, otherwise the nearest ancestor's.
|
/// its own when opted in, otherwise the nearest ancestor's.
|
||||||
pub(super) move_idx: MoveIdx,
|
pub(super) move_idx: MoveIdx,
|
||||||
@@ -63,27 +74,26 @@ pub struct Painter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Painter<'a> {
|
impl<'a> Painter<'a> {
|
||||||
fn primitive_at<P: Primitive>(&mut self, primitive: P, region: UiRegion) {
|
fn primitive_at<P: Primitive>(&mut self, primitive: P, region: DrawRegion) {
|
||||||
let kind = self.rsc.ui_mut().primitives.kind::<P>();
|
let kind = self.rsc.ui_mut().primitives.kind::<P>();
|
||||||
self.write(kind, primitive, region);
|
self.write(kind, primitive, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes the kind, for a caller writing many of one primitive.
|
/// Takes the kind, for a caller writing many of one primitive.
|
||||||
fn write<P: Primitive>(&mut self, kind: PrimitiveKind<P>, primitive: P, region: UiRegion) {
|
fn write<P: Primitive>(&mut self, kind: PrimitiveKind<P>, primitive: P, region: DrawRegion) {
|
||||||
self.write_resolved(kind, primitive, region, self.resolve(region));
|
self.write_resolved(
|
||||||
}
|
kind,
|
||||||
|
primitive,
|
||||||
/// A box in this widget's extent coordinates, composed into its region
|
region,
|
||||||
/// node's coordinates.
|
region.resolve(self.region, self.placement),
|
||||||
fn resolve(&self, region: UiRegion) -> UiRegion {
|
);
|
||||||
region.within(&self.extent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_resolved<P: Primitive>(
|
fn write_resolved<P: Primitive>(
|
||||||
&mut self,
|
&mut self,
|
||||||
kind: PrimitiveKind<P>,
|
kind: PrimitiveKind<P>,
|
||||||
primitive: P,
|
primitive: P,
|
||||||
region: UiRegion,
|
region: DrawRegion,
|
||||||
resolved: UiRegion,
|
resolved: UiRegion,
|
||||||
) {
|
) {
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
@@ -112,107 +122,54 @@ impl<'a> Painter<'a> {
|
|||||||
|
|
||||||
/// Writes a primitive over the whole of this widget's own box.
|
/// Writes a primitive over the whole of this widget's own box.
|
||||||
pub fn primitive(&mut self, primitive: impl PrimitiveLike) {
|
pub fn primitive(&mut self, primitive: impl PrimitiveLike) {
|
||||||
|
let at = DrawRegion::Extent(UiRegion::FULL);
|
||||||
let primitive = primitive.into_primitive(self);
|
let primitive = primitive.into_primitive(self);
|
||||||
self.primitive_at(primitive, UiRegion::FULL)
|
self.primitive_at(primitive, at)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes a primitive in a part of this widget's own box, in that box's
|
/// Writes in the frame by default. `DrawRegion::Extent` keeps the local
|
||||||
/// coordinates.
|
/// geometry attached to this widget's box without reading its placement.
|
||||||
pub fn primitive_within(&mut self, primitive: impl PrimitiveLike, region: UiRegion) {
|
pub fn primitive_within(
|
||||||
|
&mut self,
|
||||||
|
primitive: impl PrimitiveLike,
|
||||||
|
region: impl Into<DrawRegion>,
|
||||||
|
) {
|
||||||
let primitive = primitive.into_primitive(self);
|
let primitive = primitive.into_primitive(self);
|
||||||
self.primitive_at(primitive, region);
|
self.primitive_at(primitive, region.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets a mask, in this widget's own box's coordinates.
|
/// Sets a mask in the selected frame or extent coordinates.
|
||||||
pub fn set_mask(&mut self, region: UiRegion) {
|
pub fn set_mask(&mut self, region: impl Into<DrawRegion>) {
|
||||||
|
let region = region.into();
|
||||||
self.mask_region = Some(region);
|
self.mask_region = Some(region);
|
||||||
assert!(self.mask == MaskIdx::NONE);
|
assert!(self.mask == MaskIdx::NONE);
|
||||||
let resolved = self.resolve(region);
|
|
||||||
let move_idx = self.move_idx;
|
|
||||||
self.mask = self.rsc.ui_mut().masks.push(Mask {
|
self.mask = self.rsc.ui_mut().masks.push(Mask {
|
||||||
region: resolved,
|
region: region.resolve(self.region, self.placement),
|
||||||
move_idx,
|
move_idx: self.move_idx,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws a widget in the whole of this widget's own box, with the frame
|
/// Draws a widget in the whole of this widget's own box: it gets the
|
||||||
/// forwarded unchanged: what a container that is only a wrapper around
|
/// same region -- the same area for its fractions to be of -- and is put
|
||||||
/// one child wants, and what every transparent container passes for the
|
/// where this widget was put. What a container that is only a wrapper
|
||||||
/// frame.
|
/// around one child wants, since its box is the child's.
|
||||||
pub fn widget<'s, W: ?Sized>(&'s mut self, id: &'s StrongWidget<W>) -> DrawResult<'s, 'a, W> {
|
pub fn widget<'s, W: ?Sized>(&'s mut self, id: &'s StrongWidget<W>) -> DrawResult<'s, 'a, W> {
|
||||||
self.widget_at(id, [None; 2], [Place::Within(Part::All); 2])
|
let own = self.placement;
|
||||||
|
self.widget_at_inner(
|
||||||
|
id,
|
||||||
|
UiRegion::FULL,
|
||||||
|
[Some(own.x), Some(own.y)],
|
||||||
|
Some(ExtentPlacement::Inherit),
|
||||||
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asks a child, saying what its fractions are of and where it is asked.
|
/// What a widget's rules declare its lengths to be, which whoever draws
|
||||||
///
|
/// it resolves into its box. Reading them depends on nothing -- the box
|
||||||
/// `narrow` is a length this widget decided for the child's frame, per
|
/// that comes of them is kept on the child, and `redraw` compares it
|
||||||
/// axis, as a length of this widget's own frame: a resolved share, or a
|
/// there.
|
||||||
/// box a sibling's answer decided. `None` forwards this widget's frame,
|
fn declared_lens<W: ?Sized>(&self, id: &StrongWidget<W>) -> [Option<LayoutLen>; 2] {
|
||||||
/// which is what a container that only divides room passes, so a
|
declared_lens(self.rsc.widgets(), id.id())
|
||||||
/// fraction under it means the same wherever it sits and however deeply
|
|
||||||
/// it is nested. A declared length narrows the frame here whatever the
|
|
||||||
/// caller says. A narrowed frame is placed in the part by the child's
|
|
||||||
/// alignment and is the box the child is asked in.
|
|
||||||
///
|
|
||||||
/// `place` is where the child is asked, per axis, as a part of this
|
|
||||||
/// widget's box: see [`Place`]. The child draws once, in that box, and
|
|
||||||
/// its answer is placed inside it by re-expressing the drawing. Nothing
|
|
||||||
/// is drawn again in a box an answer chose; a container that puts the
|
|
||||||
/// answer somewhere else says so with [`Self::place_at`].
|
|
||||||
pub fn widget_at<'s, W: ?Sized>(
|
|
||||||
&'s mut self,
|
|
||||||
id: &'s StrongWidget<W>,
|
|
||||||
narrow: [Option<Len>; 2],
|
|
||||||
place: [Place; 2],
|
|
||||||
) -> DrawResult<'s, 'a, W> {
|
|
||||||
let region_node = self.rsc.widgets().is_region_node(id.id());
|
|
||||||
let declared = self.declared_lens(id);
|
|
||||||
let align = self.rsc.widgets().alignment(id.id());
|
|
||||||
let (frame, extent) =
|
|
||||||
frame_and_extent(self.extent, self.frame, place, narrow, declared, align);
|
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
|
||||||
if region_node {
|
|
||||||
diag::bump(Counter::RegionNodeDraws);
|
|
||||||
diag::region_node(id.id(), self.id, extent);
|
|
||||||
}
|
|
||||||
// A child listed twice would be moved twice.
|
|
||||||
let re_asked = self.children.contains(&id.id());
|
|
||||||
if !re_asked {
|
|
||||||
self.children.push(id.id());
|
|
||||||
}
|
|
||||||
let px = frame.to_px(self.window);
|
|
||||||
let (size, answer_holds, holds) = self.state.draw_inner(
|
|
||||||
id.id(),
|
|
||||||
DrawInfo {
|
|
||||||
layer: self.layer,
|
|
||||||
parent: Some(self.id),
|
|
||||||
depth: self.depth + 1,
|
|
||||||
parent_move: self.move_idx,
|
|
||||||
region_node,
|
|
||||||
mask: self.mask,
|
|
||||||
frame,
|
|
||||||
part: extent,
|
|
||||||
placed: place,
|
|
||||||
asked: place,
|
|
||||||
narrow,
|
|
||||||
re_asked,
|
|
||||||
px,
|
|
||||||
},
|
|
||||||
None,
|
|
||||||
self.rsc,
|
|
||||||
);
|
|
||||||
let holds = self.in_parent(holds, extent, place, narrow, declared);
|
|
||||||
let answer_holds = self.in_parent(answer_holds, extent, place, narrow, declared);
|
|
||||||
match self.under.iter_mut().find(|(child, _)| *child == id.id()) {
|
|
||||||
Some((_, kept)) => *kept = holds,
|
|
||||||
None => self.under.push((id.id(), holds)),
|
|
||||||
}
|
|
||||||
DrawResult {
|
|
||||||
child: id,
|
|
||||||
painter: self,
|
|
||||||
size,
|
|
||||||
answer_holds,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes back a child that was drawn only to find out how long it is.
|
/// Takes back a child that was drawn only to find out how long it is.
|
||||||
@@ -220,43 +177,200 @@ impl<'a> Painter<'a> {
|
|||||||
/// this frame; what it answered is still something this widget asked.
|
/// this frame; what it answered is still something this widget asked.
|
||||||
pub fn undraw<W: ?Sized>(&mut self, id: &StrongWidget<W>) {
|
pub fn undraw<W: ?Sized>(&mut self, id: &StrongWidget<W>) {
|
||||||
self.children.retain(|child| *child != id.id());
|
self.children.retain(|child| *child != id.id());
|
||||||
self.under.retain(|(child, _)| *child != id.id());
|
self.extent_children.retain(|(child, _)| *child != id.id());
|
||||||
self.state.undraw_rec(id.id(), self.rsc);
|
self.state.undraw_rec(id.id(), self.rsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Puts a child asked about in this draw somewhere else in this
|
/// Draws a child in `region`, relative to this widget's frame. The child
|
||||||
/// widget's box: its answer, placed in this part instead. The drawing
|
/// resolves declared lengths and reports against that frame, then places
|
||||||
/// is re-expressed there rather than made again -- what a row does once
|
/// its drawing by its own alignment.
|
||||||
/// it knows every slot, having measured each child from its cursor.
|
///
|
||||||
pub fn place_at<W: ?Sized>(&mut self, id: &StrongWidget<W>, place: [Place; 2]) {
|
/// `DrawRegion::Extent` gives a part of where this widget's drawing sits
|
||||||
debug_assert!(
|
/// instead, for a container whose children belong inside that rather than
|
||||||
self.children.contains(&id.id()),
|
/// inside the box it was offered. The part is what is kept, so moving the
|
||||||
"'{}' placed a child it did not ask about in this draw",
|
/// extent re-places the child rather than drawing this widget again.
|
||||||
self.label()
|
pub fn widget_within<'s, W: ?Sized>(
|
||||||
);
|
&'s mut self,
|
||||||
let at = self.placing();
|
id: &'s StrongWidget<W>,
|
||||||
self.state.place_in(id.id(), &at, place, self.rsc);
|
region: impl Into<DrawRegion>,
|
||||||
|
) -> DrawResult<'s, 'a, W> {
|
||||||
|
match region.into() {
|
||||||
|
DrawRegion::Frame(region) => self.widget_at(id, region, [None; 2]),
|
||||||
|
DrawRegion::Extent(part) => {
|
||||||
|
let within = part.within(&self.placement);
|
||||||
|
self.widget_at_inner(
|
||||||
|
id,
|
||||||
|
within,
|
||||||
|
[None; 2],
|
||||||
|
Some(ExtentPlacement::Within(part)),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This widget as the thing its children are placed within.
|
/// Draws a widget in `region`, saying where in it the drawing goes.
|
||||||
fn placing(&self) -> Placing {
|
///
|
||||||
Placing {
|
/// `region` is the child's own area: what a fraction it declares or
|
||||||
id: self.id,
|
/// reports is a fraction of, and the coordinates the regions it writes
|
||||||
extent: self.extent,
|
/// compose within. It is the same box on the ask that measures and the
|
||||||
frame: self.frame,
|
/// ask that places, which is what stops a fraction under it being
|
||||||
window: self.window,
|
/// resolved twice.
|
||||||
depth: self.depth,
|
///
|
||||||
move_idx: self.move_idx,
|
/// `placement` is what of that region the child's drawing takes, per
|
||||||
|
/// axis, wherever this widget is choosing. `None` leaves the axis to the
|
||||||
|
/// child's own answer and alignment, which is what
|
||||||
|
/// [`Self::widget_within`] passes. A span passes the whole row as the
|
||||||
|
/// region, so `rel(0.5)` is half the row wherever the child sits in it,
|
||||||
|
/// and places the child by passing the slot along its axis.
|
||||||
|
pub fn widget_at<'s, W: ?Sized>(
|
||||||
|
&'s mut self,
|
||||||
|
id: &'s StrongWidget<W>,
|
||||||
|
region: UiRegion,
|
||||||
|
placement: [Option<UiSpan>; 2],
|
||||||
|
) -> DrawResult<'s, 'a, W> {
|
||||||
|
self.widget_at_inner(id, region, placement, None, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn widget_at_inner<'s, W: ?Sized>(
|
||||||
|
&'s mut self,
|
||||||
|
id: &'s StrongWidget<W>,
|
||||||
|
region: UiRegion,
|
||||||
|
placement: [Option<UiSpan>; 2],
|
||||||
|
extent: Option<ExtentPlacement>,
|
||||||
|
measuring: bool,
|
||||||
|
) -> DrawResult<'s, 'a, W> {
|
||||||
|
self.extent_children.retain(|(child, _)| *child != id.id());
|
||||||
|
if let Some(extent) = extent {
|
||||||
|
self.extent_children.push((id.id(), extent));
|
||||||
|
}
|
||||||
|
let region_node = self.rsc.widgets().is_region_node(id.id());
|
||||||
|
let declared = self.declared_lens(id);
|
||||||
|
let align = self.rsc.widgets().alignment(id.id());
|
||||||
|
let (local, placement) = ask_box(region, declared, align, placement);
|
||||||
|
let within = match local == UiRegion::FULL {
|
||||||
|
true => self.region,
|
||||||
|
false => local.within(&self.region),
|
||||||
|
};
|
||||||
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
|
if region_node {
|
||||||
|
diag::bump(Counter::RegionNodeDraws);
|
||||||
|
diag::region_node(id.id(), self.id, within);
|
||||||
|
}
|
||||||
|
// A child listed twice would be moved twice.
|
||||||
|
if !self.children.contains(&id.id()) {
|
||||||
|
self.children.push(id.id());
|
||||||
|
}
|
||||||
|
let first_ask = self.offer(id.id());
|
||||||
|
let given_len = local.size();
|
||||||
|
let offer_len = match first_ask {
|
||||||
|
true => given_len,
|
||||||
|
false => self
|
||||||
|
.state
|
||||||
|
.active
|
||||||
|
.get(&id.id())
|
||||||
|
.map_or(given_len, |a| a.offer_len),
|
||||||
|
};
|
||||||
|
let offer_region = match first_ask {
|
||||||
|
true => local,
|
||||||
|
false => self
|
||||||
|
.state
|
||||||
|
.active
|
||||||
|
.get(&id.id())
|
||||||
|
.map_or(local, |a| a.offer_region),
|
||||||
|
};
|
||||||
|
let offer_placement = if first_ask {
|
||||||
|
placement
|
||||||
|
} else {
|
||||||
|
self.state
|
||||||
|
.active
|
||||||
|
.get(&id.id())
|
||||||
|
.map_or(placement, |a| a.offer_placement)
|
||||||
|
};
|
||||||
|
let px = given_len.to_px(self.px);
|
||||||
|
let offered_px = offer_len.to_px(self.offered_px);
|
||||||
|
// The answer and what it holds for, both about the box asked in. The
|
||||||
|
// child's record may say something else once its drawing has been
|
||||||
|
// placed: a drawing made again in its placed box holds for that box.
|
||||||
|
let (size, answer_holds, holds) = self.state.draw_inner(
|
||||||
|
id.id(),
|
||||||
|
within,
|
||||||
|
DrawInfo {
|
||||||
|
layer: self.layer,
|
||||||
|
parent: Some(self.id),
|
||||||
|
depth: self.depth + 1,
|
||||||
|
parent_move: self.move_idx,
|
||||||
|
region_node,
|
||||||
mask: self.mask,
|
mask: self.mask,
|
||||||
|
given_region: local,
|
||||||
|
offer_region,
|
||||||
|
offer_len,
|
||||||
|
offer_placement,
|
||||||
|
px,
|
||||||
|
offered_px,
|
||||||
|
placement,
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
measuring,
|
||||||
|
self.rsc,
|
||||||
|
);
|
||||||
|
let in_parent = |holds: LayoutHolds| {
|
||||||
|
let mut result = LayoutHolds::ANY;
|
||||||
|
for axis in AXES {
|
||||||
|
let n = axis as usize;
|
||||||
|
let chosen = placement[n].unwrap_or(UiSpan::FULL).len();
|
||||||
|
match extent {
|
||||||
|
// Its box is this widget's own, so what its drawing holds
|
||||||
|
// for is what this widget's extent holds for.
|
||||||
|
Some(ExtentPlacement::Inherit) if declared[n].is_none() => {
|
||||||
|
result.frame[n] = holds.frame[n].through(local.axis(axis).len());
|
||||||
|
result.extent[n] = holds.extent[n];
|
||||||
|
if holds.placement.is_some() {
|
||||||
|
result.placement = Some(self.placement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Its box is a part of this widget's extent, so what it
|
||||||
/// What a widget's rules declare its lengths to be, which whoever draws
|
// holds for is a range on that extent and none of it a
|
||||||
/// it resolves into its frame. Reading them depends on nothing -- the box
|
// range on the frame. Only the part's length reaches it,
|
||||||
/// that comes of them is kept on the child, and `redraw` compares it
|
// which is what lets the extent move without a redraw.
|
||||||
/// there.
|
Some(ExtentPlacement::Within(part)) if declared[n].is_none() => {
|
||||||
fn declared_lens<W: ?Sized>(&self, id: &StrongWidget<W>) -> [Option<LayoutLen>; 2] {
|
result.extent[n] = holds.frame[n]
|
||||||
declared_lens(self.rsc.widgets(), id.id())
|
.and(holds.extent[n].through(chosen))
|
||||||
|
.through(part.axis(axis).len());
|
||||||
|
}
|
||||||
|
// Its box is a length of this widget's frame: an
|
||||||
|
// ordinary ask, or a declared length, which is that
|
||||||
|
// length wherever the box it sits in came from.
|
||||||
|
_ => {
|
||||||
|
result.frame[n] = holds.frame[n].through(local.axis(axis).len()).and(
|
||||||
|
holds.extent[n]
|
||||||
|
.through(chosen)
|
||||||
|
.through(local.axis(axis).len()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
};
|
||||||
|
self.under = self.under.and(in_parent(holds));
|
||||||
|
let mut answer_holds = in_parent(answer_holds);
|
||||||
|
// What it reports is a fraction of the box it was given, which is a
|
||||||
|
// part of this widget's extent -- so the same fraction is a different
|
||||||
|
// length once that extent is, and pixels are not. The answer only:
|
||||||
|
// the drawing this holds is re-placed rather than made again.
|
||||||
|
if matches!(extent, Some(ExtentPlacement::Within(_)))
|
||||||
|
&& AXES.into_iter().any(|axis| {
|
||||||
|
declared[axis as usize].is_none() && size.axis(axis).rel != crate::Rel::ZERO
|
||||||
|
})
|
||||||
|
{
|
||||||
|
answer_holds.placement = Some(self.placement);
|
||||||
|
}
|
||||||
|
DrawResult {
|
||||||
|
child: id,
|
||||||
|
painter: self,
|
||||||
|
size: in_parent_frame(size, local.size(), declared),
|
||||||
|
answer_holds,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What a child says its length is without being drawn, if it can say.
|
/// What a child says its length is without being drawn, if it can say.
|
||||||
@@ -287,6 +401,66 @@ impl<'a> Painter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Measures a child's length from its hint, a retained answer, or `draw`.
|
||||||
|
/// A fresh draw evaluates the offer without placing its answer. The caller
|
||||||
|
/// must later place or undraw the child.
|
||||||
|
pub fn measure_len<W: ?Sized>(
|
||||||
|
&mut self,
|
||||||
|
child: &StrongWidget<W>,
|
||||||
|
axis: Axis,
|
||||||
|
region: UiRegion,
|
||||||
|
placement: [Option<UiSpan>; 2],
|
||||||
|
) -> LayoutLen {
|
||||||
|
let offered = placement;
|
||||||
|
let declared = self.declared_lens(child);
|
||||||
|
let align = self.rsc.widgets().alignment(child.id());
|
||||||
|
let (local, placement) = ask_box(region, declared, align, placement);
|
||||||
|
let first_ask = self.at_offer && !self.offered.contains(&child.id());
|
||||||
|
|
||||||
|
if let Some(hint) = self.size_hint(child, axis) {
|
||||||
|
return hint;
|
||||||
|
}
|
||||||
|
let px = local.size().to_px(self.px);
|
||||||
|
let retained =
|
||||||
|
self.state
|
||||||
|
.retained_size(child.id(), px, placement, self.move_idx, self.rsc.widgets());
|
||||||
|
let Some((size, holds)) = retained else {
|
||||||
|
return self
|
||||||
|
.widget_at_inner(child, region, offered, None, true)
|
||||||
|
.len(axis);
|
||||||
|
};
|
||||||
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
|
diag::bump(Counter::RetainedSizeHits);
|
||||||
|
self.depend_on(child);
|
||||||
|
if first_ask {
|
||||||
|
self.offered.push(child.id());
|
||||||
|
let active = self.state.active.get_mut(&child.id()).unwrap();
|
||||||
|
active.offer_len = local.size();
|
||||||
|
active.offer_region = local;
|
||||||
|
active.offer_placement = placement;
|
||||||
|
}
|
||||||
|
let placement = UiRegion {
|
||||||
|
x: placement[0].unwrap_or(UiSpan::FULL),
|
||||||
|
y: placement[1].unwrap_or(UiSpan::FULL),
|
||||||
|
};
|
||||||
|
let holds = holds.in_frame(placement);
|
||||||
|
for (axis, under) in AXES.into_iter().zip(self.answer_under.frame.iter_mut()) {
|
||||||
|
*under = under.and(holds[axis as usize].through(local.axis(axis).len()));
|
||||||
|
}
|
||||||
|
in_parent_frame(size, local.size(), declared).axis(axis)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether this is the first box a child is asked about in during a draw
|
||||||
|
/// that is itself in the box it was asked in -- the question a cold
|
||||||
|
/// layout asks, whose answer is the one to keep.
|
||||||
|
fn offer(&mut self, child: WidgetId) -> bool {
|
||||||
|
if !self.at_offer || self.offered.contains(&child) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
self.offered.push(child);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn depend_on<W: ?Sized>(&mut self, child: &StrongWidget<W>) {
|
fn depend_on<W: ?Sized>(&mut self, child: &StrongWidget<W>) {
|
||||||
if !self.size_deps.contains(&child.id()) {
|
if !self.size_deps.contains(&child.id()) {
|
||||||
self.size_deps.push(child.id());
|
self.size_deps.push(child.id());
|
||||||
@@ -307,10 +481,11 @@ impl<'a> Painter<'a> {
|
|||||||
|
|
||||||
/// Writes glyphs in the selected frame or extent coordinates.
|
/// Writes glyphs in the selected frame or extent coordinates.
|
||||||
// TODO: merge the text methods into the primitive ones.
|
// TODO: merge the text methods into the primitive ones.
|
||||||
pub fn glyphs(&mut self, text: &RenderedText, origin: UiRegion) {
|
pub fn glyphs(&mut self, text: &RenderedText, origin: impl Into<DrawRegion>) {
|
||||||
|
let origin = origin.into();
|
||||||
// Glyph offsets and sizes are pixels, which compose additively.
|
// Glyph offsets and sizes are pixels, which compose additively.
|
||||||
// Only the shared origin needs composing through the extent.
|
// Only the shared origin needs the frame/extent composition.
|
||||||
let resolved = self.resolve(origin);
|
let resolved = origin.resolve(self.region, self.placement);
|
||||||
let kind = self.rsc.ui_mut().primitives.kind::<GlyphPrimitive>();
|
let kind = self.rsc.ui_mut().primitives.kind::<GlyphPrimitive>();
|
||||||
for glyph in text.glyphs.iter() {
|
for glyph in text.glyphs.iter() {
|
||||||
let place = |mut region: UiRegion| {
|
let place = |mut region: UiRegion| {
|
||||||
@@ -334,33 +509,30 @@ impl<'a> Painter<'a> {
|
|||||||
color: text.color,
|
color: text.color,
|
||||||
flags: glyph.entry.flags(),
|
flags: glyph.entry.flags(),
|
||||||
},
|
},
|
||||||
place(origin),
|
origin.map(place),
|
||||||
place(resolved),
|
place(resolved),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The symbolic length of this widget's own box along one axis, in the
|
/// The box this widget's parent gave it, in the coordinates its own
|
||||||
/// lengths of its frame that it places its children in. Reading it pins
|
/// primitives are written in -- so a region composed `within` it may be
|
||||||
/// the drawing to that length -- and to nothing about where the box
|
/// drawn directly. Its own box is [`Self::placement`] of this one.
|
||||||
/// starts, which is what lets a container move without being drawn
|
pub fn region(&self) -> UiRegion {
|
||||||
/// again. One axis at a time, because a container that divides one axis
|
self.region
|
||||||
/// holds for any length of the other.
|
|
||||||
pub fn extent_len(&mut self, axis: Axis) -> Len {
|
|
||||||
let len = self.extent.axis(axis).len();
|
|
||||||
self.extent_len[axis as usize] = Some(len);
|
|
||||||
len
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The symbolic length of this widget's frame along one axis: what a
|
/// Where this widget's drawing goes inside the box it was given, in that
|
||||||
/// fraction it or anything under it declares is a fraction of. A
|
/// box's coordinates: what its own answer took of it, or what its parent
|
||||||
/// container reads it to hand a length of it down -- padding, which
|
/// chose for it. `FULL` on the ask that measures, since nothing has been
|
||||||
/// takes its pixels off. Reading it pins the drawing to that frame, the
|
/// placed yet.
|
||||||
/// way [`Self::extent_len`] pins it to the box.
|
///
|
||||||
pub fn frame_len(&mut self, axis: Axis) -> Len {
|
/// Reading it is what says the drawing depends on it, so a widget that
|
||||||
let len = self.frame.axis(axis);
|
/// positions its own content reads it and is drawn again once its box is
|
||||||
self.frame_own_len[axis as usize] = Some(len);
|
/// known, and one that fills whatever it is given never is.
|
||||||
len
|
pub fn placement(&mut self) -> UiRegion {
|
||||||
|
self.reads_placement = true;
|
||||||
|
self.placement
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Where this widget sits in a box longer than the length it takes. A
|
/// Where this widget sits in a box longer than the length it takes. A
|
||||||
@@ -388,6 +560,14 @@ impl<'a> Painter<'a> {
|
|||||||
.is_some()
|
.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The part of this widget's box that something of `size` takes, at the
|
||||||
|
/// near edge. A container that reports one child's size gives every child
|
||||||
|
/// this, so what it draws is inside what it says it occupies.
|
||||||
|
pub fn box_of(&self, size: Size) -> UiRegion {
|
||||||
|
let lens = placed_lens(size, [None; 2], [false; 2]);
|
||||||
|
placed_box(UiRegion::FULL, lens, RegionAlign::NEAR)
|
||||||
|
}
|
||||||
|
|
||||||
/// This widget's own box in pixels. Reading it makes the drawing one
|
/// This widget's own box in pixels. Reading it makes the drawing one
|
||||||
/// that holds for this box only, until `holds` says how far it goes.
|
/// that holds for this box only, until `holds` says how far it goes.
|
||||||
pub fn px_size(&mut self) -> PxVec2 {
|
pub fn px_size(&mut self) -> PxVec2 {
|
||||||
@@ -397,8 +577,8 @@ impl<'a> Painter<'a> {
|
|||||||
/// One axis of this widget's own box in pixels. Prefer this to
|
/// One axis of this widget's own box in pixels. Prefer this to
|
||||||
/// [`Self::px_size`] when the other axis cannot affect the drawing.
|
/// [`Self::px_size`] when the other axis cannot affect the drawing.
|
||||||
pub fn px_len(&mut self, axis: Axis) -> Px {
|
pub fn px_len(&mut self, axis: Axis) -> Px {
|
||||||
let part = self.extent.axis(axis).len();
|
let part = self.placement.axis(axis).len();
|
||||||
let len = part.to_px(self.window.axis(axis));
|
let len = part.to_px(self.px.axis(axis));
|
||||||
let own = &mut self.extent_own[axis as usize];
|
let own = &mut self.extent_own[axis as usize];
|
||||||
if *own == Holds::ANY {
|
if *own == Holds::ANY {
|
||||||
*own = Holds::at(len);
|
*own = Holds::at(len);
|
||||||
@@ -411,10 +591,10 @@ impl<'a> Painter<'a> {
|
|||||||
/// of the box, and the same reported size. A widget that read its length
|
/// of the box, and the same reported size. A widget that read its length
|
||||||
/// in pixels holds for that one alone until it says otherwise.
|
/// in pixels holds for that one alone until it says otherwise.
|
||||||
pub fn holds(&mut self, axis: Axis, holds: impl Into<Holds>) {
|
pub fn holds(&mut self, axis: Axis, holds: impl Into<Holds>) {
|
||||||
let part = self.extent.axis(axis).len();
|
let part = self.placement.axis(axis).len();
|
||||||
let holds = holds.into();
|
let holds = holds.into();
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
holds.contains(part.to_px(self.window.axis(axis))),
|
holds.contains(part.to_px(self.px.axis(axis))),
|
||||||
"'{}' ({:?}) says its drawing holds for lengths that leave out its own box",
|
"'{}' ({:?}) says its drawing holds for lengths that leave out its own box",
|
||||||
self.label(),
|
self.label(),
|
||||||
self.id
|
self.id
|
||||||
@@ -422,34 +602,30 @@ impl<'a> Painter<'a> {
|
|||||||
self.extent_own[axis as usize] = holds;
|
self.extent_own[axis as usize] = holds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A window length in pixels, which is what every length in layout is
|
/// One axis of the box this widget's parent gave it, in pixels -- what a
|
||||||
/// measured in. Reading one pins the drawing to this window wherever the
|
/// fraction of its area resolves against, and so what a container divides
|
||||||
/// length is a fraction of it; one that is only pixels is that many
|
/// among its children. Its own box is a part of this one.
|
||||||
/// pixels in any window and pins nothing.
|
pub fn region_px_len(&mut self, axis: Axis) -> Px {
|
||||||
pub fn to_px(&mut self, len: Len, axis: Axis) -> Px {
|
let len = self.px.axis(axis);
|
||||||
let window = self.window.axis(axis);
|
let own = &mut self.own[axis as usize];
|
||||||
if len.rel != Rel::ZERO {
|
|
||||||
let own = &mut self.window_own[axis as usize];
|
|
||||||
if *own == Holds::ANY {
|
if *own == Holds::ANY {
|
||||||
*own = Holds::at(window);
|
*own = Holds::at(len);
|
||||||
}
|
}
|
||||||
}
|
len
|
||||||
len.to_px(window)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The windows this drawing holds for, stated rather than taken: a
|
/// [`Self::holds`] stated about the region rather than about this
|
||||||
/// container that branched on a length in pixels says which side of the
|
/// widget's own box, for a container whose drawing turns on the box it
|
||||||
/// boundary it was on, which is wider than the one window reading that
|
/// was given rather than on the part of it it took.
|
||||||
/// length pins, and replaces it.
|
pub fn region_holds(&mut self, axis: Axis, holds: impl Into<Holds>) {
|
||||||
pub fn window_holds(&mut self, axis: Axis, holds: impl Into<Holds>) {
|
|
||||||
let holds = holds.into();
|
let holds = holds.into();
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
holds.contains(self.window.axis(axis)),
|
holds.contains(self.px.axis(axis)),
|
||||||
"'{}' ({:?}) says its drawing holds for windows that leave out this one",
|
"'{}' ({:?}) says its drawing holds for lengths that leave out its region",
|
||||||
self.label(),
|
self.label(),
|
||||||
self.id
|
self.id
|
||||||
);
|
);
|
||||||
self.window_own[axis as usize] = holds;
|
self.own[axis as usize] = holds;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_data(&mut self) -> &mut TextData {
|
pub fn text_data(&mut self) -> &mut TextData {
|
||||||
@@ -537,77 +713,19 @@ impl PrimitiveLike for &TextureHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Moves what a child depends on into this widget's own terms: this
|
/// A child's answer as lengths of the parent's own region. A widget reports
|
||||||
/// method's `impl` block is where a `Painter`'s own boxes are, so it takes
|
/// a fraction of its own region, and `of` is that region as a length of this
|
||||||
/// only what the child was asked with.
|
/// one. Pixels come through untouched, being that many pixels wherever they
|
||||||
impl Painter<'_> {
|
/// end up. A declared axis is already the parent's: it resolved the rule in
|
||||||
/// Frame ranges are already ranges on the window and combine directly.
|
/// its own region, and the rule is what the report says.
|
||||||
/// A frame pin becomes this widget's own frame wherever a length of it
|
fn in_parent_frame(size: Size, of: UiVec2, declared: [Option<LayoutLen>; 2]) -> Size {
|
||||||
/// is what reached the child; where only pixels did, no length of this
|
let mut size = size;
|
||||||
/// frame can change the child's and the pin stops here.
|
for (axis, declared) in AXES.into_iter().zip(declared) {
|
||||||
///
|
if declared.is_none() {
|
||||||
/// Extent validity maps back through the part of this widget's box,
|
*size.axis_mut(axis) = size.axis(axis).within_len(of.axis(axis));
|
||||||
/// where the box the child was asked in is that part; a declared length
|
|
||||||
/// places the box inside the part instead, and then only that length
|
|
||||||
/// reaches the child. A narrowed frame is not one of these: it decides
|
|
||||||
/// what fractions under the child mean and leaves the box the part it
|
|
||||||
/// was given.
|
|
||||||
fn in_parent(
|
|
||||||
&self,
|
|
||||||
holds: LayoutHolds,
|
|
||||||
extent: UiRegion,
|
|
||||||
place: [Place; 2],
|
|
||||||
narrow: [Option<Len>; 2],
|
|
||||||
declared: [Option<LayoutLen>; 2],
|
|
||||||
) -> LayoutHolds {
|
|
||||||
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.
|
|
||||||
result.window[n] = holds.window[n];
|
|
||||||
let reaches = narrow[n].is_none()
|
|
||||||
&& !matches!(place[n].part(), Part::Sized(_))
|
|
||||||
&& declared[n].is_none_or(|len| len.rel != Rel::ZERO);
|
|
||||||
result.frame_len[n] = holds.frame_len[n].and(reaches.then(|| self.frame.axis(axis)));
|
|
||||||
match (place[n].part(), declared[n].is_some()) {
|
|
||||||
// Its box is this widget's own, or a part of it in that
|
|
||||||
// box's own lengths: so what it holds for is a range on this
|
|
||||||
// widget's own box, which is what lets that box move without
|
|
||||||
// a redraw. A length it pinned is this widget's length
|
|
||||||
// wherever the part is the whole of it, and pins the same
|
|
||||||
// way.
|
|
||||||
(Part::All, false) => {
|
|
||||||
result.extent[n] = holds.extent[n];
|
|
||||||
result.extent_len[n] = holds.extent_len[n];
|
|
||||||
}
|
|
||||||
// Its box is a part of this widget's own box, in that box's
|
|
||||||
// own lengths, so what it holds for maps back through that
|
|
||||||
// part into a range on this widget's box. A length it pinned
|
|
||||||
// is this widget's length less the part's pixels where the
|
|
||||||
// part is the whole of the box less pixels, which is the one
|
|
||||||
// shape that inverts exactly; any other part pins this
|
|
||||||
// widget's own length.
|
|
||||||
(Part::Of(span), false) => {
|
|
||||||
let part_len = span.len();
|
|
||||||
result.extent[n] = holds.extent[n].through(part_len);
|
|
||||||
result.extent_len[n] = holds.extent_len[n].map(|pinned| match part_len.rel {
|
|
||||||
Rel::ONE => pinned - Len::from_parts(Rel::ZERO, part_len.px),
|
|
||||||
_ => 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.
|
|
||||||
_ => {
|
|
||||||
result.window[n] =
|
|
||||||
result.window[n].and(holds.extent[n].through(extent.axis(axis).len()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
size
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What a widget declares a length of its box to be. `leftover` is not one: a
|
/// What a widget declares a length of its box to be. `leftover` is not one: a
|
||||||
@@ -641,89 +759,68 @@ pub(crate) fn fills(reported: LayoutLen, declared: Option<LayoutLen>, decided: b
|
|||||||
reported.leftover != Weight::ZERO || declared.is_some() || decided
|
reported.leftover != Weight::ZERO || declared.is_some() || decided
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Where a widget's drawing goes inside the part its parent gave it: what
|
/// What of the box it was given a widget's drawing occupies, as lengths of
|
||||||
/// it reported, on the side of the part its alignment says, and the whole
|
/// that box: the size it reported wherever that is a part to be placed, and
|
||||||
/// part wherever the answer fills it.
|
/// the whole of the box wherever the answer fills it.
|
||||||
///
|
///
|
||||||
/// The length it reported is a length of its frame, and the part is one too,
|
/// A reported fraction is a fraction of the box the widget drew in, where a
|
||||||
/// so this takes one from the other rather than composing it into the part.
|
/// declared one is a fraction of the box its parent handed down -- a span
|
||||||
/// That is what makes a fraction the same fraction wherever the part it is
|
/// reporting `rel(1.0)` means all of what it was given, whatever that was a
|
||||||
/// placed in sits and however long it is -- the fraction is resolved once,
|
/// fraction of. So this is a length of the box rather than a length composed
|
||||||
/// here, against the frame it was reported of.
|
/// into it, and a box in pixels is this step from the given box's pixels.
|
||||||
pub(crate) fn placed_extent(
|
pub(crate) fn placed_lens(
|
||||||
part: UiRegion,
|
|
||||||
size: Size,
|
size: Size,
|
||||||
declared: [Option<LayoutLen>; 2],
|
declared: [Option<LayoutLen>; 2],
|
||||||
fill: [bool; 2],
|
decided: [bool; 2],
|
||||||
align: RegionAlign,
|
) -> UiVec2 {
|
||||||
) -> UiRegion {
|
let mut lens = UiVec2::FULL_SIZE;
|
||||||
let mut placed = part;
|
for (axis, (declared, decided)) in AXES.into_iter().zip(declared.into_iter().zip(decided)) {
|
||||||
for axis in AXES {
|
|
||||||
let n = axis as usize;
|
|
||||||
let reported = size.axis(axis);
|
let reported = size.axis(axis);
|
||||||
if fills(reported, declared[n], fill[n]) {
|
if !fills(reported, declared, decided) {
|
||||||
|
*lens.axis_mut(axis) = Len::from_parts(reported.rel, reported.px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lens
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Where that drawing sits: those lengths taken of the box the widget was
|
||||||
|
/// asked in, on the side of it that the widget's alignment says.
|
||||||
|
pub(crate) fn placed_box(region: UiRegion, lens: UiVec2, align: RegionAlign) -> UiRegion {
|
||||||
|
let mut placed = region;
|
||||||
|
for axis in AXES {
|
||||||
|
// The whole of the box is already where it sits, and the arithmetic
|
||||||
|
// below is the identity for it.
|
||||||
|
if lens.axis(axis) == Len::FULL {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let len = Len::from_parts(reported.rel, reported.px);
|
|
||||||
let span = placed.axis_mut(axis);
|
let span = placed.axis_mut(axis);
|
||||||
|
let len = lens.axis(axis).within_len(span.len());
|
||||||
span.start += (span.len() - len).scale(align.axis(axis).rel());
|
span.start += (span.len() - len).scale(align.axis(axis).rel());
|
||||||
span.end = span.start + len;
|
span.end = span.start + len;
|
||||||
}
|
}
|
||||||
placed
|
placed
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The frame length and the box a child is asked in, in the coordinates the
|
/// A declared axis gets a frame of that length, aligned within the parent's
|
||||||
/// widget asking draws in.
|
/// slot (or the offer). Undeclared axes keep the offered frame and chosen
|
||||||
///
|
/// placement, so their reported fractions retain that reference.
|
||||||
/// `own` is that widget's own box, and `place` what of it the child is
|
pub(crate) fn ask_box(
|
||||||
/// given. `narrow` is a frame the container decided for the child -- a row's
|
mut region: UiRegion,
|
||||||
/// slot, or padding's frame less its pixels -- and [`Part::Sized`] one a
|
|
||||||
/// sibling's answer decided; both are window lengths, like every other
|
|
||||||
/// length here, since a slot of a row is not a fraction of anything the row
|
|
||||||
/// can name. The child's declaration is a fraction of whichever reached it,
|
|
||||||
/// and is the only one of the three that also places the box: a box the
|
|
||||||
/// caller decided is what `place` names.
|
|
||||||
pub(crate) fn frame_and_extent(
|
|
||||||
own: UiRegion,
|
|
||||||
parent_frame: UiVec2,
|
|
||||||
place: [Place; 2],
|
|
||||||
narrow: [Option<Len>; 2],
|
|
||||||
declared: [Option<LayoutLen>; 2],
|
declared: [Option<LayoutLen>; 2],
|
||||||
align: RegionAlign,
|
align: RegionAlign,
|
||||||
) -> (UiVec2, UiRegion) {
|
placement: [Option<UiSpan>; 2],
|
||||||
let part = part_of(own, place, align);
|
) -> (UiRegion, [Option<UiSpan>; 2]) {
|
||||||
let mut frame = parent_frame;
|
let mut placed = [None; 2];
|
||||||
let mut extent = part;
|
for (axis, (len, chosen)) in AXES.into_iter().zip(declared.into_iter().zip(placement)) {
|
||||||
for axis in AXES {
|
let Some(len) = len else {
|
||||||
let n = axis as usize;
|
placed[axis as usize] = chosen;
|
||||||
let sized = match place[n].part() {
|
continue;
|
||||||
Part::Sized(len) => Some(len),
|
|
||||||
_ => None,
|
|
||||||
};
|
};
|
||||||
let base = sized
|
let span = region.axis_mut(axis);
|
||||||
.or(narrow[n])
|
let len = Len::from_parts(len.rel, len.px);
|
||||||
.unwrap_or_else(|| parent_frame.axis(axis));
|
let slot = chosen.unwrap_or(*span);
|
||||||
let len = declared[n]
|
span.start = slot.start + (slot.len() - len).scale(align.axis(axis).rel());
|
||||||
.map(|len| Len::from_parts(len.rel, len.px).within_len(base))
|
span.end = span.start + len;
|
||||||
.unwrap_or(base);
|
|
||||||
*frame.axis_mut(axis) = len;
|
|
||||||
if declared[n].is_some() {
|
|
||||||
let slot = part.axis(axis);
|
|
||||||
let start = slot.start + (slot.len() - len).scale(align.axis(axis).rel());
|
|
||||||
*extent.axis_mut(axis) = UiSpan::new(start, start + len);
|
|
||||||
}
|
}
|
||||||
}
|
(region, placed)
|
||||||
(frame, extent)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The part of a widget's own box a `place` names, in the coordinates that
|
|
||||||
/// box is in.
|
|
||||||
fn part_of(extent: UiRegion, place: [Place; 2], align: RegionAlign) -> UiRegion {
|
|
||||||
let mut part = extent;
|
|
||||||
for axis in AXES {
|
|
||||||
*part.axis_mut(axis) = place[axis as usize]
|
|
||||||
.part()
|
|
||||||
.of(*extent.axis(axis), align.axis(axis));
|
|
||||||
}
|
|
||||||
part
|
|
||||||
}
|
}
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
use crate::{AxisAlign, Len, PrimitiveHandle, UiRegion, UiSpan};
|
|
||||||
|
|
||||||
/// What of a widget's own box a child is given, along one axis.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
||||||
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.
|
|
||||||
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
|
|
||||||
/// container read its own box -- and a box chosen from its own answer
|
|
||||||
/// then feeds back into the answer.
|
|
||||||
Of(UiSpan),
|
|
||||||
/// A box of this length, wherever in the parent's box the child's own
|
|
||||||
/// alignment puts it, and that same length as its frame. Unlike `From`,
|
|
||||||
/// it is a length decided from above rather than a place along a
|
|
||||||
/// container's cursor -- what a stack's sizing child decides for the
|
|
||||||
/// rest.
|
|
||||||
Sized(Len),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Part {
|
|
||||||
/// Where it lands in the coordinates `extent` is in.
|
|
||||||
pub(crate) fn of(self, extent: UiSpan, align: AxisAlign) -> UiSpan {
|
|
||||||
match self {
|
|
||||||
Self::All => extent,
|
|
||||||
Self::From(span) => UiSpan::new(extent.start + span.start, extent.start + span.end),
|
|
||||||
Self::Of(span) => span.within(&extent),
|
|
||||||
Self::Sized(len) => {
|
|
||||||
let start = extent.start + (extent.len() - len).scale(align.rel());
|
|
||||||
UiSpan::new(start, start + len)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where a child goes along one axis, as a part of this widget's box.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
||||||
pub enum Place {
|
|
||||||
/// The child's answer, aligned inside the part by the child's alignment.
|
|
||||||
Within(Part),
|
|
||||||
/// Exactly the part; the answer is not placed inside it again.
|
|
||||||
Fill(Part),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Place {
|
|
||||||
pub(crate) fn part(self) -> Part {
|
|
||||||
match self {
|
|
||||||
Self::Within(part) | Self::Fill(part) => part,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the part is the drawing's box outright, rather than the box
|
|
||||||
/// the answer is placed inside.
|
|
||||||
pub(crate) fn fills(self) -> bool {
|
|
||||||
matches!(self, Self::Fill(_))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A primitive as it was written: its box in the widget's own box's
|
|
||||||
/// coordinates, which is what a move of that box re-composes from.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct RetainedPrimitive {
|
|
||||||
pub handle: PrimitiveHandle,
|
|
||||||
pub region: UiRegion,
|
|
||||||
}
|
|
||||||
+439
-398
File diff suppressed because it is too large.
Load diff
+9
-21
@@ -117,28 +117,16 @@ pub struct Branch {
|
|||||||
|
|
||||||
impl Widget for Branch {
|
impl Widget for Branch {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
let cut = Len::from_parts(Rel::ZERO, Px::from_int(40));
|
let mut top = UiRegion::FULL;
|
||||||
let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut)));
|
top.y.end = top.y.start.offset(Px::from_int(40));
|
||||||
let measured = painter
|
let measured = painter.widget_within(&self.probe, top).len(Axis::X);
|
||||||
.widget_at(&self.probe, [None; 2], [Place::Within(Part::All), top])
|
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
||||||
.len(Axis::X);
|
|
||||||
let len = measured.apply_leftover();
|
|
||||||
let px = painter.to_px(len, Axis::X);
|
|
||||||
// The range it actually branched on, said the way a container says
|
|
||||||
// one: pinning the window instead would redraw this widget on every
|
|
||||||
// resize, which is a fixture that never exercises reuse.
|
|
||||||
let threshold = Px::from_f32(self.threshold);
|
|
||||||
let holds = match px > threshold {
|
|
||||||
true => Holds::from(threshold + Px::STEP..=Px::MAX),
|
|
||||||
false => Holds::from(Px::MIN..=threshold),
|
|
||||||
};
|
|
||||||
painter.window_holds(Axis::X, holds.through(len));
|
|
||||||
|
|
||||||
let below = Place::Within(Part::From(UiSpan::new(cut, painter.extent_len(Axis::Y))));
|
let mut below = UiRegion::FULL;
|
||||||
let place = [Place::Within(Part::All), below];
|
below.y.start = below.y.start.offset(Px::from_int(40));
|
||||||
match px > threshold {
|
match px > Px::from_f32(self.threshold) {
|
||||||
true => painter.widget_at(&self.wide, [None; 2], place),
|
true => painter.widget_within(&self.wide, below),
|
||||||
false => painter.widget_at(&self.narrow, [None; 2], place),
|
false => painter.widget_within(&self.narrow, below),
|
||||||
};
|
};
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ pub struct Masked {
|
|||||||
|
|
||||||
impl Widget for Masked {
|
impl Widget for Masked {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
painter.set_mask(UiRegion::FULL);
|
painter.set_mask(DrawRegion::Extent(UiRegion::FULL));
|
||||||
painter.widget(&self.inner);
|
painter.widget(&self.inner);
|
||||||
// What it occupies is its box, on both axes, for the reason `Scroll`
|
// What it occupies is its box, on both axes, for the reason `Scroll`
|
||||||
// reports the same: it clips what is inside to that box, so it can
|
// reports the same: it clips what is inside to that box, so it can
|
||||||
|
|||||||
@@ -7,14 +7,7 @@ pub struct Offset {
|
|||||||
|
|
||||||
impl Widget for Offset {
|
impl Widget for Offset {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
// The whole of this widget's box, moved: the frame passes through, so
|
let region = UiRegion::FULL.offset(self.amt);
|
||||||
// what the child declares or reports means the same as it would
|
painter.widget_within(&self.inner, region).size()
|
||||||
// without the offset.
|
|
||||||
let moved = |len: Len, amt: Len| Place::Within(Part::From(UiSpan::new(amt, len + amt)));
|
|
||||||
let place = [
|
|
||||||
moved(painter.extent_len(Axis::X), self.amt.x),
|
|
||||||
moved(painter.extent_len(Axis::Y), self.amt.y),
|
|
||||||
];
|
|
||||||
painter.widget_at(&self.inner, [None; 2], place).size()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,32 +13,8 @@ impl Widget for Pad {
|
|||||||
// it; where the box is bigger -- a share of a row, a rule over this
|
// it; where the box is bigger -- a share of a row, a rule over this
|
||||||
// widget -- the slack is the inner's to sit in, and forcing the near
|
// widget -- the slack is the inner's to sit in, and forcing the near
|
||||||
// edge pinned it to a corner it had not asked for.
|
// edge pinned it to a corner it had not asked for.
|
||||||
//
|
let inside = DrawRegion::Extent(self.padding.region());
|
||||||
// Padding is an inset of both: it comes off the frame, so `rel(1)`
|
let inner = painter.widget_within(&self.inner, inside).size();
|
||||||
// under it fills this widget rather than overflowing it by the
|
|
||||||
// padding, and it comes off the box, so what is drawn sits inside.
|
|
||||||
// The two stay distinct -- the box can be narrower still, where a row
|
|
||||||
// asked this widget in the room left, and a text wraps at that.
|
|
||||||
let inset = |lead: Px, trail: Px| {
|
|
||||||
Place::Within(Part::Of(UiSpan::new(
|
|
||||||
Len::from_parts(Rel::ZERO, lead),
|
|
||||||
Len::from_parts(Rel::ONE, -trail),
|
|
||||||
)))
|
|
||||||
};
|
|
||||||
let place = [
|
|
||||||
inset(self.padding.left, self.padding.right),
|
|
||||||
inset(self.padding.top, self.padding.bottom),
|
|
||||||
];
|
|
||||||
// Read from this widget's own frame rather than written as a
|
|
||||||
// fraction of it: a frame is a length of the window like everything
|
|
||||||
// else here, and taking the padding off is the whole of what this
|
|
||||||
// widget does to it.
|
|
||||||
let narrow = [
|
|
||||||
(Axis::X, self.padding.left + self.padding.right),
|
|
||||||
(Axis::Y, self.padding.top + self.padding.bottom),
|
|
||||||
]
|
|
||||||
.map(|(axis, pixels)| Some(painter.frame_len(axis) - Len::from_parts(Rel::ZERO, pixels)));
|
|
||||||
let inner = painter.widget_at(&self.inner, narrow, place).size();
|
|
||||||
Size {
|
Size {
|
||||||
x: LayoutLen {
|
x: LayoutLen {
|
||||||
px: inner.x.px + self.padding.left + self.padding.right,
|
px: inner.x.px + self.padding.left + self.padding.right,
|
||||||
|
|||||||
@@ -12,13 +12,15 @@ pub struct Scroll {
|
|||||||
impl Widget for Scroll {
|
impl Widget for Scroll {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
let container_len = painter.px_len(self.axis);
|
let container_len = painter.px_len(self.axis);
|
||||||
// Asked in the whole viewport, then put at the scrolled offset.
|
// Draw in the whole container only when its scrolling-axis length is
|
||||||
let answer_len = painter
|
// not already known, then draw it at the scrolled offset.
|
||||||
.widget_at(&self.inner, [None; 2], [Place::Fill(Part::All); 2])
|
let whole = UiRegion::FULL;
|
||||||
.len(self.axis);
|
let own = painter.placement();
|
||||||
let fixed = painter.to_px(Len::from_parts(answer_len.rel, answer_len.px), self.axis);
|
let answer_len =
|
||||||
|
painter.measure_len(&self.inner, self.axis, whole, [Some(own.x), Some(own.y)]);
|
||||||
|
let content = answer_len.apply_leftover();
|
||||||
self.container_len = container_len;
|
self.container_len = container_len;
|
||||||
self.content_len = fixed.max(container_len);
|
self.content_len = content.to_px(container_len);
|
||||||
|
|
||||||
if self.snap_end {
|
if self.snap_end {
|
||||||
self.amt = self.content_len - self.container_len;
|
self.amt = self.content_len - self.container_len;
|
||||||
@@ -31,9 +33,9 @@ impl Widget for Scroll {
|
|||||||
// the drawing holds for that length alone. One scrolled part way sits
|
// 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
|
// where it is until the box shrinks past what is left of it. Kept to
|
||||||
// the end, it moves with every length.
|
// the end, it moves with every length.
|
||||||
let fixed_len = answer_len.rel == Rel::ZERO && answer_len.leftover == Weight::ZERO;
|
let fixed_len = content.rel == Rel::ZERO;
|
||||||
if fixed_len && self.content_len <= self.container_len && align == AxisAlign::NEG {
|
if fixed_len && self.content_len <= self.container_len && align == AxisAlign::NEG {
|
||||||
painter.holds(self.axis, fixed..=Px::MAX);
|
painter.holds(self.axis, self.content_len..=Px::MAX);
|
||||||
} else if fixed_len && !self.snap_end {
|
} else if fixed_len && !self.snap_end {
|
||||||
let left = self.content_len - self.amt;
|
let left = self.content_len - self.amt;
|
||||||
painter.holds(self.axis, Px::MIN..=left);
|
painter.holds(self.axis, Px::MIN..=left);
|
||||||
@@ -44,7 +46,7 @@ impl Widget for Scroll {
|
|||||||
// have placed the whole scroll in a box longer than it.
|
// have placed the whole scroll in a box longer than it.
|
||||||
let slack = (self.container_len - self.content_len).max(Px::ZERO);
|
let slack = (self.container_len - self.content_len).max(Px::ZERO);
|
||||||
let anchor = slack.mul(align.rel());
|
let anchor = slack.mul(align.rel());
|
||||||
let mut content = UiSpan::FULL;
|
let mut region = UiRegion::FULL;
|
||||||
// Content that fills the viewport and has not been scrolled is the
|
// 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
|
// 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
|
// its own length in pixels is the same box in another form, and the
|
||||||
@@ -53,18 +55,19 @@ impl Widget for Scroll {
|
|||||||
// each part of it.
|
// each part of it.
|
||||||
let moved = anchor != Px::ZERO || self.amt != Px::ZERO;
|
let moved = anchor != Px::ZERO || self.amt != Px::ZERO;
|
||||||
if moved || self.content_len != self.container_len {
|
if moved || self.content_len != self.container_len {
|
||||||
let start = Len::from_parts(Rel::ZERO, anchor - self.amt);
|
let offset = UiVec2::from_axis(
|
||||||
content = UiSpan::new(start, start.offset(self.content_len));
|
self.axis,
|
||||||
}
|
Len::from_parts(Rel::ZERO, anchor - self.amt),
|
||||||
// The viewport is the inner's frame, so a fraction it declares or
|
Len::ZERO,
|
||||||
// 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)),
|
|
||||||
);
|
);
|
||||||
|
region = region.offset(offset);
|
||||||
|
region.axis_mut(self.axis).end = region.axis(self.axis).start.offset(self.content_len);
|
||||||
|
}
|
||||||
|
// The viewport is the inner's region, 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 is put is the content
|
||||||
|
// box, scrolled.
|
||||||
|
painter.widget_at(&self.inner, whole, [Some(region.x), Some(region.y)]);
|
||||||
// What it occupies is its box, on both axes: it clips its content to
|
// 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
|
// 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
|
// more. The content's length is what it scrolls through, not what it
|
||||||
|
|||||||
+36
-50
@@ -10,38 +10,38 @@ pub struct Span {
|
|||||||
impl Widget for Span {
|
impl Widget for Span {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
let axis = self.dir.axis;
|
let axis = self.dir.axis;
|
||||||
// The row: this span's own box, as a length of the frame its children
|
// The row: this span's own box, as a span of the region it was given.
|
||||||
// are laid out against. Its start is nothing's business -- a slot is
|
// Its children are laid out along it, and what they declare or report
|
||||||
// a length from it -- so what this reads is the length alone.
|
// is a fraction of the region -- the area this span was told it has,
|
||||||
let far = painter.extent_len(axis);
|
// which it passes on unchanged.
|
||||||
|
let own = painter.placement();
|
||||||
|
let row = *own.axis(axis);
|
||||||
|
// Across itself the span's own box is the child's region: a span is
|
||||||
|
// what contains its children there, and nothing divides that axis.
|
||||||
|
// Along it the whole region is, so a fraction means the same thing
|
||||||
|
// for every child however much of the row is left when it is asked.
|
||||||
|
let region = UiRegion::from_axis(axis, UiSpan::FULL, *own.axis(!axis));
|
||||||
let along = |from: Len, to: Len| match self.dir.sign {
|
let along = |from: Len, to: Len| match self.dir.sign {
|
||||||
Sign::Pos => UiSpan::new(from, to),
|
Sign::Pos => UiSpan::new(row.start + from, row.start + to),
|
||||||
Sign::Neg => UiSpan::new(far - to, far - from),
|
Sign::Neg => UiSpan::new(row.end - to, row.end - from),
|
||||||
};
|
};
|
||||||
// Across itself the child sits where its own alignment says, in the
|
let far = row.len();
|
||||||
// whole of the row: a span is what contains its children there, and
|
// A length for every child before their final boxes are chosen: from
|
||||||
// nothing divides that axis.
|
// a hint where one exists, and from drawing otherwise.
|
||||||
let across = Place::Within(Part::All);
|
|
||||||
// A length for every child before their final slots are chosen. The
|
|
||||||
// frame passes through unchanged, so `rel(0.5)` is half the area this
|
|
||||||
// span was given whatever else is in it and wherever this child sits
|
|
||||||
// among them; what it is asked in is the room left from the cursor,
|
|
||||||
// because a text has to wrap at the width actually there. This is
|
|
||||||
// the one ask a fixed child gets: its slot is its answer, and the
|
|
||||||
// drawing is moved there once the shares are known.
|
|
||||||
let mut cursor = Len::rel_min();
|
let mut cursor = Len::rel_min();
|
||||||
let mut sizes = Vec::with_capacity(self.children.len());
|
let mut lens = Vec::with_capacity(self.children.len());
|
||||||
for child in &self.children {
|
for child in &self.children {
|
||||||
let room = Place::Within(Part::From(along(cursor, far)));
|
// The whole region is the child's, so `rel(0.5)` is half the area
|
||||||
let size = painter
|
// this span was given whatever else is in it and wherever this
|
||||||
.widget_at(child, [None; 2], axis.pair(room, across))
|
// child sits among them. What it is placed in is the room left
|
||||||
.size();
|
// from the cursor, because a text has to wrap at the width
|
||||||
let len = size.axis(axis);
|
// actually there.
|
||||||
|
let room = axis.pair(Some(along(cursor, far)), None);
|
||||||
|
let len = painter.measure_len(child, axis, region, room);
|
||||||
cursor.px += len.px + self.gap;
|
cursor.px += len.px + self.gap;
|
||||||
cursor.rel += len.rel;
|
cursor.rel += len.rel;
|
||||||
sizes.push(size);
|
lens.push(len);
|
||||||
}
|
}
|
||||||
let lens: Vec<LayoutLen> = sizes.iter().map(|size| size.axis(axis)).collect();
|
|
||||||
|
|
||||||
let gaps = self
|
let gaps = self
|
||||||
.gap
|
.gap
|
||||||
@@ -55,7 +55,7 @@ impl Widget for Span {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// What is left for the shares to divide: the row less everything
|
// What is left for the shares to divide: the row less everything
|
||||||
// fixed, as a length of the frame rather than a number of pixels.
|
// fixed, as a length of the region rather than a number of pixels.
|
||||||
let room = far - Len::from_parts(total.rel, total.px);
|
let room = far - Len::from_parts(total.rel, total.px);
|
||||||
// Whether anything is left over is a question in pixels: `rel(0.5)`
|
// Whether anything is left over is a question in pixels: `rel(0.5)`
|
||||||
// beside 300 px is full at 600 and overfull at 400. Asked of `room`
|
// beside 300 px is full at 600 and overfull at 400. Asked of `room`
|
||||||
@@ -68,12 +68,12 @@ impl Widget for Span {
|
|||||||
// exist at all turns on this.
|
// exist at all turns on this.
|
||||||
let mut shares = false;
|
let mut shares = false;
|
||||||
if total.leftover > Weight::ZERO {
|
if total.leftover > Weight::ZERO {
|
||||||
shares = painter.to_px(room, axis) > Px::ZERO;
|
shares = room.to_px(painter.region_px_len(axis)) > Px::ZERO;
|
||||||
let holds = match shares {
|
let holds = match shares {
|
||||||
true => Holds::from(Px::STEP..=Px::MAX),
|
true => Holds::from(Px::STEP..=Px::MAX),
|
||||||
false => Holds::from(Px::MIN..=Px::ZERO),
|
false => Holds::from(Px::MIN..=Px::ZERO),
|
||||||
};
|
};
|
||||||
painter.window_holds(axis, holds.through(room));
|
painter.region_holds(axis, holds.through(room));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Across itself a span is as long as its longest child -- unless a
|
// Across itself a span is as long as its longest child -- unless a
|
||||||
@@ -92,8 +92,7 @@ impl Widget for Span {
|
|||||||
let mut taken = Weight::ZERO;
|
let mut taken = Weight::ZERO;
|
||||||
let mut start = Len::rel_min();
|
let mut start = Len::rel_min();
|
||||||
let mut ortho = LayoutLen::ZERO;
|
let mut ortho = LayoutLen::ZERO;
|
||||||
for (child, size) in self.children.iter().zip(&sizes) {
|
for (child, len) in self.children.iter().zip(&lens) {
|
||||||
let len = size.axis(axis);
|
|
||||||
// A child asking for nothing but a part of what is left over,
|
// A child asking for nothing but a part of what is left over,
|
||||||
// when nothing is, is not drawn at all. One that also asked for
|
// when nothing is, is not drawn at all. One that also asked for
|
||||||
// pixels or a fraction keeps those and overflows.
|
// pixels or a fraction keeps those and overflows.
|
||||||
@@ -110,27 +109,14 @@ impl Widget for Span {
|
|||||||
fixed.px += len.px;
|
fixed.px += len.px;
|
||||||
fixed.rel += len.rel;
|
fixed.rel += len.rel;
|
||||||
start = shared(fixed, taken, total.leftover, room);
|
start = shared(fixed, taken, total.leftover, room);
|
||||||
// Along the row the span says where the child goes, and that slot
|
// Along the row the span says where the child goes; across it the
|
||||||
// is the child's box outright rather than something to place an
|
// child sits where its own alignment says. Its region is the
|
||||||
// answer inside again. A share is decided here and nowhere
|
// whole of what this span was given either way, which is what its
|
||||||
// else: its slot narrows its frame, and the child is asked in
|
// fractions are of.
|
||||||
// it, since a text wraps at the width it is actually given. A
|
let placed =
|
||||||
// fixed child's slot is its own answer, so its drawing is put
|
painter.widget_at(child, region, axis.pair(Some(along(from, start)), None));
|
||||||
// there as it is.
|
|
||||||
let slot = along(from, start);
|
|
||||||
let place = axis.pair(Place::Fill(Part::From(slot)), across);
|
|
||||||
let used = match len.leftover > Weight::ZERO && shares {
|
|
||||||
true => {
|
|
||||||
let mut narrow = [None; 2];
|
|
||||||
narrow[axis as usize] = Some(slot.len());
|
|
||||||
painter.widget_at(child, narrow, place).len(!axis)
|
|
||||||
}
|
|
||||||
false => {
|
|
||||||
painter.place_at(child, place);
|
|
||||||
size.axis(!axis)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if shrinks {
|
if shrinks {
|
||||||
|
let used = placed.len(!axis);
|
||||||
// Choosing between a fixed and a relative length from the
|
// Choosing between a fixed and a relative length from the
|
||||||
// span's own eventual width admits multiple fixed points.
|
// span's own eventual width admits multiple fixed points.
|
||||||
// A scalable child therefore makes Children scalable too;
|
// A scalable child therefore makes Children scalable too;
|
||||||
|
|||||||
@@ -13,39 +13,29 @@ impl Widget for Stack {
|
|||||||
StackSize::Default => None,
|
StackSize::Default => None,
|
||||||
StackSize::Child(i) => Some(i),
|
StackSize::Child(i) => Some(i),
|
||||||
};
|
};
|
||||||
// Whichever child sizes the stack is given the stack's whole box --
|
// Whichever child sizes the stack keeps the stack's whole region as
|
||||||
// the stack is the length that child asked for, so placing that
|
// its own -- the stack is the length that child asked for, so taking
|
||||||
// answer inside the box it decided would apply it twice.
|
// the fraction of the stack's box again would take it twice -- and is
|
||||||
|
// put where the stack itself is put.
|
||||||
let size = match sizing.and_then(|i| self.children.get(i).map(|c| (i, c))) {
|
let size = match sizing.and_then(|i| self.children.get(i).map(|c| (i, c))) {
|
||||||
// On the layer that child ends up on, so the ask below is a reuse
|
// On the layer that child ends up on, so the ask below is a reuse
|
||||||
// rather than a second drawing of it somewhere else: a retained
|
// rather than a second drawing of it somewhere else: a retained
|
||||||
// drawing belongs to the layer it was made on.
|
// drawing belongs to the layer it was made on.
|
||||||
Some((i, child)) => {
|
Some((i, child)) => {
|
||||||
painter.child_layer_at(i);
|
painter.child_layer_at(i);
|
||||||
painter
|
painter.widget(child).size()
|
||||||
.widget_at(child, [None; 2], [Place::Fill(Part::All); 2])
|
|
||||||
.size()
|
|
||||||
}
|
}
|
||||||
None => Size::LEFTOVER,
|
None => Size::LEFTOVER,
|
||||||
};
|
};
|
||||||
// Every other child gets the box the sizing child decided: the
|
|
||||||
// stack is that length, so that is the box they are asked in, and a
|
|
||||||
// fraction under them is a fraction of it. A share leaves the axis
|
|
||||||
// to whoever gave the stack its box. Where a child sits in a box
|
|
||||||
// bigger than itself is its own business.
|
|
||||||
let place = [Axis::X, Axis::Y].map(|axis| {
|
|
||||||
let len = size.axis(axis);
|
|
||||||
match len.leftover == Weight::ZERO {
|
|
||||||
true => Place::Fill(Part::Sized(Len::from_parts(len.rel, len.px))),
|
|
||||||
false => Place::Within(Part::All),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (i, child) in self.children.iter().enumerate() {
|
for (i, child) in self.children.iter().enumerate() {
|
||||||
if sizing == Some(i) {
|
if sizing == Some(i) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
painter.child_layer_at(i);
|
painter.child_layer_at(i);
|
||||||
painter.widget_at(child, [None; 2], place);
|
// Every other child has the stack's own box for its region, since
|
||||||
|
// the stack is what contains it, and where it sits in one bigger
|
||||||
|
// than itself is its own business.
|
||||||
|
painter.widget_within(child, DrawRegion::Extent(UiRegion::FULL));
|
||||||
}
|
}
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl TextView {
|
|||||||
// hair under that line, and the break made in it is not the break a
|
// hair under that line, and the break made in it is not the break a
|
||||||
// cold layout makes there.
|
// cold layout makes there.
|
||||||
let size = Size::from_px(PxVec2::ceil_from_f32(tex.size));
|
let size = Size::from_px(PxVec2::ceil_from_f32(tex.size));
|
||||||
painter.glyphs(tex, region);
|
painter.glyphs(tex, DrawRegion::Extent(region));
|
||||||
(region, size)
|
(region, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,18 +21,16 @@ struct BranchesOnMeasurement {
|
|||||||
|
|
||||||
impl Widget for BranchesOnMeasurement {
|
impl Widget for BranchesOnMeasurement {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
let cut = Len::from_parts(Rel::ZERO, Px::from_int(40));
|
let mut top = UiRegion::FULL;
|
||||||
let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut)));
|
top.y.end = top.y.start.offset(Px::from_int(40));
|
||||||
let measured = painter
|
let measured = painter.widget_within(&self.probe, top).len(Axis::X);
|
||||||
.widget_at(&self.probe, [None; 2], [Place::Within(Part::All), top])
|
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
||||||
.len(Axis::X);
|
|
||||||
let px = painter.to_px(measured.apply_leftover(), Axis::X);
|
|
||||||
|
|
||||||
let below = Place::Within(Part::From(UiSpan::new(cut, painter.extent_len(Axis::Y))));
|
let mut below = UiRegion::FULL;
|
||||||
let place = [Place::Within(Part::All), below];
|
below.y.start = below.y.start.offset(Px::from_int(40));
|
||||||
match px > Px::from_f32(self.threshold) {
|
match px > Px::from_f32(self.threshold) {
|
||||||
true => painter.widget_at(&self.wide, [None; 2], place),
|
true => painter.widget_within(&self.wide, below),
|
||||||
false => painter.widget_at(&self.narrow, [None; 2], place),
|
false => painter.widget_within(&self.narrow, below),
|
||||||
};
|
};
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-89
@@ -83,10 +83,11 @@ fn a_text_in_a_span_wraps_at_the_room_left_rather_than_the_whole_row() {
|
|||||||
assert!(crowded > whole_row, "{crowded} against {whole_row}");
|
assert!(crowded > whole_row, "{crowded} against {whole_row}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Padding is an inset: it narrows the frame a fraction resolves against and
|
/// The same reading through a pad: its inset is the whole box less the
|
||||||
/// adds itself back to the padded widget's reported length.
|
/// padding, so half of the inset plus the padding is half the box plus one
|
||||||
|
/// padding, not two.
|
||||||
#[test]
|
#[test]
|
||||||
fn a_pad_puts_its_padding_around_a_fraction_of_the_whole_box() {
|
fn a_pad_reports_a_fraction_of_its_inset_as_a_fraction_of_its_box() {
|
||||||
let mut h = Harness::new((400, 100));
|
let mut h = Harness::new((400, 100));
|
||||||
let inner = rect(Color::GREEN).width(rel(0.5)).add(&mut h.rsc);
|
let inner = rect(Color::GREEN).width(rel(0.5)).add(&mut h.rsc);
|
||||||
let padded = (inner,).span(Dir::RIGHT).pad(10).add(&mut h.rsc);
|
let padded = (inner,).span(Dir::RIGHT).pad(10).add(&mut h.rsc);
|
||||||
@@ -95,85 +96,10 @@ fn a_pad_puts_its_padding_around_a_fraction_of_the_whole_box() {
|
|||||||
// placed inside it by its own alignment, which is not what is under test.
|
// placed inside it by its own alignment, which is not what is under test.
|
||||||
h.set_root((padded, tail).span(Dir::RIGHT).width(rel(1.0)));
|
h.set_root((padded, tail).span(Dir::RIGHT).width(rel(1.0)));
|
||||||
|
|
||||||
assert_corners!(h, inner, (10, 10), (200, 90));
|
|
||||||
assert_corners!(h, padded, (0, 0), (210, 100));
|
assert_corners!(h, padded, (0, 0), (210, 100));
|
||||||
assert_corners!(h, tail, (210, 0), (310, 100));
|
assert_corners!(h, tail, (210, 0), (310, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
const PARAGRAPH: &str = "Wrapping shapes one source into as many lines as the box \
|
|
||||||
leaves room for, so a paragraph's height is an answer and not a setting.";
|
|
||||||
|
|
||||||
/// The worked example of what padding insets: in a 900 px row after a 24 px
|
|
||||||
/// icon, a `rel(1.0)` inside `pad(16)` is 900 - 32 and overflows the row by
|
|
||||||
/// the icon's width, while a wrapping text beside it is asked in the room
|
|
||||||
/// left, 900 - 24 - 32, and wraps there.
|
|
||||||
#[test]
|
|
||||||
fn padding_keeps_the_frame_distinct_from_the_room_left_in_a_row() {
|
|
||||||
let mut h = Harness::new((900, 200));
|
|
||||||
let icon = rect(Color::RED).width(24).add(&mut h.rsc);
|
|
||||||
let fill = rect(Color::GREEN).width(rel(1.0)).add(&mut h.rsc);
|
|
||||||
let padded = fill.pad(16).add(&mut h.rsc);
|
|
||||||
h.set_root((icon, padded).span(Dir::RIGHT).width(rel(1.0)));
|
|
||||||
let fill_width = h.region(&fill).unwrap().size().x;
|
|
||||||
assert_eq!(fill_width, Px::from_int(868));
|
|
||||||
|
|
||||||
let mut h = Harness::new((900, 200));
|
|
||||||
let icon = rect(Color::RED).width(24).add(&mut h.rsc);
|
|
||||||
let text = wtext(PARAGRAPH).size(16).wrap(true).add(&mut h.rsc);
|
|
||||||
let padded = text.pad(16).add(&mut h.rsc);
|
|
||||||
h.set_root((icon, padded).span(Dir::RIGHT).width(rel(1.0)));
|
|
||||||
let active = &h.render.active[&text.id()];
|
|
||||||
let window = h.render.output_size().x;
|
|
||||||
let asked = active.part.x.len().to_px(window);
|
|
||||||
assert_eq!(active.frame.x.to_px(window), Px::from_int(868));
|
|
||||||
assert_eq!(asked, Px::from_int(844));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The other way round: a share inside padding. A slot is a length of the
|
|
||||||
/// row, which is already the padded width, so what the span decided reaches
|
|
||||||
/// the child as it stands -- taking the padding off a second time would make
|
|
||||||
/// `rel(1.0)` in the slot shorter than the slot.
|
|
||||||
#[test]
|
|
||||||
fn a_share_inside_padding_fills_the_slot_it_was_given() {
|
|
||||||
let mut h = Harness::new((900, 200));
|
|
||||||
let fill = rect(Color::GREEN).width(rel(1.0)).add(&mut h.rsc);
|
|
||||||
let first = Span {
|
|
||||||
children: vec![fill.add_strong(&mut h.rsc)],
|
|
||||||
dir: Dir::RIGHT,
|
|
||||||
gap: Px::ZERO,
|
|
||||||
}
|
|
||||||
.width(leftover(1))
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let second = rect(Color::BLUE).width(leftover(1)).add(&mut h.rsc);
|
|
||||||
let row = (first, second).span(Dir::RIGHT).add(&mut h.rsc);
|
|
||||||
h.set_root(row.pad(16));
|
|
||||||
|
|
||||||
assert_eq!(h.region(&first).unwrap().size().x, Px::from_int(434));
|
|
||||||
assert_eq!(h.region(&fill).unwrap().size().x, Px::from_int(434));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The same padding in a share instead: the slot is 450, so both the
|
|
||||||
/// fraction and the wrap are the slot less the padding, and the two agree.
|
|
||||||
#[test]
|
|
||||||
fn padding_narrows_both_frame_and_box_inside_a_share() {
|
|
||||||
let mut h = Harness::new((900, 200));
|
|
||||||
let fill = rect(Color::GREEN).width(rel(1.0)).add(&mut h.rsc);
|
|
||||||
let padded = fill.pad(16).width(leftover(1)).add(&mut h.rsc);
|
|
||||||
let other = rect(Color::BLUE).width(leftover(1)).add(&mut h.rsc);
|
|
||||||
h.set_root((padded, other).span(Dir::RIGHT).width(rel(1.0)));
|
|
||||||
assert_eq!(h.region(&fill).unwrap().size().x, Px::from_int(418));
|
|
||||||
|
|
||||||
let mut h = Harness::new((900, 200));
|
|
||||||
let text = wtext(PARAGRAPH).size(16).wrap(true).add(&mut h.rsc);
|
|
||||||
let padded = text.pad(16).width(leftover(1)).add(&mut h.rsc);
|
|
||||||
let other = rect(Color::BLUE).width(leftover(1)).add(&mut h.rsc);
|
|
||||||
h.set_root((padded, other).span(Dir::RIGHT).width(rel(1.0)));
|
|
||||||
let active = &h.render.active[&text.id()];
|
|
||||||
let window = h.render.output_size().x;
|
|
||||||
assert_eq!(active.frame.x.to_px(window), Px::from_int(418));
|
|
||||||
assert_eq!(active.part.x.len().to_px(window), Px::from_int(418));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_span_ruled_across_itself_does_not_measure_its_children_there() {
|
fn a_span_ruled_across_itself_does_not_measure_its_children_there() {
|
||||||
let mut h = Harness::new((400, 200));
|
let mut h = Harness::new((400, 200));
|
||||||
@@ -500,7 +426,7 @@ fn a_row_of_equal_shares_fills_it_exactly() {
|
|||||||
/// a step of. Kept in step with `snap_floor` in `prelude.wgsl`.
|
/// a step of. Kept in step with `snap_floor` in `prelude.wgsl`.
|
||||||
fn drawn_edges(h: &Harness, id: WidgetId, axis: Axis) -> (f32, f32) {
|
fn drawn_edges(h: &Harness, id: WidgetId, axis: Axis) -> (f32, f32) {
|
||||||
let active = &h.render.active[&id];
|
let active = &h.render.active[&id];
|
||||||
let region = h.render.moves.resolve(active.move_idx, active.extent);
|
let region = h.render.moves.resolve(active.parent_move, active.region);
|
||||||
let dim = h.size().axis(axis);
|
let dim = h.size().axis(axis);
|
||||||
let snap = |v: f32| (v + Px::STEP.to_f32() * 0.5).floor();
|
let snap = |v: f32| (v + Px::STEP.to_f32() * 0.5).floor();
|
||||||
let edge = |s: Len| snap(s.rel.to_f32() * dim + s.px.to_f32());
|
let edge = |s: Len| snap(s.rel.to_f32() * dim + s.px.to_f32());
|
||||||
@@ -811,13 +737,3 @@ fn a_fixed_child_is_centered_in_its_wrappers_share() {
|
|||||||
assert_corners!(h, wrapper, (200, 0), (900, 400));
|
assert_corners!(h, wrapper, (200, 0), (900, 400));
|
||||||
assert_corners!(h, leaf, (500, 150), (600, 250));
|
assert_corners!(h, leaf, (500, 150), (600, 250));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The root's frame is the window and its rule is a fraction of that, which
|
|
||||||
/// is one resolution and not two: nothing above it narrowed anything.
|
|
||||||
#[test]
|
|
||||||
fn a_root_with_a_fraction_rule_is_that_fraction_of_the_window() {
|
|
||||||
let mut h = Harness::new((900, 200));
|
|
||||||
let root = rect(Color::RED).width(rel(0.5)).add(&mut h.rsc);
|
|
||||||
h.set_root(root);
|
|
||||||
assert_eq!(h.region(&root).unwrap().size().x, Px::from_int(450));
|
|
||||||
}
|
|
||||||
+102
-109
@@ -156,9 +156,9 @@ fn a_span_child_that_declares_its_length_is_drawn_once() {
|
|||||||
h.set_root((hinted, asked).span(Dir::RIGHT));
|
h.set_root((hinted, asked).span(Dir::RIGHT));
|
||||||
|
|
||||||
assert_eq!(told_draws.get(), 1);
|
assert_eq!(told_draws.get(), 1);
|
||||||
// Asked once, from the cursor; its slot is its answer and the drawing is
|
// Only the available length changes: positioning the final slot does
|
||||||
// moved there.
|
// not invalidate a numeric size read.
|
||||||
assert_eq!(asked_draws.get(), 1);
|
assert_eq!(asked_draws.get(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -213,12 +213,9 @@ struct FromHint {
|
|||||||
impl Widget for FromHint {
|
impl Widget for FromHint {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
let len = painter.size_hint(&self.inner, Axis::Y).unwrap();
|
let len = painter.size_hint(&self.inner, Axis::Y).unwrap();
|
||||||
let top = UiSpan::new(Len::ZERO, Len::from_parts(Rel::ZERO, len.px));
|
let mut region = UiRegion::FULL;
|
||||||
painter.widget_at(
|
region.y.end = region.y.start.offset(len.px);
|
||||||
&self.inner,
|
painter.widget_within(&self.inner, region);
|
||||||
[None; 2],
|
|
||||||
[Place::Within(Part::All), Place::Within(Part::From(top))],
|
|
||||||
);
|
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,9 +252,10 @@ impl Widget for ReadsBox {
|
|||||||
/// Reads its box across one axis only, so its drawing holds for a taller
|
/// Reads its box across one axis only, so its drawing holds for a taller
|
||||||
/// box on its own and only a wider one is worth a draw.
|
/// box on its own and only a wider one is worth a draw.
|
||||||
///
|
///
|
||||||
/// Both of these report a quarter of what they read. The quarter-sized box
|
/// Both of these report a quarter of what they read, without saying that the
|
||||||
/// the answer places them in is not a question: the drawing is moved there,
|
/// drawing holds there too, so each length they are asked at costs two draws:
|
||||||
/// so each length they are asked at costs one draw.
|
/// one to answer, and one in the quarter-sized box that answer places them
|
||||||
|
/// in. The counts below are in those pairs.
|
||||||
struct ReadsWidth {
|
struct ReadsWidth {
|
||||||
draws: Rc<Cell<usize>>,
|
draws: Rc<Cell<usize>>,
|
||||||
}
|
}
|
||||||
@@ -307,51 +305,6 @@ fn a_span_ruled_across_itself_moves_its_child_without_redrawing_it() {
|
|||||||
assert_eq!(h.render.active[&span.id()].size.y, LayoutLen::rel(1.0));
|
assert_eq!(h.render.active[&span.id()].size.y, LayoutLen::rel(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A row places its children as lengths from where its own box starts, so a
|
|
||||||
/// child that grew moves the ones after it and nothing else: each of them is
|
|
||||||
/// the same box in a new place, which the retained drawing follows without
|
|
||||||
/// being made again. Both kinds of length: one the row resolves from a rule,
|
|
||||||
/// and one it takes from what the child reported.
|
|
||||||
#[test]
|
|
||||||
fn a_row_moves_what_follows_a_child_that_grew_rather_than_drawing_it() {
|
|
||||||
for declared in [false, true] {
|
|
||||||
let mut h = Harness::new((400, 200));
|
|
||||||
let first = rect(Color::RED).width(50).add(&mut h.rsc);
|
|
||||||
let ruled = Rc::new(Cell::new(0));
|
|
||||||
let second = Counted {
|
|
||||||
draws: ruled.clone(),
|
|
||||||
size: Size::LEFTOVER,
|
|
||||||
reads_box: false,
|
|
||||||
};
|
|
||||||
let second = match declared {
|
|
||||||
true => second.width(rel(0.25)).add(&mut h.rsc),
|
|
||||||
false => second.width(60).add(&mut h.rsc),
|
|
||||||
};
|
|
||||||
let (third, reported) = counted(&mut h, Size::from((70, 20)), false);
|
|
||||||
h.set_root((first, second, third).span(Dir::RIGHT).width(rel(1.0)));
|
|
||||||
let (was_ruled, was_reported) = (ruled.get(), reported.get());
|
|
||||||
// A quarter of the row is a quarter of the row, wherever it sits in
|
|
||||||
// it and whatever the first child takes.
|
|
||||||
let width = match declared {
|
|
||||||
true => 100,
|
|
||||||
false => 60,
|
|
||||||
};
|
|
||||||
assert_corners!(h, second, (50, 0), (50 + width, 200));
|
|
||||||
|
|
||||||
h.set_len(first, Axis::X, 80);
|
|
||||||
h.frame();
|
|
||||||
|
|
||||||
assert_eq!(ruled.get(), was_ruled, "the ruled child was drawn again");
|
|
||||||
assert_eq!(
|
|
||||||
reported.get(),
|
|
||||||
was_reported,
|
|
||||||
"the reported child was drawn again"
|
|
||||||
);
|
|
||||||
assert_corners!(h, second, (80, 0), (80 + width, 200));
|
|
||||||
assert_corners!(h, third, (80 + width, 90), (150 + width, 110));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The output is the root of the box chain, so a resize is a box that changed
|
/// The output is the root of the box chain, so a resize is a box that changed
|
||||||
/// length like any other -- there is not a second rule for the window. A
|
/// length like any other -- there is not a second rule for the window. A
|
||||||
/// drawing that holds for one length is drawn again whichever box moved.
|
/// drawing that holds for one length is drawn again whichever box moved.
|
||||||
@@ -383,7 +336,7 @@ fn a_resize_redraws_what_read_its_box() {
|
|||||||
h.resize((800, 100));
|
h.resize((800, 100));
|
||||||
h.frame();
|
h.frame();
|
||||||
|
|
||||||
assert_eq!(draws.get(), settled + 1);
|
assert_eq!(draws.get(), settled + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -403,7 +356,7 @@ fn a_resize_only_redraws_read_axes() {
|
|||||||
|
|
||||||
h.resize((800, 300));
|
h.resize((800, 300));
|
||||||
h.frame();
|
h.frame();
|
||||||
assert_eq!(draws.get(), settled + 1, "width changes its answer");
|
assert_eq!(draws.get(), settled + 2, "width changes its answer");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A window is measured onto the grid like everything else, so a resize too
|
/// A window is measured onto the grid like everything else, so a resize too
|
||||||
@@ -430,7 +383,7 @@ fn a_resize_within_one_step_is_not_a_resize() {
|
|||||||
|
|
||||||
h.resize((400.0 + step, 200.0));
|
h.resize((400.0 + step, 200.0));
|
||||||
h.frame();
|
h.frame();
|
||||||
assert_eq!(draws.get(), settled + 1);
|
assert_eq!(draws.get(), settled + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The same for a box that changes because a sibling did: what is compared
|
/// The same for a box that changes because a sibling did: what is compared
|
||||||
@@ -796,6 +749,36 @@ fn primitive_bounds(h: &Harness, id: WidgetId) -> Vec<PixelRegion> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn frame_geometry_and_extent_geometry_keep_their_references() {
|
||||||
|
struct Both(Rc<Cell<usize>>);
|
||||||
|
impl Widget for Both {
|
||||||
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
|
self.0.set(self.0.get() + 1);
|
||||||
|
painter.primitive_within(RectPrimitive::color(Color::RED), UiRegion::FULL);
|
||||||
|
painter.primitive(RectPrimitive::color(Color::BLUE));
|
||||||
|
Size::LEFTOVER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for node in [false, true] {
|
||||||
|
let mut h = Harness::new((400, 200));
|
||||||
|
let first = rect(Color::GREEN).width(100).add(&mut h.rsc);
|
||||||
|
let draws = Rc::new(Cell::new(0));
|
||||||
|
let both = Both(draws.clone()).add(&mut h.rsc);
|
||||||
|
h.rsc.widgets_mut().set_region_node(both, node);
|
||||||
|
h.set_root((first, both).span(Dir::RIGHT));
|
||||||
|
let count = draws.get();
|
||||||
|
h.set_len(first, Axis::X, 200);
|
||||||
|
h.frame();
|
||||||
|
assert_eq!(draws.get(), count);
|
||||||
|
let bounds = primitive_bounds(&h, both.id());
|
||||||
|
assert_eq!(bounds[0].top_left.x, Px::ZERO);
|
||||||
|
assert_eq!(bounds[0].bot_right.x, Px::from_int(400));
|
||||||
|
assert_eq!(bounds[1].top_left.x, Px::from_int(200));
|
||||||
|
assert_eq!(bounds[1].bot_right.x, Px::from_int(400));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn changing_an_inherited_extent_keeps_the_original_measurement_offer() {
|
fn changing_an_inherited_extent_keeps_the_original_measurement_offer() {
|
||||||
fn build(h: &mut Harness, width: i32, text: &str) -> (WeakWidget<Text>, WeakWidget<Rect>) {
|
fn build(h: &mut Harness, width: i32, text: &str) -> (WeakWidget<Text>, WeakWidget<Rect>) {
|
||||||
@@ -875,14 +858,7 @@ fn resizing_a_fixed_frame_recomposes_its_contents_without_drawing_them() {
|
|||||||
}
|
}
|
||||||
impl Widget for Frame {
|
impl Widget for Frame {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
painter.widget_at(
|
painter.widget_within(&self.child, self.region);
|
||||||
&self.child,
|
|
||||||
[None; 2],
|
|
||||||
[
|
|
||||||
Place::Within(Part::From(self.region.x)),
|
|
||||||
Place::Within(Part::From(self.region.y)),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -890,7 +866,7 @@ fn resizing_a_fixed_frame_recomposes_its_contents_without_drawing_them() {
|
|||||||
impl Widget for Painted {
|
impl Widget for Painted {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
self.0.set(self.0.get() + 1);
|
self.0.set(self.0.get() + 1);
|
||||||
painter.set_mask(UiRegion::FULL);
|
painter.set_mask(DrawRegion::Extent(UiRegion::FULL));
|
||||||
painter.primitive(RectPrimitive::color(Color::BLUE));
|
painter.primitive(RectPrimitive::color(Color::BLUE));
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
@@ -939,6 +915,43 @@ fn resizing_a_fixed_frame_recomposes_its_contents_without_drawing_them() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_span_does_not_place_its_measurement_before_assigning_the_childs_slot() {
|
||||||
|
struct MeasuredBox(Rc<Cell<usize>>);
|
||||||
|
|
||||||
|
impl Widget for MeasuredBox {
|
||||||
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
|
self.0.set(self.0.get() + 1);
|
||||||
|
painter.px_size();
|
||||||
|
painter.primitive(RectPrimitive::color(Color::BLUE));
|
||||||
|
Size::from((100, 50))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut h = Harness::new((400, 200));
|
||||||
|
let draws = Rc::new(Cell::new(0));
|
||||||
|
let leaf = MeasuredBox(draws.clone()).add(&mut h.rsc);
|
||||||
|
h.set_root((leaf,).span(Dir::RIGHT).width(rel(1.0)).height(rel(1.0)));
|
||||||
|
|
||||||
|
assert_eq!(draws.get(), 3);
|
||||||
|
assert_corners!(h, leaf, (0, 75), (100, 125));
|
||||||
|
assert_eq!(
|
||||||
|
primitive_bounds(&h, leaf.id()),
|
||||||
|
vec![h.region(&leaf.id()).unwrap()]
|
||||||
|
);
|
||||||
|
h.frame();
|
||||||
|
assert_eq!(draws.get(), 3);
|
||||||
|
|
||||||
|
h.resize((600, 300));
|
||||||
|
h.frame();
|
||||||
|
assert_eq!(draws.get(), 6);
|
||||||
|
assert_corners!(h, leaf, (0, 125), (100, 175));
|
||||||
|
assert_eq!(
|
||||||
|
primitive_bounds(&h, leaf.id()),
|
||||||
|
vec![h.region(&leaf.id()).unwrap()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn glyph_origins_compose_identically_when_drawn_and_when_retained() {
|
fn glyph_origins_compose_identically_when_drawn_and_when_retained() {
|
||||||
struct Glyphs {
|
struct Glyphs {
|
||||||
@@ -953,7 +966,8 @@ fn glyph_origins_compose_identically_when_drawn_and_when_retained() {
|
|||||||
UiSpan::new(Len::rel(0.23) + Len::px(-7.125), Len::FULL),
|
UiSpan::new(Len::rel(0.23) + Len::px(-7.125), Len::FULL),
|
||||||
UiSpan::new(Len::rel(0.37) + Len::px(3.25), Len::FULL),
|
UiSpan::new(Len::rel(0.37) + Len::px(3.25), Len::FULL),
|
||||||
);
|
);
|
||||||
painter.glyphs(text, origin);
|
painter.glyphs(text, DrawRegion::Frame(origin));
|
||||||
|
painter.glyphs(text, DrawRegion::Extent(origin));
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -966,11 +980,8 @@ fn glyph_origins_compose_identically_when_drawn_and_when_retained() {
|
|||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
painter.widget_at(
|
painter.widget_at(
|
||||||
&self.child,
|
&self.child,
|
||||||
[Some(self.region.x.len()), None],
|
self.region,
|
||||||
[
|
[Some(self.extent.x), Some(self.extent.y)],
|
||||||
Place::Fill(Part::From(self.extent.x)),
|
|
||||||
Place::Fill(Part::From(self.extent.y)),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
@@ -1117,7 +1128,7 @@ fn widening_and_restoring_a_contract_does_not_invalidate_its_reader() {
|
|||||||
assert_eq!(leaf_draws.get(), settled + 1);
|
assert_eq!(leaf_draws.get(), settled + 1);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn padding_and_stack_boxes_follow_the_extent_without_drawing_again() {
|
fn padding_and_stack_frames_follow_the_extent_without_drawing_again() {
|
||||||
struct Observed<W> {
|
struct Observed<W> {
|
||||||
widget: W,
|
widget: W,
|
||||||
draws: Rc<Cell<usize>>,
|
draws: Rc<Cell<usize>>,
|
||||||
@@ -1136,11 +1147,8 @@ fn padding_and_stack_boxes_follow_the_extent_without_drawing_again() {
|
|||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
painter.widget_at(
|
painter.widget_at(
|
||||||
&self.child,
|
&self.child,
|
||||||
[None; 2],
|
UiRegion::FULL,
|
||||||
[
|
[Some(self.extent.x), Some(self.extent.y)],
|
||||||
Place::Fill(Part::From(self.extent.x)),
|
|
||||||
Place::Fill(Part::From(self.extent.y)),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
@@ -1171,18 +1179,13 @@ fn padding_and_stack_boxes_follow_the_extent_without_drawing_again() {
|
|||||||
h.set_root(root);
|
h.set_root(root);
|
||||||
(root, leaf, fixed, draws)
|
(root, leaf, fixed, draws)
|
||||||
};
|
};
|
||||||
// The same box in three places. A pad places its child as lengths of
|
|
||||||
// its own box measured from where that box starts, so moving it is
|
|
||||||
// nothing to the pad -- where changing its length is a different
|
|
||||||
// question, and does draw it again.
|
|
||||||
let at = |start: f32| {
|
|
||||||
let span = |start: Len| UiSpan::new(start, start + Len::rel(0.4));
|
|
||||||
UiRegion::new(span(Len::rel(start) + Len::px(3.125)), span(Len::px(11.25)))
|
|
||||||
};
|
|
||||||
let mut warm = Harness::new((403, 211));
|
let mut warm = Harness::new((403, 211));
|
||||||
let (root, leaf, fixed, draws) = plant(&mut warm, at(0.13));
|
let (root, leaf, fixed, draws) = plant(&mut warm, UiRegion::FULL);
|
||||||
for start in [0.13, -0.17, 0.31] {
|
for (start, end) in [(0.13, 0.83), (-0.17, 1.23), (0.31, 0.67)] {
|
||||||
let extent = at(start);
|
let extent = UiRegion::new(
|
||||||
|
UiSpan::new(Len::rel(start) + Len::px(3.125), Len::rel(end)),
|
||||||
|
UiSpan::new(Len::px(11.25), Len::rel(end)),
|
||||||
|
);
|
||||||
let before = draws.get();
|
let before = draws.get();
|
||||||
warm.rsc[root].extent = extent;
|
warm.rsc[root].extent = extent;
|
||||||
warm.frame();
|
warm.frame();
|
||||||
@@ -1224,13 +1227,13 @@ fn moving_an_extent_child_preserves_the_slot_chosen_from_its_measurement() {
|
|||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
painter.widget_at(
|
painter.widget_at(
|
||||||
&self.child,
|
&self.child,
|
||||||
[None; 2],
|
UiRegion::FULL,
|
||||||
[
|
[
|
||||||
Place::Fill(Part::From(UiSpan::new(
|
Some(UiSpan::new(
|
||||||
Len::px(self.start),
|
Len::px(self.start),
|
||||||
Len::px(self.start + 200.0),
|
Len::px(self.start + 200.0),
|
||||||
))),
|
)),
|
||||||
Place::Fill(Part::From(UiSpan::FULL)),
|
Some(UiSpan::FULL),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
@@ -1264,14 +1267,7 @@ fn extent_frames_keep_fractional_reports_and_numeric_dependencies_valid() {
|
|||||||
impl Widget for Container {
|
impl Widget for Container {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
painter
|
painter
|
||||||
.widget_at(
|
.widget_within(&self.child, DrawRegion::Extent(self.region))
|
||||||
&self.child,
|
|
||||||
[None; 2],
|
|
||||||
[
|
|
||||||
Place::Within(Part::From(self.region.x)),
|
|
||||||
Place::Within(Part::From(self.region.y)),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
.size()
|
.size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1286,11 +1282,8 @@ fn extent_frames_keep_fractional_reports_and_numeric_dependencies_valid() {
|
|||||||
painter
|
painter
|
||||||
.widget_at(
|
.widget_at(
|
||||||
&self.child,
|
&self.child,
|
||||||
[None; 2],
|
UiRegion::FULL,
|
||||||
[
|
[Some(self.extent.x), Some(self.extent.y)],
|
||||||
Place::Fill(Part::From(self.extent.x)),
|
|
||||||
Place::Fill(Part::From(self.extent.y)),
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
.size(),
|
.size(),
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-64
@@ -60,69 +60,6 @@ fn a_wheel_scrolls_the_content_and_stops_at_its_end() {
|
|||||||
assert_corners!(h, top, (0, 0), (400, 200));
|
assert_corners!(h, top, (0, 0), (400, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fixed_content_and_a_share_fill_one_viewport() {
|
|
||||||
let mut h = Harness::new((900, 100));
|
|
||||||
let content = rect(Color::RED)
|
|
||||||
.width(LayoutLen {
|
|
||||||
px: Px::from_int(600),
|
|
||||||
rel: Rel::ZERO,
|
|
||||||
leftover: Weight::ONE,
|
|
||||||
})
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let scroll = Scroll::new(content.add_strong(&mut h.rsc), Axis::X);
|
|
||||||
h.set_root(scroll);
|
|
||||||
|
|
||||||
assert_corners!(h, content, (0, 0), (900, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fixed_content_wider_than_the_viewport_still_scrolls() {
|
|
||||||
let mut h = Harness::new((900, 100));
|
|
||||||
let content = rect(Color::RED).width(1200).add(&mut h.rsc);
|
|
||||||
let scroll = Scroll::new(content.add_strong(&mut h.rsc), Axis::X);
|
|
||||||
h.set_root(scroll);
|
|
||||||
|
|
||||||
assert_corners!(h, content, (-300, 0), (900, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn a_lone_share_fills_without_scrolling() {
|
|
||||||
let mut h = Harness::new((900, 100));
|
|
||||||
let content = rect(Color::RED).width(LayoutLen::LEFTOVER).add(&mut h.rsc);
|
|
||||||
let scroll = Scroll::new(content.add_strong(&mut h.rsc), Axis::X);
|
|
||||||
h.set_root(scroll);
|
|
||||||
|
|
||||||
assert_corners!(h, content, (0, 0), (900, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn wrapping_content_beside_a_fixed_length_is_stable_warm_and_cold() {
|
|
||||||
fn plant(h: &mut Harness) -> (WidgetId, WidgetId) {
|
|
||||||
let fixed = rect(Color::RED).width(600).add(&mut h.rsc);
|
|
||||||
let text = wtext("Wrapping shapes one source into as many lines as the box leaves room for, so a paragraph's height is an answer and not a setting.")
|
|
||||||
.size(16)
|
|
||||||
.wrap(true)
|
|
||||||
.width(LayoutLen::LEFTOVER)
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let content = (fixed, text).span(Dir::RIGHT).add(&mut h.rsc);
|
|
||||||
let scroll = Scroll::new(content.add_strong(&mut h.rsc), Axis::X);
|
|
||||||
h.set_root(scroll);
|
|
||||||
(text.id(), content.id())
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut warm = Harness::new((900, 300));
|
|
||||||
let (text, content) = plant(&mut warm);
|
|
||||||
warm.rsc.widgets_mut().get_dyn_mut(text);
|
|
||||||
warm.frame();
|
|
||||||
|
|
||||||
let mut cold = Harness::new((900, 300));
|
|
||||||
let (cold_text, cold_content) = plant(&mut cold);
|
|
||||||
|
|
||||||
assert_eq!(warm.region(&text), cold.region(&cold_text));
|
|
||||||
assert_eq!(warm.region(&content), cold.region(&cold_content));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A widget that clips to its box may not report more than the box: its
|
/// A widget that clips to its box may not report more than the box: its
|
||||||
/// parent would place the part it cut off, and the framework would put a
|
/// parent would place the part it cut off, and the framework would put a
|
||||||
/// drawing longer than its box somewhere. `Masked` is the second of these
|
/// drawing longer than its box somewhere. `Masked` is the second of these
|
||||||
@@ -134,7 +71,7 @@ fn a_clipping_widget_reporting_more_than_its_box_is_caught() {
|
|||||||
|
|
||||||
impl Widget for Clipper {
|
impl Widget for Clipper {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
painter.set_mask(UiRegion::FULL);
|
painter.set_mask(painter.region());
|
||||||
painter.widget(&self.0).size()
|
painter.widget(&self.0).size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,180 +14,6 @@ use iris::harness::Harness;
|
|||||||
use iris::prelude::*;
|
use iris::prelude::*;
|
||||||
use iris::random::Branch;
|
use iris::random::Branch;
|
||||||
|
|
||||||
fn assert_same_regions(
|
|
||||||
warm: &Harness,
|
|
||||||
warm_ids: &[WidgetId],
|
|
||||||
cold: &Harness,
|
|
||||||
cold_ids: &[WidgetId],
|
|
||||||
) {
|
|
||||||
let mut wrong = Vec::new();
|
|
||||||
for (i, (&w, &c)) in warm_ids.iter().zip(cold_ids).enumerate() {
|
|
||||||
let (got, want) = (warm.region(&w), cold.region(&c));
|
|
||||||
if got != want {
|
|
||||||
wrong.push(format!("widget {i}: warm {got:?} cold {want:?}"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert!(wrong.is_empty(), "{}", wrong.join("\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ten widgets, shrunk from seed 2 at depth 5. The stack is as tall as its
|
|
||||||
/// first child, so its other children belong in that one-line box. A cold
|
|
||||||
/// layout used to keep the span's answer from the larger measuring box while
|
|
||||||
/// a repaint asked it in the stack's final box.
|
|
||||||
fn plant_stack_in_its_sizing_childs_box(h: &mut Harness) -> Vec<WidgetId> {
|
|
||||||
let sizing = wtext("one line, overflowing whatever it is given")
|
|
||||||
.size(16)
|
|
||||||
.wrap(false)
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let filler = rect(Color::CYAN.alpha(252)).add(&mut h.rsc);
|
|
||||||
let plain = wtext("one line, overflowing whatever it is given")
|
|
||||||
.size(16)
|
|
||||||
.wrap(false)
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let span = (filler, plain).span(Dir::DOWN).add(&mut h.rsc);
|
|
||||||
let pad = Pad {
|
|
||||||
padding: Padding::ZERO,
|
|
||||||
inner: span.add_strong(&mut h.rsc),
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let probe = rect(Color::RED).add(&mut h.rsc);
|
|
||||||
let wide = rect(Color::YELLOW.alpha(252)).add(&mut h.rsc);
|
|
||||||
let narrow = rect(Color::RED).add(&mut h.rsc);
|
|
||||||
let branch = Branch {
|
|
||||||
probe: probe.add_strong(&mut h.rsc),
|
|
||||||
wide: wide.add_strong(&mut h.rsc),
|
|
||||||
narrow: narrow.add_strong(&mut h.rsc),
|
|
||||||
threshold: 55.0,
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let stack = Stack {
|
|
||||||
children: vec![
|
|
||||||
sizing.add_strong(&mut h.rsc),
|
|
||||||
pad.add_strong(&mut h.rsc),
|
|
||||||
branch.add_strong(&mut h.rsc),
|
|
||||||
],
|
|
||||||
size: StackSize::Child(0),
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
h.rsc
|
|
||||||
.widgets_mut()
|
|
||||||
.set_size_rules(stack.id(), Some(LayoutLen::LEFTOVER), None);
|
|
||||||
h.set_root(stack);
|
|
||||||
vec![
|
|
||||||
sizing.id(),
|
|
||||||
filler.id(),
|
|
||||||
plain.id(),
|
|
||||||
span.id(),
|
|
||||||
pad.id(),
|
|
||||||
probe.id(),
|
|
||||||
wide.id(),
|
|
||||||
narrow.id(),
|
|
||||||
branch.id(),
|
|
||||||
stack.id(),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn repainting_a_stack_uses_the_box_its_sizing_child_decided() {
|
|
||||||
let mut warm = Harness::new((900, 1200));
|
|
||||||
let ids = plant_stack_in_its_sizing_childs_box(&mut warm);
|
|
||||||
for &id in &ids {
|
|
||||||
warm.rsc.widgets_mut().get_dyn_mut(id);
|
|
||||||
}
|
|
||||||
warm.frame();
|
|
||||||
|
|
||||||
let mut cold = Harness::new((900, 1200));
|
|
||||||
let cold_ids = plant_stack_in_its_sizing_childs_box(&mut cold);
|
|
||||||
|
|
||||||
assert_same_regions(&warm, &ids, &cold, &cold_ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ten widgets, shrunk from seed 108 at depth 5. The nested reverse spans
|
|
||||||
/// evaluate the branch in successively narrower boxes. The answer from the
|
|
||||||
/// final, decided box must be the one retained after every span is reordered.
|
|
||||||
fn plant_branch_in_nested_reverse_spans(
|
|
||||||
h: &mut Harness,
|
|
||||||
reordered: bool,
|
|
||||||
) -> (Vec<WidgetId>, [WeakWidget<Span>; 3]) {
|
|
||||||
let pair = |first: StrongWidget, second: StrongWidget| match reordered {
|
|
||||||
true => vec![second, first],
|
|
||||||
false => vec![first, second],
|
|
||||||
};
|
|
||||||
let probe = rect(Color::RED.alpha(63)).add(&mut h.rsc);
|
|
||||||
let wide = rect(Color::RED).add(&mut h.rsc);
|
|
||||||
let narrow = wtext(PARAGRAPH).size(16).wrap(true).add(&mut h.rsc);
|
|
||||||
let branch = Branch {
|
|
||||||
probe: probe.add_strong(&mut h.rsc),
|
|
||||||
wide: wide.add_strong(&mut h.rsc),
|
|
||||||
narrow: narrow.add_strong(&mut h.rsc),
|
|
||||||
threshold: 483.0,
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let wrapped = wtext(PARAGRAPH).size(16).wrap(true).add(&mut h.rsc);
|
|
||||||
let down = Span {
|
|
||||||
children: pair(
|
|
||||||
branch.add_strong(&mut h.rsc),
|
|
||||||
wrapped.add_strong(&mut h.rsc),
|
|
||||||
),
|
|
||||||
dir: Dir::DOWN,
|
|
||||||
gap: Px::ZERO,
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let inner_filler = rect(Color::CYAN.alpha(63)).add(&mut h.rsc);
|
|
||||||
let inner = Span {
|
|
||||||
children: pair(
|
|
||||||
down.add_strong(&mut h.rsc),
|
|
||||||
inner_filler.add_strong(&mut h.rsc),
|
|
||||||
),
|
|
||||||
dir: Dir::LEFT,
|
|
||||||
gap: Px::ZERO,
|
|
||||||
}
|
|
||||||
.height(LayoutLen::rel(1.0))
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let outer_filler = rect(Color::GREEN.alpha(63)).add(&mut h.rsc);
|
|
||||||
let outer = Span {
|
|
||||||
children: pair(
|
|
||||||
inner.add_strong(&mut h.rsc),
|
|
||||||
outer_filler.add_strong(&mut h.rsc),
|
|
||||||
),
|
|
||||||
dir: Dir::LEFT,
|
|
||||||
gap: Px::ZERO,
|
|
||||||
}
|
|
||||||
.height(LayoutLen::rel(1.0))
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
h.set_root(outer);
|
|
||||||
(
|
|
||||||
vec![
|
|
||||||
probe.id(),
|
|
||||||
wide.id(),
|
|
||||||
narrow.id(),
|
|
||||||
branch.id(),
|
|
||||||
wrapped.id(),
|
|
||||||
down.id(),
|
|
||||||
inner_filler.id(),
|
|
||||||
inner.id(),
|
|
||||||
outer_filler.id(),
|
|
||||||
outer.id(),
|
|
||||||
],
|
|
||||||
[down, inner, outer],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reordering_nested_spans_keeps_the_answer_from_the_decided_box() {
|
|
||||||
let mut warm = Harness::new((900, 1200));
|
|
||||||
let (ids, spans) = plant_branch_in_nested_reverse_spans(&mut warm, false);
|
|
||||||
for span in spans {
|
|
||||||
warm.rsc[span].children.rotate_left(1);
|
|
||||||
}
|
|
||||||
warm.frame();
|
|
||||||
|
|
||||||
let mut cold = Harness::new((900, 1200));
|
|
||||||
let (cold_ids, _) = plant_branch_in_nested_reverse_spans(&mut cold, true);
|
|
||||||
|
|
||||||
assert_same_regions(&warm, &ids, &cold, &cold_ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Six widgets, shrunk from a 402-widget tree the fuzzer found. Nothing about
|
/// Six widgets, shrunk from a 402-widget tree the fuzzer found. Nothing about
|
||||||
/// the tree changes -- every widget is marked for redraw and the frame is
|
/// the tree changes -- every widget is marked for redraw and the frame is
|
||||||
/// taken again -- so no box may move, and a warm frame has to land where a
|
/// taken again -- so no box may move, and a warm frame has to land where a
|
||||||
@@ -733,51 +559,6 @@ fn a_widget_under_a_region_node_is_asked_in_the_box_that_node_was_offered() {
|
|||||||
const PARAGRAPH: &str = "Wrapping shapes one source into as many lines as the \
|
const PARAGRAPH: &str = "Wrapping shapes one source into as many lines as the \
|
||||||
box leaves room for, so a paragraph's height is an answer and not a setting.";
|
box leaves room for, so a paragraph's height is an answer and not a setting.";
|
||||||
|
|
||||||
fn plant_stack_resized_from_free(h: &mut Harness, fixed: bool) -> (Vec<WidgetId>, WidgetId) {
|
|
||||||
let sizing = rect(Color::CYAN.alpha(126)).add(&mut h.rsc);
|
|
||||||
h.rsc.widgets_mut().set_size_rules(sizing.id(), None, None);
|
|
||||||
if fixed {
|
|
||||||
h.rsc.widgets_mut().set_size_rules(
|
|
||||||
sizing.id(),
|
|
||||||
Some(LayoutLen::px(112)),
|
|
||||||
Some(LayoutLen::px(101)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let text = wtext(PARAGRAPH).size(16).wrap(true).add(&mut h.rsc);
|
|
||||||
let pad = Pad {
|
|
||||||
padding: Padding::ZERO,
|
|
||||||
inner: text.add_strong(&mut h.rsc),
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let stack = Stack {
|
|
||||||
children: vec![sizing.add_strong(&mut h.rsc), pad.add_strong(&mut h.rsc)],
|
|
||||||
size: StackSize::Child(0),
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
h.set_root(stack);
|
|
||||||
(
|
|
||||||
vec![sizing.id(), text.id(), pad.id(), stack.id()],
|
|
||||||
sizing.id(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fixing_a_stacks_sizing_child_repositions_its_overlay() {
|
|
||||||
let mut warm = Harness::new((900, 1200));
|
|
||||||
let (ids, sizing) = plant_stack_resized_from_free(&mut warm, false);
|
|
||||||
warm.frame();
|
|
||||||
warm.rsc.widgets_mut().set_size_rules(
|
|
||||||
sizing,
|
|
||||||
Some(LayoutLen::px(112)),
|
|
||||||
Some(LayoutLen::px(101)),
|
|
||||||
);
|
|
||||||
warm.frame();
|
|
||||||
|
|
||||||
let mut cold = Harness::new((900, 1200));
|
|
||||||
let (cold_ids, _) = plant_stack_resized_from_free(&mut cold, true);
|
|
||||||
assert_same_regions(&warm, &ids, &cold, &cold_ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Eight widgets, shrunk from a 118-widget tree (seed 1121, depth 4,
|
/// Eight widgets, shrunk from a 118-widget tree (seed 1121, depth 4,
|
||||||
/// `shuffle-swap-for-three`). The stack takes its size from the span above,
|
/// `shuffle-swap-for-three`). The stack takes its size from the span above,
|
||||||
/// the span takes its width from the longest line of the texts in it, and
|
/// the span takes its width from the longest line of the texts in it, and
|
||||||
@@ -891,179 +672,3 @@ fn adding_text_to_a_reverse_row_keeps_its_shared_height() {
|
|||||||
let (_, other, _) = build(&mut cold, true);
|
let (_, other, _) = build(&mut cold, true);
|
||||||
assert_eq!(warm.region(&shared), cold.region(&other));
|
assert_eq!(warm.region(&shared), cold.region(&other));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Nine widgets, shrunk from seed 946 at depth 6. The column is a share of
|
|
||||||
/// the row while its rect has room to draw and a fixed width once it has
|
|
||||||
/// not, so the row asks it twice: in the room, where it answers a share,
|
|
||||||
/// and in its slot, where it answers its text's width. Emptying the column
|
|
||||||
/// changes only the first answer. A local redraw that asked only the second
|
|
||||||
/// question kept the row as it was; the column has to defer to the row.
|
|
||||||
fn plant_column_that_is_a_share_only_while_its_rect_fits(
|
|
||||||
h: &mut Harness,
|
|
||||||
emptied: bool,
|
|
||||||
) -> (Vec<WidgetId>, WeakWidget<Span>, Vec<StrongWidget>) {
|
|
||||||
let first = wtext(PARAGRAPH).size(16).wrap(true).add(&mut h.rsc);
|
|
||||||
let filler = rect(Color::CYAN.alpha(126)).add(&mut h.rsc);
|
|
||||||
let second = wtext(PARAGRAPH).size(16).wrap(true).add(&mut h.rsc);
|
|
||||||
let mut spare: Vec<StrongWidget> =
|
|
||||||
vec![filler.add_strong(&mut h.rsc), second.add_strong(&mut h.rsc)];
|
|
||||||
let mut children: Vec<StrongWidget> = vec![first.add_strong(&mut h.rsc)];
|
|
||||||
if !emptied {
|
|
||||||
children.append(&mut spare);
|
|
||||||
}
|
|
||||||
let column = Span {
|
|
||||||
children,
|
|
||||||
dir: Dir::DOWN,
|
|
||||||
gap: Px::ZERO,
|
|
||||||
}
|
|
||||||
.height(159)
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let left = rect(Color::MAGENTA.alpha(189)).add(&mut h.rsc);
|
|
||||||
let right = rect(Color::BLUE.alpha(0)).add(&mut h.rsc);
|
|
||||||
let row = Span {
|
|
||||||
children: vec![
|
|
||||||
left.add_strong(&mut h.rsc),
|
|
||||||
column.add_strong(&mut h.rsc),
|
|
||||||
right.add_strong(&mut h.rsc),
|
|
||||||
],
|
|
||||||
dir: Dir::RIGHT,
|
|
||||||
gap: Px::ZERO,
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let end = rect(Color::MAGENTA.alpha(189)).add(&mut h.rsc);
|
|
||||||
let root = Span {
|
|
||||||
children: vec![end.add_strong(&mut h.rsc), row.add_strong(&mut h.rsc)],
|
|
||||||
dir: Dir::LEFT,
|
|
||||||
gap: Px::ZERO,
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
h.set_root(root);
|
|
||||||
(
|
|
||||||
vec![
|
|
||||||
first.id(),
|
|
||||||
filler.id(),
|
|
||||||
second.id(),
|
|
||||||
column.id(),
|
|
||||||
left.id(),
|
|
||||||
right.id(),
|
|
||||||
row.id(),
|
|
||||||
end.id(),
|
|
||||||
root.id(),
|
|
||||||
],
|
|
||||||
column,
|
|
||||||
spare,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn emptying_a_column_the_row_asked_twice_asks_the_row_again() {
|
|
||||||
let mut warm = Harness::new((900, 1200));
|
|
||||||
let (ids, column, _spare) =
|
|
||||||
plant_column_that_is_a_share_only_while_its_rect_fits(&mut warm, false);
|
|
||||||
warm.frame();
|
|
||||||
// Kept alive: dropping the last share of a widget frees its id.
|
|
||||||
let _removed: Vec<StrongWidget> = warm.rsc[column].children.drain(1..).collect();
|
|
||||||
warm.frame();
|
|
||||||
|
|
||||||
let mut cold = Harness::new((900, 1200));
|
|
||||||
let (cold_ids, _, _spare) =
|
|
||||||
plant_column_that_is_a_share_only_while_its_rect_fits(&mut cold, true);
|
|
||||||
cold.frame();
|
|
||||||
|
|
||||||
assert_same_regions(&warm, &ids, &cold, &cold_ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Six widgets, shrunk from seed 59 at depth 5 (`resize-size`). The column
|
|
||||||
/// divides the box it is given between two shares, so its drawing holds for
|
|
||||||
/// that box's length alone, and the pads above it pass that dependency up:
|
|
||||||
/// each one's box is a part of the box it was asked in. Padding narrowing
|
|
||||||
/// the frame it hands down does not change that, and while it was taken to,
|
|
||||||
/// changing the rule over the pads relocated the column's drawing into the
|
|
||||||
/// new box instead of dividing it again.
|
|
||||||
fn plant_two_shares_under_two_pads(h: &mut Harness, height: f32) -> Vec<WidgetId> {
|
|
||||||
let top = rect(Color::CYAN.alpha(126)).add(&mut h.rsc);
|
|
||||||
let bottom = rect(Color::RED).add(&mut h.rsc);
|
|
||||||
let column = (top, bottom).span(Dir::DOWN).add(&mut h.rsc);
|
|
||||||
let inner = Pad {
|
|
||||||
padding: Padding::ZERO,
|
|
||||||
inner: column.add_strong(&mut h.rsc),
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let outer = Pad {
|
|
||||||
padding: Padding::ZERO,
|
|
||||||
inner: inner.add_strong(&mut h.rsc),
|
|
||||||
}
|
|
||||||
.height(height)
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let beside = rect(Color::BLUE).add(&mut h.rsc);
|
|
||||||
h.set_root((outer, beside).span(Dir::RIGHT));
|
|
||||||
vec![
|
|
||||||
top.id(),
|
|
||||||
bottom.id(),
|
|
||||||
column.id(),
|
|
||||||
inner.id(),
|
|
||||||
outer.id(),
|
|
||||||
beside.id(),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn changing_a_rule_over_two_pads_divides_the_column_again() {
|
|
||||||
let mut warm = Harness::new((900, 1200));
|
|
||||||
let ids = plant_two_shares_under_two_pads(&mut warm, 88.0);
|
|
||||||
warm.frame();
|
|
||||||
warm.rsc
|
|
||||||
.widgets_mut()
|
|
||||||
.set_size_rules(ids[4], None, Some(LayoutLen::px(105)));
|
|
||||||
warm.frame();
|
|
||||||
|
|
||||||
let mut cold = Harness::new((900, 1200));
|
|
||||||
let cold_ids = plant_two_shares_under_two_pads(&mut cold, 105.0);
|
|
||||||
cold.frame();
|
|
||||||
|
|
||||||
assert_same_regions(&warm, &ids, &cold, &cold_ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Six widgets, shrunk from seed 942 at depth 6 (`resize`). A `Branch` asks
|
|
||||||
/// its probe in the top 40 px of its box and forwards the frame, so the
|
|
||||||
/// scroll's own box is 40 px tall whatever the window is -- but its content
|
|
||||||
/// is as tall as the frame, which is the window, and a scroll kept to its
|
|
||||||
/// end has to be told when that changes. Resolving a length against the
|
|
||||||
/// window is what reads it, so that is where the dependency is taken.
|
|
||||||
fn plant_a_window_tall_column_in_a_short_scroll(h: &mut Harness) -> Vec<WidgetId> {
|
|
||||||
let leaf = rect(Color::RED).add(&mut h.rsc);
|
|
||||||
let column = Span {
|
|
||||||
children: vec![leaf.add_strong(&mut h.rsc)],
|
|
||||||
dir: Dir::RIGHT,
|
|
||||||
gap: Px::ZERO,
|
|
||||||
}
|
|
||||||
.height(rel(1.0))
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
let scroll = Scroll::new(column.add_strong(&mut h.rsc), Axis::Y).add(&mut h.rsc);
|
|
||||||
let wide = rect(Color::BLUE).add(&mut h.rsc);
|
|
||||||
let narrow = rect(Color::GREEN).add(&mut h.rsc);
|
|
||||||
let root = Branch {
|
|
||||||
probe: scroll.add_strong(&mut h.rsc),
|
|
||||||
wide: wide.add_strong(&mut h.rsc),
|
|
||||||
narrow: narrow.add_strong(&mut h.rsc),
|
|
||||||
threshold: 55.0,
|
|
||||||
}
|
|
||||||
.add(&mut h.rsc);
|
|
||||||
h.set_root(root);
|
|
||||||
vec![leaf.id(), column.id(), scroll.id(), root.id()]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn resizing_under_a_short_scroll_snaps_its_window_tall_content_again() {
|
|
||||||
let mut warm = Harness::new((1920, 1200));
|
|
||||||
let ids = plant_a_window_tall_column_in_a_short_scroll(&mut warm);
|
|
||||||
warm.frame();
|
|
||||||
warm.resize((640, 900));
|
|
||||||
warm.frame();
|
|
||||||
|
|
||||||
let mut cold = Harness::new((640, 900));
|
|
||||||
let cold_ids = plant_a_window_tall_column_in_a_short_scroll(&mut cold);
|
|
||||||
cold.frame();
|
|
||||||
|
|
||||||
assert_same_regions(&warm, &ids, &cold, &cold_ids);
|
|
||||||
}
|
|
||||||
+4
-60
@@ -103,11 +103,6 @@ pub enum Case {
|
|||||||
/// A resize and then a size change, so a retained answer is asked to
|
/// A resize and then a size change, so a retained answer is asked to
|
||||||
/// survive two different kinds of invalidation in a row.
|
/// survive two different kinds of invalidation in a row.
|
||||||
ResizeSize,
|
ResizeSize,
|
||||||
/// A size change and then a resize, which is the other order and not the
|
|
||||||
/// same test: a length answered as a fraction of one box and kept as a
|
|
||||||
/// fraction of another agrees at the size it was changed at and parts
|
|
||||||
/// from it at every other one.
|
|
||||||
SizeResize,
|
|
||||||
/// A few declared sizes.
|
/// A few declared sizes.
|
||||||
Size,
|
Size,
|
||||||
/// Every declared size at once, so every reader of a size has a changed
|
/// Every declared size at once, so every reader of a size has a changed
|
||||||
@@ -124,13 +119,12 @@ pub enum Case {
|
|||||||
Shuffle(Shuffle),
|
Shuffle(Shuffle),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ALL: [Case; 16] = [
|
pub const ALL: [Case; 15] = [
|
||||||
Case::Repaint,
|
Case::Repaint,
|
||||||
Case::RepaintSome,
|
Case::RepaintSome,
|
||||||
Case::Resize,
|
Case::Resize,
|
||||||
Case::ResizeRepaint,
|
Case::ResizeRepaint,
|
||||||
Case::ResizeSize,
|
Case::ResizeSize,
|
||||||
Case::SizeResize,
|
|
||||||
Case::Size,
|
Case::Size,
|
||||||
Case::EverySize,
|
Case::EverySize,
|
||||||
Case::Align,
|
Case::Align,
|
||||||
@@ -152,7 +146,6 @@ impl Case {
|
|||||||
Self::Resize => "resize",
|
Self::Resize => "resize",
|
||||||
Self::ResizeRepaint => "resize-repaint",
|
Self::ResizeRepaint => "resize-repaint",
|
||||||
Self::ResizeSize => "resize-size",
|
Self::ResizeSize => "resize-size",
|
||||||
Self::SizeResize => "size-resize",
|
|
||||||
Self::Size => "size",
|
Self::Size => "size",
|
||||||
Self::EverySize => "every-size",
|
Self::EverySize => "every-size",
|
||||||
Self::Align => "align",
|
Self::Align => "align",
|
||||||
@@ -177,15 +170,6 @@ impl Case {
|
|||||||
_ => (STILL, STILL),
|
_ => (STILL, STILL),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The window the warm tree is taken to after the change, where the case
|
|
||||||
/// is about what the change left behind rather than about the change.
|
|
||||||
fn then_resize(self) -> Option<(f32, f32)> {
|
|
||||||
match self {
|
|
||||||
Self::SizeResize => Some(INNER),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark(warm: &mut Harness, tree: &Tree, step: usize) {
|
fn mark(warm: &mut Harness, tree: &Tree, step: usize) {
|
||||||
@@ -300,7 +284,7 @@ fn change(case: Case, warm: &mut Harness, tree: &mut Tree, plan: &Plan, rng: &mu
|
|||||||
warm.frame();
|
warm.frame();
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
Case::Size | Case::ResizeSize | Case::SizeResize => Edits {
|
Case::Size | Case::ResizeSize => Edits {
|
||||||
sizes: some_sizes(warm, tree, rng),
|
sizes: some_sizes(warm, tree, rng),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
@@ -400,17 +384,6 @@ fn describe_widget(id: WidgetId, h: &Harness) -> String {
|
|||||||
label
|
label
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One widget's layout as it stands: the frame its fractions resolved
|
|
||||||
/// against, the box it was asked in, the box its drawing went in, and what
|
|
||||||
/// it reported. In window units, which is what both trees are in.
|
|
||||||
fn record(id: WidgetId, h: &Harness) -> String {
|
|
||||||
let active = &h.render.active[&id];
|
|
||||||
format!(
|
|
||||||
"frame {} ask {} box {} size {}",
|
|
||||||
active.frame, active.part, active.extent, active.size,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Runs `case` on the tree `plan` describes, warm and cold, and says where
|
/// Runs `case` on the tree `plan` describes, warm and cold, and says where
|
||||||
/// the two disagree. `seed` chooses only the values a case picks at random,
|
/// the two disagree. `seed` chooses only the values a case picks at random,
|
||||||
/// so one plan under one case is one comparison however it was reached.
|
/// so one plan under one case is one comparison however it was reached.
|
||||||
@@ -427,29 +400,12 @@ pub fn diverges(plan: &Plan, case: Case, seed: u64) -> Option<String> {
|
|||||||
warm.frame();
|
warm.frame();
|
||||||
}
|
}
|
||||||
let cold_plan = change(case, &mut warm, &mut tree, plan, &mut Rng::new(seed));
|
let cold_plan = change(case, &mut warm, &mut tree, plan, &mut Rng::new(seed));
|
||||||
// Whatever the change left, seen at another window: an answer kept as a
|
|
||||||
// fraction of the wrong length is the same number of pixels where it was
|
|
||||||
// made and a different one everywhere else.
|
|
||||||
let end = match case.then_resize() {
|
|
||||||
Some(after) => {
|
|
||||||
warm.resize(after);
|
|
||||||
warm.frame();
|
|
||||||
after
|
|
||||||
}
|
|
||||||
None => end,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut cold = Harness::new(end);
|
let mut cold = Harness::new(end);
|
||||||
let (root, cold_tree) = build(&mut cold.rsc, &cold_plan);
|
let (root, cold_tree) = build(&mut cold.rsc, &cold_plan);
|
||||||
cold.state.root = Some(root);
|
cold.state.root = Some(root);
|
||||||
cold.frame();
|
cold.frame();
|
||||||
|
|
||||||
let places: HashMap<WidgetId, usize> = tree
|
|
||||||
.ids
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, &id)| (id, i))
|
|
||||||
.collect();
|
|
||||||
let mut drawn = 0;
|
let mut drawn = 0;
|
||||||
for (i, (&w, &c)) in tree.ids.iter().zip(&cold_tree.ids).enumerate() {
|
for (i, (&w, &c)) in tree.ids.iter().zip(&cold_tree.ids).enumerate() {
|
||||||
let (got, want) = (warm.region(&w), cold.region(&c));
|
let (got, want) = (warm.region(&w), cold.region(&c));
|
||||||
@@ -460,7 +416,6 @@ pub fn diverges(plan: &Plan, case: Case, seed: u64) -> Option<String> {
|
|||||||
// Where two trees disagree is rarely where the cause is, so the
|
// Where two trees disagree is rarely where the cause is, so the
|
||||||
// ancestry comes with it, marking the widgets that own a region.
|
// ancestry comes with it, marking the widgets that own a region.
|
||||||
let mut chain = Vec::new();
|
let mut chain = Vec::new();
|
||||||
let mut records = Vec::new();
|
|
||||||
let mut at = Some(w);
|
let mut at = Some(w);
|
||||||
while let Some(id) = at {
|
while let Some(id) = at {
|
||||||
let active = &warm.render.active[&id];
|
let active = &warm.render.active[&id];
|
||||||
@@ -469,22 +424,11 @@ pub fn diverges(plan: &Plan, case: Case, seed: u64) -> Option<String> {
|
|||||||
false => "*",
|
false => "*",
|
||||||
};
|
};
|
||||||
chain.push(format!("{}{node}", describe(id, &warm)));
|
chain.push(format!("{}{node}", describe(id, &warm)));
|
||||||
// What each level was asked in on both sides, since the level
|
|
||||||
// where the two stop agreeing is the one to look at rather than
|
|
||||||
// the leaf that reported the difference.
|
|
||||||
let cold_id = places.get(&id).and_then(|&i| cold_tree.ids.get(i));
|
|
||||||
records.push(format!(
|
|
||||||
" {}\n warm {}\n cold {}",
|
|
||||||
describe(id, &warm),
|
|
||||||
record(id, &warm),
|
|
||||||
cold_id.map_or("-".into(), |&id| record(id, &cold)),
|
|
||||||
));
|
|
||||||
at = active.parent;
|
at = active.parent;
|
||||||
}
|
}
|
||||||
return Some(format!(
|
return Some(format!(
|
||||||
"widget {i}\n warm {got:?}\n cold {want:?}\n {}\n{}",
|
"widget {i}\n warm {got:?}\n cold {want:?}\n {}",
|
||||||
chain.join(" < "),
|
chain.join(" < ")
|
||||||
records.join("\n"),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
match drawn {
|
match drawn {
|
||||||
|
|||||||
+2
-6
@@ -70,14 +70,10 @@ fn no_grown_tree_lays_out_differently_warm_than_cold() {
|
|||||||
over_seeds(seeds, |seed| {
|
over_seeds(seeds, |seed| {
|
||||||
let grown = plan(seed, depth, &Edits::default());
|
let grown = plan(seed, depth, &Edits::default());
|
||||||
for &case in &cases {
|
for &case in &cases {
|
||||||
if diverges(&grown, case, seed).is_none() {
|
let Some(how) = diverges(&grown, case, seed) else {
|
||||||
continue;
|
continue;
|
||||||
}
|
};
|
||||||
let small = shrink(grown.clone(), case, seed);
|
let small = shrink(grown.clone(), case, seed);
|
||||||
// Described from the shrunk tree: the grown tree's chain names
|
|
||||||
// widgets that are no longer there, and the ancestry of the
|
|
||||||
// failure is what a test is written from.
|
|
||||||
let how = diverges(&small, case, seed).unwrap_or_default();
|
|
||||||
println!(
|
println!(
|
||||||
"seed {seed} case {}: {how}\ngrown {} widgets, shrank to {}\n{small:#?}",
|
"seed {seed} case {}: {how}\ngrown {} widgets, shrank to {}\n{small:#?}",
|
||||||
case.name(),
|
case.name(),
|
||||||
|
|||||||
Reference in new issue
Block a user