12 unstable releases (3 breaking)

0.4.0 Jan 21, 2024
0.4.0-rc.0 Jan 20, 2024
0.3.0 Dec 28, 2023
0.2.0 Oct 22, 2023
0.1.0-alpha.2 Sep 30, 2023

#244 in Visualization

33 downloads per month
Used in 3 crates

MIT license

6MB
6.5K SLoC

vsvg-viewer crate

This crate is part of the vsvg project.

Status: Beta. It works, but the API is subject to change.

What's this?

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.

Usage

vsvg-viewer offers two main features:

  • a basic vsvg::Document viewer
  • a fully customisable application built on the vsvg::Document viewer

Basic 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

For users familiar with vpype, this basically corresponds to what happens with vpype [...] show.

Customisable app

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

Dependencies

~31–76MB
~1.5M SLoC