summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-16 21:32:29 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-16 21:32:29 +0100
commit9a800daa82833c57eee04e92c701ca9a05a67d3b (patch)
treea2c790f606037319393e9da3150bf58b44d4171d /src/layout
parent0cdf17216f47312f634d2dea8db237118ede72ce (diff)
Image fit modes
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/mod.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 7d2837de..949fff64 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -16,8 +16,9 @@ use std::rc::Rc;
use crate::font::FontStore;
use crate::frame::Frame;
+use crate::geom::{Linear, Spec};
use crate::image::ImageStore;
-use crate::library::DocumentNode;
+use crate::library::{DocumentNode, SizedNode};
use crate::Context;
/// Layout a document node into a collection of frames.
@@ -93,6 +94,23 @@ pub struct PackedNode {
hash: u64,
}
+impl PackedNode {
+ /// Force a size for this node.
+ ///
+ /// If at least one of `width` and `height` is `Some`, this wraps the node
+ /// in a [`SizedNode`]. Otherwise, it returns the node unchanged.
+ pub fn sized(self, width: Option<Linear>, height: Option<Linear>) -> PackedNode {
+ if width.is_some() || height.is_some() {
+ Layout::pack(SizedNode {
+ sizing: Spec::new(width, height),
+ child: self,
+ })
+ } else {
+ self
+ }
+ }
+}
+
impl Layout for PackedNode {
fn layout(
&self,