Skip to main content

Module sdk

Module sdk 

Source
Expand description

The safe Rust SDK for writing eov plugins.

Implement Plugin and export it with crate::export_plugin!:

use eov_plugin_api::prelude::*;

struct Hello {
    host: Host,
}

impl Plugin for Hello {
    fn create(host: Host, _init: PluginInit) -> Result<Self, String> {
        host.add_toolbar_button(ToolbarButtonSpec {
            button_id: "hello".into(),
            tooltip: "Say hello".into(),
            icon_svg: "<svg xmlns='http://www.w3.org/2000/svg'/>".into(),
            ..Default::default()
        })
        .map_err(|e| e.to_string())?;
        Ok(Self { host })
    }

    fn on_event(&self, event: HostEvent) -> Result<(), String> {
        if let HostEvent::ToolbarButtonClicked { .. } = event {
            self.host.notify(NotifyLevel::Info, "Hello from a plugin");
        }
        Ok(())
    }
}

eov_plugin_api::export_plugin!(Hello);

Every call into the plugin is wrapped in catch_unwind: a panic becomes an error the host reports (and the host disables the plugin) instead of aborting eov.

§Slide formats

A plugin that reads slides eov cannot read itself declares the formats in its manifest ([[slide_formats]]), implements Plugin::open_slide and returns a SlideReader per slide; crate::export_plugin! exports the rest:

use eov_plugin_api::prelude::*;

struct Flat;

impl SlideReader for Flat {
    fn info(&self) -> SlideInfo {
        SlideInfo {
            levels: vec![SlideLevel { width: 1024, height: 1024, ..Default::default() }],
            ..Default::default()
        }
    }

    fn read_region(&self, _region: &SlideRegion, out: &mut [u8]) -> Result<(), String> {
        for px in out.chunks_exact_mut(4) {
            px.copy_from_slice(&[230, 200, 220, 255]);
        }
        Ok(())
    }
}

struct FlatFormat;

impl Plugin for FlatFormat {
    fn create(_host: Host, _init: PluginInit) -> Result<Self, String> {
        Ok(Self)
    }

    fn open_slide(&self, request: &SlideOpenRequest) -> Result<Box<dyn SlideReader>, String> {
        std::fs::metadata(&request.location).map_err(|e| e.to_string())?;
        Ok(Box::new(Flat))
    }
}

eov_plugin_api::export_plugin!(FlatFormat);

Structs§

Frame
A rendered frame handed to Plugin::apply_filter.
Host
A cheap, cloneable, thread-safe handle to the host.
HostError
An error returned by a host call.
Image
An RGBA8 image with straight alpha, row-major, without padding.
Job
A background job shown in the host UI. Dropping an unfinished job marks it finished.
Layer
A handle to an overlay layer.
Surface
A handle to an open surface.

Constants§

ROOT_MODULE_LOADER_SYMBOL
Name of the static abi_stable looks up in a plugin library. Spelled out so that crate::export_plugin! needs no abi_stable dependency in the plugin crate; a unit test keeps it in sync.

Traits§

Plugin
An eov plugin.
SlideReader
One slide opened by Plugin::open_slide.

Type Aliases§

HostResult