mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 02:18:11 +08:00
Hook up layer tree structure with frontend (#372)
* Hook up layer tree structure with frontend (decoding and Vue are WIP) * Fix off by one error * Avoid leaking memory * Parse layer structure into list of layers * Fix thumbnail updates * Correctly popagate deletions * Fix selection state in layer tree * Respect expansion during root serialization * Allow expanding of subfolders * Fix arrow direction Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
co-authored by
Dennis Kobert
parent
88bb24a206
commit
f5e03df80b
@@ -5,7 +5,10 @@ use graphene::{
|
||||
layers::{Layer, LayerData as DocumentLayerData},
|
||||
LayerId,
|
||||
};
|
||||
use serde::{ser::SerializeSeq, Deserialize, Serialize};
|
||||
use serde::{
|
||||
ser::{SerializeSeq, SerializeStruct},
|
||||
Deserialize, Serialize,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
|
||||
@@ -117,6 +120,33 @@ impl Serialize for Path {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
pub struct RawBuffer(Vec<u8>);
|
||||
|
||||
impl From<Vec<u64>> for RawBuffer {
|
||||
fn from(iter: Vec<u64>) -> Self {
|
||||
// https://github.com/rust-lang/rust-clippy/issues/4484
|
||||
let v_from_raw: Vec<u8> = unsafe {
|
||||
// prepare for an auto-forget of the initial vec:
|
||||
let v_orig: &mut Vec<_> = &mut *std::mem::ManuallyDrop::new(iter);
|
||||
Vec::from_raw_parts(v_orig.as_mut_ptr() as *mut u8, v_orig.len() * 8, v_orig.capacity() * 8)
|
||||
// v_orig is never used again, so no aliasing issue
|
||||
};
|
||||
Self(v_from_raw)
|
||||
}
|
||||
}
|
||||
impl Serialize for RawBuffer {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let mut buffer = serializer.serialize_struct("Buffer", 2)?;
|
||||
buffer.serialize_field("ptr", &(self.0.as_ptr() as usize))?;
|
||||
buffer.serialize_field("len", &(self.0.len()))?;
|
||||
buffer.end()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct LayerPanelEntry {
|
||||
pub name: String,
|
||||
|
||||
Reference in New Issue
Block a user