mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-26 05:18:13 +08:00
Implement backend part of the layer selection (#172)
* Implement backend part of the layer selection
This commit is contained in:
committed by
Keavon Chambers
parent
13dd51dbf8
commit
0e8cbad003
@@ -1,5 +1,5 @@
|
||||
use crate::frontend::layer_panel::LayerPanelEntry;
|
||||
use crate::message_prelude::*;
|
||||
use document_core::{response::LayerPanelEntry, DocumentResponse, LayerId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub type Callback = Box<dyn Fn(FrontendMessage)>;
|
||||
@@ -16,22 +16,6 @@ pub enum FrontendMessage {
|
||||
DisableTextInput,
|
||||
}
|
||||
|
||||
impl From<DocumentResponse> for Message {
|
||||
fn from(response: DocumentResponse) -> Self {
|
||||
let frontend: FrontendMessage = response.into();
|
||||
frontend.into()
|
||||
}
|
||||
}
|
||||
impl From<DocumentResponse> for FrontendMessage {
|
||||
fn from(response: DocumentResponse) -> Self {
|
||||
match response {
|
||||
DocumentResponse::ExpandFolder { path, children } => Self::ExpandFolder { path, children },
|
||||
DocumentResponse::CollapseFolder { path } => Self::CollapseFolder { path },
|
||||
_ => unimplemented!("The frontend does not handle {:?}", response),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FrontendMessageHandler {
|
||||
callback: crate::Callback,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
use crate::document::LayerData;
|
||||
use document_core::{layers::LayerDataTypes, LayerId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
pub struct LayerPanelEntry {
|
||||
pub name: String,
|
||||
pub visible: bool,
|
||||
pub layer_type: LayerType,
|
||||
pub layer_data: LayerData,
|
||||
pub path: Vec<LayerId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
pub enum LayerType {
|
||||
Folder,
|
||||
Shape,
|
||||
Circle,
|
||||
Rect,
|
||||
Line,
|
||||
PolyLine,
|
||||
Ellipse,
|
||||
}
|
||||
|
||||
impl fmt::Display for LayerType {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
let name = match self {
|
||||
LayerType::Folder => "Folder",
|
||||
LayerType::Shape => "Shape",
|
||||
LayerType::Rect => "Rectangle",
|
||||
LayerType::Line => "Line",
|
||||
LayerType::Circle => "Circle",
|
||||
LayerType::PolyLine => "Polyline",
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod frontend_message_handler;
|
||||
pub mod layer_panel;
|
||||
|
||||
pub use frontend_message_handler::{Callback, FrontendMessage, FrontendMessageDiscriminant, FrontendMessageHandler};
|
||||
|
||||
Reference in New Issue
Block a user