Files
Graphite/core/editor/src/lib.rs
T0mstone b556dd6bfd Polish a few things (#81)
* Implement/suppress various compiler/clippy lints

* Change `tool_init` to take `ToolType` by value

* Factor out error conversion into a function

* Consume parameters with `todo`

* Make `workspace` stuff public

Making them public also removes the warnings
without having to suppress them.

Also, this commit removes the unused import of
`EditorError`

* Remove allow(unused_variables), use vars in `todo`

Also implements `Debug` on `DocumentToolData`
2021-04-22 17:05:25 +02:00

58 lines
1.1 KiB
Rust

// since our policy is tabs, we want to stop clippy from warning about that
#![allow(clippy::tabs_in_doc_comments)]
#[macro_use]
mod macros;
mod dispatcher;
mod error;
pub mod hint;
pub mod tools;
pub mod workspace;
#[doc(inline)]
pub use error::EditorError;
#[doc(inline)]
pub use document_core::color::Color;
#[doc(inline)]
pub use dispatcher::events;
#[doc(inline)]
pub use dispatcher::Callback;
use dispatcher::Dispatcher;
use document_core::document::Document;
use tools::ToolFsmState;
use workspace::Workspace;
pub struct EditorState {
tool_state: ToolFsmState,
workspace: Workspace,
document: Document,
}
// TODO: serialize with serde to save the current editor state
pub struct Editor {
state: EditorState,
dispatcher: Dispatcher,
}
impl Editor {
pub fn new(callback: Callback) -> Self {
Self {
state: EditorState {
tool_state: ToolFsmState::new(),
workspace: Workspace::new(),
document: Document::default(),
},
dispatcher: Dispatcher::new(callback),
}
}
pub fn handle_event(&mut self, event: events::Event) -> Result<(), EditorError> {
self.dispatcher.handle_event(&mut self.state, &event)
}
}