summaryrefslogtreecommitdiff
path: root/src/style.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-03 13:23:59 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-03 13:23:59 +0200
commit0fc25d732d7cbc37cf801645849d1060f2cec4a3 (patch)
tree706aa8d1bf4135d1dd3ac17a5023bc5e24ded69d /src/style.rs
parent8dbc5b60cc4a88f68ee82607af3a3c454cd8f68b (diff)
Port to kurbo 🎋
Diffstat (limited to 'src/style.rs')
-rw-r--r--src/style.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/style.rs b/src/style.rs
index 7da7f0c6..b6c1a278 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -2,7 +2,7 @@
use fontdock::{fallback, FallbackTree, FontStretch, FontStyle, FontVariant, FontWeight};
-use crate::geom::{Margins, Size, Value4};
+use crate::geom::{Insets, Sides, Size};
use crate::length::{Length, ScaleLength};
use crate::paper::{Paper, PaperClass, PAPER_A4};
@@ -101,9 +101,9 @@ pub struct PageStyle {
pub class: PaperClass,
/// The width and height of the page.
pub size: Size,
- /// The amount of white space on each side. If a side is set to `None`, the
- /// default for the paper class is used.
- pub margins: Value4<Option<ScaleLength>>,
+ /// The amount of white space in the order [left, top, right, bottom]. If a
+ /// side is set to `None`, the default for the paper class is used.
+ pub margins: Sides<Option<ScaleLength>>,
}
impl PageStyle {
@@ -112,19 +112,19 @@ impl PageStyle {
Self {
class: paper.class,
size: paper.size(),
- margins: Value4::with_all(None),
+ margins: Sides::uniform(None),
}
}
- /// The absolute margins.
- pub fn margins(&self) -> Margins {
- let size = self.size;
+ /// The absolute insets.
+ pub fn insets(&self) -> Insets {
+ let Size { width, height } = self.size;
let default = self.class.default_margins();
- Margins {
- left: self.margins.left.unwrap_or(default.left).raw_scaled(size.x),
- top: self.margins.top.unwrap_or(default.top).raw_scaled(size.y),
- right: self.margins.right.unwrap_or(default.right).raw_scaled(size.x),
- bottom: self.margins.bottom.unwrap_or(default.bottom).raw_scaled(size.y),
+ Insets {
+ x0: -self.margins.left.unwrap_or(default.left).raw_scaled(width),
+ y0: -self.margins.top.unwrap_or(default.top).raw_scaled(height),
+ x1: -self.margins.right.unwrap_or(default.right).raw_scaled(width),
+ y1: -self.margins.bottom.unwrap_or(default.bottom).raw_scaled(height),
}
}
}