mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 00:48:12 +08:00
committed by
Keavon Chambers
parent
31fb0d7148
commit
916d10980d
@@ -8,13 +8,13 @@ use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Write;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Default)]
|
||||
pub struct Folder {
|
||||
pub struct FolderLayer {
|
||||
next_assignment_id: LayerId,
|
||||
pub layer_ids: Vec<LayerId>,
|
||||
layers: Vec<Layer>,
|
||||
}
|
||||
|
||||
impl LayerData for Folder {
|
||||
impl LayerData for FolderLayer {
|
||||
fn render(&mut self, svg: &mut String, transforms: &mut Vec<glam::DAffine2>, view_mode: ViewMode) {
|
||||
for layer in &mut self.layers {
|
||||
let _ = writeln!(svg, "{}", layer.render(transforms, view_mode));
|
||||
@@ -37,7 +37,7 @@ impl LayerData for Folder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Folder {
|
||||
impl FolderLayer {
|
||||
/// When a insertion id is provided, try to insert the layer with the given id.
|
||||
/// If that id is already used, return None.
|
||||
/// When no insertion id is provided, search for the next free id and insert it with that.
|
||||
@@ -109,7 +109,7 @@ impl Folder {
|
||||
self.layer_ids.iter().position(|x| *x == layer_id).ok_or_else(|| DocumentError::LayerNotFound([layer_id].into()))
|
||||
}
|
||||
|
||||
pub fn folder(&self, id: LayerId) -> Option<&Folder> {
|
||||
pub fn folder(&self, id: LayerId) -> Option<&FolderLayer> {
|
||||
match self.layer(id) {
|
||||
Some(Layer {
|
||||
data: LayerDataType::Folder(folder), ..
|
||||
@@ -118,7 +118,7 @@ impl Folder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn folder_mut(&mut self, id: LayerId) -> Option<&mut Folder> {
|
||||
pub fn folder_mut(&mut self, id: LayerId) -> Option<&mut FolderLayer> {
|
||||
match self.layer_mut(id) {
|
||||
Some(Layer {
|
||||
data: LayerDataType::Folder(folder), ..
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::blend_mode::BlendMode;
|
||||
use super::folder::Folder;
|
||||
use super::simple_shape::Shape;
|
||||
use super::folder_layer::FolderLayer;
|
||||
use super::shape_layer::ShapeLayer;
|
||||
use super::style::ViewMode;
|
||||
use super::text::Text;
|
||||
use super::text_layer::TextLayer;
|
||||
use crate::intersection::Quad;
|
||||
use crate::DocumentError;
|
||||
use crate::LayerId;
|
||||
@@ -13,9 +13,9 @@ use std::fmt::Write;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub enum LayerDataType {
|
||||
Folder(Folder),
|
||||
Shape(Shape),
|
||||
Text(Text),
|
||||
Folder(FolderLayer),
|
||||
Shape(ShapeLayer),
|
||||
Text(TextLayer),
|
||||
}
|
||||
|
||||
impl LayerDataType {
|
||||
@@ -149,28 +149,28 @@ impl Layer {
|
||||
self.current_bounding_box_with_transform(self.transform)
|
||||
}
|
||||
|
||||
pub fn as_folder_mut(&mut self) -> Result<&mut Folder, DocumentError> {
|
||||
pub fn as_folder_mut(&mut self) -> Result<&mut FolderLayer, DocumentError> {
|
||||
match &mut self.data {
|
||||
LayerDataType::Folder(f) => Ok(f),
|
||||
_ => Err(DocumentError::NotAFolder),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_folder(&self) -> Result<&Folder, DocumentError> {
|
||||
pub fn as_folder(&self) -> Result<&FolderLayer, DocumentError> {
|
||||
match &self.data {
|
||||
LayerDataType::Folder(f) => Ok(f),
|
||||
_ => Err(DocumentError::NotAFolder),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_text_mut(&mut self) -> Result<&mut Text, DocumentError> {
|
||||
pub fn as_text_mut(&mut self) -> Result<&mut TextLayer, DocumentError> {
|
||||
match &mut self.data {
|
||||
LayerDataType::Text(t) => Ok(t),
|
||||
_ => Err(DocumentError::NotText),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_text(&self) -> Result<&Text, DocumentError> {
|
||||
pub fn as_text(&self) -> Result<&TextLayer, DocumentError> {
|
||||
match &self.data {
|
||||
LayerDataType::Text(t) => Ok(t),
|
||||
_ => Err(DocumentError::NotText),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pub mod blend_mode;
|
||||
pub mod folder;
|
||||
pub mod folder_layer;
|
||||
pub mod layer_info;
|
||||
pub mod simple_shape;
|
||||
pub mod shape_layer;
|
||||
pub mod style;
|
||||
pub mod text;
|
||||
pub mod text_layer;
|
||||
|
||||
@@ -13,14 +13,14 @@ fn glam_to_kurbo(transform: DAffine2) -> Affine {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Shape {
|
||||
pub struct ShapeLayer {
|
||||
pub path: BezPath,
|
||||
pub style: style::PathStyle,
|
||||
pub render_index: i32,
|
||||
pub closed: bool,
|
||||
}
|
||||
|
||||
impl LayerData for Shape {
|
||||
impl LayerData for ShapeLayer {
|
||||
fn render(&mut self, svg: &mut String, transforms: &mut Vec<DAffine2>, view_mode: ViewMode) {
|
||||
let mut path = self.path.clone();
|
||||
let transform = self.transform(transforms, view_mode);
|
||||
@@ -60,7 +60,7 @@ impl LayerData for Shape {
|
||||
}
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
impl ShapeLayer {
|
||||
pub fn transform(&self, transforms: &[DAffine2], mode: ViewMode) -> DAffine2 {
|
||||
let start = match (mode, self.render_index) {
|
||||
(ViewMode::Outline, _) => 0,
|
||||
@@ -15,7 +15,7 @@ fn glam_to_kurbo(transform: DAffine2) -> Affine {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Text {
|
||||
pub struct TextLayer {
|
||||
pub text: String,
|
||||
pub style: style::PathStyle,
|
||||
pub size: f64,
|
||||
@@ -26,7 +26,7 @@ pub struct Text {
|
||||
cached_path: Option<BezPath>,
|
||||
}
|
||||
|
||||
impl LayerData for Text {
|
||||
impl LayerData for TextLayer {
|
||||
fn render(&mut self, svg: &mut String, transforms: &mut Vec<DAffine2>, view_mode: ViewMode) {
|
||||
let transform = self.transform(transforms, view_mode);
|
||||
let inverse = transform.inverse();
|
||||
@@ -84,7 +84,7 @@ impl LayerData for Text {
|
||||
}
|
||||
}
|
||||
|
||||
impl Text {
|
||||
impl TextLayer {
|
||||
pub fn transform(&self, transforms: &[DAffine2], mode: ViewMode) -> DAffine2 {
|
||||
let start = match mode {
|
||||
ViewMode::Outline => 0,
|
||||
Reference in New Issue
Block a user