mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-04 05:18:19 +00:00
Groundwork for integrating Specta (#949)
* add derive(specta::Type) * use specta from git * introduce Uuid type * remove unnecessary specta::Type * document export_types test * upgrade Specta The previous Specta branch had some hacks that were just for this project. They have all been converted into proper features so they can be merged into main. * remove some unnecessary specta::Type uses * add MessageDiscriminantDef explanation * manually export types with specta * rename 'specta.rs' to 'export_types.rs' * rename 'export_types' to 'generate_ts_types' --------- Co-authored-by: Oscar Beaumont <oscar@otbeaumont.me>
This commit is contained in:
parent
e0146d57f7
commit
5388b59e97
72 changed files with 286 additions and 140 deletions
|
@ -33,4 +33,5 @@ kurbo = { git = "https://github.com/linebender/kurbo.git", features = [
|
|||
], optional = true }
|
||||
glam = { version = "^0.22", default-features = false, features = ["scalar-math", "libm"]}
|
||||
node-macro = {path = "../node-macro"}
|
||||
specta.workspace = true
|
||||
# forma = { version = "0.1.0", package = "forma-render" }
|
||||
|
|
|
@ -15,6 +15,7 @@ use async_trait::async_trait;
|
|||
pub mod generic;
|
||||
pub mod ops;
|
||||
pub mod structural;
|
||||
pub mod uuid;
|
||||
pub mod value;
|
||||
|
||||
#[cfg(feature = "gpu")]
|
||||
|
|
|
@ -436,7 +436,7 @@ mod image {
|
|||
use super::{Color, ImageSlice};
|
||||
use alloc::vec::Vec;
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
#[derive(Clone, Debug, PartialEq, DynAny, Default)]
|
||||
#[derive(Clone, Debug, PartialEq, DynAny, Default, specta::Type)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Image {
|
||||
pub width: u32,
|
||||
|
|
|
@ -18,7 +18,7 @@ use bytemuck::{Pod, Zeroable};
|
|||
#[repr(C)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "gpu", derive(Pod, Zeroable))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default, DynAny)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default, DynAny, specta::Type)]
|
||||
pub struct Color {
|
||||
red: f32,
|
||||
green: f32,
|
||||
|
|
42
node-graph/gcore/src/uuid.rs
Normal file
42
node-graph/gcore/src/uuid.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, specta::Type)]
|
||||
pub struct Uuid(
|
||||
#[serde(with = "u64_string")]
|
||||
#[specta(type = String)]
|
||||
u64,
|
||||
);
|
||||
|
||||
mod u64_string {
|
||||
use serde::{self, Deserialize, Deserializer, Serializer};
|
||||
use std::str::FromStr;
|
||||
|
||||
// The signature of a serialize_with function must follow the pattern:
|
||||
//
|
||||
// fn serialize<S>(&T, S) -> Result<S::Ok, S::Error>
|
||||
// where
|
||||
// S: Serializer
|
||||
//
|
||||
// although it may also be generic over the input types T.
|
||||
pub fn serialize<S>(value: &u64, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&value.to_string())
|
||||
}
|
||||
|
||||
// The signature of a deserialize_with function must follow the pattern:
|
||||
//
|
||||
// fn deserialize<'de, D>(D) -> Result<T, D::Error>
|
||||
// where
|
||||
// D: Deserializer<'de>
|
||||
//
|
||||
// although it may also be generic over the output types T.
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<u64, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
u64::from_str(&s).map_err(serde::de::Error::custom)
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ use core::ops::{Index, IndexMut};
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[repr(usize)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Copy, Serialize, Deserialize)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Copy, Serialize, Deserialize, specta::Type)]
|
||||
pub enum ManipulatorType {
|
||||
Anchor,
|
||||
InHandle,
|
||||
|
|
|
@ -17,7 +17,7 @@ use alloc::vec::Vec;
|
|||
/// The downside is that currently it requires a lot of iteration.
|
||||
|
||||
type ElementId = u64;
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, specta::Type)]
|
||||
pub struct IdBackedVec<T> {
|
||||
/// Contained elements
|
||||
elements: Vec<T>,
|
||||
|
|
|
@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
|
|||
/// / | \
|
||||
/// "Anchor" "InHandle" "OutHandle" <- These are ManipulatorPoints and the only editable "primitive"
|
||||
/// ```
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, Default)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, Default, specta::Type)]
|
||||
pub struct ManipulatorGroup {
|
||||
/// Editable points for the anchor and handles.
|
||||
pub points: [Option<ManipulatorPoint>; 3],
|
||||
|
|
|
@ -3,7 +3,7 @@ use glam::{DAffine2, DVec2};
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// [ManipulatorPoint] represents any editable Bezier point, either an anchor or handle
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
pub struct ManipulatorPoint {
|
||||
/// The sibling element if this is a handle
|
||||
pub position: glam::DVec2,
|
||||
|
@ -60,7 +60,7 @@ impl ManipulatorPoint {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, specta::Type)]
|
||||
pub struct ManipulatorPointEditorState {
|
||||
/// Whether or not this manipulator point can be selected.
|
||||
pub can_be_selected: bool,
|
||||
|
|
|
@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
|
|||
/// [Subpath] represents a single vector path, containing many [ManipulatorGroups].
|
||||
/// For each closed shape we keep a [Subpath] which contains the [ManipulatorGroup]s (handles and anchors) that define that shape.
|
||||
// TODO Add "closed" bool to subpath
|
||||
#[derive(PartialEq, Clone, Debug, Default, Serialize, Deserialize, DynAny)]
|
||||
#[derive(PartialEq, Clone, Debug, Default, Serialize, Deserialize, DynAny, specta::Type)]
|
||||
pub struct Subpath(IdBackedVec<ManipulatorGroup>);
|
||||
|
||||
impl Subpath {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue