Files
Graphite/editor/src/frontend/frontend_message_handler.rs
Henry Sloan 9e73cce281 Add two-way tool option messaging system between frontend/backend (#361)
* Add two-way tool option messaging system

* Rename tool option functions

* Move repeated frontend messaging code to function

* Address style comments

* Rename variable to be more descriptive

* Move tool options update to SetActiveTool message

* Refactor record of all tool options

* Only pass active tool options to bar

Co-authored-by: Keavon Chambers <keavon@keavon.com>
2021-08-29 00:43:27 -04:00

63 lines
1.8 KiB
Rust

use crate::frontend::layer_panel::LayerPanelEntry;
use crate::message_prelude::*;
use crate::tool::tool_options::ToolOptions;
use crate::Color;
use serde::{Deserialize, Serialize};
pub type Callback = Box<dyn Fn(FrontendMessage)>;
#[impl_message(Message, Frontend)]
#[derive(PartialEq, Clone, Deserialize, Serialize, Debug)]
pub enum FrontendMessage {
CollapseFolder { path: Vec<LayerId> },
ExpandFolder { path: Vec<LayerId>, children: Vec<LayerPanelEntry> },
SetActiveTool { tool_name: String, tool_options: Option<ToolOptions> },
SetActiveDocument { document_index: usize },
UpdateOpenDocumentsList { open_documents: Vec<String> },
DisplayError { description: String },
DisplayConfirmationToCloseDocument { document_index: usize },
DisplayConfirmationToCloseAllDocuments,
UpdateCanvas { document: String },
UpdateScrollbars { position: (f64, f64), size: (f64, f64), multiplier: (f64, f64) },
UpdateLayer { path: Vec<LayerId>, data: LayerPanelEntry },
ExportDocument { document: String, name: String },
SaveDocument { document: String, name: String },
OpenDocumentBrowse,
EnableTextInput,
DisableTextInput,
UpdateWorkingColors { primary: Color, secondary: Color },
SetCanvasZoom { new_zoom: f64 },
SetCanvasRotation { new_radians: f64 },
}
pub struct FrontendMessageHandler {
callback: crate::Callback,
}
impl FrontendMessageHandler {
pub fn new(callback: Callback) -> Self {
Self { callback }
}
}
impl MessageHandler<FrontendMessage, ()> for FrontendMessageHandler {
fn process_action(&mut self, message: FrontendMessage, _data: (), _responses: &mut VecDeque<Message>) {
(self.callback)(message)
}
advertise_actions!(
FrontendMessageDiscriminant;
DisplayError,
CollapseFolder,
ExpandFolder,
SetActiveTool,
UpdateCanvas,
UpdateScrollbars,
EnableTextInput,
DisableTextInput,
SetCanvasZoom,
SetCanvasRotation,
OpenDocumentBrowse,
);
}