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 .await
.into_iter() .into_iter()
.filter_map(|item| match item { .filter_map(|item| match item {
LayoutItem::Spacing(_) => None, Layouted::Spacing(_) => None,
LayoutItem::Box(layout, _) => Some(layout), Layouted::Box(layout, _) => Some(layout),
}) })
.collect() .collect()
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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