summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-02-03 12:22:02 +0100
committerLaurenz <laurmaedje@gmail.com>2020-02-03 12:22:02 +0100
commit3150fd56437ecf8b2a5902c18e3f9ace800b768c (patch)
treedb8a7e9fc868145804db97da81bd0669aaf55454 /src/layout
parent40ea35cbe7482ce04096c4d63a848c8601cc1848 (diff)
Better Debug/Display and Derives 🧽
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/actions.rs14
-rw-r--r--src/layout/line.rs10
-rw-r--r--src/layout/mod.rs4
-rw-r--r--src/layout/model.rs5
-rw-r--r--src/layout/stack.rs10
-rw-r--r--src/layout/text.rs3
6 files changed, 23 insertions, 23 deletions
diff --git a/src/layout/actions.rs b/src/layout/actions.rs
index b61f2201..314084e5 100644
--- a/src/layout/actions.rs
+++ b/src/layout/actions.rs
@@ -1,7 +1,7 @@
//! Drawing and configuration actions composing layouts.
use std::io::{self, Write};
-use std::fmt::{self, Display, Formatter};
+use std::fmt::{self, Debug, Formatter};
use toddle::query::FontIndex;
use crate::size::{Size, Size2D};
@@ -11,7 +11,7 @@ use self::LayoutAction::*;
/// A layouting action, which is the basic building block layouts are composed
/// of.
-#[derive(Clone)]
+#[derive(Clone, PartialEq)]
pub enum LayoutAction {
/// Move to an absolute position.
MoveAbsolute(Size2D),
@@ -34,20 +34,18 @@ impl Serialize for LayoutAction {
}
}
-impl Display for LayoutAction {
+impl Debug for LayoutAction {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
use LayoutAction::*;
match self {
MoveAbsolute(s) => write!(f, "move {} {}", s.x, s.y),
- SetFont(i, s) => write!(f, "font {} {} {}", i.id, i.variant, s),
+ SetFont(i, s) => write!(f, "font {}_{} {}", i.id, i.variant, s),
WriteText(s) => write!(f, "write \"{}\"", s),
- DebugBox(s) => write!(f, "box {}", s),
+ DebugBox(s) => write!(f, "box {} {}", s.x, s.y),
}
}
}
-debug_display!(LayoutAction);
-
/// A sequence of layouting actions.
///
/// The sequence of actions is optimized as the actions are added. For example,
@@ -60,7 +58,7 @@ debug_display!(LayoutAction);
/// `add_layout` method, which allows a layout to be added at a position,
/// effectively translating all movement actions inside the layout by the
/// position.
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq)]
pub struct LayoutActions {
origin: Size2D,
actions: Vec<LayoutAction>,
diff --git a/src/layout/line.rs b/src/layout/line.rs
index 2c8e45f2..18ace29f 100644
--- a/src/layout/line.rs
+++ b/src/layout/line.rs
@@ -13,7 +13,7 @@ use super::*;
/// Performs the line layouting.
-#[derive(Debug, Clone)]
+#[derive(Debug)]
pub struct LineLayouter {
/// The context for layouting.
ctx: LineContext,
@@ -46,7 +46,7 @@ pub struct LineContext {
/// A line run is a sequence of boxes with the same alignment that are arranged
/// in a line. A real line can consist of multiple runs with different
/// alignments.
-#[derive(Debug, Clone)]
+#[derive(Debug)]
struct LineRun {
/// The so-far accumulated layouts in the line.
layouts: Vec<(Size, Layout)>,
@@ -102,7 +102,7 @@ impl LineLayouter {
} else if layout.alignment.primary > alignment.primary {
let mut rest_run = LineRun::new();
- let usable = self.stack.usable().get_primary(axes);
+ let usable = self.stack.usable().primary(axes);
rest_run.usable = Some(match layout.alignment.primary {
Alignment::Origin => unreachable!("origin > x"),
Alignment::Center => usable - 2 * self.run.size.x,
@@ -228,7 +228,7 @@ impl LineLayouter {
/// a function how much space it has to layout itself.
pub fn remaining(&self) -> LayoutSpaces {
let mut spaces = self.stack.remaining();
- *spaces[0].dimensions.get_secondary_mut(self.ctx.axes)
+ *spaces[0].dimensions.secondary_mut(self.ctx.axes)
-= self.run.size.y;
spaces
}
@@ -262,7 +262,7 @@ impl LineLayouter {
true => offset,
false => self.run.size.x
- offset
- - layout.dimensions.get_primary(self.ctx.axes),
+ - layout.dimensions.primary(self.ctx.axes),
};
let pos = Size2D::with_x(x);
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index bcabf7f3..8c120c6b 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -33,7 +33,7 @@ pub mod prelude {
pub type MultiLayout = Vec<Layout>;
/// A finished box with content at fixed positions.
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq)]
pub struct Layout {
/// The size of the box.
pub dimensions: Size2D,
@@ -91,7 +91,7 @@ impl Serialize for MultiLayout {
pub type LayoutSpaces = SmallVec<[LayoutSpace; 2]>;
/// The space into which content is laid out.
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, PartialEq)]
pub struct LayoutSpace {
/// The maximum size of the box to layout in.
pub dimensions: Size2D,
diff --git a/src/layout/model.rs b/src/layout/model.rs
index 2eac9a8c..d23968d8 100644
--- a/src/layout/model.rs
+++ b/src/layout/model.rs
@@ -5,7 +5,6 @@
use std::future::Future;
use std::pin::Pin;
use smallvec::smallvec;
-use toddle::query::{SharedFontLoader, FontProvider};
use crate::GlobalFontLoader;
use crate::error::Errors;
@@ -19,6 +18,7 @@ use super::*;
/// Performs the model layouting.
+#[derive(Debug)]
pub struct ModelLayouter<'a> {
ctx: LayoutContext<'a>,
layouter: LineLayouter,
@@ -52,6 +52,7 @@ pub struct LayoutContext<'a> {
}
/// The result of layouting: Some layouted things and a list of errors.
+#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Layouted<T> {
/// The result of the layouting process.
pub output: T,
@@ -63,7 +64,7 @@ pub struct Layouted<T> {
pub type Commands<'a> = Vec<Command<'a>>;
/// Commands issued to the layouting engine by models.
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub enum Command<'a> {
/// Layout the given model in the current context (i.e. not nested). The
/// content of the model is not laid out into a separate box and then added,
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index 8f76ccbf..891815e9 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -27,7 +27,7 @@ use super::*;
/// Performs the stack layouting.
-#[derive(Debug, Clone)]
+#[derive(Debug)]
pub struct StackLayouter {
/// The context for layouting.
ctx: StackContext,
@@ -57,7 +57,7 @@ pub struct StackContext {
/// A layout space composed of subspaces which can have different axes and
/// alignments.
-#[derive(Debug, Clone)]
+#[derive(Debug)]
struct Space {
/// The index of this space in the list of spaces.
index: usize,
@@ -134,7 +134,7 @@ impl StackLayouter {
// A hard space is simply an empty box.
SpacingKind::Hard => {
// Reduce the spacing such that it definitely fits.
- spacing.min_eq(self.space.usable.get_secondary(self.ctx.axes));
+ spacing.min_eq(self.space.usable.secondary(self.ctx.axes));
let dimensions = Size2D::with_y(spacing);
self.update_metrics(dimensions);
@@ -179,7 +179,7 @@ impl StackLayouter {
self.space.size = size.specialized(axes);
self.space.extra = extra.specialized(axes);
- *self.space.usable.get_secondary_mut(axes) -= dimensions.y;
+ *self.space.usable.secondary_mut(axes) -= dimensions.y;
}
/// Update the rulers to account for the new layout. Returns true if a
@@ -328,7 +328,7 @@ impl StackLayouter {
// the usable space for following layouts at it's origin by its
// extent along the secondary axis.
*bound.get_mut(axes.secondary, Origin)
- += axes.secondary.factor() * layout.dimensions.get_secondary(*axes);
+ += axes.secondary.factor() * layout.dimensions.secondary(*axes);
}
// ------------------------------------------------------------------ //
diff --git a/src/layout/text.rs b/src/layout/text.rs
index 6b512a07..c6fa45d1 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -14,6 +14,7 @@ use super::*;
/// Performs the text layouting.
+#[derive(Debug)]
struct TextLayouter<'a> {
ctx: TextContext<'a>,
text: &'a str,
@@ -24,7 +25,7 @@ struct TextLayouter<'a> {
}
/// The context for text layouting.
-#[derive(Copy, Clone)]
+#[derive(Debug, Copy, Clone)]
pub struct TextContext<'a> {
/// The font loader to retrieve fonts from when typesetting text
/// using [`layout_text`].