58 releases

0.8.21-pre Jul 10, 2024
0.8.20-pre Mar 8, 2024
0.8.19-pre Feb 28, 2024
0.8.16-pre Oct 23, 2023
0.4.11 Jul 30, 2021

#73 in Rendering

Download history 255/week @ 2024-03-31 2/week @ 2024-04-07 3/week @ 2024-05-19 1/week @ 2024-05-26 8/week @ 2024-06-02 5/week @ 2024-06-09 1/week @ 2024-06-16 2/week @ 2024-06-23 158/week @ 2024-06-30 130/week @ 2024-07-07 17/week @ 2024-07-14

307 downloads per month
Used in 4 crates

MIT license

155KB
4K 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

~11MB
~177K SLoC