mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 15:28:04 +08:00
Code cleanup and refactoring to enhance consistency (#1695)
- Move message handler payload data into structs
- Organize the file structure used by `editor/src/messages/portfolio/document` `/node_graph` and `/graph_operation`
- Make derive attributes use `serde::Serialize, serde::Deserialize` consistently instead of `use serde::{Deserialize, Serialize};` imports
- Various other code cleanup and refactoring
This commit is contained in:
@@ -3,10 +3,9 @@ use crate::messages::input_mapper::utility_types::input_mouse::{EditorMouseState
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
use core::time::Duration;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[impl_message(Message, InputPreprocessor)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum InputPreprocessorMessage {
|
||||
BoundsOfViewports { bounds_of_viewports: Vec<ViewportBounds> },
|
||||
DoubleClick { editor_mouse_state: EditorMouseState, modifier_keys: ModifierKeys },
|
||||
|
||||
@@ -6,6 +6,10 @@ use crate::messages::prelude::*;
|
||||
|
||||
use glam::DVec2;
|
||||
|
||||
pub struct InputPreprocessorMessageData {
|
||||
pub keyboard_platform: KeyboardPlatformLayout,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct InputPreprocessorMessageHandler {
|
||||
pub frame_time: FrameTimeInfo,
|
||||
@@ -14,8 +18,10 @@ pub struct InputPreprocessorMessageHandler {
|
||||
pub viewport_bounds: ViewportBounds,
|
||||
}
|
||||
|
||||
impl MessageHandler<InputPreprocessorMessage, KeyboardPlatformLayout> for InputPreprocessorMessageHandler {
|
||||
fn process_message(&mut self, message: InputPreprocessorMessage, responses: &mut VecDeque<Message>, keyboard_platform: KeyboardPlatformLayout) {
|
||||
impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageData> for InputPreprocessorMessageHandler {
|
||||
fn process_message(&mut self, message: InputPreprocessorMessage, responses: &mut VecDeque<Message>, data: InputPreprocessorMessageData) {
|
||||
let InputPreprocessorMessageData { keyboard_platform } = data;
|
||||
|
||||
match message {
|
||||
InputPreprocessorMessage::BoundsOfViewports { bounds_of_viewports } => {
|
||||
assert_eq!(bounds_of_viewports.len(), 1, "Only one viewport is currently supported");
|
||||
@@ -189,7 +195,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
input_preprocessor.process_message(message, &mut responses, KeyboardPlatformLayout::Standard);
|
||||
let data = InputPreprocessorMessageData {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
|
||||
assert!(input_preprocessor.keyboard.get(Key::Alt as usize));
|
||||
assert_eq!(responses.pop_front(), Some(InputMapperMessage::KeyDown(Key::Alt).into()));
|
||||
@@ -205,7 +214,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
input_preprocessor.process_message(message, &mut responses, KeyboardPlatformLayout::Standard);
|
||||
let data = InputPreprocessorMessageData {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
|
||||
assert!(input_preprocessor.keyboard.get(Key::Control as usize));
|
||||
assert_eq!(responses.pop_front(), Some(InputMapperMessage::KeyDown(Key::Control).into()));
|
||||
@@ -221,7 +233,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
input_preprocessor.process_message(message, &mut responses, KeyboardPlatformLayout::Standard);
|
||||
let data = InputPreprocessorMessageData {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
|
||||
assert!(input_preprocessor.keyboard.get(Key::Shift as usize));
|
||||
assert_eq!(responses.pop_front(), Some(InputMapperMessage::KeyDown(Key::Shift).into()));
|
||||
@@ -239,7 +254,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
input_preprocessor.process_message(message, &mut responses, KeyboardPlatformLayout::Standard);
|
||||
let data = InputPreprocessorMessageData {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
|
||||
assert!(!input_preprocessor.keyboard.get(Key::Control as usize));
|
||||
assert_eq!(responses.pop_front(), Some(InputMapperMessage::KeyUp(Key::Control).into()));
|
||||
@@ -256,7 +274,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
input_preprocessor.process_message(message, &mut responses, KeyboardPlatformLayout::Standard);
|
||||
let data = InputPreprocessorMessageData {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
|
||||
assert!(input_preprocessor.keyboard.get(Key::Control as usize));
|
||||
assert!(input_preprocessor.keyboard.get(Key::Shift as usize));
|
||||
|
||||
@@ -4,4 +4,4 @@ mod input_preprocessor_message_handler;
|
||||
#[doc(inline)]
|
||||
pub use input_preprocessor_message::{InputPreprocessorMessage, InputPreprocessorMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use input_preprocessor_message_handler::InputPreprocessorMessageHandler;
|
||||
pub use input_preprocessor_message_handler::{InputPreprocessorMessageData, InputPreprocessorMessageHandler};
|
||||
|
||||
Reference in New Issue
Block a user