diff --git a/dessin-dioxus/README.md b/dessin-dioxus/README.md index 265c853..7e460ff 100644 --- a/dessin-dioxus/README.md +++ b/dessin-dioxus/README.md @@ -1,67 +1,3 @@ -# [dessin](https://docs.rs/dessin/) +# dessin-dioxus -**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 -``` - -Documentation on [docs.rs](https://docs.rs/dessin/0.8.2-pre/) - -### Overview - -```rust -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 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(); - -``` +License: MIT diff --git a/dessin-dioxus/src/lib.rs b/dessin-dioxus/src/lib.rs index e31f40d..3ee858a 100644 --- a/dessin-dioxus/src/lib.rs +++ b/dessin-dioxus/src/lib.rs @@ -1,3 +1,5 @@ +#![doc = include_str!("../README.md")] + use ::image::ImageFormat; use dessin::prelude::*; use dioxus::prelude::*; diff --git a/dessin-image/README.md b/dessin-image/README.md new file mode 100644 index 0000000..975ad67 --- /dev/null +++ b/dessin-image/README.md @@ -0,0 +1,3 @@ +# dessin-image + +License: MIT diff --git a/dessin-image/src/lib.rs b/dessin-image/src/lib.rs index 9a72439..29005c1 100644 --- a/dessin-image/src/lib.rs +++ b/dessin-image/src/lib.rs @@ -1,3 +1,5 @@ +#![doc = include_str!("../README.md")] + use ::image::{DynamicImage, RgbaImage}; use dessin::{ export::{Export, Exporter}, diff --git a/dessin-macros/README.md b/dessin-macros/README.md new file mode 100644 index 0000000..e69de29 diff --git a/dessin-pdf/README.md b/dessin-pdf/README.md index a45e5dd..dba3e3a 100644 --- a/dessin-pdf/README.md +++ b/dessin-pdf/README.md @@ -1 +1,3 @@ -# Dessin PDF \ No newline at end of file +# dessin-pdf + +License: MIT diff --git a/dessin-svg/README.md b/dessin-svg/README.md index 265c853..b2c4e91 100644 --- a/dessin-svg/README.md +++ b/dessin-svg/README.md @@ -1,67 +1,3 @@ -# [dessin](https://docs.rs/dessin/) +# dessin-svg -**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 -``` - -Documentation on [docs.rs](https://docs.rs/dessin/0.8.2-pre/) - -### Overview - -```rust -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 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(); - -``` +License: MIT diff --git a/dessin/Cargo.toml b/dessin/Cargo.toml index 389fe8a..0a766cc 100644 --- a/dessin/Cargo.toml +++ b/dessin/Cargo.toml @@ -3,7 +3,7 @@ authors = [ "Olivier Lemoine ", "Francois Morillon ", ] -description = "Build complex drawing for PDF, SVG, ..." +description = "Build complex drawing for PDF, SVG, Images or Dioxus" categories = ["graphics", "gui", "rendering", "template-engine"] keywords = ["graphics", "draw", "layout"] edition = "2021" diff --git a/dessin/README.md b/dessin/README.md index 4770eb6..cda62b1 100644 --- a/dessin/README.md +++ b/dessin/README.md @@ -1,32 +1,18 @@ -# [dessin](https://docs.rs/dessin/) +# dessin -**dessin is library aimed at building complex drawings, combine them, move them and export them as PDF or SVG.** +**dessin** is library aimed at building complex drawings, combine them, move them and export them as PDF or SVG. -## Getting started +Details about the [macro][`crate::macros`]. -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](https://docs.rs/dessin/0.8.2-pre/) - -### Overview +### Example ```rust use dessin::prelude::*; -use dessin_svg::ToSVG; +use palette::{named, Srgb}; -#[derive(Default)] +#[derive(Default, Shape)] struct MyShape { - text: String + text: String, } impl MyShape { fn say_this(&mut self, what: &str) { @@ -34,40 +20,123 @@ impl MyShape { } } impl From for Shape { - fn from(value: MyShape) -> Self { - dessin!(Text: #( - fill={Color::RED} - text={value.text} - )).into() + fn from(MyShape { text }: MyShape) -> Self { + dessin2!(*Text(fill = Srgb::::from_format(named::RED).into_linear(), { 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(); +fn main() { + let dessin = dessin2!(for x in 0..10 { + let radius = x as f32 * 10.; + + dessin2!([ + *Circle( + fill = Srgb::::from_format(named::RED).into_linear(), + { radius }, + translate = [x as f32 * 5., 10.], + ), + *Text(fill = Srgb::::from_format(named::BLACK).into_linear(), font_size = 10., text = "Hi !",), + ]) + }); + + let dessin = dessin2!([ + { dessin }(scale = [2., 2.]), + MyShape(say_this = "Hello world"), + ]); +} +``` + +### Components + +[Base components][`crate::shapes`] are defined in the `shapes` module. + +[Components using base ones][`crate::contrib`] are defined in the `contrib` module. + +In `dessin`, a component is just a struct/enum that can be converted to a [Shape][crate::shapes::Shape], +and implements the [Default][`std::default::Default`] trait. +This means that a component can be as simple as: +```rust +use dessin::prelude::*; + +#[derive(Default)] +struct MyComponent {} + +impl From for Shape { + fn from(my_component: MyComponent) -> Shape { + dessin2!( + // Implementation... + ) + } +} ``` + +Since the [dessin2!][`dessin_macros::dessin2`] macro is only syntactic sugar for creating a [Shape][crate::shapes::Shape], +all parameters are simply rust function with the following signature: `fn (&mut self, argument_value: ArgumentType) {...}`. + +It can be tedious to create these function for all parameters, so the derive macro [Shape][`dessin_macro::shape`] +is here to do exactly that. + +So +```rust + #[derive(Default, Shape)] +struct MyComponent { + // This auto implements ShapeOp for MyComponent using `my_local_transform` as the storage. + #[local_transform] + my_local_transform: Transform2, + + // Generate a function for u32 + value: u32, + + // Does not generate a function for this field + #[shape(skip)] + skip_value: u32, + + // Generates a function for Into + #[shape(into)] + into_value: u32, + + // Generates a function that does not take any arguments, but set `my_bool` to true + #[shape(bool)] + my_bool: bool, +} + +``` + +becomes +```rust + + #[derive(Default)] +struct MyComponent { + my_local_transform: Transform2, + value: u32, + skip_value: u32, + into_value: u32, + my_bool: bool, +} + +impl ShapeOp for MyComponent { /* skip impl */ } + +impl MyComponent { + pub fn value(&mut self, value: u32) -> &mut Self { + /* skip impl */ + } + pub fn into_value>(&mut self, value: T) -> &mut Self { + /* skip impl */ + } + pub fn my_bool(&mut self) -> &mut Self { + /* skip impl */ + } +} + +``` +To be precise, all functions generated by this derive macro, return `&mut Self` to chain function together. +Generated functions have the same name as their corresponding field. +This derive macro also generate corresponding `with_xxxx`, taking `self` instead of `&mut self` and returning `Self`. + +One still does need to implement `From for Shape { ... }` manually. + +### Implement own export format. +Documentation can be found in the [`export`] module. + +License: MIT diff --git a/dessin/src/lib.rs b/dessin/src/lib.rs index b7df120..43f5cc4 100644 --- a/dessin/src/lib.rs +++ b/dessin/src/lib.rs @@ -155,6 +155,7 @@ #![warn(missing_docs)] #![allow(clippy::tabs_in_doc_comments)] +#![doc = include_str!("../../README.md")] pub mod macros;