summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-30 22:18:55 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-30 22:18:55 +0200
commit181f756a9e8f7b664101058fe91e36b3858c2d02 (patch)
tree542e7c694e91d8cc91fa97a328e9bda0567db679 /src/layout
parent0d44cf532136f3ba8e34d6f967f9e844cfb9c3f0 (diff)
Format everything with rustfmt! 💚
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/line.rs6
-rw-r--r--src/layout/mod.rs2
-rw-r--r--src/layout/primitive.rs12
-rw-r--r--src/layout/stack.rs44
-rw-r--r--src/layout/text.rs4
-rw-r--r--src/layout/tree.rs58
6 files changed, 61 insertions, 65 deletions
diff --git a/src/layout/line.rs b/src/layout/line.rs
index 069a4e56..26b3d6a4 100644
--- a/src/layout/line.rs
+++ b/src/layout/line.rs
@@ -246,9 +246,7 @@ impl LineLayouter {
for (offset, layout) in layouts {
let x = match self.ctx.axes.primary.is_positive() {
true => offset,
- false => self.run.size.x
- - offset
- - layout.size.primary(self.ctx.axes),
+ false => self.run.size.x - offset - layout.size.primary(self.ctx.axes),
};
let pos = Size::with_x(x);
@@ -258,7 +256,7 @@ impl LineLayouter {
self.stack.add(BoxLayout {
size: self.run.size.specialized(self.ctx.axes),
align: self.run.align.unwrap_or(LayoutAlign::new(Start, Start)),
- elements
+ elements,
});
self.run = LineRun::new();
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index efb2f169..853a66ec 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -10,7 +10,7 @@ mod tree;
/// Basic types used across the layouting engine.
pub mod prelude {
pub use super::primitive::*;
- pub use super::{BoxLayout, layout, LayoutContext, LayoutSpace, MultiLayout};
+ pub use super::{layout, BoxLayout, LayoutContext, LayoutSpace, MultiLayout};
pub use Dir::*;
pub use GenAlign::*;
pub use GenAxis::*;
diff --git a/src/layout/primitive.rs b/src/layout/primitive.rs
index 1d79f530..6b5df7db 100644
--- a/src/layout/primitive.rs
+++ b/src/layout/primitive.rs
@@ -140,7 +140,11 @@ pub enum SpecAxis {
impl SpecAxis {
/// The generic version of this axis in the given system of axes.
pub fn to_generic(self, axes: LayoutAxes) -> GenAxis {
- if self == axes.primary.axis() { Primary } else { Secondary }
+ if self == axes.primary.axis() {
+ Primary
+ } else {
+ Secondary
+ }
}
}
@@ -240,7 +244,11 @@ impl SpecAlign {
pub fn to_generic(self, axes: LayoutAxes) -> GenAlign {
let get = |spec: SpecAxis, align: GenAlign| {
let axis = spec.to_generic(axes);
- if axes.get(axis).is_positive() { align } else { align.inv() }
+ if axes.get(axis).is_positive() {
+ align
+ } else {
+ align.inv()
+ }
};
match self {
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index 62f2c976..73e246e2 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -19,8 +19,8 @@
//! The position of the first aligned box thus depends on the length of the
//! sentence in the second box.
-use crate::geom::Value4;
use super::*;
+use crate::geom::Value4;
/// Performs the stack layouting.
pub struct StackLayouter {
@@ -130,14 +130,11 @@ impl StackLayouter {
let size = Size::with_y(spacing);
self.update_metrics(size);
- self.space.layouts.push((
- self.ctx.axes,
- BoxLayout {
- size: size.specialized(self.ctx.axes),
- align: LayoutAlign::new(Start, Start),
- elements: LayoutElements::new(),
- }
- ));
+ self.space.layouts.push((self.ctx.axes, BoxLayout {
+ size: size.specialized(self.ctx.axes),
+ align: LayoutAlign::new(Start, Start),
+ elements: LayoutElements::new(),
+ }));
self.space.last_spacing = LastSpacing::Hard;
}
@@ -179,8 +176,7 @@ impl StackLayouter {
fn update_rulers(&mut self, align: LayoutAlign) -> bool {
let allowed = self.is_fitting_alignment(align);
if allowed {
- *self.space.rulers.get_mut(self.ctx.axes.secondary, Start) =
- align.secondary;
+ *self.space.rulers.get_mut(self.ctx.axes.secondary, Start) = align.secondary;
}
allowed
}
@@ -226,7 +222,7 @@ impl StackLayouter {
/// if no space is capable of that.
pub fn skip_to_fitting_space(&mut self, size: Size) {
let start = self.next_space();
- for (index, space) in self.ctx.spaces[start..].iter().enumerate() {
+ for (index, space) in self.ctx.spaces[start ..].iter().enumerate() {
if space.usable().fits(size) {
self.finish_space(true);
self.start_space(start + index, true);
@@ -246,7 +242,7 @@ impl StackLayouter {
expansion: LayoutExpansion::new(false, false),
}];
- for space in &self.ctx.spaces[self.next_space()..] {
+ for space in &self.ctx.spaces[self.next_space() ..] {
spaces.push(space.inner());
}
@@ -288,8 +284,12 @@ impl StackLayouter {
// expand if necessary.)
let usable = space.usable();
- if space.expansion.horizontal { self.space.size.x = usable.x; }
- if space.expansion.vertical { self.space.size.y = usable.y; }
+ if space.expansion.horizontal {
+ self.space.size.x = usable.x;
+ }
+ if space.expansion.vertical {
+ self.space.size.y = usable.y;
+ }
let size = self.space.size.padded(space.padding);
@@ -347,8 +347,7 @@ impl StackLayouter {
// We reduce the bounding box of this layout at it's end by the
// accumulated secondary extent of all layouts we have seen so far,
// which are the layouts after this one since we iterate reversed.
- *bound.get_mut(axes.secondary, End) -=
- axes.secondary.factor() * extent.y;
+ *bound.get_mut(axes.secondary, End) -= axes.secondary.factor() * extent.y;
// Then, we add this layout's secondary extent to the accumulator.
let size = layout.size.generalized(*axes);
@@ -369,9 +368,8 @@ impl StackLayouter {
// The space in which this layout is aligned is given by the
// distances between the borders of it's bounding box.
- let usable =
- Size::new(bound.right - bound.left, bound.bottom - bound.top)
- .generalized(axes);
+ let usable = Size::new(bound.right - bound.left, bound.bottom - bound.top)
+ .generalized(axes);
let local = usable.anchor(align, axes) - size.anchor(align, axes);
let pos = Size::new(bound.left, bound.top) + local.specialized(axes);
@@ -379,11 +377,7 @@ impl StackLayouter {
elements.extend_offset(pos, layout.elements);
}
- self.layouts.push(BoxLayout {
- size,
- align: self.ctx.align,
- elements,
- });
+ self.layouts.push(BoxLayout { size, align: self.ctx.align, elements });
// ------------------------------------------------------------------ //
// Step 5: Start the next space.
diff --git a/src/layout/text.rs b/src/layout/text.rs
index c1f1f1e7..a43437b1 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -7,11 +7,11 @@
use fontdock::{FaceId, FaceQuery, FontStyle};
use ttf_parser::GlyphId;
+use super::elements::{LayoutElement, Shaped};
+use super::*;
use crate::font::SharedFontLoader;
use crate::geom::Size;
use crate::style::TextStyle;
-use super::elements::{LayoutElement, Shaped};
-use super::*;
/// Layouts text into a box.
pub async fn layout_text(text: &str, ctx: TextContext<'_>) -> BoxLayout {
diff --git a/src/layout/tree.rs b/src/layout/tree.rs
index 16a2930a..aa0e0df1 100644
--- a/src/layout/tree.rs
+++ b/src/layout/tree.rs
@@ -1,19 +1,16 @@
//! Layouting of syntax trees.
+use super::line::{LineContext, LineLayouter};
+use super::text::{layout_text, TextContext};
+use super::*;
use crate::style::LayoutStyle;
use crate::syntax::decoration::Decoration;
use crate::syntax::span::{Span, Spanned};
-use crate::syntax::tree::{CallExpr, SyntaxNode, SyntaxTree, Code};
+use crate::syntax::tree::{CallExpr, Code, SyntaxNode, SyntaxTree};
use crate::{DynFuture, Feedback, Pass};
-use super::line::{LineContext, LineLayouter};
-use super::text::{layout_text, TextContext};
-use super::*;
/// Layout a syntax tree into a collection of boxes.
-pub async fn layout_tree(
- tree: &SyntaxTree,
- ctx: LayoutContext<'_>,
-) -> Pass<MultiLayout> {
+pub async fn layout_tree(tree: &SyntaxTree, ctx: LayoutContext<'_>) -> Pass<MultiLayout> {
let mut layouter = TreeLayouter::new(ctx);
layouter.layout_tree(tree).await;
layouter.finish()
@@ -75,8 +72,12 @@ impl<'a> TreeLayouter<'a> {
}
SyntaxNode::Text(text) => {
- if self.style.text.italic { decorate(self, Decoration::Italic); }
- if self.style.text.bolder { decorate(self, Decoration::Bold); }
+ if self.style.text.italic {
+ decorate(self, Decoration::Italic);
+ }
+ if self.style.text.bolder {
+ decorate(self, Decoration::Bold);
+ }
self.layout_text(text).await;
}
@@ -90,10 +91,8 @@ impl<'a> TreeLayouter<'a> {
}
fn layout_space(&mut self) {
- self.layouter.add_primary_spacing(
- self.style.text.word_spacing(),
- SpacingKind::WORD,
- );
+ self.layouter
+ .add_primary_spacing(self.style.text.word_spacing(), SpacingKind::WORD);
}
fn layout_parbreak(&mut self) {
@@ -105,24 +104,20 @@ impl<'a> TreeLayouter<'a> {
async fn layout_text(&mut self, text: &str) {
self.layouter.add(
- layout_text(
- text,
- TextContext {
- loader: &self.ctx.loader,
- style: &self.style.text,
- dir: self.ctx.axes.primary,
- align: self.ctx.align,
- }
- ).await
+ layout_text(text, TextContext {
+ loader: &self.ctx.loader,
+ style: &self.style.text,
+ dir: self.ctx.axes.primary,
+ align: self.ctx.align,
+ })
+ .await,
);
}
async fn layout_raw(&mut self, lines: &[String]) {
// TODO: Make this more efficient.
let fallback = self.style.text.fallback.clone();
- self.style.text.fallback
- .list_mut()
- .insert(0, "monospace".to_string());
+ self.style.text.fallback.list_mut().insert(0, "monospace".to_string());
self.style.text.fallback.flatten();
let mut first = true;
@@ -176,7 +171,7 @@ impl<'a> TreeLayouter<'a> {
AddSpacing(space, kind, axis) => match axis {
Primary => self.layouter.add_primary_spacing(space, kind),
Secondary => self.layouter.add_secondary_spacing(space, kind),
- }
+ },
BreakLine => self.layouter.finish_line(),
BreakPage => {
@@ -203,13 +198,14 @@ impl<'a> TreeLayouter<'a> {
// new page style and update it within the layouter.
let margins = style.margins();
self.ctx.base = style.size.unpadded(margins);
- self.layouter.set_spaces(vec![
- LayoutSpace {
+ self.layouter.set_spaces(
+ vec![LayoutSpace {
size: style.size,
padding: margins,
expansion: LayoutExpansion::new(true, true),
- }
- ], true);
+ }],
+ true,
+ );
} else {
error!(
@self.feedback, span,