mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Add tool_state functionality to wasm-wrapper (#42)
This commit is contained in:
committed by
Keavon Chambers
parent
d6e02c6832
commit
543fc4fec1
@@ -1,10 +1,18 @@
|
||||
use crate::wrappers::Color;
|
||||
use crate::wrappers::{translate_tool, Color};
|
||||
use graphite_editor_core::tools::ToolState;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub static mut TOOL_STATE: ToolState = ToolState::default();
|
||||
|
||||
/// Modify the currently selected tool in the document state store
|
||||
#[wasm_bindgen]
|
||||
pub fn select_tool(tool: String) {
|
||||
todo!()
|
||||
pub fn select_tool(tool: String) -> Result<(), JsValue> {
|
||||
let tool_state = unsafe { &mut TOOL_STATE };
|
||||
if let Some(tool) = translate_tool(tool.as_str()) {
|
||||
Ok(tool_state.select_tool(tool))
|
||||
} else {
|
||||
Err(JsValue::from(format!("Couldn't select {} because it was not recognized as a valid tool", tool)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Mouse movement with the bounds of the canvas
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use graphite_editor_core::tools::{SelectAppendMode, ToolType};
|
||||
use graphite_editor_core::Color as InnerColor;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
@@ -11,3 +12,29 @@ impl Color {
|
||||
Self(InnerColor::from_rgbaf32(red, green, blue, alpha).unwrap_throw())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn translate_tool(name: &str) -> Option<ToolType> {
|
||||
match name {
|
||||
"Select" => Some(ToolType::Select),
|
||||
"Crop" => Some(ToolType::Crop),
|
||||
"Navigate" => Some(ToolType::Navigate),
|
||||
"Sample" => Some(ToolType::Sample),
|
||||
"Path" => Some(ToolType::Path),
|
||||
"Pen" => Some(ToolType::Pen),
|
||||
"Line" => Some(ToolType::Line),
|
||||
"Rectangle" => Some(ToolType::Rectangle),
|
||||
"Ellipse" => Some(ToolType::Ellipse),
|
||||
"Shape" => Some(ToolType::Shape),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn translate_append_mode(name: &str) -> Option<SelectAppendMode> {
|
||||
match name {
|
||||
"New" => Some(SelectAppendMode::New),
|
||||
"Add" => Some(SelectAppendMode::Add),
|
||||
"Subtract" => Some(SelectAppendMode::Subtract),
|
||||
"Intersect" => Some(SelectAppendMode::Intersect),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user