Skip to main content

ferroui_controls_inking/
ink_platform_services.rs

1use super::{InkError, InkStroke};
2use ferroui_base::Point;
3use std::future::Future;
4use std::pin::Pin;
5use std::rc::Rc;
6
7/// Persisted representation. The portable format preserves FerroUI telemetry;
8/// the other two formats use a platform service with genuine ISF support.
9#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
10#[repr(i32)]
11pub enum InkPersistenceFormat {
12    GifWithEmbeddedIsf = 0,
13    Isf = 1,
14    #[default]
15    Portable = 2,
16}
17
18pub type InkServiceFuture<T> = Pin<Box<dyn Future<Output = Result<T, InkError>>>>;
19
20/// Optional OS interoperability. The native Windows implementation uses the
21/// Windows ink engine for ISF, embedded ISF/GIF and the system ink clipboard.
22/// Core drawing, collection editing and portable persistence require no service.
23pub trait IInkPlatformServices {
24    /// Capture the supplied strokes' values before returning the future.
25    /// Stroke handles remain editable by their owners while native I/O awaits.
26    fn save(
27        &self,
28        strokes: Vec<Rc<InkStroke>>,
29        format: InkPersistenceFormat,
30    ) -> InkServiceFuture<Vec<u8>>;
31    fn load(&self, data: Vec<u8>) -> InkServiceFuture<Vec<Rc<InkStroke>>>;
32    fn copy_to_clipboard(&self, strokes: &[Rc<InkStroke>]) -> Result<(), InkError>;
33    fn can_paste(&self) -> Result<bool, InkError>;
34    fn paste(&self, position: Point) -> Result<Vec<Rc<InkStroke>>, InkError>;
35}