Skip to main content

laser_pdf/elements/
v_gap.rs

1use crate::*;
2
3/// A vertical gap element that creates empty vertical space.
4/// 
5/// This element takes up the specified height (or available height if smaller)
6/// without rendering any content. Useful for adding spacing between elements.
7pub struct VGap(pub f32);
8
9impl Element for VGap {
10    fn measure(&self, ctx: MeasureCtx) -> ElementSize {
11        size(self, ctx.first_height)
12    }
13
14    fn draw(&self, ctx: DrawCtx) -> ElementSize {
15        size(self, ctx.first_height)
16    }
17}
18
19fn size(v_gap: &VGap, first_height: f32) -> ElementSize {
20    ElementSize {
21        width: None,
22        height: Some(v_gap.0.min(first_height)),
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use crate::test_utils::*;
30
31    #[test]
32    fn test_line() {
33        for output in (ElementTestParams {
34            first_height: 11.,
35            ..Default::default()
36        })
37        .run(&VGap(28.3))
38        {
39            output.assert_size(ElementSize {
40                width: None,
41                height: Some(if output.first_height == 11. {
42                    11.
43                } else {
44                    28.3
45                }),
46            });
47
48            if let Some(b) = output.breakable {
49                b.assert_break_count(0)
50                    .assert_extra_location_min_height(None);
51            }
52        }
53    }
54}