mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-20 11:28:30 +08:00
Options bar widgets for tools to control tool behavior (#283)
* Add JSON-backed options widget
* Add initial tool settings messaging to backend
* Add shape side selection with JSON deserialization
* Enforce minimum number of n-gon sides
* Make tool settings JSON errors safer
* Make tool settings JSON errors safer
* Refactor ToolOptions to ToolSettings
* Revert "Refactor ToolOptions to ToolSettings"
This reverts commit 651161fd16.
* Refactor all instances of "settings" to "options"
* Fix names and formatting
* Rearrange ToolOptions data to enforce types
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::EDITOR_STATE;
|
||||
use editor_core::input::input_preprocessor::ModifierKeys;
|
||||
use editor_core::input::mouse::ScrollDelta;
|
||||
use editor_core::message_prelude::*;
|
||||
use editor_core::tool::tool_options::ToolOptions;
|
||||
use editor_core::{
|
||||
input::mouse::{MouseState, ViewportPosition},
|
||||
LayerId,
|
||||
@@ -23,6 +24,18 @@ pub fn select_tool(tool: String) -> Result<(), JsValue> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Update the options for a given tool
|
||||
#[wasm_bindgen]
|
||||
pub fn set_tool_options(tool: String, options: &JsValue) -> Result<(), JsValue> {
|
||||
match options.into_serde::<ToolOptions>() {
|
||||
Ok(options) => EDITOR_STATE.with(|editor| match translate_tool(&tool) {
|
||||
Some(tool) => editor.borrow_mut().handle_message(ToolMessage::SetToolOptions(tool, options)).map_err(convert_error),
|
||||
None => Err(Error::new(&format!("Couldn't select {} because it was not recognized as a valid tool", tool)).into()),
|
||||
}),
|
||||
Err(err) => Err(Error::new(&format!("Invalud JSON for ToolOptions: {}", err)).into()),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn select_document(document: usize) -> Result<(), JsValue> {
|
||||
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SelectDocument(document)).map_err(convert_error))
|
||||
|
||||
Reference in New Issue
Block a user