summaryrefslogtreecommitdiff
path: root/src/library/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-03-11 11:58:56 +0100
committerLaurenz <laurmaedje@gmail.com>2022-03-11 11:58:56 +0100
commite6b532391deb1e30dc356c4d20dd48199f748f29 (patch)
tree7b631414931164b9a47c9d154172195fc0e1316c /src/library/layout
parentb71113d37a29bab5c7dc4b501c33ee9afbdb8213 (diff)
More restructuring
Diffstat (limited to 'src/library/layout')
-rw-r--r--src/library/layout/hide.rs30
-rw-r--r--src/library/layout/mod.rs4
-rw-r--r--src/library/layout/transform.rs86
3 files changed, 0 insertions, 120 deletions
diff --git a/src/library/layout/hide.rs b/src/library/layout/hide.rs
deleted file mode 100644
index 861a1208..00000000
--- a/src/library/layout/hide.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-use crate::library::prelude::*;
-
-/// Hide a node without affecting layout.
-#[derive(Debug, Hash)]
-pub struct HideNode(pub LayoutNode);
-
-#[class]
-impl HideNode {
- fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> {
- Ok(Template::inline(Self(args.expect("body")?)))
- }
-}
-
-impl Layout for HideNode {
- fn layout(
- &self,
- ctx: &mut Context,
- regions: &Regions,
- styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
- let mut frames = self.0.layout(ctx, regions, styles)?;
-
- // Clear the frames.
- for frame in &mut frames {
- *frame = Arc::new(Frame { elements: vec![], ..**frame });
- }
-
- Ok(frames)
- }
-}
diff --git a/src/library/layout/mod.rs b/src/library/layout/mod.rs
index 944548ab..588b15aa 100644
--- a/src/library/layout/mod.rs
+++ b/src/library/layout/mod.rs
@@ -5,23 +5,19 @@ mod columns;
mod container;
mod flow;
mod grid;
-mod hide;
mod pad;
mod page;
mod place;
mod spacing;
mod stack;
-mod transform;
pub use align::*;
pub use columns::*;
pub use container::*;
pub use flow::*;
pub use grid::*;
-pub use hide::*;
pub use pad::*;
pub use page::*;
pub use place::*;
pub use spacing::*;
pub use stack::*;
-pub use transform::*;
diff --git a/src/library/layout/transform.rs b/src/library/layout/transform.rs
deleted file mode 100644
index fafb37a4..00000000
--- a/src/library/layout/transform.rs
+++ /dev/null
@@ -1,86 +0,0 @@
-use crate::geom::Transform;
-use crate::library::prelude::*;
-
-/// Transform a node without affecting layout.
-#[derive(Debug, Hash)]
-pub struct TransformNode<const T: TransformKind> {
- /// Transformation to apply to the contents.
- pub transform: Transform,
- /// The node whose contents should be transformed.
- pub child: LayoutNode,
-}
-
-/// Transform a node by translating it without affecting layout.
-pub type MoveNode = TransformNode<MOVE>;
-
-/// Transform a node by rotating it without affecting layout.
-pub type RotateNode = TransformNode<ROTATE>;
-
-/// Transform a node by scaling it without affecting layout.
-pub type ScaleNode = TransformNode<SCALE>;
-
-#[class]
-impl<const T: TransformKind> TransformNode<T> {
- /// The origin of the transformation.
- pub const ORIGIN: Spec<Option<Align>> = Spec::default();
-
- fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> {
- let transform = match T {
- MOVE => {
- let tx = args.named("x")?.unwrap_or_default();
- let ty = args.named("y")?.unwrap_or_default();
- Transform::translation(tx, ty)
- }
- ROTATE => {
- let angle = args.named_or_find("angle")?.unwrap_or_default();
- Transform::rotation(angle)
- }
- SCALE | _ => {
- let all = args.find()?;
- let sx = args.named("x")?.or(all).unwrap_or(Relative::one());
- let sy = args.named("y")?.or(all).unwrap_or(Relative::one());
- Transform::scale(sx, sy)
- }
- };
-
- Ok(Template::inline(Self {
- transform,
- child: args.expect("body")?,
- }))
- }
-}
-
-impl<const T: TransformKind> Layout for TransformNode<T> {
- fn layout(
- &self,
- ctx: &mut Context,
- regions: &Regions,
- styles: StyleChain,
- ) -> TypResult<Vec<Arc<Frame>>> {
- let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON);
- let mut frames = self.child.layout(ctx, regions, styles)?;
-
- for frame in &mut frames {
- let Spec { x, y } = origin.zip(frame.size).map(|(o, s)| o.resolve(s));
- let transform = Transform::translation(x, y)
- .pre_concat(self.transform)
- .pre_concat(Transform::translation(-x, -y));
-
- Arc::make_mut(frame).transform(transform);
- }
-
- Ok(frames)
- }
-}
-
-/// Kinds of transformations.
-pub type TransformKind = usize;
-
-/// A translation on the X and Y axes.
-const MOVE: TransformKind = 0;
-
-/// A rotational transformation.
-const ROTATE: TransformKind = 1;
-
-/// A scale transformation.
-const SCALE: TransformKind = 2;