|
1 |
| -use crate::{consts::ROTATE_SNAP_INTERVAL, frontend::layer_panel::*}; |
| 1 | +use crate::consts::ROTATE_SNAP_INTERVAL; |
2 | 2 | use glam::{DAffine2, DVec2};
|
| 3 | +use graphene::layers::{BlendMode, LayerDataType}; |
3 | 4 | use graphene::{
|
4 | 5 | layers::{Layer, LayerData as DocumentLayerData},
|
5 | 6 | LayerId,
|
6 | 7 | };
|
7 | 8 | use serde::{ser::SerializeSeq, Deserialize, Serialize};
|
8 | 9 | use std::collections::HashMap;
|
9 |
| - |
10 |
| -#[derive(Debug, Clone, Deserialize, PartialEq)] |
11 |
| -pub struct Path(Vec<LayerId>); |
12 |
| - |
13 |
| -impl From<Vec<LayerId>> for Path { |
14 |
| - fn from(iter: Vec<LayerId>) -> Self { |
15 |
| - Self(iter) |
16 |
| - } |
17 |
| -} |
18 |
| -impl Serialize for Path { |
19 |
| - fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
20 |
| - where |
21 |
| - S: serde::Serializer, |
22 |
| - { |
23 |
| - let mut seq = serializer.serialize_seq(Some(self.0.len()))?; |
24 |
| - for e in self.0.iter() { |
25 |
| - #[cfg(target_arch = "wasm32")] |
26 |
| - { |
27 |
| - // LayerIds are sent as (u32, u32) because json does not support u64s |
28 |
| - let id = ((e >> 32) as u32, (e << 32 >> 32) as u32); |
29 |
| - seq.serialize_element(&id)?; |
30 |
| - } |
31 |
| - #[cfg(not(target_arch = "wasm32"))] |
32 |
| - seq.serialize_element(e)?; |
33 |
| - } |
34 |
| - seq.end() |
35 |
| - } |
36 |
| -} |
| 10 | +use std::fmt; |
37 | 11 |
|
38 | 12 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Copy)]
|
39 | 13 | pub struct LayerData {
|
@@ -117,3 +91,70 @@ pub fn layer_panel_entry(layer_data: &LayerData, transform: DAffine2, layer: &La
|
117 | 91 | thumbnail,
|
118 | 92 | }
|
119 | 93 | }
|
| 94 | + |
| 95 | +#[derive(Debug, Clone, Deserialize, PartialEq)] |
| 96 | +pub struct Path(Vec<LayerId>); |
| 97 | + |
| 98 | +impl From<Vec<LayerId>> for Path { |
| 99 | + fn from(iter: Vec<LayerId>) -> Self { |
| 100 | + Self(iter) |
| 101 | + } |
| 102 | +} |
| 103 | +impl Serialize for Path { |
| 104 | + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
| 105 | + where |
| 106 | + S: serde::Serializer, |
| 107 | + { |
| 108 | + let mut seq = serializer.serialize_seq(Some(self.0.len()))?; |
| 109 | + for e in self.0.iter() { |
| 110 | + #[cfg(target_arch = "wasm32")] |
| 111 | + { |
| 112 | + // LayerIds are sent as (u32, u32) because json does not support u64s |
| 113 | + let id = ((e >> 32) as u32, (e << 32 >> 32) as u32); |
| 114 | + seq.serialize_element(&id)?; |
| 115 | + } |
| 116 | + #[cfg(not(target_arch = "wasm32"))] |
| 117 | + seq.serialize_element(e)?; |
| 118 | + } |
| 119 | + seq.end() |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 124 | +pub struct LayerPanelEntry { |
| 125 | + pub name: String, |
| 126 | + pub visible: bool, |
| 127 | + pub blend_mode: BlendMode, |
| 128 | + pub opacity: f64, |
| 129 | + pub layer_type: LayerType, |
| 130 | + pub layer_data: LayerData, |
| 131 | + pub path: crate::document::layer_panel::Path, |
| 132 | + pub thumbnail: String, |
| 133 | +} |
| 134 | + |
| 135 | +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] |
| 136 | +pub enum LayerType { |
| 137 | + Folder, |
| 138 | + Shape, |
| 139 | +} |
| 140 | + |
| 141 | +impl fmt::Display for LayerType { |
| 142 | + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 143 | + let name = match self { |
| 144 | + LayerType::Folder => "Folder", |
| 145 | + LayerType::Shape => "Shape", |
| 146 | + }; |
| 147 | + |
| 148 | + formatter.write_str(name) |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +impl From<&LayerDataType> for LayerType { |
| 153 | + fn from(data: &LayerDataType) -> Self { |
| 154 | + use LayerDataType::*; |
| 155 | + match data { |
| 156 | + Folder(_) => LayerType::Folder, |
| 157 | + Shape(_) => LayerType::Shape, |
| 158 | + } |
| 159 | + } |
| 160 | +} |
0 commit comments