dessin

Crates.iodessin
lib.rsdessin
version0.8.21-pre
sourcesrc
created_at2021-07-21 12:57:55.286082
updated_at2024-07-10 09:43:21.746309
descriptionBuild complex drawing for PDF, SVG, ...
homepage
repositoryhttps://github.com/432-technologies/dessin
max_upload_size
id425511
size312,122
morillon françois (SadCl0wn)

documentation

README

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();

Commit count: 106

cargo fmt