-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
695783b
commit 058af28
Showing
10 changed files
with
138 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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(); | ||
|
||
``` | ||
License: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# dessin-image | ||
|
||
License: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# Dessin PDF | ||
# dessin-pdf | ||
|
||
License: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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(); | ||
|
||
``` | ||
License: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ authors = [ | |
"Olivier Lemoine <[email protected]>", | ||
"Francois Morillon <[email protected]>", | ||
] | ||
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,142 @@ | ||
# [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) { | ||
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() | ||
fn from(MyShape { text }: MyShape) -> Self { | ||
dessin2!(*Text(fill = Srgb::<f32>::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::<f32>::from_format(named::RED).into_linear(), | ||
{ radius }, | ||
translate = [x as f32 * 5., 10.], | ||
), | ||
*Text(fill = Srgb::<f32>::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<MyComponent> 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<f32>, | ||
|
||
// 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<u32> | ||
#[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<f32>, | ||
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<T: Into<u32>>(&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<MyComponent> for Shape { ... }` manually. | ||
|
||
### Implement own export format. | ||
Documentation can be found in the [`export`] module. | ||
|
||
License: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters