`along` said nothing about what it did. It is `Span::slot` now: the
stretch of the row between two distances from where the span starts
laying out, as a span of its own box, with the mirror for a negative
direction in one place. `far` is `row`, which is what the comment above
it already called it, and `shares` is `has_room` beside the
`any_leftover` it was folded into. `reached` now guards on the leftover
weight it divides by rather than on the numerator that happened to be
zero with it.
The pairs layout returns are named rather than positional: `Answer`
{size, holds} and `Drawn` {answer, drawing_holds} replace
`(Size, LayoutHolds)` and a three-tuple with two `LayoutHolds` in it,
which was the one shape the cold dump exists to catch. `try_reuse`
answers `bool` rather than `Option<()>`, and the four hand-written
copies of `move_idx != parent_move` are `ActiveData::is_region_node`.
`AXES` was declared in three modules; it is `Axis::BOTH`. `rel_min`,
`rel_max` and the unused `select_len` are gone -- `ZERO` and `FULL`
already said those. Three doc comments sat on `impl` blocks instead of
the single method inside them. `reposition` and `redepth` walked their
children by index, looking the parent up again per child; both take the
list and put it back. `Scroll`'s `fixed` and `fixed_len` are
`answer_px` and `answer_is_px`, which says which one is the length.
fmt, workspace clippy under `-D warnings` with and without
`layout-diagnostics`, and the workspace tests are clean. The cold dump
over 400 depth-5 trees is byte-identical to `6c84b6f`: 34,492 boxes,
no seed moved.
102 lines
4.6 KiB
Rust
102 lines
4.6 KiB
Rust
use crate::{
|
|
Declared, LayerId, LayoutHolds, MaskIdx, MoveIdx, PlaceDesc, RegionAlign, RetainedPrimitive,
|
|
Size, TextureHandle, UiRegion, UiVec2, WidgetId,
|
|
};
|
|
|
|
/// What is kept of a widget its parent has asked about. `drawn` says whether
|
|
/// it currently draws; one that does not is kept so that a change to it, or
|
|
/// under it, still reaches whoever asked.
|
|
#[derive(Debug)]
|
|
pub struct ActiveData {
|
|
pub id: WidgetId,
|
|
/// Where its drawing goes, in its region node's coordinates.
|
|
pub placement: UiRegion,
|
|
/// What a fraction declared or reported under this widget is a fraction
|
|
/// of, as a length of the window.
|
|
pub rel_base: UiVec2,
|
|
/// Where its drawing was put, and where it was asked. The two differ
|
|
/// where a container asks in one place and puts the answer in another --
|
|
/// a row measures from its cursor and puts the child in its slot. Each
|
|
/// carries the rel base that ask stated, so asking again from either is
|
|
/// the same question it was.
|
|
pub placed: PlaceDesc,
|
|
pub asked: PlaceDesc,
|
|
/// The box it was asked in, in the parent's region-node coordinates: the
|
|
/// box its drawing was made in and the one its contract is about. Its
|
|
/// drawing is placed elsewhere by re-expression, never by asking again.
|
|
pub region: UiRegion,
|
|
/// The measured answer and its dependencies. A hint-only dependency or
|
|
/// a widget first encountered during placement has no measurement yet.
|
|
pub answer: Option<Answer>,
|
|
/// Asked more than once in its parent's last draw -- measured in one box
|
|
/// and then asked in the one the parent decided. The parent's layout
|
|
/// rests on the first answer and its drawing on the last, so only the
|
|
/// parent can ask either again.
|
|
pub re_asked: bool,
|
|
/// What the widget reported, in window-unit lengths.
|
|
pub size: Size,
|
|
/// The window and region reads that this drawing holds for, and the
|
|
/// rel base and region it pinned.
|
|
pub holds: LayoutHolds,
|
|
pub drawn: bool,
|
|
pub parent: Option<WidgetId>,
|
|
/// How far down the tree it was drawn, the root being 1. Carried down a
|
|
/// draw rather than worked out by walking up, so it is right for every
|
|
/// widget a frame visits and cannot drift while one is being drawn.
|
|
pub depth: usize,
|
|
pub textures: Vec<TextureHandle>,
|
|
/// Its primitives, each keeping the box it was written in -- in this
|
|
/// widget's placement coordinates, which is what a move recomposes from.
|
|
pub primitives: Vec<RetainedPrimitive>,
|
|
/// An owned mask holds one reference independently of its primitives.
|
|
pub mask_region: Option<UiRegion>,
|
|
pub children: Vec<WidgetId>,
|
|
/// The children whose size this widget read while drawing.
|
|
pub size_deps: Vec<WidgetId>,
|
|
/// The movable region its primitives are positioned through: its own when
|
|
/// opted in, otherwise the nearest ancestor's.
|
|
pub move_idx: MoveIdx,
|
|
/// The declared lengths whoever drew this widget resolved into its rel base.
|
|
/// A change to one moves a box this widget cannot fix by drawing again,
|
|
/// and comparing them is what says so.
|
|
pub declared: Declared,
|
|
/// Its alignment when it was last drawn, which a change to the property
|
|
/// is found against.
|
|
pub own_align: RegionAlign,
|
|
/// The movable region whose coordinates its placement is in when this
|
|
/// widget does not own a region node.
|
|
pub parent_move: MoveIdx,
|
|
/// The mask its drawing is clipped to: one it set itself, or the one it
|
|
/// inherited from whoever drew it.
|
|
pub mask: MaskIdx,
|
|
/// That inherited one. The two differ exactly where the widget set a
|
|
/// mask of its own, which is the one it owns and the one a move rewrites
|
|
/// -- and the one a redraw of it must not be handed back, since setting
|
|
/// a mask asserts there is none.
|
|
pub parent_mask: MaskIdx,
|
|
pub layer: LayerId,
|
|
}
|
|
|
|
impl ActiveData {
|
|
/// What it answered when its parent asked, where it has been asked at
|
|
/// all. Not `size`, which is what its last drawing reported: a drawing
|
|
/// re-expressed in the box that answer chose is not a second answer.
|
|
pub fn measured(&self) -> Option<Size> {
|
|
self.answer.map(|answer| answer.size)
|
|
}
|
|
|
|
/// Whether it owns a region node rather than sharing the one it was drawn
|
|
/// under, which is what its two move indices being different says.
|
|
pub fn is_region_node(&self) -> bool {
|
|
self.move_idx != self.parent_move
|
|
}
|
|
}
|
|
|
|
/// What a widget answered when it was asked: the size it reported, and the
|
|
/// boxes and windows that answer holds for.
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub struct Answer {
|
|
pub size: Size,
|
|
pub holds: LayoutHolds,
|
|
}
|