svgplot/
view_box.rs

1use crate::SvgInteger;
2
3/// The viewBox attribute defines the position and dimension, in user space, of an SVG viewport.
4///
5/// The value of the viewBox attribute is a list of four numbers: min-x, min-y, width and height.
6/// The numbers, which are separated by whitespace and/or a comma, specify a rectangle in user space
7/// which is mapped to the bounds of the viewport established for the associated SVG element
8/// (not the browser viewport).
9///
10/// A viewBox can be constructed out of a tuple:
11/// ```rust
12/// let view_box: svgplot::ViewBox = (1, 2, 3, 4).into();
13/// assert_eq!(view_box.min_x, 1);
14/// assert_eq!(view_box.min_y, 2);
15/// assert_eq!(view_box.width, 3);
16/// assert_eq!(view_box.height, 4);
17/// ```
18pub struct ViewBox {
19    pub min_x: SvgInteger,
20    pub min_y: SvgInteger,
21    pub width: SvgInteger,
22    pub height: SvgInteger,
23}
24
25impl From<(SvgInteger, SvgInteger, SvgInteger, SvgInteger)> for ViewBox {
26    fn from(value: (SvgInteger, SvgInteger, SvgInteger, SvgInteger)) -> Self {
27        Self {
28            min_x: value.0,
29            min_y: value.1,
30            width: value.2,
31            height: value.3,
32        }
33    }
34}
35
36#[test]
37fn test() {
38    let view_box: ViewBox = (1, 2, 3, 4).into();
39    assert_eq!(view_box.min_x, 1);
40    assert_eq!(view_box.min_y, 2);
41    assert_eq!(view_box.width, 3);
42    assert_eq!(view_box.height, 4);
43}