Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aaba7dbfee | ||
|
|
4328eac756 | ||
|
|
b842e4f474 | ||
|
|
49cec82c1b | ||
|
|
0954770ceb | ||
|
|
1956be3f3d | ||
|
|
34cafb6edc |
No files matched your search
@@ -54,7 +54,7 @@ pub(crate) enum Counter {
|
|||||||
TextShapes,
|
TextShapes,
|
||||||
TextBreaks,
|
TextBreaks,
|
||||||
GlyphPlacements,
|
GlyphPlacements,
|
||||||
OutsidePlacement,
|
OutsidePinnedLen,
|
||||||
OutsideFrame,
|
OutsideFrame,
|
||||||
OutsideExtent,
|
OutsideExtent,
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ impl Counter {
|
|||||||
"text shapes",
|
"text shapes",
|
||||||
"text line breaks",
|
"text line breaks",
|
||||||
"glyph placements",
|
"glyph placements",
|
||||||
"reuse outside: the placement it was pinned to",
|
"reuse outside: the length it was pinned to",
|
||||||
"reuse outside: a frame length",
|
"reuse outside: a frame length",
|
||||||
"reuse outside: an extent length",
|
"reuse outside: an extent length",
|
||||||
];
|
];
|
||||||
|
|||||||
+45
-61
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
DrawRegion, LayerId, LayoutHolds, LayoutLen, MaskIdx, MoveIdx, RegionAlign, RetainedPrimitive,
|
LayerId, LayoutHolds, LayoutLen, MaskIdx, MoveIdx, Place, RegionAlign, RetainedPrimitive, Size,
|
||||||
Size, TextureHandle, UiRegion, UiVec2, WidgetId,
|
TextureHandle, UiRegion, WidgetId,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// What is kept of a widget its parent has asked about. `drawn` says whether
|
/// What is kept of a widget its parent has asked about. `drawn` says whether
|
||||||
@@ -9,28 +9,35 @@ use crate::{
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ActiveData {
|
pub struct ActiveData {
|
||||||
pub id: WidgetId,
|
pub id: WidgetId,
|
||||||
/// The box its parent gave it, in `parent_move`'s coordinates: what it
|
/// Its frame in `parent_move`'s coordinates: what a fraction it declares
|
||||||
/// was asked about, and what a fraction under it is a fraction of. A
|
/// or reports is a fraction of, composed. Everything it draws sits inside
|
||||||
/// local redraw asks here.
|
/// this by way of `extent`.
|
||||||
pub region: UiRegion,
|
pub frame_abs: UiRegion,
|
||||||
/// Where its drawing sits inside that box, in the box's own coordinates.
|
/// Where its drawing goes, in the frame's own coordinates.
|
||||||
pub placement: UiRegion,
|
pub extent: UiRegion,
|
||||||
/// The original frame in its parent widget's coordinates. Recomposition
|
/// That frame in its parent's frame coordinates, before composition:
|
||||||
/// and pixel-length evaluation both follow this chain.
|
/// forwarded whole by a transparent container, narrowed by a declared
|
||||||
pub given_region: UiRegion,
|
/// length. Its length is the same on every ask, which is what
|
||||||
/// The lengths of the box its parent first asked about it in, as
|
/// a local redraw relies on to ask its parent's own question again.
|
||||||
/// lengths of the box the parent was itself offered. Any later box it
|
pub frame: UiRegion,
|
||||||
/// was given was decided knowing its answer, so this is the question
|
/// What of its parent's extent the drawing was given, and what it was
|
||||||
/// asked again -- and a chain of fractions has no frame in it, which is
|
/// given at the parent's first ask of it -- the question a cold layout
|
||||||
/// why a region node between two widgets cannot break it.
|
/// asks. A part is a length from the extent's start, so an extent that
|
||||||
pub offer_len: UiVec2,
|
/// moved re-places every child by re-adding that start.
|
||||||
pub offer_placement: [Option<crate::UiSpan>; 2],
|
pub place: [Place; 2],
|
||||||
|
pub offer_place: [Place; 2],
|
||||||
|
/// The box that ask gave it, in its frame's coordinates. Kept rather
|
||||||
|
/// than worked out again from where its parent's own box is now: a
|
||||||
|
/// parent drawn again in the box its own answer chose gives its children
|
||||||
|
/// boxes it never measured anything in, and the measurement this widget
|
||||||
|
/// answered is the one its parent's layout was built on.
|
||||||
|
pub offer_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)>,
|
||||||
/// What the widget said it used of its box, the last time it drew.
|
/// What the widget said it used of its frame, the last time it drew.
|
||||||
pub size: Size,
|
pub size: Size,
|
||||||
/// The frame, extent and explicit placement reads that this drawing holds for.
|
/// The frame and extent reads that this drawing holds for.
|
||||||
pub holds: LayoutHolds,
|
pub holds: LayoutHolds,
|
||||||
pub drawn: bool,
|
pub drawn: bool,
|
||||||
pub parent: Option<WidgetId>,
|
pub parent: Option<WidgetId>,
|
||||||
@@ -39,30 +46,24 @@ 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<DrawRegion>,
|
pub mask_region: Option<UiRegion>,
|
||||||
/// 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, so this widget's drawing does not have to depend on
|
|
||||||
/// where its own drawing 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 box.
|
/// The declared lengths whoever drew this widget resolved into its frame.
|
||||||
/// 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 `region` uses.
|
/// The movable region whose coordinates `frame_abs` uses.
|
||||||
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.
|
||||||
@@ -76,37 +77,20 @@ pub struct ActiveData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveData {
|
impl ActiveData {
|
||||||
/// Whether what it answered still stands for a box of these pixel
|
/// What it answered when its parent measured it, where it has been
|
||||||
/// lengths -- the box it was asked in, where `holds` is about the box its
|
/// measured at all. Not `size`, which is what its last drawing reported:
|
||||||
/// answer then chose.
|
/// a drawing made in the box that answer chose is answering a different
|
||||||
pub fn answers_at(&self, px: crate::PxVec2) -> bool {
|
/// question.
|
||||||
self.answer.is_some_and(|(_, holds)| {
|
pub fn measured(&self) -> Option<Size> {
|
||||||
holds.contains(
|
self.answer.map(|(size, _)| size)
|
||||||
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
|
/// Whether what it answered still stands for a frame of these pixel
|
||||||
/// wrapper whose box is its child's, or a part of it.
|
/// lengths. The answer was given in the box its parent first asked
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
/// about, which is what it is checked against -- `holds` on the record
|
||||||
pub(crate) enum ExtentPlacement {
|
/// is about the box the answer then chose.
|
||||||
Inherit,
|
pub fn answers_at(&self, px: crate::PxVec2, part: UiRegion) -> bool {
|
||||||
Within(UiRegion),
|
self.answer
|
||||||
}
|
.is_some_and(|(_, holds)| holds.contains(px, part))
|
||||||
|
|
||||||
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]),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
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,
|
|
||||||
}
|
|
||||||
+33
-33
@@ -1,63 +1,63 @@
|
|||||||
use crate::{Axis, Holds, PxVec2, UiRegion};
|
use crate::{Axis, Holds, Len, PxVec2, UiRegion};
|
||||||
|
|
||||||
/// Dependencies of one evaluation, before the frame and extent are composed.
|
const AXES: [Axis; 2] = [Axis::X, Axis::Y];
|
||||||
|
|
||||||
|
/// What one evaluation of a widget depends on: the pixel lengths of its
|
||||||
|
/// frame and of its own box that its drawing and its answer hold for, and
|
||||||
|
/// the symbolic length of its own box where it read one.
|
||||||
|
///
|
||||||
|
/// The symbolic length is a pin rather than a range: 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. It 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.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub struct LayoutHolds {
|
pub struct LayoutHolds {
|
||||||
pub frame: [Holds; 2],
|
pub frame: [Holds; 2],
|
||||||
pub extent: [Holds; 2],
|
pub extent: [Holds; 2],
|
||||||
pub placement: Option<UiRegion>,
|
pub extent_len: [Option<Len>; 2],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutHolds {
|
impl LayoutHolds {
|
||||||
pub const ANY: Self = Self {
|
pub const ANY: Self = Self {
|
||||||
frame: [Holds::ANY; 2],
|
frame: [Holds::ANY; 2],
|
||||||
extent: [Holds::ANY; 2],
|
extent: [Holds::ANY; 2],
|
||||||
placement: None,
|
extent_len: [None; 2],
|
||||||
};
|
};
|
||||||
|
|
||||||
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.frame[n] = self.frame[n].and(other.frame[n]);
|
||||||
|
result.extent[n] = self.extent[n].and(other.extent[n]);
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
self.placement.is_none()
|
self.extent_len[n].is_none()
|
||||||
|| other.placement.is_none()
|
|| other.extent_len[n].is_none()
|
||||||
|| self.placement == other.placement
|
|| self.extent_len[n] == other.extent_len[n]
|
||||||
);
|
);
|
||||||
Self {
|
result.extent_len[n] = self.extent_len[n].or(other.extent_len[n]);
|
||||||
frame: [
|
|
||||||
self.frame[0].and(other.frame[0]),
|
|
||||||
self.frame[1].and(other.frame[1]),
|
|
||||||
],
|
|
||||||
extent: [
|
|
||||||
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 {
|
||||||
self.placement
|
(0..2).all(|n| {
|
||||||
.is_none_or(|placement| other.placement == Some(placement))
|
|
||||||
&& [0, 1].into_iter().all(|n| {
|
|
||||||
self.frame[n].lo <= other.frame[n].lo
|
self.frame[n].lo <= other.frame[n].lo
|
||||||
&& self.frame[n].hi >= other.frame[n].hi
|
&& 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))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains(self, px: PxVec2, placement: UiRegion) -> bool {
|
pub fn contains(self, px: PxVec2, extent: UiRegion) -> bool {
|
||||||
self.placement.is_none_or(|old| old == placement)
|
AXES.into_iter().all(|axis| {
|
||||||
&& [Axis::X, Axis::Y].into_iter().all(|axis| {
|
let n = axis as usize;
|
||||||
self.frame[axis as usize].contains(px.axis(axis))
|
let len = extent.axis(axis).len();
|
||||||
&& self.extent[axis as usize]
|
self.frame[n].contains(px.axis(axis))
|
||||||
.contains(placement.axis(axis).len().to_px(px.axis(axis)))
|
&& self.extent[n].contains(len.to_px(px.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)]
|
||||||
|
|||||||
+317
-370
@@ -1,9 +1,9 @@
|
|||||||
#[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, DrawRegion, ExtentPlacement, Holds, LayoutHolds, LayoutLen, Len, Px, PxVec2, RegionAlign,
|
Axis, Holds, LayoutHolds, LayoutLen, Len, Part, Place, Px, PxVec2, RegionAlign, RenderedText,
|
||||||
RenderedText, RetainedPrimitive, Size, StrongWidget, TextAttrs, TextBuffer, TextData,
|
RetainedPrimitive, Size, StrongWidget, TextAttrs, TextBuffer, TextData, TextureHandle,
|
||||||
TextureHandle, UiRegion, UiRenderState, UiRsc, UiSpan, UiVec2, Weight, WidgetId, Widgets,
|
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,
|
||||||
@@ -17,51 +17,57 @@ 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,
|
||||||
|
|
||||||
/// The box its parent gave it, in the coordinates of `move_idx`: what a
|
/// What a fraction this widget declares or reports is a fraction of, in
|
||||||
/// fraction of this widget's area is a fraction of, and what every region
|
/// the coordinates of `move_idx`: forwarded from its parent unchanged
|
||||||
/// it writes composes within. The same box on the ask that measures and
|
/// through a span, a stack or a scroll, and narrowed only by what was
|
||||||
/// the ask that places, which is what keeps a fraction under it from
|
/// decided above it -- a declared length, or the root. Its length
|
||||||
/// being resolved twice.
|
/// is the same on every ask of the widget, which is what keeps a fraction
|
||||||
pub(super) region: UiRegion,
|
/// under it from being resolved twice.
|
||||||
/// Where this widget's drawing sits inside that box, in the box's own
|
pub(super) frame: UiRegion,
|
||||||
/// coordinates: `FULL` while its answer is not yet known, and the box
|
/// Where this widget's drawing goes, in the frame's own coordinates.
|
||||||
/// its answer or its parent chose once one of them has.
|
/// Everything it writes is in these coordinates, and its children are
|
||||||
pub(super) placement: UiRegion,
|
/// placed as parts of it.
|
||||||
/// Whether this draw read its placement, which makes the drawing one
|
pub(super) extent: UiRegion,
|
||||||
/// that holds for that placement alone -- the way reading a length in
|
/// The extent's symbolic length where this draw read it, which makes the
|
||||||
/// pixels makes it hold for that length.
|
/// drawing one that holds for that length alone -- the way reading a
|
||||||
pub(super) reads_placement: bool,
|
/// length in pixels makes it hold for that number of pixels.
|
||||||
/// That box in pixels, which its children's are a length of: threaded
|
pub(super) extent_len: [Option<Len>; 2],
|
||||||
/// down from the box this widget was given rather than composed back up
|
/// Symbolic box lengths read only to compute the answer. A container can
|
||||||
/// the chain, so every length in layout is one multiply from its
|
/// replace the provisional drawings used for that answer with drawings
|
||||||
/// parent's and [`Holds::through`] inverts exactly that.
|
/// in decided boxes, so this contract is independent of the final one.
|
||||||
|
pub(super) answer_extent_len: [Option<Len>; 2],
|
||||||
|
/// The frame in pixels, which its children's frames are a length of:
|
||||||
|
/// threaded down 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) 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<DrawRegion>,
|
pub(super) mask_region: Option<UiRegion>,
|
||||||
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
|
/// The children asked about so far, so the first place each was asked in
|
||||||
/// is the one recorded as its offer.
|
/// is the one recorded as its offer.
|
||||||
pub(super) offered: Vec<WidgetId>,
|
pub(super) offered: Vec<WidgetId>,
|
||||||
/// The lengths of the box this widget was first asked about in, in
|
/// Whether this draw is at the place its parent first asked about, which
|
||||||
/// pixels. Its children's offers are a fraction of it.
|
/// makes the questions it asks the ones a cold layout asks and their
|
||||||
pub(super) offered_px: PxVec2,
|
/// answers the ones to keep.
|
||||||
/// 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,
|
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 its box in pixels, per axis: every
|
/// What this draw itself read of its frame in pixels, per axis: every
|
||||||
/// length 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) own: [Holds; 2],
|
pub(super) frame_own: [Holds; 2],
|
||||||
/// Dependencies of every child drawing, including unmeasured overlays.
|
/// The same for its own box.
|
||||||
pub(super) under: LayoutHolds,
|
pub(super) extent_own: [Holds; 2],
|
||||||
|
/// Pixel-box dependencies used only to compute the answer. These do not
|
||||||
|
/// constrain a retained drawing placed inside that answer.
|
||||||
|
pub(super) answer_extent_own: [Holds; 2],
|
||||||
|
/// The final drawing kept for each child. Asking one child again replaces
|
||||||
|
/// its provisional drawing and therefore replaces this contract too.
|
||||||
|
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,
|
||||||
@@ -74,26 +80,29 @@ pub struct Painter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Painter<'a> {
|
impl<'a> Painter<'a> {
|
||||||
fn primitive_at<P: Primitive>(&mut self, primitive: P, region: DrawRegion) {
|
fn primitive_at<P: Primitive>(&mut self, primitive: P, region: UiRegion) {
|
||||||
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: DrawRegion) {
|
fn write<P: Primitive>(&mut self, kind: PrimitiveKind<P>, primitive: P, region: UiRegion) {
|
||||||
self.write_resolved(
|
self.write_resolved(kind, primitive, region, self.resolve(region));
|
||||||
kind,
|
}
|
||||||
primitive,
|
|
||||||
region,
|
/// A box in this widget's extent coordinates, composed into the
|
||||||
region.resolve(self.region, self.placement),
|
/// coordinates its move slot is in: through the extent, then through the
|
||||||
);
|
/// frame the extent is a part of. The same two steps a recomposition
|
||||||
|
/// replays, so a moved drawing lands where a cold one does.
|
||||||
|
fn resolve(&self, region: UiRegion) -> UiRegion {
|
||||||
|
region.within(&self.extent).within(&self.frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
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: DrawRegion,
|
region: UiRegion,
|
||||||
resolved: UiRegion,
|
resolved: UiRegion,
|
||||||
) {
|
) {
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
@@ -122,137 +131,68 @@ 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, at)
|
self.primitive_at(primitive, UiRegion::FULL)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes in the frame by default. `DrawRegion::Extent` keeps the local
|
/// Writes a primitive in a part of this widget's own box, in that box's
|
||||||
/// geometry attached to this widget's box without reading its placement.
|
/// coordinates.
|
||||||
pub fn primitive_within(
|
pub fn primitive_within(&mut self, primitive: impl PrimitiveLike, region: UiRegion) {
|
||||||
&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.into());
|
self.primitive_at(primitive, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets a mask in the selected frame or extent coordinates.
|
/// Sets a mask, in this widget's own box's coordinates.
|
||||||
pub fn set_mask(&mut self, region: impl Into<DrawRegion>) {
|
pub fn set_mask(&mut self, region: UiRegion) {
|
||||||
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: region.resolve(self.region, self.placement),
|
region: resolved,
|
||||||
move_idx: self.move_idx,
|
move_idx,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws a widget in the whole of this widget's own box: it gets the
|
/// Draws a widget in the whole of this widget's own box, with the frame
|
||||||
/// same region -- the same area for its fractions to be of -- and is put
|
/// forwarded unchanged: what a container that is only a wrapper around
|
||||||
/// where this widget was put. What a container that is only a wrapper
|
/// one child wants, and what every transparent container passes for the
|
||||||
/// around one child wants, since its box is the child's.
|
/// frame.
|
||||||
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> {
|
||||||
let own = self.placement;
|
self.widget_at(id, UiRegion::FULL, [Place::Within(Part::All); 2])
|
||||||
self.widget_at_inner(
|
|
||||||
id,
|
|
||||||
UiRegion::FULL,
|
|
||||||
[Some(own.x), Some(own.y)],
|
|
||||||
Some(ExtentPlacement::Inherit),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What a widget's rules declare its lengths to be, which whoever draws
|
/// Draws a child, saying what its fractions are of and where its drawing
|
||||||
/// it resolves into its box. Reading them depends on nothing -- the box
|
/// goes.
|
||||||
/// that comes of them is kept on the child, and `redraw` compares it
|
|
||||||
/// there.
|
|
||||||
fn declared_lens<W: ?Sized>(&self, id: &StrongWidget<W>) -> [Option<LayoutLen>; 2] {
|
|
||||||
declared_lens(self.rsc.widgets(), id.id())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Takes back a child that was drawn only to find out how long it is.
|
|
||||||
/// Its drawing is dropped and it is not one of this widget's children
|
|
||||||
/// this frame; what it answered is still something this widget asked.
|
|
||||||
pub fn undraw<W: ?Sized>(&mut self, id: &StrongWidget<W>) {
|
|
||||||
self.children.retain(|child| *child != id.id());
|
|
||||||
self.extent_children.retain(|(child, _)| *child != id.id());
|
|
||||||
self.state.undraw_rec(id.id(), self.rsc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Draws a child in `region`, relative to this widget's frame. The child
|
|
||||||
/// resolves declared lengths and reports against that frame, then places
|
|
||||||
/// its drawing by its own alignment.
|
|
||||||
///
|
///
|
||||||
/// `DrawRegion::Extent` gives a part of where this widget's own drawing
|
/// `frame` is that reference, in this widget's own frame coordinates:
|
||||||
/// sits instead, which is what a container whose children belong inside
|
/// [`UiRegion::FULL`] forwards this widget's frame, which is what a
|
||||||
/// its drawing rather than inside the box it was offered wants. The
|
/// container that only divides room passes, so a fraction under it means
|
||||||
/// child's box then follows the extent without this widget's drawing
|
/// the same wherever it sits and however deeply it is nested. Narrowing
|
||||||
/// depending on where that extent is, so moving it re-places the child
|
/// it is for what is decided from above, and a declared length narrows
|
||||||
/// rather than drawing this widget again.
|
/// it here.
|
||||||
pub fn widget_within<'s, W: ?Sized>(
|
|
||||||
&'s mut self,
|
|
||||||
id: &'s StrongWidget<W>,
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Draws a widget in `region`, saying where in it the drawing goes.
|
|
||||||
///
|
///
|
||||||
/// `region` is the child's own area: what a fraction it declares or
|
/// `place` is where the drawing goes, per axis, as a part of this
|
||||||
/// reports is a fraction of, and the coordinates the regions it writes
|
/// widget's extent: see [`Place`]. A narrowed frame is its own extent,
|
||||||
/// compose within. It is the same box on the ask that measures and the
|
/// since the narrowing is what said where the drawing goes.
|
||||||
/// ask that places, which is what stops a fraction under it being
|
|
||||||
/// resolved twice.
|
|
||||||
///
|
|
||||||
/// `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>(
|
pub fn widget_at<'s, W: ?Sized>(
|
||||||
&'s mut self,
|
&'s mut self,
|
||||||
id: &'s StrongWidget<W>,
|
id: &'s StrongWidget<W>,
|
||||||
region: UiRegion,
|
frame: UiRegion,
|
||||||
placement: [Option<UiSpan>; 2],
|
place: [Place; 2],
|
||||||
) -> DrawResult<'s, 'a, W> {
|
) -> 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 region_node = self.rsc.widgets().is_region_node(id.id());
|
||||||
let declared = self.declared_lens(id);
|
let declared = self.declared_lens(id);
|
||||||
let align = self.rsc.widgets().alignment(id.id());
|
let align = self.rsc.widgets().alignment(id.id());
|
||||||
let (local, placement) = ask_box(region, declared, align, placement);
|
let (local, extent) = frame_and_extent(
|
||||||
|
frame,
|
||||||
|
part_of(self.extent, place),
|
||||||
|
narrowed_by(declared, frame),
|
||||||
|
align,
|
||||||
|
);
|
||||||
let within = match local == UiRegion::FULL {
|
let within = match local == UiRegion::FULL {
|
||||||
true => self.region,
|
true => self.frame,
|
||||||
false => local.within(&self.region),
|
false => local.within(&self.frame),
|
||||||
};
|
};
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
if region_node {
|
if region_node {
|
||||||
@@ -264,31 +204,20 @@ impl<'a> Painter<'a> {
|
|||||||
self.children.push(id.id());
|
self.children.push(id.id());
|
||||||
}
|
}
|
||||||
let first_ask = self.offer(id.id());
|
let first_ask = self.offer(id.id());
|
||||||
let given_len = local.size();
|
let offer_place = if first_ask {
|
||||||
let offer_len = match first_ask {
|
place
|
||||||
true => given_len,
|
|
||||||
false => self
|
|
||||||
.state
|
|
||||||
.active
|
|
||||||
.get(&id.id())
|
|
||||||
.map_or(given_len, |a| a.offer_len),
|
|
||||||
};
|
|
||||||
let offer_placement = if first_ask {
|
|
||||||
placement
|
|
||||||
} else {
|
} else {
|
||||||
self.state
|
self.state
|
||||||
.active
|
.active
|
||||||
.get(&id.id())
|
.get(&id.id())
|
||||||
.map_or(placement, |a| a.offer_placement)
|
.map_or(place, |a| a.offer_place)
|
||||||
};
|
};
|
||||||
let px = given_len.to_px(self.px);
|
let px = local.size().to_px(self.px);
|
||||||
let offered_px = offer_len.to_px(self.offered_px);
|
// The answer and what it holds for, both about the place asked in.
|
||||||
// The answer and what it holds for, both about the box asked in. The
|
// The child's record may say something else once its drawing has been
|
||||||
// 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.
|
// placed: a drawing made again in its placed box holds for that box.
|
||||||
let (size, answer_holds, holds) = self.state.draw_inner(
|
let (size, answer_holds, holds) = self.state.draw_inner(
|
||||||
id.id(),
|
id.id(),
|
||||||
within,
|
|
||||||
DrawInfo {
|
DrawInfo {
|
||||||
layer: self.layer,
|
layer: self.layer,
|
||||||
parent: Some(self.id),
|
parent: Some(self.id),
|
||||||
@@ -296,80 +225,47 @@ impl<'a> Painter<'a> {
|
|||||||
parent_move: self.move_idx,
|
parent_move: self.move_idx,
|
||||||
region_node,
|
region_node,
|
||||||
mask: self.mask,
|
mask: self.mask,
|
||||||
given_region: local,
|
frame: local,
|
||||||
offer_len,
|
frame_abs: within,
|
||||||
offer_placement,
|
part: extent,
|
||||||
|
place,
|
||||||
|
offer_place,
|
||||||
px,
|
px,
|
||||||
offered_px,
|
|
||||||
placement,
|
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
measuring,
|
|
||||||
self.rsc,
|
self.rsc,
|
||||||
);
|
);
|
||||||
let in_parent = |holds: LayoutHolds| {
|
let compose = |holds| in_parent(holds, local, extent, place, declared);
|
||||||
let mut result = LayoutHolds::ANY;
|
let holds = compose(holds);
|
||||||
for axis in AXES {
|
match self.under.iter_mut().find(|(child, _)| *child == id.id()) {
|
||||||
let n = axis as usize;
|
Some((_, kept)) => *kept = holds,
|
||||||
let chosen = placement[n].unwrap_or(UiSpan::FULL).len();
|
None => self.under.push((id.id(), holds)),
|
||||||
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 both what
|
|
||||||
// it was given and what it took of that are ranges on the
|
|
||||||
// extent and none of them a range on the frame. That is
|
|
||||||
// what lets this widget's drawing move without being made
|
|
||||||
// again: only the part's length reaches the child, and
|
|
||||||
// where the part sits is re-placed rather than redrawn.
|
|
||||||
Some(ExtentPlacement::Within(part)) if declared[n].is_none() => {
|
|
||||||
result.extent[n] = holds.frame[n]
|
|
||||||
.and(holds.extent[n].through(chosen))
|
|
||||||
.through(part.axis(axis).len());
|
|
||||||
}
|
|
||||||
// A declared length is a length of this widget's frame
|
|
||||||
// wherever the box it sits in came from, so what the child
|
|
||||||
// holds for is a range on the frame either way.
|
|
||||||
_ => {
|
|
||||||
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, and that box
|
|
||||||
// is a part of this widget's extent -- so the same fraction is a
|
|
||||||
// different length once the extent is. Only the report: where the
|
|
||||||
// extent moved without changing what it holds, the drawing under it
|
|
||||||
// is re-placed rather than made again, which is what the extent ask
|
|
||||||
// is for. Pixels come up unchanged and say nothing.
|
|
||||||
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 {
|
DrawResult {
|
||||||
child: id,
|
child: id,
|
||||||
painter: self,
|
painter: self,
|
||||||
size: in_parent_frame(size, local.size(), declared),
|
size: in_parent_frame(size, local.size(), declared),
|
||||||
answer_holds,
|
answer_holds: compose(answer_holds),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Takes back a child that was drawn only to find out how long it is.
|
||||||
|
/// Its drawing is dropped and it is not one of this widget's children
|
||||||
|
/// this frame; what it answered is still something this widget asked.
|
||||||
|
pub fn undraw<W: ?Sized>(&mut self, id: &StrongWidget<W>) {
|
||||||
|
self.children.retain(|child| *child != id.id());
|
||||||
|
self.under.retain(|(child, _)| *child != id.id());
|
||||||
|
self.state.undraw_rec(id.id(), self.rsc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What a widget's rules declare its lengths to be, which whoever draws
|
||||||
|
/// it resolves into its frame. Reading them depends on nothing -- the box
|
||||||
|
/// that comes of them is kept on the child, and `redraw` compares it
|
||||||
|
/// there.
|
||||||
|
fn declared_lens<W: ?Sized>(&self, id: &StrongWidget<W>) -> [Option<LayoutLen>; 2] {
|
||||||
|
declared_lens(self.rsc.widgets(), id.id())
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
/// Asking counts as reading its size.
|
/// Asking counts as reading its size.
|
||||||
pub fn size_hint<W: ?Sized>(&mut self, id: &StrongWidget<W>, axis: Axis) -> Option<LayoutLen> {
|
pub fn size_hint<W: ?Sized>(&mut self, id: &StrongWidget<W>, axis: Axis) -> Option<LayoutLen> {
|
||||||
@@ -398,57 +294,11 @@ 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_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
|
/// 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
|
/// that is itself the one its parent measured -- the question a cold
|
||||||
/// layout asks, whose answer is the one to keep.
|
/// layout asks, whose answer is the one to keep. A drawing made again in
|
||||||
|
/// a box chosen from an answer asks about that box instead, and what it
|
||||||
|
/// hears back is not a measurement of anything.
|
||||||
fn offer(&mut self, child: WidgetId) -> bool {
|
fn offer(&mut self, child: WidgetId) -> bool {
|
||||||
if !self.at_offer || self.offered.contains(&child) {
|
if !self.at_offer || self.offered.contains(&child) {
|
||||||
return false;
|
return false;
|
||||||
@@ -477,11 +327,10 @@ 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: impl Into<DrawRegion>) {
|
pub fn glyphs(&mut self, text: &RenderedText, origin: UiRegion) {
|
||||||
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 the frame/extent composition.
|
// Only the shared origin needs composing through the extent.
|
||||||
let resolved = origin.resolve(self.region, self.placement);
|
let resolved = self.resolve(origin);
|
||||||
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| {
|
||||||
@@ -505,30 +354,44 @@ impl<'a> Painter<'a> {
|
|||||||
color: text.color,
|
color: text.color,
|
||||||
flags: glyph.entry.flags(),
|
flags: glyph.entry.flags(),
|
||||||
},
|
},
|
||||||
origin.map(place),
|
place(origin),
|
||||||
place(resolved),
|
place(resolved),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The box this widget's parent gave it, in the coordinates its own
|
/// The symbolic length of this widget's own box along one axis, in the
|
||||||
/// primitives are written in -- so a region composed `within` it may be
|
/// lengths of its frame that it places its children in. Reading it pins
|
||||||
/// drawn directly. Its own box is [`Self::placement`] of this one.
|
/// the drawing to that length -- and to nothing about where the box
|
||||||
pub fn region(&self) -> UiRegion {
|
/// starts, which is what lets a container move without being drawn
|
||||||
self.region
|
/// again. One axis at a time, because a container that divides one axis
|
||||||
|
/// 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);
|
||||||
|
self.answer_extent_len[axis as usize] = Some(len);
|
||||||
|
len
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Where this widget's drawing goes inside the box it was given, in that
|
/// The symbolic length used to compute this widget's answer, where the
|
||||||
/// box's coordinates: what its own answer took of it, or what its parent
|
/// final drawing itself is rebuilt without depending on that length.
|
||||||
/// chose for it. `FULL` on the ask that measures, since nothing has been
|
pub fn answer_extent_len(&mut self, axis: Axis) -> Len {
|
||||||
/// placed yet.
|
let len = self.extent.axis(axis).len();
|
||||||
///
|
self.answer_extent_len[axis as usize] = Some(len);
|
||||||
/// Reading it is what says the drawing depends on it, so a widget that
|
len
|
||||||
/// positions its own content reads it and is drawn again once its box is
|
}
|
||||||
/// known, and one that fills whatever it is given never is.
|
|
||||||
pub fn placement(&mut self) -> UiRegion {
|
/// Says that the final drawing uses a symbolic length already read for
|
||||||
self.reads_placement = true;
|
/// the answer.
|
||||||
self.placement
|
pub fn drawing_uses_extent_len(&mut self, axis: Axis, len: Len) {
|
||||||
|
debug_assert_eq!(self.extent.axis(axis).len(), len);
|
||||||
|
self.extent_len[axis as usize] = Some(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A part of this widget's box, expressed in its frame coordinates so it
|
||||||
|
/// can be used as a child frame decided here.
|
||||||
|
pub fn extent_part(&self, axis: Axis, part: Part) -> UiSpan {
|
||||||
|
part.of(*self.extent.axis(axis))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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
|
||||||
@@ -556,24 +419,24 @@ 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 {
|
||||||
PxVec2::new(self.px_len(Axis::X), self.px_len(Axis::Y))
|
PxVec2::new(self.px_len(Axis::X), self.px_len(Axis::Y))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This widget's own box in pixels, used only to compute its answer.
|
||||||
|
pub fn answer_px_size(&mut self) -> PxVec2 {
|
||||||
|
PxVec2::new(
|
||||||
|
self.answer_px_len(Axis::X),
|
||||||
|
self.answer_px_len(Axis::Y),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.placement.axis(axis).len();
|
let part = self.extent.axis(axis).len();
|
||||||
let len = part.to_px(self.px.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 {
|
||||||
@@ -582,12 +445,23 @@ impl<'a> Painter<'a> {
|
|||||||
len
|
len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One pixel length used only to compute this widget's answer. The final
|
||||||
|
/// drawing may be retained when that answer is placed in another box.
|
||||||
|
pub fn answer_px_len(&mut self, axis: Axis) -> Px {
|
||||||
|
let len = self.extent.axis(axis).len().to_px(self.px.axis(axis));
|
||||||
|
let own = &mut self.answer_extent_own[axis as usize];
|
||||||
|
if *own == Holds::ANY {
|
||||||
|
*own = Holds::at(len);
|
||||||
|
}
|
||||||
|
len
|
||||||
|
}
|
||||||
|
|
||||||
/// The lengths of this widget's own box on `axis` that what it is drawing
|
/// The lengths of this widget's own box on `axis` that what it is drawing
|
||||||
/// holds for -- the same primitives, in the same fractions and offsets
|
/// holds for -- the same primitives, in the same fractions and offsets
|
||||||
/// 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.placement.axis(axis).len();
|
let part = self.extent.axis(axis).len();
|
||||||
let holds = holds.into();
|
let holds = holds.into();
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
holds.contains(part.to_px(self.px.axis(axis))),
|
holds.contains(part.to_px(self.px.axis(axis))),
|
||||||
@@ -598,30 +472,30 @@ impl<'a> Painter<'a> {
|
|||||||
self.extent_own[axis as usize] = holds;
|
self.extent_own[axis as usize] = holds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One axis of the box this widget's parent gave it, in pixels -- what a
|
/// One axis of this widget's frame in pixels -- what a fraction of its
|
||||||
/// fraction of its area resolves against, and so what a container divides
|
/// area resolves against, and so what a container divides among its
|
||||||
/// among its children. Its own box is a part of this one.
|
/// children. Its own box is a part of this one.
|
||||||
pub fn region_px_len(&mut self, axis: Axis) -> Px {
|
pub fn frame_px_len(&mut self, axis: Axis) -> Px {
|
||||||
let len = self.px.axis(axis);
|
let len = self.px.axis(axis);
|
||||||
let own = &mut self.own[axis as usize];
|
let own = &mut self.frame_own[axis as usize];
|
||||||
if *own == Holds::ANY {
|
if *own == Holds::ANY {
|
||||||
*own = Holds::at(len);
|
*own = Holds::at(len);
|
||||||
}
|
}
|
||||||
len
|
len
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`Self::holds`] stated about the region rather than about this
|
/// [`Self::holds`] stated about the frame rather than about this
|
||||||
/// widget's own box, for a container whose drawing turns on the box it
|
/// widget's own box, for a container whose drawing turns on what its
|
||||||
/// was given rather than on the part of it it took.
|
/// fractions are of rather than on the part of it it took.
|
||||||
pub fn region_holds(&mut self, axis: Axis, holds: impl Into<Holds>) {
|
pub fn frame_holds(&mut self, axis: Axis, holds: impl Into<Holds>) {
|
||||||
let holds = holds.into();
|
let holds = holds.into();
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
holds.contains(self.px.axis(axis)),
|
holds.contains(self.px.axis(axis)),
|
||||||
"'{}' ({:?}) says its drawing holds for lengths that leave out its region",
|
"'{}' ({:?}) says its drawing holds for lengths that leave out its frame",
|
||||||
self.label(),
|
self.label(),
|
||||||
self.id
|
self.id
|
||||||
);
|
);
|
||||||
self.own[axis as usize] = holds;
|
self.frame_own[axis as usize] = holds;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_data(&mut self) -> &mut TextData {
|
pub fn text_data(&mut self) -> &mut TextData {
|
||||||
@@ -709,6 +583,57 @@ impl PrimitiveLike for &TextureHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What a child depends on, said about the boxes the widget that drew it
|
||||||
|
/// has rather than the ones the child was given.
|
||||||
|
///
|
||||||
|
/// `frame` is the child's frame in this widget's frame coordinates and
|
||||||
|
/// `extent` the box it was given, in the child's own frame coordinates. Both
|
||||||
|
/// reach it as one length, so what it holds for maps back through that
|
||||||
|
/// length exactly -- and where the box it was given is this widget's own,
|
||||||
|
/// what it says about that box is what this widget can say about its own.
|
||||||
|
pub(crate) fn in_parent(
|
||||||
|
holds: LayoutHolds,
|
||||||
|
frame: UiRegion,
|
||||||
|
extent: UiRegion,
|
||||||
|
place: [Place; 2],
|
||||||
|
declared: [Option<LayoutLen>; 2],
|
||||||
|
) -> LayoutHolds {
|
||||||
|
let mut result = LayoutHolds::ANY;
|
||||||
|
for axis in AXES {
|
||||||
|
let n = axis as usize;
|
||||||
|
let frame_len = frame.axis(axis).len();
|
||||||
|
result.frame[n] = holds.frame[n].through(frame_len);
|
||||||
|
match (place[n].part(), declared[n]) {
|
||||||
|
// 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, None) if *frame.axis(axis) == UiSpan::FULL => {
|
||||||
|
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.
|
||||||
|
(Part::Of(span), None) => {
|
||||||
|
result.extent[n] = holds.extent[n].through(span.len());
|
||||||
|
}
|
||||||
|
// Its box is a part of this widget's frame: 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.frame[n] = result.frame[n].and(
|
||||||
|
holds.extent[n]
|
||||||
|
.through(extent.axis(axis).len())
|
||||||
|
.through(frame_len),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
/// A child's answer as lengths of the parent's own region. A widget reports
|
/// A child's answer as lengths of the parent's own region. A widget reports
|
||||||
/// a fraction of its own region, and `of` is that region as a length of this
|
/// a fraction of its own region, and `of` is that region as a length of this
|
||||||
/// one. Pixels come through untouched, being that many pixels wherever they
|
/// one. Pixels come through untouched, being that many pixels wherever they
|
||||||
@@ -755,68 +680,90 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What of the box it was given a widget's drawing occupies, as lengths of
|
/// Where a widget's drawing goes inside the part its parent gave it: what
|
||||||
/// that box: the size it reported wherever that is a part to be placed, and
|
/// it reported, on the side of the part its alignment says, and the whole
|
||||||
/// the whole of the box wherever the answer fills it.
|
/// part wherever the answer fills it.
|
||||||
///
|
///
|
||||||
/// A reported fraction is a fraction of the box the widget drew in, where a
|
/// The length it reported is a length of its frame, and the part is one too,
|
||||||
/// declared one is a fraction of the box its parent handed down -- a span
|
/// so this takes one from the other rather than composing it into the part.
|
||||||
/// reporting `rel(1.0)` means all of what it was given, whatever that was a
|
/// That is what makes a fraction the same fraction wherever the part it is
|
||||||
/// fraction of. So this is a length of the box rather than a length composed
|
/// placed in sits and however long it is -- the fraction is resolved once,
|
||||||
/// into it, and a box in pixels is this step from the given box's pixels.
|
/// here, against the frame it was reported of.
|
||||||
pub(crate) fn placed_lens(
|
pub(crate) fn placed_extent(
|
||||||
|
part: UiRegion,
|
||||||
size: Size,
|
size: Size,
|
||||||
declared: [Option<LayoutLen>; 2],
|
declared: [Option<LayoutLen>; 2],
|
||||||
decided: [bool; 2],
|
fill: [bool; 2],
|
||||||
) -> UiVec2 {
|
align: RegionAlign,
|
||||||
let mut lens = UiVec2::FULL_SIZE;
|
) -> UiRegion {
|
||||||
for (axis, (declared, decided)) in AXES.into_iter().zip(declared.into_iter().zip(decided)) {
|
let mut placed = part;
|
||||||
let reported = size.axis(axis);
|
|
||||||
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 {
|
for axis in AXES {
|
||||||
// The whole of the box is already where it sits, and the arithmetic
|
let n = axis as usize;
|
||||||
// below is the identity for it.
|
let reported = size.axis(axis);
|
||||||
if lens.axis(axis) == Len::FULL {
|
if fills(reported, declared[n], fill[n]) {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A declared axis gets a frame of that length, aligned within the parent's
|
/// The part of a widget's own box a `place` names, in the coordinates that
|
||||||
/// slot (or the offer). Undeclared axes keep the offered frame and chosen
|
/// box is in.
|
||||||
/// placement, so their reported fractions retain that reference.
|
pub(crate) fn part_of(extent: UiRegion, place: [Place; 2]) -> UiRegion {
|
||||||
pub(crate) fn ask_box(
|
let mut part = extent;
|
||||||
mut region: UiRegion,
|
for axis in AXES {
|
||||||
declared: [Option<LayoutLen>; 2],
|
*part.axis_mut(axis) = place[axis as usize].part().of(*extent.axis(axis));
|
||||||
align: RegionAlign,
|
|
||||||
placement: [Option<UiSpan>; 2],
|
|
||||||
) -> (UiRegion, [Option<UiSpan>; 2]) {
|
|
||||||
let mut placed = [None; 2];
|
|
||||||
for (axis, (len, chosen)) in AXES.into_iter().zip(declared.into_iter().zip(placement)) {
|
|
||||||
let Some(len) = len else {
|
|
||||||
placed[axis as usize] = chosen;
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let span = region.axis_mut(axis);
|
|
||||||
let len = Len::from_parts(len.rel, len.px);
|
|
||||||
let slot = chosen.unwrap_or(*span);
|
|
||||||
span.start = slot.start + (slot.len() - len).scale(align.axis(axis).rel());
|
|
||||||
span.end = span.start + len;
|
|
||||||
}
|
}
|
||||||
(region, placed)
|
part
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The length a rule gives a child's frame, per axis: a fraction in it is a
|
||||||
|
/// fraction of the frame the child was given, which is the one length the
|
||||||
|
/// rule can mean.
|
||||||
|
pub(crate) fn narrowed_by(declared: [Option<LayoutLen>; 2], frame: UiRegion) -> [Option<Len>; 2] {
|
||||||
|
AXES.map(|axis| {
|
||||||
|
declared[axis as usize]
|
||||||
|
.map(|len| Len::from_parts(len.rel, len.px).within_len(frame.axis(axis).len()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The frame a child is asked in and the box its drawing goes in, both in
|
||||||
|
/// the coordinates of the widget asking.
|
||||||
|
///
|
||||||
|
/// `frame` is what the caller said the child's fractions are of, and `part`
|
||||||
|
/// what of the caller's own box the drawing takes. `narrow` is the length a
|
||||||
|
/// declared rule gives the frame, which makes the frame the box the drawing
|
||||||
|
/// goes in -- a rule is what decided where it goes, and there is nothing
|
||||||
|
/// left to place inside it. A caller that narrowed the frame itself said the
|
||||||
|
/// same thing.
|
||||||
|
///
|
||||||
|
/// The length is the caller's to supply so that a widget asked again gets
|
||||||
|
/// the frame it already has rather than a second resolution of its rule.
|
||||||
|
pub(crate) fn frame_and_extent(
|
||||||
|
mut frame: UiRegion,
|
||||||
|
part: UiRegion,
|
||||||
|
narrow: [Option<Len>; 2],
|
||||||
|
align: RegionAlign,
|
||||||
|
) -> (UiRegion, UiRegion) {
|
||||||
|
let mut extent = part;
|
||||||
|
for (axis, narrow) in AXES.into_iter().zip(narrow) {
|
||||||
|
let span = frame.axis_mut(axis);
|
||||||
|
let narrowed = match narrow {
|
||||||
|
Some(len) => {
|
||||||
|
let slot = part.axis(axis);
|
||||||
|
let start = slot.start + (slot.len() - len).scale(align.axis(axis).rel());
|
||||||
|
*span = UiSpan::new(start, start + len);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
None => *span != UiSpan::FULL,
|
||||||
|
};
|
||||||
|
if narrowed {
|
||||||
|
*extent.axis_mut(axis) = UiSpan::FULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(frame, extent)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
use crate::{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),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Part {
|
||||||
|
/// Where it lands in the coordinates `extent` is in.
|
||||||
|
pub(crate) fn of(self, extent: UiSpan) -> 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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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,
|
||||||
|
}
|
||||||
+329
-332
File diff suppressed because it is too large.
Load diff
+9
-7
@@ -117,16 +117,18 @@ 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 mut top = UiRegion::FULL;
|
let cut = Len::from_parts(Rel::ZERO, Px::from_int(40));
|
||||||
top.y.end = top.y.start.offset(Px::from_int(40));
|
let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut)));
|
||||||
let measured = painter.widget_within(&self.probe, top).len(Axis::X);
|
let measured = painter
|
||||||
|
.widget_at(&self.probe, UiRegion::FULL, [Place::Within(Part::All), top])
|
||||||
|
.len(Axis::X);
|
||||||
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
||||||
|
|
||||||
let mut below = UiRegion::FULL;
|
let below = Place::Within(Part::Of(UiSpan::new(cut, Len::FULL)));
|
||||||
below.y.start = below.y.start.offset(Px::from_int(40));
|
let place = [Place::Within(Part::All), below];
|
||||||
match px > Px::from_f32(self.threshold) {
|
match px > Px::from_f32(self.threshold) {
|
||||||
true => painter.widget_within(&self.wide, below),
|
true => painter.widget_at(&self.wide, UiRegion::FULL, place),
|
||||||
false => painter.widget_within(&self.narrow, below),
|
false => painter.widget_at(&self.narrow, UiRegion::FULL, place),
|
||||||
};
|
};
|
||||||
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(DrawRegion::Extent(UiRegion::FULL));
|
painter.set_mask(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,7 +7,14 @@ 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 {
|
||||||
let region = UiRegion::FULL.offset(self.amt);
|
// The whole of this widget's box, moved: the frame passes through, so
|
||||||
painter.widget_within(&self.inner, region).size()
|
// what the child declares or reports means the same as it would
|
||||||
|
// 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, UiRegion::FULL, place).size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,8 +13,24 @@ 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());
|
//
|
||||||
let inner = painter.widget_within(&self.inner, inside).size();
|
// The padding goes around what it pads: the frame passes through, so
|
||||||
|
// the inner's fractions mean what they would without it, and only
|
||||||
|
// the box it draws in is moved in by the pixels. Said as a part of
|
||||||
|
// this widget's own box in that box's own lengths, so nothing here
|
||||||
|
// reads how long the box is -- and a box chosen from this widget's
|
||||||
|
// own answer therefore does not feed back into that answer.
|
||||||
|
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),
|
||||||
|
];
|
||||||
|
let inner = painter.widget_at(&self.inner, UiRegion::FULL, 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,15 +12,14 @@ 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);
|
||||||
// Draw in the whole container only when its scrolling-axis length is
|
// Measured in the whole viewport, then drawn at the scrolled offset.
|
||||||
// not already known, then draw it at the scrolled offset.
|
|
||||||
let whole = UiRegion::FULL;
|
let whole = UiRegion::FULL;
|
||||||
let own = painter.placement();
|
let answer_len = painter
|
||||||
let answer_len =
|
.widget_at(&self.inner, whole, [Place::Fill(Part::All); 2])
|
||||||
painter.measure_len(&self.inner, self.axis, whole, [Some(own.x), Some(own.y)]);
|
.len(self.axis);
|
||||||
let content = answer_len.apply_leftover();
|
let fixed = Len::from_parts(answer_len.rel, answer_len.px).to_px(container_len);
|
||||||
self.container_len = container_len;
|
self.container_len = container_len;
|
||||||
self.content_len = content.to_px(container_len);
|
self.content_len = fixed.max(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;
|
||||||
@@ -33,9 +32,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 = content.rel == Rel::ZERO;
|
let fixed_len = answer_len.rel == Rel::ZERO && answer_len.leftover == Weight::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, self.content_len..=Px::MAX);
|
painter.holds(self.axis, fixed..=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);
|
||||||
@@ -46,7 +45,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 region = UiRegion::FULL;
|
let mut content = UiSpan::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
|
||||||
@@ -55,19 +54,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 offset = UiVec2::from_axis(
|
let start = Len::from_parts(Rel::ZERO, anchor - self.amt);
|
||||||
self.axis,
|
content = UiSpan::new(start, start.offset(self.content_len));
|
||||||
Len::from_parts(Rel::ZERO, anchor - self.amt),
|
|
||||||
Len::ZERO,
|
|
||||||
);
|
|
||||||
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
|
// The viewport is the inner's frame, so a fraction it declares or
|
||||||
// reports is a fraction of what is on screen rather than of the
|
// 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
|
// content box its own answer decided. Where it is drawn is the
|
||||||
// box, scrolled.
|
// content box, scrolled.
|
||||||
painter.widget_at(&self.inner, whole, [Some(region.x), Some(region.y)]);
|
painter.widget_at(
|
||||||
|
&self.inner,
|
||||||
|
whole,
|
||||||
|
self.axis
|
||||||
|
.pair(Place::Fill(Part::From(content)), Place::Fill(Part::All)),
|
||||||
|
);
|
||||||
// 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
|
||||||
|
|||||||
+53
-34
@@ -10,34 +10,30 @@ 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 span of the region it was given.
|
// The row: this span's own box, as a length of the frame its children
|
||||||
// Its children are laid out along it, and what they declare or report
|
// are laid out against. Its start is nothing's business -- a slot is
|
||||||
// is a fraction of the region -- the area this span was told it has,
|
// a length from it -- so what this reads is the length alone.
|
||||||
// which it passes on unchanged.
|
let far = painter.answer_extent_len(axis);
|
||||||
let own = painter.placement();
|
let measure_along = |from: Len, to: Len| match self.dir.sign {
|
||||||
let row = *own.axis(axis);
|
Sign::Pos => UiSpan::new(from, to),
|
||||||
// Across itself the span's own box is the child's region: a span is
|
Sign::Neg => UiSpan::new(far - to, far - from),
|
||||||
// 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 {
|
|
||||||
Sign::Pos => UiSpan::new(row.start + from, row.start + to),
|
|
||||||
Sign::Neg => UiSpan::new(row.end - to, row.end - from),
|
|
||||||
};
|
};
|
||||||
let far = row.len();
|
// Across itself the child sits where its own alignment says, in the
|
||||||
// A length for every child before their final boxes are chosen: from
|
// whole of the row: a span is what contains its children there, and
|
||||||
// a hint where one exists, and from drawing otherwise.
|
// nothing divides that axis.
|
||||||
|
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 drawn in is the room left from the cursor,
|
||||||
|
// because a text has to wrap at the width actually there.
|
||||||
let mut cursor = Len::rel_min();
|
let mut cursor = Len::rel_min();
|
||||||
let mut lens = 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 {
|
||||||
// The whole region is the child's, so `rel(0.5)` is half the area
|
let room = Place::Fill(Part::From(measure_along(cursor, far)));
|
||||||
// this span was given whatever else is in it and wherever this
|
let len = painter
|
||||||
// child sits among them. What it is placed in is the room left
|
.widget_at(child, UiRegion::FULL, axis.pair(room, across))
|
||||||
// from the cursor, because a text has to wrap at the width
|
.len(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;
|
||||||
lens.push(len);
|
lens.push(len);
|
||||||
@@ -54,9 +50,10 @@ impl Widget for Span {
|
|||||||
|sum, len| sum + *len,
|
|sum, len| sum + *len,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let fixed_total = Len::from_parts(total.rel, total.px);
|
||||||
// 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 region rather than a number of pixels.
|
// fixed, as a length of the frame rather than a number of pixels.
|
||||||
let room = far - Len::from_parts(total.rel, total.px);
|
let room = far - fixed_total;
|
||||||
// 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`
|
||||||
// itself, and answered back through the same expression, so the
|
// itself, and answered back through the same expression, so the
|
||||||
@@ -68,14 +65,26 @@ 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 = room.to_px(painter.region_px_len(axis)) > Px::ZERO;
|
shares = room.to_px(painter.frame_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.region_holds(axis, holds.through(room));
|
painter.frame_holds(axis, holds.through(room));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if shares {
|
||||||
|
painter.drawing_uses_extent_len(axis, far);
|
||||||
|
}
|
||||||
|
let drawing_far = match shares {
|
||||||
|
true => far,
|
||||||
|
false => fixed_total,
|
||||||
|
};
|
||||||
|
let along = |from: Len, to: Len| match self.dir.sign {
|
||||||
|
Sign::Pos => UiSpan::new(from, to),
|
||||||
|
Sign::Neg => UiSpan::new(drawing_far - to, drawing_far - from),
|
||||||
|
};
|
||||||
|
|
||||||
// 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
|
||||||
// rule beside it gives that length outright, and then reading them
|
// rule beside it gives that length outright, and then reading them
|
||||||
// answers nothing and makes its size depend on theirs for it. A rule
|
// answers nothing and makes its size depend on theirs for it. A rule
|
||||||
@@ -109,12 +118,22 @@ 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; across it the
|
// Along the row the span says where the child goes, and that slot
|
||||||
// child sits where its own alignment says. Its region is the
|
// is the drawing's box outright rather than something to place an
|
||||||
// whole of what this span was given either way, which is what its
|
// answer inside again.
|
||||||
// fractions are of.
|
let span = along(from, start);
|
||||||
let placed =
|
let (frame, slot) = match len.leftover > Weight::ZERO && shares {
|
||||||
painter.widget_at(child, region, axis.pair(Some(along(from, start)), None));
|
true => (
|
||||||
|
UiRegion::from_axis(
|
||||||
|
axis,
|
||||||
|
painter.extent_part(axis, Part::From(span)),
|
||||||
|
UiSpan::FULL,
|
||||||
|
),
|
||||||
|
Place::Fill(Part::All),
|
||||||
|
),
|
||||||
|
false => (UiRegion::FULL, Place::Fill(Part::From(span))),
|
||||||
|
};
|
||||||
|
let placed = painter.widget_at(child, frame, axis.pair(slot, across));
|
||||||
if shrinks {
|
if shrinks {
|
||||||
let used = placed.len(!axis);
|
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
|
||||||
|
|||||||
@@ -13,17 +13,18 @@ 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 keeps the stack's whole region as
|
// Whichever child sizes the stack is given the stack's whole box --
|
||||||
// its own -- the stack is the length that child asked for, so taking
|
// the stack is the length that child asked for, so placing that
|
||||||
// the fraction of the stack's box again would take it twice -- and is
|
// answer inside the box it decided would apply it twice.
|
||||||
// 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.widget(child).size()
|
painter
|
||||||
|
.widget_at(child, UiRegion::FULL, [Place::Fill(Part::All); 2])
|
||||||
|
.size()
|
||||||
}
|
}
|
||||||
None => Size::LEFTOVER,
|
None => Size::LEFTOVER,
|
||||||
};
|
};
|
||||||
@@ -32,10 +33,15 @@ impl Widget for Stack {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
painter.child_layer_at(i);
|
painter.child_layer_at(i);
|
||||||
// Every other child has the stack's own box for its region, since
|
let place = [Axis::X, Axis::Y].map(|axis| {
|
||||||
// the stack is what contains it, and where it sits in one bigger
|
let len = size.axis(axis);
|
||||||
// than itself is its own business.
|
let part = match len.leftover > Weight::ZERO {
|
||||||
painter.widget_within(child, DrawRegion::Extent(UiRegion::FULL));
|
true => Part::All,
|
||||||
|
false => Part::From(UiSpan::new(Len::ZERO, Len::from_parts(len.rel, len.px))),
|
||||||
|
};
|
||||||
|
Place::Within(part)
|
||||||
|
});
|
||||||
|
painter.widget_at(child, UiRegion::FULL, place);
|
||||||
}
|
}
|
||||||
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, DrawRegion::Extent(region));
|
painter.glyphs(tex, region);
|
||||||
(region, size)
|
(region, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,16 +21,18 @@ 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 mut top = UiRegion::FULL;
|
let cut = Len::from_parts(Rel::ZERO, Px::from_int(40));
|
||||||
top.y.end = top.y.start.offset(Px::from_int(40));
|
let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut)));
|
||||||
let measured = painter.widget_within(&self.probe, top).len(Axis::X);
|
let measured = painter
|
||||||
|
.widget_at(&self.probe, UiRegion::FULL, [Place::Within(Part::All), top])
|
||||||
|
.len(Axis::X);
|
||||||
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
||||||
|
|
||||||
let mut below = UiRegion::FULL;
|
let below = Place::Within(Part::From(UiSpan::new(cut, painter.extent_len(Axis::Y))));
|
||||||
below.y.start = below.y.start.offset(Px::from_int(40));
|
let place = [Place::Within(Part::All), below];
|
||||||
match px > Px::from_f32(self.threshold) {
|
match px > Px::from_f32(self.threshold) {
|
||||||
true => painter.widget_within(&self.wide, below),
|
true => painter.widget_at(&self.wide, UiRegion::FULL, place),
|
||||||
false => painter.widget_within(&self.narrow, below),
|
false => painter.widget_at(&self.narrow, UiRegion::FULL, place),
|
||||||
};
|
};
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-7
@@ -83,11 +83,12 @@ 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}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The same reading through a pad: its inset is the whole box less the
|
/// The same reading through a pad: padding goes around what it pads and
|
||||||
/// padding, so half of the inset plus the padding is half the box plus one
|
/// does not narrow what a fraction under it is a fraction of, so half of the
|
||||||
/// padding, not two.
|
/// window plus the padding is what the pad takes and where the next child
|
||||||
|
/// starts.
|
||||||
#[test]
|
#[test]
|
||||||
fn a_pad_reports_a_fraction_of_its_inset_as_a_fraction_of_its_box() {
|
fn a_pad_puts_its_padding_around_a_fraction_of_the_whole_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);
|
||||||
@@ -96,8 +97,9 @@ fn a_pad_reports_a_fraction_of_its_inset_as_a_fraction_of_its_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, padded, (0, 0), (210, 100));
|
assert_corners!(h, inner, (10, 10), (210, 90));
|
||||||
assert_corners!(h, tail, (210, 0), (310, 100));
|
assert_corners!(h, padded, (0, 0), (220, 100));
|
||||||
|
assert_corners!(h, tail, (220, 0), (320, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -426,7 +428,8 @@ 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.parent_move, active.region);
|
let drawn = active.extent.within(&active.frame_abs);
|
||||||
|
let region = h.render.moves.resolve(active.parent_move, drawn);
|
||||||
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());
|
||||||
|
|||||||
+137
-105
@@ -12,6 +12,7 @@ struct Counted {
|
|||||||
draws: Rc<Cell<usize>>,
|
draws: Rc<Cell<usize>>,
|
||||||
size: Size,
|
size: Size,
|
||||||
reads_box: bool,
|
reads_box: bool,
|
||||||
|
reads_answer_box: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for Counted {
|
impl Widget for Counted {
|
||||||
@@ -19,6 +20,8 @@ impl Widget for Counted {
|
|||||||
self.draws.set(self.draws.get() + 1);
|
self.draws.set(self.draws.get() + 1);
|
||||||
if self.reads_box {
|
if self.reads_box {
|
||||||
painter.px_size();
|
painter.px_size();
|
||||||
|
} else if self.reads_answer_box {
|
||||||
|
painter.answer_px_size();
|
||||||
}
|
}
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
@@ -38,11 +41,18 @@ fn counted(h: &mut Harness, size: Size, reads_box: bool) -> (WeakWidget<Counted>
|
|||||||
draws: draws.clone(),
|
draws: draws.clone(),
|
||||||
size,
|
size,
|
||||||
reads_box,
|
reads_box,
|
||||||
|
reads_answer_box: false,
|
||||||
}
|
}
|
||||||
.add(&mut h.rsc);
|
.add(&mut h.rsc);
|
||||||
(id, Counts(draws))
|
(id, Counts(draws))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn answer_counted(h: &mut Harness, size: Size) -> (WeakWidget<Counted>, Counts) {
|
||||||
|
let (id, draws) = counted(h, size, false);
|
||||||
|
h.rsc[id].reads_answer_box = true;
|
||||||
|
(id, draws)
|
||||||
|
}
|
||||||
|
|
||||||
struct Layered {
|
struct Layered {
|
||||||
children: [StrongWidget<Rect>; 2],
|
children: [StrongWidget<Rect>; 2],
|
||||||
_revision: usize,
|
_revision: usize,
|
||||||
@@ -156,8 +166,8 @@ 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);
|
||||||
// Only the available length changes: positioning the final slot does
|
// Its final slot is a parent decision, so it is evaluated there after
|
||||||
// not invalidate a numeric size read.
|
// the provisional ask established its length.
|
||||||
assert_eq!(asked_draws.get(), 2);
|
assert_eq!(asked_draws.get(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,9 +223,12 @@ 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 mut region = UiRegion::FULL;
|
let top = UiSpan::new(Len::ZERO, Len::from_parts(Rel::ZERO, len.px));
|
||||||
region.y.end = region.y.start.offset(len.px);
|
painter.widget_at(
|
||||||
painter.widget_within(&self.inner, region);
|
&self.inner,
|
||||||
|
UiRegion::FULL,
|
||||||
|
[Place::Within(Part::All), Place::Within(Part::From(top))],
|
||||||
|
);
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,7 +250,7 @@ fn a_parent_that_only_read_a_hint_relays_out_when_the_hint_changes() {
|
|||||||
assert_corners!(h, inner, (0, 0), (400, 120));
|
assert_corners!(h, inner, (0, 0), (400, 120));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads its box's size, which nothing but its own draw can put right.
|
/// Reads its box's size to compute its answer.
|
||||||
struct ReadsBox {
|
struct ReadsBox {
|
||||||
draws: Rc<Cell<usize>>,
|
draws: Rc<Cell<usize>>,
|
||||||
}
|
}
|
||||||
@@ -245,26 +258,36 @@ struct ReadsBox {
|
|||||||
impl Widget for ReadsBox {
|
impl Widget for ReadsBox {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
self.draws.set(self.draws.get() + 1);
|
self.draws.set(self.draws.get() + 1);
|
||||||
Size::from_px(painter.px_size().div_int(4))
|
Size::from_px(painter.answer_px_size().div_int(4))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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, without saying that the
|
/// Both report a quarter of what they read. Their empty drawings are
|
||||||
/// drawing holds there too, so each length they are asked at costs two draws:
|
/// independent of that read, so a changed question 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>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ReadsDrawingWidth {
|
||||||
|
draws: Rc<Cell<usize>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Widget for ReadsDrawingWidth {
|
||||||
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
|
self.draws.set(self.draws.get() + 1);
|
||||||
|
painter.px_len(Axis::X);
|
||||||
|
Size::LEFTOVER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Widget for ReadsWidth {
|
impl Widget for ReadsWidth {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
self.draws.set(self.draws.get() + 1);
|
self.draws.set(self.draws.get() + 1);
|
||||||
Size::from_px(PxVec2::new(
|
Size::from_px(PxVec2::new(
|
||||||
painter.px_len(Axis::X).div_int(4),
|
painter.answer_px_len(Axis::X).div_int(4),
|
||||||
Px::from_int(20),
|
Px::from_int(20),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -305,6 +328,52 @@ 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,
|
||||||
|
reads_answer_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.
|
||||||
@@ -336,7 +405,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 + 2);
|
assert_eq!(draws.get(), settled + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -356,7 +425,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 + 2, "width changes its answer");
|
assert_eq!(draws.get(), settled + 1, "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
|
||||||
@@ -383,7 +452,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 + 2);
|
assert_eq!(draws.get(), settled + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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
|
||||||
@@ -452,7 +521,7 @@ fn a_change_two_levels_under_its_reader_still_reaches_it() {
|
|||||||
// Every wrapper up to the outer pad read the size below it, so the outer
|
// Every wrapper up to the outer pad read the size below it, so the outer
|
||||||
// pad is what draws again -- and the span it hands the box to is the same
|
// pad is what draws again -- and the span it hands the box to is the same
|
||||||
// size as before, which is what lets a draw reuse its way past the leaf.
|
// size as before, which is what lets a draw reuse its way past the leaf.
|
||||||
let (leaf, _) = counted(&mut h, Size::px((100, 100).into()), true);
|
let (leaf, _) = counted(&mut h, Size::px((100, 100).into()), false);
|
||||||
let padded = leaf.pad(10).add(&mut h.rsc);
|
let padded = leaf.pad(10).add(&mut h.rsc);
|
||||||
let below = rect(Color::RED).add(&mut h.rsc);
|
let below = rect(Color::RED).add(&mut h.rsc);
|
||||||
h.set_root((padded, below).span(Dir::DOWN).pad(12));
|
h.set_root((padded, below).span(Dir::DOWN).pad(12));
|
||||||
@@ -749,36 +818,6 @@ 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>) {
|
||||||
@@ -858,7 +897,14 @@ 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_within(&self.child, self.region);
|
painter.widget_at(
|
||||||
|
&self.child,
|
||||||
|
UiRegion::FULL,
|
||||||
|
[
|
||||||
|
Place::Within(Part::From(self.region.x)),
|
||||||
|
Place::Within(Part::From(self.region.y)),
|
||||||
|
],
|
||||||
|
);
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -866,7 +912,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(DrawRegion::Extent(UiRegion::FULL));
|
painter.set_mask(UiRegion::FULL);
|
||||||
painter.primitive(RectPrimitive::color(Color::BLUE));
|
painter.primitive(RectPrimitive::color(Color::BLUE));
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
@@ -915,43 +961,6 @@ 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 {
|
||||||
@@ -966,8 +975,7 @@ 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, DrawRegion::Frame(origin));
|
painter.glyphs(text, origin);
|
||||||
painter.glyphs(text, DrawRegion::Extent(origin));
|
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -981,7 +989,10 @@ fn glyph_origins_compose_identically_when_drawn_and_when_retained() {
|
|||||||
painter.widget_at(
|
painter.widget_at(
|
||||||
&self.child,
|
&self.child,
|
||||||
self.region,
|
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
|
||||||
}
|
}
|
||||||
@@ -1076,7 +1087,7 @@ fn a_declared_size_change_stops_at_an_independent_parent() {
|
|||||||
fn an_unmeasured_child_still_invalidates_its_parents_drawing_on_resize() {
|
fn an_unmeasured_child_still_invalidates_its_parents_drawing_on_resize() {
|
||||||
let mut h = Harness::new((400, 200));
|
let mut h = Harness::new((400, 200));
|
||||||
let draws = Rc::new(Cell::new(0));
|
let draws = Rc::new(Cell::new(0));
|
||||||
let leaf = ReadsWidth {
|
let leaf = ReadsDrawingWidth {
|
||||||
draws: draws.clone(),
|
draws: draws.clone(),
|
||||||
}
|
}
|
||||||
.add(&mut h.rsc);
|
.add(&mut h.rsc);
|
||||||
@@ -1087,7 +1098,7 @@ fn an_unmeasured_child_still_invalidates_its_parents_drawing_on_resize() {
|
|||||||
h.frame();
|
h.frame();
|
||||||
|
|
||||||
assert!(draws.get() > settled);
|
assert!(draws.get() > settled);
|
||||||
assert_corners!(h, leaf, (300, 90), (500, 110));
|
assert_corners!(h, leaf, (0, 0), (800, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1128,7 +1139,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_frames_follow_the_extent_without_drawing_again() {
|
fn padding_and_stack_boxes_follow_the_extent_without_drawing_again() {
|
||||||
struct Observed<W> {
|
struct Observed<W> {
|
||||||
widget: W,
|
widget: W,
|
||||||
draws: Rc<Cell<usize>>,
|
draws: Rc<Cell<usize>>,
|
||||||
@@ -1148,7 +1159,10 @@ fn padding_and_stack_frames_follow_the_extent_without_drawing_again() {
|
|||||||
painter.widget_at(
|
painter.widget_at(
|
||||||
&self.child,
|
&self.child,
|
||||||
UiRegion::FULL,
|
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
|
||||||
}
|
}
|
||||||
@@ -1179,13 +1193,18 @@ fn padding_and_stack_frames_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, UiRegion::FULL);
|
let (root, leaf, fixed, draws) = plant(&mut warm, at(0.13));
|
||||||
for (start, end) in [(0.13, 0.83), (-0.17, 1.23), (0.31, 0.67)] {
|
for start in [0.13, -0.17, 0.31] {
|
||||||
let extent = UiRegion::new(
|
let extent = at(start);
|
||||||
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();
|
||||||
@@ -1214,7 +1233,7 @@ fn moving_an_extent_child_preserves_the_slot_chosen_from_its_measurement() {
|
|||||||
struct Measured;
|
struct Measured;
|
||||||
impl Widget for Measured {
|
impl Widget for Measured {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
let width = painter.px_len(Axis::X);
|
let width = painter.answer_px_len(Axis::X);
|
||||||
painter.primitive(RectPrimitive::color(Color::BLUE));
|
painter.primitive(RectPrimitive::color(Color::BLUE));
|
||||||
Size::from((80, if width > Px::from_int(100) { 40 } else { 60 }))
|
Size::from((80, if width > Px::from_int(100) { 40 } else { 60 }))
|
||||||
}
|
}
|
||||||
@@ -1229,11 +1248,11 @@ fn moving_an_extent_child_preserves_the_slot_chosen_from_its_measurement() {
|
|||||||
&self.child,
|
&self.child,
|
||||||
UiRegion::FULL,
|
UiRegion::FULL,
|
||||||
[
|
[
|
||||||
Some(UiSpan::new(
|
Place::Fill(Part::From(UiSpan::new(
|
||||||
Len::px(self.start),
|
Len::px(self.start),
|
||||||
Len::px(self.start + 200.0),
|
Len::px(self.start + 200.0),
|
||||||
)),
|
))),
|
||||||
Some(UiSpan::FULL),
|
Place::Fill(Part::From(UiSpan::FULL)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
Size::LEFTOVER
|
Size::LEFTOVER
|
||||||
@@ -1267,7 +1286,14 @@ 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_within(&self.child, DrawRegion::Extent(self.region))
|
.widget_at(
|
||||||
|
&self.child,
|
||||||
|
UiRegion::FULL,
|
||||||
|
[
|
||||||
|
Place::Within(Part::From(self.region.x)),
|
||||||
|
Place::Within(Part::From(self.region.y)),
|
||||||
|
],
|
||||||
|
)
|
||||||
.size()
|
.size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1283,7 +1309,10 @@ fn extent_frames_keep_fractional_reports_and_numeric_dependencies_valid() {
|
|||||||
.widget_at(
|
.widget_at(
|
||||||
&self.child,
|
&self.child,
|
||||||
UiRegion::FULL,
|
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(),
|
||||||
);
|
);
|
||||||
@@ -1304,7 +1333,10 @@ fn extent_frames_keep_fractional_reports_and_numeric_dependencies_valid() {
|
|||||||
} else {
|
} else {
|
||||||
Size::from((80, 27))
|
Size::from((80, 27))
|
||||||
};
|
};
|
||||||
let (leaf, _) = counted(h, size, !fractional);
|
let (leaf, _) = match fractional {
|
||||||
|
true => counted(h, size, false),
|
||||||
|
false => answer_counted(h, size),
|
||||||
|
};
|
||||||
let child = Container {
|
let child = Container {
|
||||||
child: leaf.add_strong(&mut h.rsc),
|
child: leaf.add_strong(&mut h.rsc),
|
||||||
region,
|
region,
|
||||||
|
|||||||
+64
-1
@@ -60,6 +60,69 @@ 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
|
||||||
@@ -71,7 +134,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(painter.region());
|
painter.set_mask(UiRegion::FULL);
|
||||||
painter.widget(&self.0).size()
|
painter.widget(&self.0).size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,180 @@ 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
|
||||||
|
|||||||
Reference in new issue
Block a user