55 releases

new 0.8.18-pre Feb 19, 2024
0.8.16-pre Oct 23, 2023
0.8.13-pre Jul 27, 2023
0.7.3 Mar 10, 2023
0.4.11 Jul 30, 2021

#22 in Rendering

Download history 125/week @ 2023-10-30 41/week @ 2023-11-06 75/week @ 2023-11-13 152/week @ 2023-11-20 249/week @ 2023-11-27 10/week @ 2023-12-04 46/week @ 2023-12-11 77/week @ 2023-12-18 138/week @ 2023-12-25 63/week @ 2024-01-01 37/week @ 2024-01-08 132/week @ 2024-01-15 128/week @ 2024-01-22 361/week @ 2024-01-29 116/week @ 2024-02-05 445/week @ 2024-02-12

1,065 downloads per month
Used in 4 crates

MIT license

155KB
3.5K SLoC

dessin

dessin is library aimed at building complex drawings, combine them, move them and export them as PDF or SVG.

Getting started

Add dessin and dessin-svg to your project dependencies

cargo add dessin dessin-svg

or if you need PDF:

cargo add dessin dessin-pdf

Documentation on docs.rs

Overview

use dessin::prelude::*;
use dessin_svg::ToSVG;

#[derive(Default)]
struct MyShape {
  text: String
}
impl MyShape {
  fn say_this(&mut self, what: &str) {
    self.text = format!("{} And check this out: `{what}`", self.text);
  }
}
impl From<MyShape> for Shape {
  fn from(value: MyShape) -> Self {
    dessin!(Text: #(
      fill={Color::RED}
      text={value.text}
    )).into()
  }
}

let dessin = dessin!(for x in {0..10}: {
  let radius = x as f32 * 10.;

  dessin!(group: [
    { Circle: #(
      fill={Color::RED}
      radius={radius}
      translate={[x as f32 * 5., 10.]}
    ) }
    { Text: #(
      fill={Color::BLACK}
      font_size={10.}
      text={"Hi !"}
    ) }
  ])
});

let dessin = dessin!(group: [
  { var { dessin }: (
    scale={[2., 2.]}
  ) }
  { MyShape: (
    say_this={"Hello world"}
  ) }
]);

let svg = dessin.to_svg().unwrap();

Dependencies

~19MB
~182K SLoC