Plumb layer panel (#107)

* WIP ExpandFolder handling

* Implement response parsing in typescript

* Update layer panel with list sent by wasm

* Add events for layer interaction

* Add proper default naming

* Fix displaying of the eye icon

* Attach path to LayerPanelEntry

* Fix lint issues

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
TrueDoctor
2021-05-07 10:41:38 -07:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent 67abeadf32
commit 437251f90e
14 changed files with 276 additions and 56 deletions
+46 -1
View File
@@ -1,4 +1,7 @@
use crate::LayerId;
use crate::{
layers::{Layer, LayerDataTypes},
LayerId,
};
use serde::{Deserialize, Serialize};
use std::fmt;
@@ -7,12 +10,19 @@ pub struct LayerPanelEntry {
pub name: String,
pub visible: bool,
pub layer_type: LayerType,
pub collapsed: bool,
pub path: Vec<LayerId>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum LayerType {
Folder,
Shape,
Circle,
Rect,
Line,
PolyLine,
Ellipse,
}
impl fmt::Display for LayerType {
@@ -20,12 +30,47 @@ impl fmt::Display for LayerType {
let name = match self {
LayerType::Folder => "folder",
LayerType::Shape => "shape",
LayerType::Rect => "rect",
LayerType::Line => "line",
LayerType::Circle => "circle",
LayerType::PolyLine => "poly line",
LayerType::Ellipse => "ellipse",
};
formatter.write_str(name)
}
}
impl From<&LayerDataTypes> for LayerType {
fn from(data: &LayerDataTypes) -> Self {
use LayerDataTypes::*;
match data {
Folder(_) => LayerType::Folder,
Shape(_) => LayerType::Shape,
Circle(_) => LayerType::Circle,
Rect(_) => LayerType::Rect,
Line(_) => LayerType::Line,
PolyLine(_) => LayerType::PolyLine,
Ellipse(_) => LayerType::Ellipse,
}
}
}
impl LayerPanelEntry {
pub fn from_layer(layer: &Layer, path: Vec<LayerId>) -> Self {
let layer_type: LayerType = (&layer.data).into();
let name = layer.name.clone().unwrap_or_else(|| format!("Unnamed {}", layer_type));
let collapsed = if let LayerDataTypes::Folder(f) = &layer.data { f.collapsed } else { true };
Self {
name,
visible: layer.visible,
layer_type,
collapsed,
path,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[repr(C)]
// TODO - Make Copy when possible