mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
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>
This commit is contained in:
committed by
Keavon Chambers
parent
05ac4ac9b8
commit
9e73cce281
@@ -1,5 +1,6 @@
|
||||
use crate::frontend::layer_panel::LayerPanelEntry;
|
||||
use crate::message_prelude::*;
|
||||
use crate::tool::tool_options::ToolOptions;
|
||||
use crate::Color;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -10,7 +11,7 @@ pub type Callback = Box<dyn Fn(FrontendMessage)>;
|
||||
pub enum FrontendMessage {
|
||||
CollapseFolder { path: Vec<LayerId> },
|
||||
ExpandFolder { path: Vec<LayerId>, children: Vec<LayerPanelEntry> },
|
||||
SetActiveTool { tool_name: String },
|
||||
SetActiveTool { tool_name: String, tool_options: Option<ToolOptions> },
|
||||
SetActiveDocument { document_index: usize },
|
||||
UpdateOpenDocumentsList { open_documents: Vec<String> },
|
||||
DisplayError { description: String },
|
||||
|
||||
@@ -117,6 +117,8 @@ fn default_tool_options() -> HashMap<ToolType, ToolOptions> {
|
||||
let tool_init = |tool: ToolType| (tool, tool.default_options());
|
||||
std::array::IntoIter::new([
|
||||
tool_init(ToolType::Select),
|
||||
tool_init(ToolType::Pen),
|
||||
tool_init(ToolType::Line),
|
||||
tool_init(ToolType::Ellipse),
|
||||
tool_init(ToolType::Shape), // TODO: Add more tool defaults
|
||||
])
|
||||
@@ -185,6 +187,8 @@ impl ToolType {
|
||||
fn default_options(&self) -> ToolOptions {
|
||||
match self {
|
||||
ToolType::Select => ToolOptions::Select { append_mode: SelectAppendMode::New },
|
||||
ToolType::Pen => ToolOptions::Pen { weight: 5 },
|
||||
ToolType::Line => ToolOptions::Line { weight: 5 },
|
||||
ToolType::Ellipse => ToolOptions::Ellipse,
|
||||
ToolType::Shape => ToolOptions::Shape {
|
||||
shape_type: ShapeType::Polygon { vertices: 6 },
|
||||
|
||||
@@ -108,7 +108,9 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessor)>
|
||||
tool_data.active_tool_type = new_tool;
|
||||
|
||||
// Notify the frontend about the new active tool to be displayed
|
||||
responses.push_back(FrontendMessage::SetActiveTool { tool_name: new_tool.to_string() }.into());
|
||||
let tool_name = new_tool.to_string();
|
||||
let tool_options = self.tool_state.document_tool_data.tool_options.get(&new_tool).map(|tool_options| *tool_options);
|
||||
responses.push_back(FrontendMessage::SetActiveTool { tool_name, tool_options }.into());
|
||||
}
|
||||
SwapColors => {
|
||||
let document_data = &mut self.tool_state.document_tool_data;
|
||||
|
||||
Reference in New Issue
Block a user