mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-01 20:48:11 +08:00
Fix all clippy lint errors
This commit is contained in:
Vendored
+2
-1
@@ -3,6 +3,7 @@
|
|||||||
"matklad.rust-analyzer",
|
"matklad.rust-analyzer",
|
||||||
"dbaeumer.vscode-eslint",
|
"dbaeumer.vscode-eslint",
|
||||||
"octref.vetur",
|
"octref.vetur",
|
||||||
"formulahendry.auto-close-tag"
|
"formulahendry.auto-close-tag",
|
||||||
|
"aaron-bond.better-comments"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
// #[test]
|
||||||
fn it_works() {
|
// fn it_works() {
|
||||||
assert_eq!(2 + 2, 4);
|
// assert_eq!(2 + 2, 4);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ pub use crate::tool::ToolMessageHandler;
|
|||||||
use crate::global::GlobalMessageHandler;
|
use crate::global::GlobalMessageHandler;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
pub struct Dispatcher {
|
pub struct Dispatcher {
|
||||||
input_preprocessor: InputPreprocessor,
|
input_preprocessor: InputPreprocessor,
|
||||||
input_mapper: InputMapper,
|
input_mapper: InputMapper,
|
||||||
@@ -30,6 +31,10 @@ const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
|
|||||||
];
|
];
|
||||||
|
|
||||||
impl Dispatcher {
|
impl Dispatcher {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_message<T: Into<Message>>(&mut self, message: T) {
|
pub fn handle_message<T: Into<Message>>(&mut self, message: T) {
|
||||||
self.messages.push_back(message.into());
|
self.messages.push_back(message.into());
|
||||||
|
|
||||||
@@ -68,18 +73,6 @@ impl Dispatcher {
|
|||||||
list
|
list
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> Dispatcher {
|
|
||||||
Dispatcher {
|
|
||||||
input_preprocessor: InputPreprocessor::default(),
|
|
||||||
global_message_handler: GlobalMessageHandler::new(),
|
|
||||||
input_mapper: InputMapper::default(),
|
|
||||||
documents_message_handler: DocumentsMessageHandler::default(),
|
|
||||||
tool_message_handler: ToolMessageHandler::default(),
|
|
||||||
messages: VecDeque::new(),
|
|
||||||
responses: vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn log_message(&self, message: &Message) {
|
fn log_message(&self, message: &Message) {
|
||||||
use Message::*;
|
use Message::*;
|
||||||
if log::max_level() == log::LevelFilter::Trace
|
if log::max_level() == log::LevelFilter::Trace
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use super::document_message_handler::CopyBufferEntry;
|
|
||||||
pub use super::layer_panel::*;
|
pub use super::layer_panel::*;
|
||||||
use super::movement_handler::{MovementMessage, MovementMessageHandler};
|
use super::movement_handler::{MovementMessage, MovementMessageHandler};
|
||||||
use super::overlay_message_handler::OverlayMessageHandler;
|
use super::overlay_message_handler::OverlayMessageHandler;
|
||||||
@@ -187,7 +186,7 @@ impl DocumentMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize_document(serialized_content: &str) -> Result<Self, DocumentError> {
|
pub fn deserialize_document(serialized_content: &str) -> Result<Self, DocumentError> {
|
||||||
log::info!("Deserialising: {:?}", serialized_content);
|
log::info!("Deserializing: {:?}", serialized_content);
|
||||||
serde_json::from_str(serialized_content).map_err(|e| DocumentError::InvalidFile(e.to_string()))
|
serde_json::from_str(serialized_content).map_err(|e| DocumentError::InvalidFile(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,8 +209,8 @@ impl DocumentMessageHandler {
|
|||||||
|
|
||||||
pub fn is_unmodified_default(&self) -> bool {
|
pub fn is_unmodified_default(&self) -> bool {
|
||||||
self.serialize_root().len() == Self::default().serialize_root().len()
|
self.serialize_root().len() == Self::default().serialize_root().len()
|
||||||
&& self.document_undo_history.len() == 0
|
&& self.document_undo_history.is_empty()
|
||||||
&& self.document_redo_history.len() == 0
|
&& self.document_redo_history.is_empty()
|
||||||
&& self.name.starts_with(DEFAULT_DOCUMENT_NAME)
|
&& self.name.starts_with(DEFAULT_DOCUMENT_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,7 +436,7 @@ impl DocumentMessageHandler {
|
|||||||
Some((document, layer_data)) => {
|
Some((document, layer_data)) => {
|
||||||
let document = std::mem::replace(&mut self.graphene_document, document);
|
let document = std::mem::replace(&mut self.graphene_document, document);
|
||||||
let layer_data = std::mem::replace(&mut self.layer_data, layer_data);
|
let layer_data = std::mem::replace(&mut self.layer_data, layer_data);
|
||||||
self.document_undo_history.push((document.clone(), layer_data.clone()));
|
self.document_undo_history.push((document, layer_data));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => Err(EditorError::NoTransactionInProgress),
|
None => Err(EditorError::NoTransactionInProgress),
|
||||||
@@ -645,7 +644,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||||||
// Fill the selection range
|
// Fill the selection range
|
||||||
self.layer_data
|
self.layer_data
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(target, _)| self.graphene_document.layer_is_between(&target, &selected, &self.layer_range_selection_reference))
|
.filter(|(target, _)| self.graphene_document.layer_is_between(target, &selected, &self.layer_range_selection_reference))
|
||||||
.for_each(|(layer_path, _)| {
|
.for_each(|(layer_path, _)| {
|
||||||
paths.push(layer_path.clone());
|
paths.push(layer_path.clone());
|
||||||
});
|
});
|
||||||
@@ -664,7 +663,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't create messages for empty operations
|
// Don't create messages for empty operations
|
||||||
if paths.len() > 0 {
|
if !paths.is_empty() {
|
||||||
// Add or set our selected layers
|
// Add or set our selected layers
|
||||||
if ctrl {
|
if ctrl {
|
||||||
responses.push_front(AddSelectedLayers(paths).into());
|
responses.push_front(AddSelectedLayers(paths).into());
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
|||||||
.document_ids
|
.document_ids
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|id| {
|
.filter_map(|id| {
|
||||||
self.documents.get(&id).map(|doc| FrontendDocumentDetails {
|
self.documents.get(id).map(|doc| FrontendDocumentDetails {
|
||||||
is_saved: doc.is_saved(),
|
is_saved: doc.is_saved(),
|
||||||
id: *id,
|
id: *id,
|
||||||
name: doc.name.clone(),
|
name: doc.name.clone(),
|
||||||
@@ -314,7 +314,7 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
|||||||
.document_ids
|
.document_ids
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|id| {
|
.filter_map(|id| {
|
||||||
self.documents.get(&id).map(|doc| FrontendDocumentDetails {
|
self.documents.get(id).map(|doc| FrontendDocumentDetails {
|
||||||
is_saved: doc.is_saved(),
|
is_saved: doc.is_saved(),
|
||||||
id: *id,
|
id: *id,
|
||||||
name: doc.name.clone(),
|
name: doc.name.clone(),
|
||||||
@@ -356,7 +356,7 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
|||||||
self.copy_buffer[clipboard as usize].clear();
|
self.copy_buffer[clipboard as usize].clear();
|
||||||
for path in paths {
|
for path in paths {
|
||||||
let document = self.active_document();
|
let document = self.active_document();
|
||||||
match (document.graphene_document.layer(&path).map(|t| t.clone()), document.layer_data(&path).clone()) {
|
match (document.graphene_document.layer(&path).map(|t| t.clone()), *document.layer_data(&path)) {
|
||||||
(Ok(layer), layer_data) => {
|
(Ok(layer), layer_data) => {
|
||||||
self.copy_buffer[clipboard as usize].push(CopyBufferEntry { layer, layer_data });
|
self.copy_buffer[clipboard as usize].push(CopyBufferEntry { layer, layer_data });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ pub struct OverlayMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MessageHandler<OverlayMessage, (&mut LayerData, &Document, &InputPreprocessor)> for OverlayMessageHandler {
|
impl MessageHandler<OverlayMessage, (&mut LayerData, &Document, &InputPreprocessor)> for OverlayMessageHandler {
|
||||||
fn process_action(&mut self, message: OverlayMessage, data: (&mut LayerData, &Document, &InputPreprocessor), responses: &mut VecDeque<Message>) {
|
fn process_action(&mut self, message: OverlayMessage, _data: (&mut LayerData, &Document, &InputPreprocessor), responses: &mut VecDeque<Message>) {
|
||||||
let (layer_data, document, ipp) = data;
|
// let (layer_data, document, ipp) = data;
|
||||||
use OverlayMessage::*;
|
use OverlayMessage::*;
|
||||||
match message {
|
match message {
|
||||||
DispatchOperation(operation) => match self.overlays_graphene_document.handle_operation(&operation) {
|
DispatchOperation(operation) => match self.overlays_graphene_document.handle_operation(&operation) {
|
||||||
|
|||||||
@@ -13,12 +13,6 @@ pub enum GlobalMessage {
|
|||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct GlobalMessageHandler {}
|
pub struct GlobalMessageHandler {}
|
||||||
|
|
||||||
impl GlobalMessageHandler {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MessageHandler<GlobalMessage, ()> for GlobalMessageHandler {
|
impl MessageHandler<GlobalMessage, ()> for GlobalMessageHandler {
|
||||||
fn process_action(&mut self, message: GlobalMessage, _data: (), _responses: &mut VecDeque<Message>) {
|
fn process_action(&mut self, message: GlobalMessage, _data: (), _responses: &mut VecDeque<Message>) {
|
||||||
use GlobalMessage::*;
|
use GlobalMessage::*;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ impl ViewportBounds {
|
|||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||||
pub struct ScrollDelta {
|
pub struct ScrollDelta {
|
||||||
|
// TODO: Switch these to `f64` values (not trivial because floats don't provide PartialEq, Eq, and Hash)
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
pub y: i32,
|
pub y: i32,
|
||||||
pub z: i32,
|
pub z: i32,
|
||||||
|
|||||||
@@ -58,13 +58,11 @@ impl SnapHandler {
|
|||||||
.unwrap_or(0.),
|
.unwrap_or(0.),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Do not move if over snap tolerance
|
// Clamp, do not move if over snap tolerance
|
||||||
let clamped_closest_move = DVec2::new(
|
DVec2::new(
|
||||||
if closest_move.x.abs() > SNAP_TOLERANCE { 0. } else { closest_move.x },
|
if closest_move.x.abs() > SNAP_TOLERANCE { 0. } else { closest_move.x },
|
||||||
if closest_move.y.abs() > SNAP_TOLERANCE { 0. } else { closest_move.y },
|
if closest_move.y.abs() > SNAP_TOLERANCE { 0. } else { closest_move.y },
|
||||||
);
|
)
|
||||||
|
|
||||||
clamped_closest_move
|
|
||||||
} else {
|
} else {
|
||||||
DVec2::ZERO
|
DVec2::ZERO
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ impl Fsm for PathToolFsmState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_total_overlays_per_type(shapes_to_draw: &Vec<VectorManipulatorShape>) -> (usize, usize, usize) {
|
fn calculate_total_overlays_per_type(shapes_to_draw: &[VectorManipulatorShape]) -> (usize, usize, usize) {
|
||||||
let (mut total_anchors, mut total_handles, mut total_anchor_handle_lines) = (0, 0, 0);
|
let (mut total_anchors, mut total_handles, mut total_anchor_handle_lines) = (0, 0, 0);
|
||||||
|
|
||||||
for shape_to_draw in shapes_to_draw {
|
for shape_to_draw in shapes_to_draw {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ pub struct JsEditorHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
impl JsEditorHandle {
|
impl JsEditorHandle {
|
||||||
#[wasm_bindgen(constructor)]
|
#[wasm_bindgen(constructor)]
|
||||||
pub fn new(handle_response: js_sys::Function) -> Self {
|
pub fn new(handle_response: js_sys::Function) -> Self {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use wasm_bindgen_test::*;
|
|||||||
|
|
||||||
wasm_bindgen_test_configure!(run_in_browser);
|
wasm_bindgen_test_configure!(run_in_browser);
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
// #[wasm_bindgen_test]
|
||||||
fn pass() {
|
// fn pass() {
|
||||||
assert_eq!(1 + 1, 2);
|
// assert_eq!(1 + 1, 2);
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::color::Color;
|
use crate::color::Color;
|
||||||
|
|
||||||
// Document
|
// Document
|
||||||
pub const GRAPHENE_DOCUMENT_VERSION: &'static str = "0.0.1";
|
pub const GRAPHENE_DOCUMENT_VERSION: &str = "0.0.1";
|
||||||
|
|
||||||
// RENDERING
|
// RENDERING
|
||||||
pub const LAYER_OUTLINE_STROKE_COLOR: Color = Color::BLACK;
|
pub const LAYER_OUTLINE_STROKE_COLOR: Color = Color::BLACK;
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ impl Document {
|
|||||||
|
|
||||||
// Determines which layer is closer to the root, if path_a return true, if path_b return false
|
// Determines which layer is closer to the root, if path_a return true, if path_b return false
|
||||||
// Answers the question: Is A closer to the root than B?
|
// Answers the question: Is A closer to the root than B?
|
||||||
pub fn layer_closer_to_root(&self, path_a: &Vec<u64>, path_b: &Vec<u64>) -> bool {
|
pub fn layer_closer_to_root(&self, path_a: &[u64], path_b: &[u64]) -> bool {
|
||||||
// Convert UUIDs to indices
|
// Convert UUIDs to indices
|
||||||
let indices_for_path_a = self.indices_for_path(path_a).unwrap();
|
let indices_for_path_a = self.indices_for_path(path_a).unwrap();
|
||||||
let indices_for_path_b = self.indices_for_path(path_b).unwrap();
|
let indices_for_path_b = self.indices_for_path(path_b).unwrap();
|
||||||
@@ -126,24 +126,20 @@ impl Document {
|
|||||||
let index_a = *indices_for_path_a.get(i).unwrap_or(&usize::MAX) as i32;
|
let index_a = *indices_for_path_a.get(i).unwrap_or(&usize::MAX) as i32;
|
||||||
let index_b = *indices_for_path_b.get(i).unwrap_or(&usize::MAX) as i32;
|
let index_b = *indices_for_path_b.get(i).unwrap_or(&usize::MAX) as i32;
|
||||||
|
|
||||||
// index_a == index_b -> true, this means the "2" indices being compared are within the same folder
|
// At the point at which the two paths first differ, compare to see which is closer to the root
|
||||||
// eg -> [2, X] == [2, X] since we are only comparing the "2" in this iteration
|
if index_a != index_b {
|
||||||
// Continue onto comparing the X indices.
|
|
||||||
if index_a == index_b {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If index_a is smaller, index_a is closer to the root
|
// If index_a is smaller, index_a is closer to the root
|
||||||
return index_a < index_b;
|
return index_a < index_b;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the target layer between a <-> b layers, inclusive
|
// Is the target layer between a <-> b layers, inclusive
|
||||||
pub fn layer_is_between(&self, target: &Vec<u64>, path_a: &Vec<u64>, path_b: &Vec<u64>) -> bool {
|
pub fn layer_is_between(&self, target: &[u64], path_a: &[u64], path_b: &[u64]) -> bool {
|
||||||
// If the target is a nonsense path, it isn't between
|
// If the target is a nonsense path, it isn't between
|
||||||
if target.len() < 1 {
|
if target.is_empty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,8 +152,8 @@ impl Document {
|
|||||||
let layer_vs_a = self.layer_closer_to_root(target, path_a);
|
let layer_vs_a = self.layer_closer_to_root(target, path_a);
|
||||||
let layer_vs_b = self.layer_closer_to_root(target, path_b);
|
let layer_vs_b = self.layer_closer_to_root(target, path_b);
|
||||||
|
|
||||||
// To be inbetween you need to be above A and below B or vice versa
|
// To be in-between you need to be above A and below B or vice versa
|
||||||
return layer_vs_a != layer_vs_b;
|
layer_vs_a != layer_vs_b
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a path to a layer, returns a vector of the indices in the layer tree
|
/// Given a path to a layer, returns a vector of the indices in the layer tree
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ use syn::parse_macro_input;
|
|||||||
///
|
///
|
||||||
/// This derive macro is enum-only.
|
/// This derive macro is enum-only.
|
||||||
///
|
///
|
||||||
/// The discriminant enum is a copy of the input enum with all fields of every variant removed.\
|
/// The discriminant enum is a copy of the input enum with all fields of every variant removed.
|
||||||
/// *) The exception to that rule is the `#[child]` attribute
|
/// The exception to that rule is the `#[child]` attribute.
|
||||||
///
|
///
|
||||||
/// # Helper attributes
|
/// # Helper attributes
|
||||||
/// - `#[sub_discriminant]`: only usable on variants with a single field; instead of no fields, the discriminant of the single field will be included in the discriminant,
|
/// - `#[sub_discriminant]`: only usable on variants with a single field; instead of no fields, the discriminant of the single field will be included in the discriminant,
|
||||||
@@ -252,7 +252,7 @@ pub fn derive_hint(input_item: TokenStream) -> TokenStream {
|
|||||||
/// SelectToolState::TransformSelected
|
/// SelectToolState::TransformSelected
|
||||||
/// }
|
/// }
|
||||||
/// (SelectToolState::TransformSelected, Event::MouseMove(x,y)) => {
|
/// (SelectToolState::TransformSelected, Event::MouseMove(x,y)) => {
|
||||||
/// #[egde("Mouse Move")]
|
/// #[edge("Mouse Move")]
|
||||||
/// SelectToolState::TransformSelected
|
/// SelectToolState::TransformSelected
|
||||||
/// }
|
/// }
|
||||||
/// (SelectToolState::TransformSelected, Event::MouseUp(mouse_state)) if *mouse_state == MouseState::Left => {
|
/// (SelectToolState::TransformSelected, Event::MouseUp(mouse_state)) if *mouse_state == MouseState::Left => {
|
||||||
|
|||||||
Reference in New Issue
Block a user