mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
38 lines
950 B
Rust
38 lines
950 B
Rust
use super::*;
|
|
|
|
/// A node that represents a rectangular box.
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct NodeBackground {
|
|
/// The background fill.
|
|
pub fill: Fill,
|
|
/// The child node to be filled in.
|
|
pub child: Node,
|
|
}
|
|
|
|
impl Layout for NodeBackground {
|
|
fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted {
|
|
let mut layouted = self.child.layout(ctx, areas);
|
|
|
|
if let Some(first) = layouted.frames_mut().first_mut() {
|
|
first.elements.insert(
|
|
0,
|
|
(
|
|
Point::ZERO,
|
|
Element::Geometry(Geometry {
|
|
shape: Shape::Rect(first.size),
|
|
fill: self.fill.clone(),
|
|
}),
|
|
),
|
|
)
|
|
}
|
|
|
|
layouted
|
|
}
|
|
}
|
|
|
|
impl From<NodeBackground> for NodeAny {
|
|
fn from(background: NodeBackground) -> Self {
|
|
Self::new(background)
|
|
}
|
|
}
|