mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-07-22 23:25:01 +00:00
Massively reorganize and clean up the whole Rust codebase (#478)
* Massively reorganize and clean up the whole Rust codebase * Additional changes during code review
This commit is contained in:
parent
011c2be26d
commit
f48d4e1884
85 changed files with 2515 additions and 2189 deletions
|
@ -1,28 +1,30 @@
|
|||
// This file is where functions are defined to be called directly from JS.
|
||||
// It serves as a thin wrapper over the editor backend API that relies
|
||||
// on the dispatcher messaging system and more complex Rust data types.
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use crate::helpers::Error;
|
||||
use crate::type_translators::{translate_blend_mode, translate_key, translate_tool_type, translate_view_mode};
|
||||
use crate::{EDITOR_HAS_CRASHED, EDITOR_INSTANCES};
|
||||
|
||||
use editor::consts::{FILE_SAVE_SUFFIX, GRAPHITE_DOCUMENT_VERSION};
|
||||
use editor::input::input_preprocessor::ModifierKeys;
|
||||
use editor::input::mouse::{EditorMouseState, ScrollDelta, ViewportBounds};
|
||||
use editor::message_prelude::*;
|
||||
use editor::misc::EditorError;
|
||||
use editor::tool::{tool_options::ToolOptions, tools, ToolType};
|
||||
use editor::viewport_tools::tool::ToolType;
|
||||
use editor::viewport_tools::tool_options::ToolOptions;
|
||||
use editor::viewport_tools::tools;
|
||||
use editor::Color;
|
||||
use editor::Editor;
|
||||
use editor::LayerId;
|
||||
|
||||
use editor::Editor;
|
||||
use serde::Serialize;
|
||||
use serde_wasm_bindgen;
|
||||
use std::sync::atomic::Ordering;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// To avoid wasm-bindgen from checking mutable reference issues using WasmRefCell
|
||||
// we must make all methods take a non mutable reference to self. Not doing this creates
|
||||
// an issue when rust calls into JS which calls back to rust in the same call stack.
|
||||
// To avoid wasm-bindgen from checking mutable reference issues using WasmRefCell we must make all methods take a non mutable reference to self.
|
||||
// Not doing this creates an issue when rust calls into JS which calls back to rust in the same call stack.
|
||||
#[wasm_bindgen]
|
||||
#[derive(Clone)]
|
||||
pub struct JsEditorHandle {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// The JavaScript `Error` type
|
||||
/// The JavaScript `Error` type
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
pub mod api;
|
||||
mod helpers;
|
||||
pub mod helpers;
|
||||
pub mod logging;
|
||||
pub mod type_translators;
|
||||
|
||||
use editor::message_prelude::FrontendMessage;
|
||||
use editor::message_prelude::*;
|
||||
|
||||
use logging::WasmLog;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
|
@ -12,13 +13,12 @@ use std::sync::atomic::AtomicBool;
|
|||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// Set up the persistent editor backend state
|
||||
static LOGGER: WasmLog = WasmLog;
|
||||
pub static EDITOR_HAS_CRASHED: AtomicBool = AtomicBool::new(false);
|
||||
pub static LOGGER: WasmLog = WasmLog;
|
||||
thread_local! {
|
||||
pub static EDITOR_INSTANCES: RefCell<HashMap<u64, (editor::Editor, api::JsEditorHandle)>> = RefCell::new(HashMap::new());
|
||||
}
|
||||
|
||||
pub static EDITOR_HAS_CRASHED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
// Initialize the backend
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn init() {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use crate::helpers::match_string_to_enum;
|
||||
|
||||
use editor::input::keyboard::Key;
|
||||
use editor::tool::ToolType;
|
||||
use graphene::layers::{style::ViewMode, BlendMode};
|
||||
use editor::viewport_tools::tool::ToolType;
|
||||
use graphene::layers::blend_mode::BlendMode;
|
||||
use graphene::layers::style::ViewMode;
|
||||
|
||||
pub fn translate_tool_type(name: &str) -> Option<ToolType> {
|
||||
use ToolType::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue