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:
Keavon Chambers
2024-03-20 21:28:51 -07:00
committed by GitHub
parent ed3f7acdd7
commit 0a9bd41be1
134 changed files with 1860 additions and 1865 deletions

View File

@@ -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 },

View File

@@ -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));

View File

@@ -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};