Replace placement calls with region nodes
This commit is contained in:
1 parent
f437495309
commit
71c9c39523
23 files changed
+374
-170
No files matched your search
+11
-28
@@ -10,8 +10,6 @@ use crate::{
|
||||
ui::render_state::DrawInfo,
|
||||
util::Vec2,
|
||||
};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
const AXES: [Axis; 2] = [Axis::X, Axis::Y];
|
||||
|
||||
/// makes your surfaces look pretty
|
||||
@@ -40,8 +38,8 @@ pub struct Painter<'a> {
|
||||
pub(super) own: [Holds; 2],
|
||||
/// What the children it asked about and drew keep it to.
|
||||
pub(super) under: [Holds; 2],
|
||||
/// The slot this widget's primitives are positioned through: its own if
|
||||
/// its parent placed it, otherwise the nearest ancestor that has one.
|
||||
/// The movable region this widget's primitives are positioned through:
|
||||
/// its own when opted in, otherwise the nearest ancestor's.
|
||||
pub(super) move_idx: MoveIdx,
|
||||
pub layer: usize,
|
||||
pub(super) depth: usize,
|
||||
@@ -101,7 +99,7 @@ impl<'a> Painter<'a> {
|
||||
|
||||
/// Draws a widget within this widget's region.
|
||||
pub fn widget<'s, W: ?Sized>(&'s mut self, id: &'s StrongWidget<W>) -> DrawResult<'s, 'a, W> {
|
||||
self.widget_at(id, UiRegion::FULL, false)
|
||||
self.widget_at(id, UiRegion::FULL)
|
||||
}
|
||||
|
||||
/// Draws a widget somewhere within this one.
|
||||
@@ -110,7 +108,7 @@ impl<'a> Painter<'a> {
|
||||
id: &'s StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
self.widget_at(id, region, false)
|
||||
self.widget_at(id, region)
|
||||
}
|
||||
|
||||
/// What a widget declares its lengths to be, which whoever draws it
|
||||
@@ -125,22 +123,6 @@ impl<'a> Painter<'a> {
|
||||
AXES.map(|axis| declared_len(widget, axis))
|
||||
}
|
||||
|
||||
/// Draws a child this widget decides the box of, and may decide again
|
||||
/// once it knows what the child came to. The child gets a slot of its
|
||||
/// own, so placing it a second time writes one entry however much it
|
||||
/// drew -- moved or resized alike, since everything under the slot is
|
||||
/// held as a fraction of its box. A child drawn any other way has no slot
|
||||
/// and can only be given a different box by drawing again.
|
||||
pub fn place<'s, W: ?Sized>(
|
||||
&'s mut self,
|
||||
id: &'s StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
diag::bump(Counter::PlaceCalls);
|
||||
self.widget_at(id, region, true)
|
||||
}
|
||||
|
||||
/// 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.
|
||||
@@ -155,8 +137,8 @@ impl<'a> Painter<'a> {
|
||||
&'s mut self,
|
||||
id: &'s StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
slotted: bool,
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
let region_node = self.rsc.widgets().is_region_node(id.id());
|
||||
let declared = self.declared_lens(id);
|
||||
// Composing `FULL` through a box is not quite the identity in f32,
|
||||
// so a child with nothing declared keeps the box it would have had.
|
||||
@@ -169,8 +151,9 @@ impl<'a> Painter<'a> {
|
||||
false => local.within(&self.region),
|
||||
};
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
if slotted {
|
||||
diag::placed(id.id(), self.id, within);
|
||||
if region_node {
|
||||
diag::bump(Counter::RegionNodeDraws);
|
||||
diag::region_node(id.id(), self.id, within);
|
||||
}
|
||||
// A child listed twice would be moved twice.
|
||||
if !self.children.contains(&id.id()) {
|
||||
@@ -190,7 +173,7 @@ impl<'a> Painter<'a> {
|
||||
parent: Some(self.id),
|
||||
depth: self.depth + 1,
|
||||
parent_move: self.move_idx,
|
||||
slotted,
|
||||
region_node,
|
||||
mask: self.mask,
|
||||
offer,
|
||||
offered_px: self.px_within_offer(offer),
|
||||
@@ -371,8 +354,8 @@ impl<'a> Painter<'a> {
|
||||
/// 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 in pixels holds for that one alone until it says otherwise.
|
||||
pub fn holds(&mut self, axis: Axis, range: RangeInclusive<f32>) {
|
||||
let holds = Holds::from(range);
|
||||
pub fn holds(&mut self, axis: Axis, holds: impl Into<Holds>) {
|
||||
let holds = holds.into();
|
||||
debug_assert!(
|
||||
holds.contains(self.state.px_of(self.move_idx, self.region).axis(axis)),
|
||||
"'{}' ({:?}) says its drawing holds for lengths that leave out its own box",
|
||||
|
||||
Reference in new issue
Block a user