Repository: GraphiteEditor/Graphite
File: editor/src/messages/portfolio/document/navigation/navigation_message_handler.rs (Rust)

Code before:
use crate::messages::portfolio::document::navigation::utility_types::NavigationOperation;
use crate::messages::portfolio::document::utility_types::misc::PTZ;
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};

use graph_craft::document::NodeId;

use glam::{DAffine2, DVec2};

pub struct NavigationMessageData<'a> {
	pub network_interface: &'a mut NodeNetworkInterface,
	pub breadcrumb_network_path: &'a [NodeId],
	pub ipp: &'a InputPreprocessorMessageHandler,
	pub selection_bounds: Option<[DVec2; 2]>,
	pub document_ptz: &'a mut PTZ,
	pub graph_view_overlay_open: bool,
}

#[derive(Debug, Clone, PartialEq, Default)]
pub struct NavigationMessageHandler {
	navigation_operation: NavigationOperation,
	mouse_position: ViewportPosition,
	finish_operation_with_click: bool,
	abortable_pan_start: Option<f64>,
	pub canvas_flipped: bool,
}

impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for NavigationMessageHandler {
	fn process_message(&mut self, message: NavigationMessage, responses: &mut VecDeque<Message>, data: NavigationMessageData) {
		let NavigationMessageData {
			network_interface,
			breadcrumb_network_path,
			ipp,
			selection_bounds,
			document_ptz,
			graph_view_overlay_open,
		} = data;

		fn get_ptz<'a>(document_ptz: &'a PTZ, network_interface: &'a NodeNetworkInterface, graph_view_overlay_open: bool, breadcrumb_network_path: &[NodeId]) -> Option<&'a PTZ> {
			if !graph_view_overlay_open {
				Some(document_ptz)
			} else {
				let network_metadata = network_interface.network_metadata(breadcrumb_network_path)?;
				Some(&network_metadata.persistent_metadata.navigation_metadata.node_graph_ptz)
			}
		}

		fn get_ptz_mut<'a>(document_ptz: &'a mut PTZ, network_interface: &'a mut NodeNetworkInterface, graph_view_overlay_open: bool, breadcrumb_network_path: &[NodeId]) -> Option<&'a mut PTZ> {
			if !graph_view_overlay_open {
				Some(document_ptz)

Review comment (suggestion):
Maybe this would be better in `PTZ` struct?

This would be consistent with the rest of the resolved document transform state. It would also allow the flipped state to be saved in the document for consistency with pan, tilt, and zoom. I'm not sure if this is desired though (@Keavon?)

 Also I guess you might have to rename it to `PTZFlip` 🙃.

Code after:
use crate::messages::portfolio::document::navigation::utility_types::NavigationOperation;
use crate::messages::portfolio::document::utility_types::misc::PTZ;
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
use glam::{DAffine2, DVec2};
use graph_craft::document::NodeId;

pub struct NavigationMessageData<'a> {
	pub network_interface: &'a mut NodeNetworkInterface,
	pub breadcrumb_network_path: &'a [NodeId],
	pub ipp: &'a InputPreprocessorMessageHandler,
	pub selection_bounds: Option<[DVec2; 2]>,
	pub document_ptz: &'a mut PTZ,
	pub graph_view_overlay_open: bool,
	pub preferences: &'a PreferencesMessageHandler,
}

#[derive(Debug, Clone, PartialEq, Default)]
pub struct NavigationMessageHandler {
	navigation_operation: NavigationOperation,
	mouse_position: ViewportPosition,
	finish_operation_with_click: bool,
	abortable_pan_start: Option<f64>,
}

impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for NavigationMessageHandler {
	fn process_message(&mut self, message: NavigationMessage, responses: &mut VecDeque<Message>, data: NavigationMessageData) {
		let NavigationMessageData {
			network_interface,
			breadcrumb_network_path,
			ipp,
			selection_bounds,
			document_ptz,
			graph_view_overlay_open,
			preferences,
		} = data;

		fn get_ptz<'a>(document_ptz: &'a PTZ, network_interface: &'a NodeNetworkInterface, graph_view_overlay_open: bool, breadcrumb_network_path: &[NodeId]) -> Option<&'a PTZ> {
			if !graph_view_overlay_open {
				Some(document_ptz)
			} else {
				let network_metadata = network_interface.network_metadata(breadcrumb_network_path)?;
				Some(&network_metadata.persistent_metadata.navigation_metadata.node_graph_ptz)
			}
		}

		fn get_ptz_mut<'a>(document_ptz: &'a mut PTZ, network_interface: &'a mut NodeNetworkInterface, graph_view_overlay_open: bool, breadcrumb_network_path: &[NodeId]) -> Option<&'a mut PTZ> {
			if !graph_view_overlay_open {
				Some(document_ptz)
			} else {