vsvg-viewer

Crates.iovsvg-viewer
lib.rsvsvg-viewer
version0.5.0
sourcesrc
created_at2023-09-29 19:45:37.95261
updated_at2024-09-21 09:51:18.114106
descriptionPortable, hardware-accelerated, extensible viewer for the vsvg crate.
homepagehttps://github.com/abey79/vsvg
repositoryhttps://github.com/abey79/vsvg
max_upload_size
id987805
size214,961
Antoine Beyeler (abey79)

documentation

README

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
Commit count: 260

cargo fmt