Skip to main content

lgui_assets/
custom_paint.rs

1use std::sync::Arc;
2
3#[cfg(feature = "svg")]
4use crate::core::PhysicalSize;
5use crate::core::{CustomPaintStyle, ScenePrimitive, UiRect};
6
7use super::AssetError;
8#[cfg(feature = "svg")]
9use super::ImageData;
10
11pub trait CustomPaintProvider: Send + Sync + 'static {
12    fn record(
13        &self,
14        key: &str,
15        bounds: UiRect,
16        style: CustomPaintStyle,
17    ) -> Result<Option<SceneFragment>, AssetError>;
18}
19
20#[derive(Clone, Debug, PartialEq)]
21pub struct SceneFragment {
22    commands: Arc<[ScenePrimitive]>,
23}
24
25impl SceneFragment {
26    pub fn new(commands: impl Into<Arc<[ScenePrimitive]>>) -> Self {
27        Self {
28            commands: commands.into(),
29        }
30    }
31
32    pub fn commands(&self) -> &[ScenePrimitive] {
33        &self.commands
34    }
35}
36
37#[cfg(feature = "svg")]
38pub trait SvgRenderer: Send + Sync + 'static {
39    fn render(&self, source: &[u8], size: PhysicalSize) -> Result<ImageData, AssetError>;
40}