Rename LayoutItem to Layouted ✏

This commit is contained in:
Laurenz 2020-10-11 13:08:27 +02:00
parent c216a4fc26
commit f04ad0ffa5
9 changed files with 22 additions and 26 deletions

View File

@ -39,8 +39,8 @@ impl Pages {
.await
.into_iter()
.filter_map(|item| match item {
LayoutItem::Spacing(_) => None,
LayoutItem::Box(layout, _) => Some(layout),
Layouted::Spacing(_) => None,
Layouted::Box(layout, _) => Some(layout),
})
.collect()
}

View File

@ -15,7 +15,7 @@ impl Layout for Fixed {
&self,
ctx: &mut LayoutContext,
constraints: LayoutConstraints,
) -> Vec<LayoutItem> {
) -> Vec<Layouted> {
let space = constraints.spaces[0];
let size = Size::new(
self.width

View File

@ -55,14 +55,14 @@ pub trait Layout {
&self,
ctx: &mut LayoutContext,
constraints: LayoutConstraints,
) -> Vec<LayoutItem>;
) -> Vec<Layouted>;
}
/// An item that is produced by [layouting] a node.
///
/// [layouting]: trait.Layout.html#method.layout
#[derive(Debug, Clone, PartialEq)]
pub enum LayoutItem {
pub enum Layouted {
/// Spacing that should be added to the parent.
Spacing(Length),
/// A box that should be aligned in the parent.

View File

@ -40,7 +40,7 @@ impl Layout for LayoutNode {
&self,
ctx: &mut LayoutContext,
constraints: LayoutConstraints,
) -> Vec<LayoutItem> {
) -> Vec<Layouted> {
match self {
Self::Spacing(spacing) => spacing.layout(ctx, constraints).await,
Self::Text(text) => text.layout(ctx, constraints).await,

View File

@ -14,7 +14,7 @@ impl Layout for Pad {
&self,
ctx: &mut LayoutContext,
constraints: LayoutConstraints,
) -> Vec<LayoutItem> {
) -> Vec<Layouted> {
self.child
.layout(ctx, LayoutConstraints {
spaces: constraints
@ -30,7 +30,7 @@ impl Layout for Pad {
.await
.into_iter()
.map(|item| match item {
LayoutItem::Box(boxed, align) => {
Layouted::Box(boxed, align) => {
let padding = self.padding.eval(boxed.size);
let padded = boxed.size + padding.size();
@ -38,7 +38,7 @@ impl Layout for Pad {
let start = Point::new(padding.left, padding.top);
outer.push_layout(start, boxed);
LayoutItem::Box(outer, align)
Layouted::Box(outer, align)
}
item => item,
})

View File

@ -20,7 +20,7 @@ impl Layout for Par {
&self,
ctx: &mut LayoutContext,
constraints: LayoutConstraints,
) -> Vec<LayoutItem> {
) -> Vec<Layouted> {
let mut layouter = LineLayouter::new(LineContext {
dirs: self.dirs,
spaces: constraints.spaces,
@ -39,8 +39,8 @@ impl Layout for Par {
for item in items {
match item {
LayoutItem::Spacing(amount) => layouter.push_spacing(amount),
LayoutItem::Box(boxed, aligns) => layouter.push_box(boxed, aligns),
Layouted::Spacing(amount) => layouter.push_spacing(amount),
Layouted::Box(boxed, aligns) => layouter.push_box(boxed, aligns),
}
}
}
@ -48,7 +48,7 @@ impl Layout for Par {
layouter
.finish()
.into_iter()
.map(|boxed| LayoutItem::Box(boxed, self.aligns))
.map(|boxed| Layouted::Box(boxed, self.aligns))
.collect()
}
}

View File

@ -11,12 +11,8 @@ pub struct Spacing {
#[async_trait(?Send)]
impl Layout for Spacing {
async fn layout(
&self,
_: &mut LayoutContext,
_: LayoutConstraints,
) -> Vec<LayoutItem> {
vec![LayoutItem::Spacing(self.amount)]
async fn layout(&self, _: &mut LayoutContext, _: LayoutConstraints) -> Vec<Layouted> {
vec![Layouted::Spacing(self.amount)]
}
}

View File

@ -36,7 +36,7 @@ impl Layout for Stack {
&self,
ctx: &mut LayoutContext,
constraints: LayoutConstraints,
) -> Vec<LayoutItem> {
) -> Vec<Layouted> {
let mut items = vec![];
let size = constraints.spaces[0].size;
@ -59,8 +59,8 @@ impl Layout for Stack {
for item in child.layout(ctx, child_constraints).await {
match item {
LayoutItem::Spacing(spacing) => space.push_spacing(spacing),
LayoutItem::Box(mut boxed, aligns) => {
Layouted::Spacing(spacing) => space.push_spacing(spacing),
Layouted::Box(mut boxed, aligns) => {
let mut last = false;
while let Err(back) = space.push_box(boxed, aligns) {
boxed = back;
@ -68,7 +68,7 @@ impl Layout for Stack {
break;
}
items.push(LayoutItem::Box(space.finish(), self.aligns));
items.push(Layouted::Box(space.finish(), self.aligns));
if i + 1 < constraints.spaces.len() {
i += 1;
@ -84,7 +84,7 @@ impl Layout for Stack {
}
}
items.push(LayoutItem::Box(space.finish(), self.aligns));
items.push(Layouted::Box(space.finish(), self.aligns));
items
}
}

View File

@ -23,7 +23,7 @@ impl Layout for Text {
&self,
ctx: &mut LayoutContext,
_constraints: LayoutConstraints,
) -> Vec<LayoutItem> {
) -> Vec<Layouted> {
let mut loader = ctx.loader.borrow_mut();
let boxed = shaping::shape(
&self.text,
@ -34,7 +34,7 @@ impl Layout for Text {
self.variant,
)
.await;
vec![LayoutItem::Box(boxed, self.aligns)]
vec![Layouted::Box(boxed, self.aligns)]
}
}