This crate is part of the vsvg project.
Status: Beta. It works, but the API is subject to change.
This crate implements an extensible egui- and wgpu-based viewer for vsvg. It's very much similar to vpype-viewer, but built on much stronger foundations:
- The egui crate is an immediate-mode UI framework, which makes it suited for easy customisation and highly interactive projects (such as whiskers).
- The wgpu crate is a wrapper over modern native and web graphics APIs. It's future-proof.
This combination enables targeting WebAssembly too.
vsvg-viewer offers two main features:
- a basic
vsvg::Document
viewer - a fully customisable application built on the
vsvg::Document
viewer
The basic vsvg::Document
viewer requires a single line of code:
fn main() -> anyhow::Result<()> {
let doc = vsvg::Document::from_svg("path/to/input.svg");
vsvg_viewer::show(&doc)
}
Here is an example screenshot:
![image](https://private-user-images.githubusercontent.com/49431240/270339711-3659fa9a-a967-41d7-bede-743e025e748e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTAwMDIsIm5iZiI6MTczOTI0OTcwMiwicGF0aCI6Ii80OTQzMTI0MC8yNzAzMzk3MTEtMzY1OWZhOWEtYTk2Ny00MWQ3LWJlZGUtNzQzZTAyNWU3NDhlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDA0NTUwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ3MzA4OWUyZDBlY2Y0YjdjMzgxMGFlMWZkZTYwMzY3ZjIxNTJlOWZmNTI4MmM0YTQzZjkwNDIyMGYxN2EyMGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.fCcR1nzjxwoOb-OL7DSKnIvtXsPjtXzM5g6y8EGZQ24)
For users familiar with vpype, this basically corresponds to what happens with vpype [...] show
.
Alternatively, vsvg-viewer can be used to build complex, interactive application around the core vsvg::Document
renderer feature:
struct MyApp {}
impl vsvg_viewer::ViewerApp for MyApp {
/* ... */
}
fn main() -> anyhow::Result<()> {
vsvg_viewer::show_with_viewer_app(MyApp::new())
}
Your app must implement the vsvg_viewer::ViewerApp
trait, which offers hooks to:
- display the custom UI, for example in side panels;
- customise options such as windows title, etc.;
- load/save state from persistent storage.
A basic example for a custom app is provided in the examples/
directory.
whiskers) uses this API to implement its sketch runner:
![image](https://private-user-images.githubusercontent.com/49431240/270341722-636a343b-d175-4b8a-9acf-812ae64f2b32.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTAwMDIsIm5iZiI6MTczOTI0OTcwMiwicGF0aCI6Ii80OTQzMTI0MC8yNzAzNDE3MjItNjM2YTM0M2ItZDE3NS00YjhhLTlhY2YtODEyYWU2NGYyYjMyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDA0NTUwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEyOWUyY2VmZWM3MWM0ZmE5MDZkOGE3MzA1NTdiMGVjMWYwNTBkNjA2NzdkZjQ4OTdjN2RkNjU4MGYxYzFlYWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.tK9_C4PSrWzN3sdeMqDpXAVfN3RyU3-jSB5JJlRQm7U)