use abi_stable::StableAbi;
use abi_stable::std_types::{ROption, RResult, RString, RVec};
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ActiveSidebarFFI {
pub plugin_id: RString,
pub button_id: ROption<RString>,
pub width_px: u32,
pub ui_path: RString,
pub component: RString,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ToolbarButtonFFI {
pub button_id: RString,
pub tooltip: RString,
pub icon_svg: RString,
pub action_id: RString,
pub tool_mode: ROption<HostToolModeFFI>,
pub hotkey: ROption<RString>,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct HudToolbarButtonFFI {
pub button_id: RString,
pub tooltip: RString,
pub icon_svg: RString,
pub toggled_icon_svg: ROption<RString>,
pub action_id: RString,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct UiPropertyFFI {
pub name: RString,
pub json_value: RString,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ViewportContextMenuItemFFI {
pub item_id: RString,
pub label: RString,
pub icon: RString,
pub enabled: bool,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ViewportOverlayPointFFI {
pub annotation_id: RString,
pub x_level0: f64,
pub y_level0: f64,
pub diameter_px: f32,
pub ring_red: u8,
pub ring_green: u8,
pub ring_blue: u8,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ViewportOverlayVertexFFI {
pub x_level0: f64,
pub y_level0: f64,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ViewportOverlayPolygonFFI {
pub annotation_id: RString,
pub vertices: RVec<ViewportOverlayVertexFFI>,
pub fill_red: u8,
pub fill_green: u8,
pub fill_blue: u8,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ConfirmationDialogRequestFFI {
pub title: RString,
pub message: RString,
pub confirm_label: RString,
pub cancel_label: RString,
pub confirm_callback: ROption<RString>,
pub confirm_args_json: ROption<RString>,
pub cancel_callback: ROption<RString>,
pub cancel_args_json: ROption<RString>,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ModalDialogRequestFFI {
pub ui_path: RString,
pub component: RString,
pub width_px: u32,
pub height_px: u32,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ViewportOverlayComponentRequestFFI {
pub ui_path: RString,
pub component: RString,
pub z_index: i32,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug, Default)]
pub struct PluginUndoRedoStateFFI {
pub enabled: bool,
pub undo_available: bool,
pub redo_available: bool,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ActionResponseFFI {
pub open_window: bool,
}
#[repr(u32)]
#[derive(StableAbi, Clone, Copy, Debug, PartialEq, Eq)]
pub enum HostLogLevelFFI {
Trace = 0,
Debug = 1,
Info = 2,
Warn = 3,
Error = 4,
}
#[repr(u32)]
#[derive(StableAbi, Clone, Copy, Debug, PartialEq, Eq)]
pub enum HostToolModeFFI {
Navigate = 0,
RegionOfInterest = 1,
MeasureDistance = 2,
PointAnnotation = 3,
PolygonAnnotation = 4,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct OpenFileInfoFFI {
pub file_id: i32,
pub path: RString,
pub filename: RString,
pub width: u64,
pub height: u64,
pub level_count: u32,
pub vendor: ROption<RString>,
pub mpp_x: ROption<f64>,
pub mpp_y: ROption<f64>,
pub objective_power: ROption<f64>,
pub scan_date: ROption<RString>,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ViewportSnapshotFFI {
pub pane_index: u32,
pub file_id: i32,
pub file_path: RString,
pub filename: RString,
pub center_x: f64,
pub center_y: f64,
pub zoom: f64,
pub width: f64,
pub height: f64,
pub image_width: f64,
pub image_height: f64,
pub bounds_left: f64,
pub bounds_top: f64,
pub bounds_right: f64,
pub bounds_bottom: f64,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct HostSnapshotFFI {
pub app_name: RString,
pub app_version: RString,
pub render_backend: RString,
pub filtering_mode: RString,
pub split_enabled: bool,
pub focused_pane: u32,
pub open_files: RVec<OpenFileInfoFFI>,
pub active_file: ROption<OpenFileInfoFFI>,
pub active_viewport: ROption<ViewportSnapshotFFI>,
pub recent_files: RVec<RString>,
pub active_sidebar: ROption<ActiveSidebarFFI>,
}
#[repr(C)]
#[derive(StableAbi, Copy, Clone)]
pub struct HostApiVTable {
pub context: u64,
pub get_snapshot: extern "C" fn(context: u64) -> HostSnapshotFFI,
pub read_region: extern "C" fn(
context: u64,
file_id: i32,
level: u32,
x: i64,
y: i64,
width: u32,
height: u32,
) -> RResult<RVec<u8>, RString>,
pub open_file: extern "C" fn(context: u64, path: RString) -> RResult<(), RString>,
pub set_active_viewport: extern "C" fn(
context: u64,
center_x: f64,
center_y: f64,
zoom: f64,
) -> RResult<(), RString>,
pub fit_active_viewport: extern "C" fn(context: u64) -> RResult<(), RString>,
pub frame_active_rect: extern "C" fn(
context: u64,
x: f64,
y: f64,
width: f64,
height: f64,
) -> RResult<(), RString>,
pub cycle_focused_pane: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
pub cycle_active_tab: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
pub toggle_series_bar: extern "C" fn(context: u64) -> RResult<(), RString>,
pub cycle_series_selection: extern "C" fn(context: u64, offset: i32) -> RResult<(), RString>,
pub activate_selected_series_entry: extern "C" fn(context: u64) -> RResult<(), RString>,
pub set_active_tool: extern "C" fn(context: u64, tool: HostToolModeFFI) -> RResult<(), RString>,
pub request_render: extern "C" fn(context: u64) -> RResult<(), RString>,
pub set_toolbar_button_active:
extern "C" fn(context: u64, button_id: RString, active: bool) -> RResult<(), RString>,
pub set_hud_toolbar_button_active:
extern "C" fn(context: u64, button_id: RString, active: bool) -> RResult<(), RString>,
pub show_sidebar: extern "C" fn(
context: u64,
button_id: RString,
width_px: u32,
ui_path: RString,
component: RString,
) -> RResult<(), RString>,
pub refresh_sidebar: extern "C" fn(context: u64) -> RResult<(), RString>,
pub hide_sidebar: extern "C" fn(context: u64) -> RResult<(), RString>,
pub show_confirmation_dialog:
extern "C" fn(context: u64, request: ConfirmationDialogRequestFFI) -> RResult<(), RString>,
pub show_modal_dialog:
extern "C" fn(context: u64, request: ModalDialogRequestFFI) -> RResult<(), RString>,
pub hide_modal_dialog: extern "C" fn(context: u64) -> RResult<(), RString>,
pub set_undo_redo_state:
extern "C" fn(context: u64, state: PluginUndoRedoStateFFI) -> RResult<(), RString>,
pub open_file_dialog: extern "C" fn(
context: u64,
filter_name: RString,
extension: RString,
) -> RResult<RString, RString>,
pub save_file_dialog: extern "C" fn(
context: u64,
default_file_name: RString,
filter_name: RString,
extension: RString,
) -> RResult<RString, RString>,
pub log_message: extern "C" fn(context: u64, level: HostLogLevelFFI, message: RString),
}
#[repr(C)]
#[derive(StableAbi, Copy, Clone)]
pub struct PluginVTable {
pub set_host_api: extern "C" fn(host_api: HostApiVTable),
pub get_toolbar_buttons: extern "C" fn() -> RVec<ToolbarButtonFFI>,
pub get_hud_toolbar_buttons: extern "C" fn() -> RVec<HudToolbarButtonFFI>,
pub on_action: extern "C" fn(action_id: RString) -> ActionResponseFFI,
pub on_hud_action:
extern "C" fn(action_id: RString, viewport: ViewportSnapshotFFI) -> ActionResponseFFI,
pub on_ui_callback: extern "C" fn(callback_name: RString, args_json: RString),
pub get_sidebar_properties: extern "C" fn() -> RVec<UiPropertyFFI>,
pub get_viewport_context_menu_items:
extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportContextMenuItemFFI>,
pub on_viewport_context_menu_action:
extern "C" fn(item_id: RString, viewport: ViewportSnapshotFFI) -> ActionResponseFFI,
pub get_viewport_overlay_points:
extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportOverlayPointFFI>,
pub get_viewport_overlay_polygons:
extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<ViewportOverlayPolygonFFI>,
pub get_viewport_overlay_component:
extern "C" fn() -> ROption<ViewportOverlayComponentRequestFFI>,
pub get_viewport_overlay_properties:
extern "C" fn(viewport: ViewportSnapshotFFI) -> RVec<UiPropertyFFI>,
pub on_point_annotation_placed:
extern "C" fn(viewport: ViewportSnapshotFFI, x_level0: f64, y_level0: f64),
pub on_polygon_annotation_placed:
extern "C" fn(viewport: ViewportSnapshotFFI, vertices: RVec<ViewportOverlayVertexFFI>),
pub on_undo: extern "C" fn() -> ActionResponseFFI,
pub on_redo: extern "C" fn() -> ActionResponseFFI,
pub on_point_annotation_moved: extern "C" fn(
viewport: ViewportSnapshotFFI,
annotation_id: RString,
x_level0: f64,
y_level0: f64,
),
pub on_polygon_annotation_moved: extern "C" fn(
viewport: ViewportSnapshotFFI,
annotation_id: RString,
vertices: RVec<ViewportOverlayVertexFFI>,
),
pub on_viewport_annotation_selected:
extern "C" fn(viewport: ViewportSnapshotFFI, annotation_id: RString),
pub get_viewport_filters: extern "C" fn() -> RVec<ViewportFilterFFI>,
pub apply_filter_cpu: extern "C" fn(
filter_id: RString,
rgba_data: *mut u8,
len: u32,
width: u32,
height: u32,
viewport: *const ViewportSnapshotFFI,
) -> bool,
pub apply_filter_gpu:
extern "C" fn(filter_id: RString, ctx: *const GpuFilterContextFFI) -> bool,
pub set_filter_enabled: extern "C" fn(filter_id: RString, enabled: bool),
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct GpuFilterContextFFI {
pub vk_device: u64,
pub vk_physical_device: u64,
pub vk_queue: u64,
pub queue_family_index: u32,
pub vk_image: u64,
pub width: u32,
pub height: u32,
pub vk_format: u32,
pub vk_done_fence: u64,
}
#[repr(C)]
#[derive(StableAbi, Clone, Debug)]
pub struct ViewportFilterFFI {
pub filter_id: RString,
pub name: RString,
pub supports_cpu: bool,
pub supports_gpu: bool,
pub enabled: bool,
}
pub type GetPluginVTableFn = unsafe extern "C" fn() -> PluginVTable;
pub const PLUGIN_VTABLE_SYMBOL: &[u8] = b"eov_get_plugin_vtable\0";
pub fn plugin_library_filename(id: &str) -> String {
if cfg!(target_os = "macos") {
format!("lib{id}.dylib")
} else if cfg!(target_os = "windows") {
format!("{id}.dll")
} else {
format!("lib{id}.so")
}
}