Rename the message system's 'data' argument to 'context' (#2872)

This commit is contained in:
Keavon Chambers
2025-07-12 22:50:59 -07:00
committed by GitHub
parent 4c75ddf936
commit 765092fbe9
68 changed files with 674 additions and 615 deletions
@@ -10,10 +10,10 @@ use crate::consts::{ASYMPTOTIC_EFFECT, COLOR_OVERLAY_GRAY, DEFAULT_DOCUMENT_NAME
use crate::messages::input_mapper::utility_types::macros::action_keys;
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
use crate::messages::portfolio::document::node_graph::NodeGraphHandlerData;
use crate::messages::portfolio::document::node_graph::NodeGraphMessageContext;
use crate::messages::portfolio::document::overlays::grid_overlays::{grid_overlay, overlay_options};
use crate::messages::portfolio::document::overlays::utility_types::{OverlaysType, OverlaysVisibilitySettings};
use crate::messages::portfolio::document::properties_panel::utility_types::PropertiesPanelMessageHandlerData;
use crate::messages::portfolio::document::properties_panel::properties_panel_message_handler::PropertiesPanelMessageContext;
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis, PTZ};
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, InputConnector, NodeTemplate};
@@ -39,7 +39,7 @@ use graphene_std::vector::style::ViewMode;
use std::time::Duration;
#[derive(ExtractField)]
pub struct DocumentMessageData<'a> {
pub struct DocumentMessageContext<'a> {
pub document_id: DocumentId,
pub ipp: &'a InputPreprocessorMessageHandler,
pub persistent_data: &'a PersistentData,
@@ -170,9 +170,9 @@ impl Default for DocumentMessageHandler {
}
#[message_handler_data]
impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessageHandler {
fn process_message(&mut self, message: DocumentMessage, responses: &mut VecDeque<Message>, data: DocumentMessageData) {
let DocumentMessageData {
impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMessageHandler {
fn process_message(&mut self, message: DocumentMessage, responses: &mut VecDeque<Message>, context: DocumentMessageContext) {
let DocumentMessageContext {
document_id,
ipp,
persistent_data,
@@ -180,14 +180,14 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
current_tool,
preferences,
device_pixel_ratio,
} = data;
} = context;
let selected_nodes_bounding_box_viewport = self.network_interface.selected_nodes_bounding_box_viewport(&self.breadcrumb_network_path);
let selected_visible_layers_bounding_box_viewport = self.selected_visible_layers_bounding_box_viewport();
match message {
// Sub-messages
DocumentMessage::Navigation(message) => {
let data = NavigationMessageData {
let context = NavigationMessageContext {
network_interface: &mut self.network_interface,
breadcrumb_network_path: &self.breadcrumb_network_path,
ipp,
@@ -201,7 +201,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
preferences,
};
self.navigation_handler.process_message(message, responses, data);
self.navigation_handler.process_message(message, responses, context);
}
DocumentMessage::Overlays(message) => {
let visibility_settings = self.overlays_visibility_settings;
@@ -210,7 +210,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
self.overlays_message_handler.process_message(
message,
responses,
OverlaysMessageData {
OverlaysMessageContext {
visibility_settings,
ipp,
device_pixel_ratio,
@@ -218,20 +218,20 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
);
}
DocumentMessage::PropertiesPanel(message) => {
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {
let context = PropertiesPanelMessageContext {
network_interface: &mut self.network_interface,
selection_network_path: &self.selection_network_path,
document_name: self.name.as_str(),
executor,
persistent_data,
};
self.properties_panel_message_handler
.process_message(message, responses, (persistent_data, properties_panel_message_handler_data));
self.properties_panel_message_handler.process_message(message, responses, context);
}
DocumentMessage::NodeGraph(message) => {
self.node_graph_handler.process_message(
message,
responses,
NodeGraphHandlerData {
NodeGraphMessageContext {
network_interface: &mut self.network_interface,
selection_network_path: &self.selection_network_path,
breadcrumb_network_path: &self.breadcrumb_network_path,
@@ -246,13 +246,13 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
);
}
DocumentMessage::GraphOperation(message) => {
let data = GraphOperationMessageData {
let context = GraphOperationMessageContext {
network_interface: &mut self.network_interface,
collapsed: &mut self.collapsed,
node_graph: &mut self.node_graph_handler,
};
let mut graph_operation_message_handler = GraphOperationMessageHandler {};
graph_operation_message_handler.process_message(message, responses, data);
graph_operation_message_handler.process_message(message, responses, context);
}
DocumentMessage::AlignSelectedLayers { axis, aggregate } => {
let axis = match axis {
@@ -14,15 +14,8 @@ use graphene_std::renderer::convert_usvg_path::convert_usvg_path;
use graphene_std::text::{Font, TypesettingConfig};
use graphene_std::vector::style::{Fill, Gradient, GradientStops, GradientType, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
#[derive(Debug, Clone)]
struct ArtboardInfo {
input_node: NodeInput,
output_nodes: Vec<InputConnector>,
merge_node: NodeId,
}
#[derive(ExtractField)]
pub struct GraphOperationMessageData<'a> {
pub struct GraphOperationMessageContext<'a> {
pub network_interface: &'a mut NodeNetworkInterface,
pub collapsed: &'a mut CollapsedLayers,
pub node_graph: &'a mut NodeGraphMessageHandler,
@@ -34,9 +27,9 @@ pub struct GraphOperationMessageHandler {}
// GraphOperationMessageHandler always modified the document network. This is so changes to the layers panel will only affect the document network.
// For changes to the selected network, use NodeGraphMessageHandler. No NodeGraphMessage's should be added here, since they will affect the selected nested network.
#[message_handler_data]
impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for GraphOperationMessageHandler {
fn process_message(&mut self, message: GraphOperationMessage, responses: &mut VecDeque<Message>, data: GraphOperationMessageData) {
let network_interface = data.network_interface;
impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for GraphOperationMessageHandler {
fn process_message(&mut self, message: GraphOperationMessage, responses: &mut VecDeque<Message>, context: GraphOperationMessageContext) {
let network_interface = context.network_interface;
match message {
GraphOperationMessage::FillSet { layer, fill } => {
@@ -323,6 +316,13 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for Gr
}
}
#[derive(Debug, Clone)]
struct ArtboardInfo {
input_node: NodeInput,
output_nodes: Vec<InputConnector>,
merge_node: NodeId,
}
fn usvg_color(c: usvg::Color, a: f32) -> Color {
Color::from_rgbaf32_unchecked(c.red as f32 / 255., c.green as f32 / 255., c.blue as f32 / 255., a)
}
@@ -11,4 +11,4 @@ pub mod utility_types;
#[doc(inline)]
pub use document_message::{DocumentMessage, DocumentMessageDiscriminant};
#[doc(inline)]
pub use document_message_handler::{DocumentMessageData, DocumentMessageHandler};
pub use document_message_handler::{DocumentMessageContext, DocumentMessageHandler};
@@ -5,4 +5,4 @@ pub mod utility_types;
#[doc(inline)]
pub use navigation_message::{NavigationMessage, NavigationMessageDiscriminant};
#[doc(inline)]
pub use navigation_message_handler::{NavigationMessageData, NavigationMessageHandler};
pub use navigation_message_handler::{NavigationMessageContext, NavigationMessageHandler};
@@ -14,7 +14,7 @@ use glam::{DAffine2, DVec2};
use graph_craft::document::NodeId;
#[derive(ExtractField)]
pub struct NavigationMessageData<'a> {
pub struct NavigationMessageContext<'a> {
pub network_interface: &'a mut NodeNetworkInterface,
pub breadcrumb_network_path: &'a [NodeId],
pub ipp: &'a InputPreprocessorMessageHandler,
@@ -33,9 +33,9 @@ pub struct NavigationMessageHandler {
}
#[message_handler_data]
impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for NavigationMessageHandler {
fn process_message(&mut self, message: NavigationMessage, responses: &mut VecDeque<Message>, data: NavigationMessageData) {
let NavigationMessageData {
impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for NavigationMessageHandler {
fn process_message(&mut self, message: NavigationMessage, responses: &mut VecDeque<Message>, context: NavigationMessageContext) {
let NavigationMessageContext {
network_interface,
breadcrumb_network_path,
ipp,
@@ -43,7 +43,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for Navigation
document_ptz,
graph_view_overlay_open,
preferences,
} = data;
} = context;
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 {
@@ -28,7 +28,7 @@ use renderer::Quad;
use std::cmp::Ordering;
#[derive(Debug, ExtractField)]
pub struct NodeGraphHandlerData<'a> {
pub struct NodeGraphMessageContext<'a> {
pub network_interface: &'a mut NodeNetworkInterface,
pub selection_network_path: &'a [NodeId],
pub breadcrumb_network_path: &'a [NodeId],
@@ -93,9 +93,9 @@ pub struct NodeGraphMessageHandler {
/// NodeGraphMessageHandler always modifies the network which the selected nodes are in. No GraphOperationMessages should be added here, since those messages will always affect the document network.
#[message_handler_data]
impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGraphMessageHandler {
fn process_message(&mut self, message: NodeGraphMessage, responses: &mut VecDeque<Message>, data: NodeGraphHandlerData<'a>) {
let NodeGraphHandlerData {
impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeGraphMessageHandler {
fn process_message(&mut self, message: NodeGraphMessage, responses: &mut VecDeque<Message>, context: NodeGraphMessageContext<'a>) {
let NodeGraphMessageContext {
network_interface,
selection_network_path,
breadcrumb_network_path,
@@ -106,7 +106,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
graph_fade_artwork_percentage,
navigation_handler,
preferences,
} = data;
} = context;
match message {
// TODO: automatically remove broadcast messages.
@@ -1833,16 +1833,18 @@ impl NodeGraphMessageHandler {
.on_update(move |node_type| {
let node_id = NodeId::new();
Message::Batched(Box::new([
NodeGraphMessage::CreateNodeFromContextMenu {
node_id: Some(node_id),
node_type: node_type.clone(),
xy: None,
add_transaction: true,
}
.into(),
NodeGraphMessage::SelectedNodesSet { nodes: vec![node_id] }.into(),
]))
Message::Batched {
messages: Box::new([
NodeGraphMessage::CreateNodeFromContextMenu {
node_id: Some(node_id),
node_type: node_type.clone(),
xy: None,
add_transaction: true,
}
.into(),
NodeGraphMessage::SelectedNodesSet { nodes: vec![node_id] }.into(),
]),
}
})
.widget_holder();
vec![LayoutGroup::Row { widgets: vec![node_chooser] }]
@@ -59,13 +59,13 @@ pub fn expose_widget(node_id: NodeId, index: usize, data_type: FrontendGraphData
} else {
"Expose this parameter as a node input in the graph"
})
.on_update(move |_parameter| {
Message::Batched(Box::new([NodeGraphMessage::ExposeInput {
.on_update(move |_parameter| Message::Batched {
messages: Box::new([NodeGraphMessage::ExposeInput {
input_connector: InputConnector::node(node_id, index),
set_to_exposed: !exposed,
start_transaction: true,
}
.into()]))
.into()]),
})
.widget_holder()
}
@@ -1307,8 +1307,8 @@ pub(crate) fn rectangle_properties(node_id: NodeId, context: &mut NodeProperties
// Uniform/individual radio input widget
let uniform = RadioEntryData::new("Uniform")
.label("Uniform")
.on_update(move |_| {
Message::Batched(Box::new([
.on_update(move |_| Message::Batched {
messages: Box::new([
NodeGraphMessage::SetInputValue {
node_id,
input_index: IndividualCornerRadiiInput::INDEX,
@@ -1321,13 +1321,13 @@ pub(crate) fn rectangle_properties(node_id: NodeId, context: &mut NodeProperties
value: TaggedValue::F64(uniform_val),
}
.into(),
]))
]),
})
.on_commit(commit_value);
let individual = RadioEntryData::new("Individual")
.label("Individual")
.on_update(move |_| {
Message::Batched(Box::new([
.on_update(move |_| Message::Batched {
messages: Box::new([
NodeGraphMessage::SetInputValue {
node_id,
input_index: IndividualCornerRadiiInput::INDEX,
@@ -1340,7 +1340,7 @@ pub(crate) fn rectangle_properties(node_id: NodeId, context: &mut NodeProperties
value: TaggedValue::F64Array4(individual_val),
}
.into(),
]))
]),
})
.on_commit(commit_value);
let radio_input = RadioInput::new(vec![uniform, individual]).selected_index(Some(is_individual as u32)).widget_holder();
@@ -1539,8 +1539,8 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte
widgets_first_row.push(
ColorInput::default()
.value(fill.clone().into())
.on_update(move |x: &ColorInput| {
Message::Batched(Box::new([
.on_update(move |x: &ColorInput| Message::Batched {
messages: Box::new([
match &fill2 {
Fill::None => NodeGraphMessage::SetInputValue {
node_id,
@@ -1567,7 +1567,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte
value: TaggedValue::Fill(x.value.to_fill(fill2.as_gradient())),
}
.into(),
]))
]),
})
.on_commit(commit_value)
.widget_holder(),
@@ -7,4 +7,4 @@ pub mod utility_types;
#[doc(inline)]
pub use overlays_message::{OverlaysMessage, OverlaysMessageDiscriminant};
#[doc(inline)]
pub use overlays_message_handler::{OverlaysMessageData, OverlaysMessageHandler};
pub use overlays_message_handler::{OverlaysMessageContext, OverlaysMessageHandler};
@@ -2,7 +2,7 @@ use super::utility_types::{OverlayProvider, OverlaysVisibilitySettings};
use crate::messages::prelude::*;
#[derive(ExtractField)]
pub struct OverlaysMessageData<'a> {
pub struct OverlaysMessageContext<'a> {
pub visibility_settings: OverlaysVisibilitySettings,
pub ipp: &'a InputPreprocessorMessageHandler,
pub device_pixel_ratio: f64,
@@ -18,9 +18,11 @@ pub struct OverlaysMessageHandler {
}
#[message_handler_data]
impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessageHandler {
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, data: OverlaysMessageData) {
let OverlaysMessageData { visibility_settings, ipp, .. } = data;
impl MessageHandler<OverlaysMessage, OverlaysMessageContext<'_>> for OverlaysMessageHandler {
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, context: OverlaysMessageContext) {
let OverlaysMessageContext { visibility_settings, ipp, .. } = context;
#[cfg(target_arch = "wasm32")]
let device_pixel_ratio = context.device_pixel_ratio;
match message {
#[cfg(target_arch = "wasm32")]
@@ -30,8 +32,6 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
use glam::{DAffine2, DVec2};
use wasm_bindgen::JsCast;
let device_pixel_ratio = data.device_pixel_ratio;
let canvas = match &self.canvas {
Some(canvas) => canvas,
None => {
@@ -40,28 +40,28 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
}
};
let context = self.context.get_or_insert_with(|| {
let context = canvas.get_context("2d").ok().flatten().expect("Failed to get canvas context");
context.dyn_into().expect("Context should be a canvas 2d context")
let canvas_context = self.context.get_or_insert_with(|| {
let canvas_context = canvas.get_context("2d").ok().flatten().expect("Failed to get canvas context");
canvas_context.dyn_into().expect("Context should be a canvas 2d context")
});
let size = ipp.viewport_bounds.size().as_uvec2();
let [a, b, c, d, e, f] = DAffine2::from_scale(DVec2::splat(device_pixel_ratio)).to_cols_array();
let _ = context.set_transform(a, b, c, d, e, f);
context.clear_rect(0., 0., ipp.viewport_bounds.size().x, ipp.viewport_bounds.size().y);
let _ = context.reset_transform();
let _ = canvas_context.set_transform(a, b, c, d, e, f);
canvas_context.clear_rect(0., 0., ipp.viewport_bounds.size().x, ipp.viewport_bounds.size().y);
let _ = canvas_context.reset_transform();
if visibility_settings.all() {
responses.add(DocumentMessage::GridOverlays(OverlayContext {
render_context: context.clone(),
render_context: canvas_context.clone(),
size: size.as_dvec2(),
device_pixel_ratio,
visibility_settings: visibility_settings.clone(),
}));
for provider in &self.overlay_providers {
responses.add(provider(OverlayContext {
render_context: context.clone(),
render_context: canvas_context.clone(),
size: size.as_dvec2(),
device_pixel_ratio,
visibility_settings: visibility_settings.clone(),
@@ -1,7 +1,5 @@
mod properties_panel_message;
mod properties_panel_message_handler;
pub mod utility_types;
pub mod properties_panel_message_handler;
#[doc(inline)]
pub use properties_panel_message::{PropertiesPanelMessage, PropertiesPanelMessageDiscriminant};
@@ -1,21 +1,34 @@
use super::utility_types::PropertiesPanelMessageHandlerData;
use graphene_std::uuid::NodeId;
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::node_graph::document_node_definitions::NodePropertiesContext;
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
use crate::messages::portfolio::utility_types::PersistentData;
use crate::messages::prelude::*;
use crate::node_graph_executor::NodeGraphExecutor;
#[derive(ExtractField)]
pub struct PropertiesPanelMessageContext<'a> {
pub network_interface: &'a mut NodeNetworkInterface,
pub selection_network_path: &'a [NodeId],
pub document_name: &'a str,
pub executor: &'a mut NodeGraphExecutor,
pub persistent_data: &'a PersistentData,
}
#[derive(Debug, Clone, Default, ExtractField)]
pub struct PropertiesPanelMessageHandler {}
#[message_handler_data]
impl MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPanelMessageHandlerData<'_>)> for PropertiesPanelMessageHandler {
fn process_message(&mut self, message: PropertiesPanelMessage, responses: &mut VecDeque<Message>, (persistent_data, data): (&PersistentData, PropertiesPanelMessageHandlerData)) {
let PropertiesPanelMessageHandlerData {
impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> for PropertiesPanelMessageHandler {
fn process_message(&mut self, message: PropertiesPanelMessage, responses: &mut VecDeque<Message>, context: PropertiesPanelMessageContext) {
let PropertiesPanelMessageContext {
network_interface,
selection_network_path,
document_name,
executor,
} = data;
persistent_data,
} = context;
match message {
PropertiesPanelMessage::Clear => {
@@ -25,7 +38,7 @@ impl MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPanelMes
});
}
PropertiesPanelMessage::Refresh => {
let mut context = NodePropertiesContext {
let mut node_properties_context = NodePropertiesContext {
persistent_data,
responses,
network_interface,
@@ -33,9 +46,9 @@ impl MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPanelMes
document_name,
executor,
};
let properties_sections = NodeGraphMessageHandler::collate_properties(&mut context);
let properties_sections = NodeGraphMessageHandler::collate_properties(&mut node_properties_context);
context.responses.add(LayoutMessage::SendLayout {
node_properties_context.responses.add(LayoutMessage::SendLayout {
layout: Layout::WidgetLayout(WidgetLayout::new(properties_sections)),
layout_target: LayoutTarget::PropertiesSections,
});
@@ -1,10 +0,0 @@
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
use crate::node_graph_executor::NodeGraphExecutor;
use graph_craft::document::NodeId;
pub struct PropertiesPanelMessageHandlerData<'a> {
pub network_interface: &'a mut NodeNetworkInterface,
pub selection_network_path: &'a [NodeId],
pub document_name: &'a str,
pub executor: &'a mut NodeGraphExecutor,
}