typst/src/layout/fixed.rs
Martin Haug e27f6c1014 Add hash impls for all nodes
This prepares the incremental PR.

Co-Authored-By: Laurenz <laurmaedje@gmail.com>
2021-05-26 22:57:29 +02:00

33 lines
968 B
Rust

use super::*;
/// A node that can fix its child's width and height.
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct FixedNode {
/// The fixed width, if any.
pub width: Option<Linear>,
/// The fixed height, if any.
pub height: Option<Linear>,
/// The child node whose size to fix.
pub child: AnyNode,
}
impl Layout for FixedNode {
fn layout(&self, ctx: &mut LayoutContext, regions: &Regions) -> Vec<Frame> {
let Regions { current, base, .. } = regions;
let size = Size::new(
self.width.map_or(current.width, |w| w.resolve(base.width)),
self.height.map_or(current.height, |h| h.resolve(base.height)),
);
let fixed = Spec::new(self.width.is_some(), self.height.is_some());
let regions = Regions::one(size, fixed);
self.child.layout(ctx, &regions)
}
}
impl From<FixedNode> for AnyNode {
fn from(fixed: FixedNode) -> Self {
Self::new(fixed)
}
}