Debian Codegraph @

third_party/rust/svg_fmt/src/layout.rs

raw
1 use crate::svg::{Rectangle, rectangle};
2
3 #[derive(Copy, Clone, Debug)]
4 pub struct VerticalLayout {
5 pub x: f32,
6 pub y: f32,
7 pub start_y: f32,
8 pub width: f32,
9 }
10
11 impl VerticalLayout {
12 pub fn new(x: f32, y: f32, width: f32) -> Self {
13 VerticalLayout {
14 x,
15 y,
16 start_y: y,
17 width,
18 }
19 }
20
21 pub fn advance(&mut self, by: f32) {
22 self.y += by;
23 }
24
25 pub fn push_rectangle(&mut self, height: f32) -> Rectangle {
26 let rect = rectangle(self.x, self.y, self.width, height);
27
28 self.y += height;
29
30 rect
31 }
32
33 pub fn total_rectangle(&self) -> Rectangle {
34 rectangle(
35 self.x, self.start_y,
36 self.width, self.y,
37 )
38 }
39
40 pub fn start_here(&mut self) {
41 self.start_y = self.y;
42 }
43 }