mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-20 03:18:06 +08:00
Add initial tool settings messaging to backend
This commit is contained in:
@@ -37,7 +37,7 @@ pub trait Fsm {
|
||||
pub struct DocumentToolData {
|
||||
pub primary_color: Color,
|
||||
pub secondary_color: Color,
|
||||
tool_settings: HashMap<ToolType, ToolSettings>,
|
||||
pub tool_settings: HashMap<ToolType, ToolSettings>,
|
||||
}
|
||||
|
||||
type SubToolMessageHandler = dyn for<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>>;
|
||||
|
||||
@@ -4,7 +4,7 @@ use document_core::color::Color;
|
||||
use crate::input::InputPreprocessor;
|
||||
use crate::{
|
||||
document::Document,
|
||||
tool::{ToolFsmState, ToolType},
|
||||
tool::{tool_settings::ToolSettings, ToolFsmState, ToolType},
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
@@ -16,6 +16,7 @@ pub enum ToolMessage {
|
||||
SelectSecondaryColor(Color),
|
||||
SwapColors,
|
||||
ResetColors,
|
||||
SetToolSettings(ToolType, ToolSettings),
|
||||
#[child]
|
||||
Fill(FillMessage),
|
||||
#[child]
|
||||
@@ -89,6 +90,9 @@ impl MessageHandler<ToolMessage, (&Document, &InputPreprocessor)> for ToolMessag
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
SetToolSettings(tool_type, tool_settings) => {
|
||||
self.tool_state.document_tool_data.tool_settings.insert(tool_type, tool_settings);
|
||||
}
|
||||
message => {
|
||||
let tool_type = match message {
|
||||
Fill(_) => ToolType::Fill,
|
||||
@@ -111,7 +115,7 @@ impl MessageHandler<ToolMessage, (&Document, &InputPreprocessor)> for ToolMessag
|
||||
}
|
||||
}
|
||||
fn actions(&self) -> ActionList {
|
||||
let mut list = actions!(ToolMessageDiscriminant; ResetColors, SwapColors, SelectTool);
|
||||
let mut list = actions!(ToolMessageDiscriminant; ResetColors, SwapColors, SelectTool, SetToolSettings);
|
||||
list.extend(self.tool_state.tool_data.active_tool().actions());
|
||||
list
|
||||
}
|
||||
|
||||
@@ -71,6 +71,13 @@ impl Fsm for ShapeToolFsmState {
|
||||
data.drag_current = input.mouse.position;
|
||||
|
||||
data.sides = 6;
|
||||
if let Some(tool_settings) = tool_data.tool_settings.get(&crate::tool::ToolType::Shape) {
|
||||
if let crate::tool::ToolSettings::Shape { shape } = tool_settings {
|
||||
if let crate::tool::Shape::Polygon { vertices } = shape {
|
||||
data.sides = *vertices as u8;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
responses.push_back(Operation::MountWorkingFolder { path: vec![] }.into());
|
||||
Dragging
|
||||
|
||||
Reference in New Issue
Block a user