18 releases

0.8.20-pre Mar 8, 2024
0.8.17-pre Jan 19, 2024
0.8.16-pre Oct 23, 2023
0.8.13-pre Jul 27, 2023

#332 in Rendering

Download history 1/week @ 2024-01-03 7/week @ 2024-01-10 41/week @ 2024-01-17 76/week @ 2024-01-24 78/week @ 2024-01-31 85/week @ 2024-02-07 315/week @ 2024-02-14 154/week @ 2024-02-21 355/week @ 2024-02-28 402/week @ 2024-03-06 226/week @ 2024-03-13 270/week @ 2024-03-20 52/week @ 2024-03-27 52/week @ 2024-04-03

409 downloads per month

MIT license

43KB
1.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::*;

#[derive(Default, Shape)]
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(MyShape { text }: MyShape) -> Self {
    dessin2!(Text!(fill = Color::RED, { text })).into()
  }
}

fn main() {
  let dessin = dessin2!(for x in 0..10 {
    let radius = x as f32 * 10.;

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

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

  let svg = dessin_svg::to_string(&dessin).unwrap();
}


lib.rs:

Macros for the dessin crate.

Dependencies

~340–800KB
~19K SLoC