summaryrefslogtreecommitdiff
path: root/src/layout/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-23 22:04:08 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-23 22:04:08 +0100
commit8a88f71cb11565c1a78bd57f02a8df17cb2bf7a0 (patch)
tree8802c1ff48e2be118e3872d25bd2f2c1f7a21b4a /src/layout/mod.rs
parentc77c5a0f0ae6560a03a85e847006c29de9c7ae62 (diff)
Transformations
Diffstat (limited to 'src/layout/mod.rs')
-rw-r--r--src/layout/mod.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index be4e994c..a491789a 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -17,9 +17,9 @@ use std::rc::Rc;
use crate::font::FontStore;
use crate::frame::Frame;
-use crate::geom::{Align, Linear, Sides, Spec};
+use crate::geom::{Align, Linear, Point, Sides, Spec, Transform};
use crate::image::ImageStore;
-use crate::library::{AlignNode, DocumentNode, MoveNode, PadNode, SizedNode};
+use crate::library::{AlignNode, DocumentNode, PadNode, SizedNode, TransformNode};
use crate::Context;
/// Layout a document node into a collection of frames.
@@ -121,15 +121,6 @@ impl PackedNode {
}
}
- /// Move this node's contents without affecting layout.
- pub fn moved(self, offset: Spec<Option<Linear>>) -> Self {
- if offset.any(Option::is_some) {
- MoveNode { child: self, offset }.pack()
- } else {
- self
- }
- }
-
/// Pad this node at the sides.
pub fn padded(self, padding: Sides<Linear>) -> Self {
if !padding.left.is_zero()
@@ -142,6 +133,23 @@ impl PackedNode {
self
}
}
+
+ /// Transform this node's contents without affecting layout.
+ pub fn moved(self, offset: Point) -> Self {
+ self.transformed(
+ Transform::translation(offset.x, offset.y),
+ Spec::new(Align::Left, Align::Top),
+ )
+ }
+
+ /// Transform this node's contents without affecting layout.
+ pub fn transformed(self, transform: Transform, origin: Spec<Align>) -> Self {
+ if !transform.is_identity() {
+ TransformNode { child: self, transform, origin }.pack()
+ } else {
+ self
+ }
+ }
}
impl Layout for PackedNode {