Skip to content

Generate a visualization of the editor's hierarchical message system tree #2499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
43f5323
Feat: implement the hierarchical tree for visualization
MohdMohsin97 Mar 29, 2025
f9ee826
rename HierarchicalTree trait function
MohdMohsin97 Mar 29, 2025
11e104f
Merge branch 'GraphiteEditor:master' into hierarchical-tree
MohdMohsin97 Apr 11, 2025
0afbaf5
Merge branch 'hierarchical-tree' of https://github.com/MohdMohsin97/G…
MohdMohsin97 Apr 11, 2025
0f9e491
feat: change the HierarchicalTree from String to DebugMessageTree struct
MohdMohsin97 Apr 12, 2025
d1a0294
Merge branch 'master' into hierarchical-tree
Keavon Apr 18, 2025
e232c5d
Nits
Keavon Apr 18, 2025
9fec71c
Merge branch 'GraphiteEditor:master' into hierarchical-tree
MohdMohsin97 Apr 19, 2025
9f5ad94
feat: impliment proc macro to extract field from messagedata structs
MohdMohsin97 Apr 19, 2025
9395617
Merge branch 'hierarchical-tree' of https://github.com/MohdMohsin97/G…
MohdMohsin97 Apr 19, 2025
dcfbb97
update the hierarchical-tree for hanlder data
MohdMohsin97 Apr 23, 2025
1e11239
Merge branch 'GraphiteEditor:master' into hierarchical-tree
MohdMohsin97 Apr 27, 2025
730db02
Merge branch 'GraphiteEditor:master' into hierarchical-tree
MohdMohsin97 May 1, 2025
fc9e258
feat: added message handler struct to hierarchical tree
MohdMohsin97 May 1, 2025
1af7c6e
Merge branch 'hierarchical-tree' of https://github.com/MohdMohsin97/G…
MohdMohsin97 May 1, 2025
160a9d0
Merge branch 'GraphiteEditor:master' into hierarchical-tree
MohdMohsin97 May 1, 2025
ee272e5
Merge branch 'hierarchical-tree' of https://github.com/MohdMohsin97/G…
MohdMohsin97 May 1, 2025
c2c629d
feat: add the line number to message handler struct
MohdMohsin97 May 10, 2025
c2c6ac5
feat: added handler path to tree and NITS
MohdMohsin97 May 12, 2025
6d4c29c
Merge branch 'master' into hierarchical-tree
MohdMohsin97 May 13, 2025
d034c4c
clean the white spaces in type string
MohdMohsin97 May 19, 2025
396ed0c
Merge branch 'hierarchical-tree' of https://github.com/MohdMohsin97/G…
MohdMohsin97 May 19, 2025
0a9741f
Merge branch 'master' into hierarchical-tree
Keavon May 19, 2025
4ee1bcf
Merge branch 'master' into hierarchical-tree
Keavon May 19, 2025
065af10
fixes some white spaces
MohdMohsin97 May 25, 2025
007610b
Merge branch 'hierarchical-tree' of https://github.com/MohdMohsin97/G…
MohdMohsin97 May 25, 2025
7bc5397
feat: added path to message enum in hierarchical tree
MohdMohsin97 May 26, 2025
ca8dbfb
feat: add file creation of hierarchical message system tree
MohdMohsin97 May 28, 2025
cff1d81
Merge branch 'GraphiteEditor:master' into hierarchical-tree
MohdMohsin97 May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update the hierarchical-tree for hanlder data
  • Loading branch information
MohdMohsin97 committed Apr 23, 2025
commit dcfbb97bf14f22763d125a336bd98e55fff3868d
1 change: 1 addition & 0 deletions editor/src/messages/animation/animation_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl AnimationMessageHandler {
}
}

#[message_handler_data]
impl MessageHandler<AnimationMessage, ()> for AnimationMessageHandler {
fn process_message(&mut self, message: AnimationMessage, responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/broadcast/broadcast_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct BroadcastMessageHandler {
listeners: HashMap<BroadcastEvent, Vec<Message>>,
}

#[message_handler_data]
impl MessageHandler<BroadcastMessage, ()> for BroadcastMessageHandler {
fn process_message(&mut self, message: BroadcastMessage, responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/debug/debug_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct DebugMessageHandler {
pub message_logging_verbosity: MessageLoggingVerbosity,
}

#[message_handler_data]
impl MessageHandler<DebugMessage, ()> for DebugMessageHandler {
fn process_message(&mut self, message: DebugMessage, responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
27 changes: 27 additions & 0 deletions editor/src/messages/debug/utility_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,35 @@ pub enum MessageLoggingVerbosity {
Contents,
}

#[derive(Debug)]
pub struct MessageData {
name: String,
fields: Vec<String>,
}

impl MessageData {
pub fn name(&self) -> &str {
&self.name
}

pub fn fields(&self) -> &Vec<String> {
&self.fields
}
}

#[derive(Debug)]
pub struct DebugMessageTree {
name: String,
variants: Option<Vec<DebugMessageTree>>,
data: Option<MessageData>,
}

impl DebugMessageTree {
pub fn new(name: &str) -> DebugMessageTree {
DebugMessageTree {
name: name.to_string(),
variants: None,
data: None,
}
}

Expand All @@ -27,11 +46,19 @@ impl DebugMessageTree {
}
}

pub fn add_data_field(&mut self, name: String, fields: Vec<String>) {
self.data = Some(MessageData { name, fields });
}

pub fn name(&self) -> &str {
&self.name
}

pub fn variants(&self) -> Option<&Vec<DebugMessageTree>> {
self.variants.as_ref()
}

pub fn data_fields(&self) -> Option<&MessageData> {
self.data.as_ref()
}
}
1 change: 1 addition & 0 deletions editor/src/messages/dialog/dialog_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct DialogMessageHandler {
preferences_dialog: PreferencesDialogMessageHandler,
}

#[message_handler_data]
impl MessageHandler<DialogMessage, DialogMessageData<'_>> for DialogMessageHandler {
fn process_message(&mut self, message: DialogMessage, responses: &mut VecDeque<Message>, data: DialogMessageData) {
let DialogMessageData { portfolio, preferences } = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Default for ExportDialogMessageHandler {
}
}

#[message_handler_data]
impl MessageHandler<ExportDialogMessage, ExportDialogMessageData<'_>> for ExportDialogMessageHandler {
fn process_message(&mut self, message: ExportDialogMessage, responses: &mut VecDeque<Message>, data: ExportDialogMessageData) {
let ExportDialogMessageData { portfolio } = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct NewDocumentDialogMessageHandler {
pub dimensions: UVec2,
}

#[message_handler_data]
impl MessageHandler<NewDocumentDialogMessage, ()> for NewDocumentDialogMessageHandler {
fn process_message(&mut self, message: NewDocumentDialogMessage, responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct PreferencesDialogMessageData<'a> {
#[derive(Debug, Clone, Default)]
pub struct PreferencesDialogMessageHandler {}

#[message_handler_data]
impl MessageHandler<PreferencesDialogMessage, PreferencesDialogMessageData<'_>> for PreferencesDialogMessageHandler {
fn process_message(&mut self, message: PreferencesDialogMessage, responses: &mut VecDeque<Message>, data: PreferencesDialogMessageData) {
let PreferencesDialogMessageData { preferences } = data;
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/globals/globals_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::messages::prelude::*;
#[derive(Debug, Default)]
pub struct GlobalsMessageHandler {}

#[message_handler_data]
impl MessageHandler<GlobalsMessage, ()> for GlobalsMessageHandler {
fn process_message(&mut self, message: GlobalsMessage, _responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct InputMapperMessageHandler {
mapping: Mapping,
}

#[message_handler_data]
impl MessageHandler<InputMapperMessage, InputMapperMessageData<'_>> for InputMapperMessageHandler {
fn process_message(&mut self, message: InputMapperMessage, responses: &mut VecDeque<Message>, data: InputMapperMessageData) {
let InputMapperMessageData { input, actions } = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct KeyMappingMessageHandler {
mapping_handler: InputMapperMessageHandler,
}

#[message_handler_data]
impl MessageHandler<KeyMappingMessage, KeyMappingMessageData<'_>> for KeyMappingMessageHandler {
fn process_message(&mut self, message: KeyMappingMessage, responses: &mut VecDeque<Message>, data: KeyMappingMessageData) {
let KeyMappingMessageData { input, actions } = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct InputPreprocessorMessageHandler {
pub viewport_bounds: ViewportBounds,
}

#[message_handler_data]
impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageData> for InputPreprocessorMessageHandler {
fn process_message(&mut self, message: InputPreprocessorMessage, responses: &mut VecDeque<Message>, data: InputPreprocessorMessageData) {
let InputPreprocessorMessageData { keyboard_platform } = data;
Expand Down
5 changes: 5 additions & 0 deletions editor/src/messages/layout/layout_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ impl LayoutMessageHandler {
}
}

#[message_handler_data(CustomData)]
impl<F: Fn(&MessageDiscriminant) -> Vec<KeysGroup>> MessageHandler<LayoutMessage, F> for LayoutMessageHandler {
fn process_message(&mut self, message: LayoutMessage, responses: &mut std::collections::VecDeque<Message>, action_input_mapping: F) {
match message {
Expand Down Expand Up @@ -438,3 +439,7 @@ impl LayoutMessageHandler {
responses.add(message);
}
}

pub fn custom_data() -> Vec<String> {
vec![String::from("Fn(&MessageDiscriminant) -> Vec<KeysGroup>")]
}
26 changes: 22 additions & 4 deletions editor/src/messages/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,18 @@ mod test {

fn print_tree_node(tree: &DebugMessageTree, prefix: &str, is_last: bool) {
// Print the current node
let branch = if is_last { "└── " } else { "├── " };
println!("{}{}{}", prefix, branch, tree.name());
let (branch, child_prefix) = match &tree.data_fields() {
Some(_) => ("├── ", format!("{}│ ", prefix)),
None => {
if is_last {
("└── ", format!("{} ", prefix))
} else {
("├── ", format!("{}│ ", prefix))
}
}
};

// Prepare prefix for children
let child_prefix = if is_last { format!("{} ", prefix) } else { format!("{}│ ", prefix) };
println!("{}{}{}", prefix, branch, tree.name());

// Print children if any
if let Some(variants) = tree.variants() {
Expand All @@ -78,5 +85,16 @@ mod test {
print_tree_node(variant, &child_prefix, is_last_child);
}
}

// Print data field if any
if let Some(data) = tree.data_fields() {
let len = data.fields().len();
println!("{}{}{}", prefix, "└── ", data.name());
for (i, field) in data.fields().iter().enumerate() {
let is_last_field = i == len - 1;
let branch = if is_last_field { "└── " } else { "├── " };
println!("{}{}{}", format!("{} ", prefix), branch, field);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct NavigationMessageHandler {
abortable_pan_start: Option<f64>,
}

#[message_handler_data]
impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for NavigationMessageHandler {
fn process_message(&mut self, message: NavigationMessage, responses: &mut VecDeque<Message>, data: NavigationMessageData) {
let NavigationMessageData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct OverlaysMessageHandler {
context: Option<web_sys::CanvasRenderingContext2d>,
}

#[message_handler_data]
impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessageHandler {
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, data: OverlaysMessageData) {
let OverlaysMessageData { overlays_visible, ipp, .. } = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::messages::prelude::*;
#[derive(Debug, Clone, Default)]
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct MenuBarMessageHandler {
pub reset_node_definitions_on_open: bool,
}

#[message_handler_data]
impl MessageHandler<MenuBarMessage, ()> for MenuBarMessageHandler {
fn process_message(&mut self, message: MenuBarMessage, responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/portfolio/portfolio_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct PortfolioMessageHandler {
pub reset_node_definitions_on_open: bool,
}

#[message_handler_data]
impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMessageHandler {
fn process_message(&mut self, message: PortfolioMessage, responses: &mut VecDeque<Message>, data: PortfolioMessageData) {
let PortfolioMessageData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct SpreadsheetMessageHandler {
viewing_vector_data_domain: VectorDataDomain,
}

#[message_handler_data]
impl MessageHandler<SpreadsheetMessage, ()> for SpreadsheetMessageHandler {
fn process_message(&mut self, message: SpreadsheetMessage, responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Default for PreferencesMessageHandler {
}
}

#[message_handler_data]
impl MessageHandler<PreferencesMessage, ()> for PreferencesMessageHandler {
fn process_message(&mut self, message: PreferencesMessage, responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
11 changes: 1 addition & 10 deletions editor/src/messages/tool/tool_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct ToolMessageHandler {
pub tool_is_active: bool,
}

#[message_handler_data]
impl MessageHandler<ToolMessage, ToolMessageData<'_>> for ToolMessageHandler {
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, data: ToolMessageData) {
let ToolMessageData {
Expand Down Expand Up @@ -327,13 +328,3 @@ impl MessageHandler<ToolMessage, ToolMessageData<'_>> for ToolMessageHandler {
list
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn print_field() {
ToolMessageData::print_field_types();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ fn update_colinear_handles(selected_layers: &[LayerNodeIdentifier], document: &D
}

type TransformData<'a> = (&'a DocumentMessageHandler, &'a InputPreprocessorMessageHandler, &'a ToolData, &'a mut ShapeState);

#[message_handler_data(CustomData)]
impl MessageHandler<TransformLayerMessage, TransformData<'_>> for TransformLayerMessageHandler {
fn process_message(&mut self, message: TransformLayerMessage, responses: &mut VecDeque<Message>, (document, input, tool_data, shape_editor): TransformData) {
let using_path_tool = tool_data.active_tool_type == ToolType::Path;
Expand Down Expand Up @@ -711,6 +713,15 @@ impl MessageHandler<TransformLayerMessage, TransformData<'_>> for TransformLayer
}
}

pub fn custom_data() -> Vec<String> {
vec![
String::from("&'a DocumentMessageHandler"),
String::from("&'a InputPreprocessorMessageHandler"),
String::from("&'a ToolData"),
String::from("&'a mut ShapeState"),
]
}

#[cfg(test)]
mod test_transform_layer {
use crate::messages::portfolio::document::graph_operation::{transform_utils, utility_types::ModifyInputsContext};
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/workspace/workspace_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct WorkspaceMessageHandler {
node_graph_visible: bool,
}

#[message_handler_data]
impl MessageHandler<WorkspaceMessage, ()> for WorkspaceMessageHandler {
fn process_message(&mut self, message: WorkspaceMessage, _responses: &mut VecDeque<Message>, _data: ()) {
match message {
Expand Down
4 changes: 4 additions & 0 deletions editor/src/utility_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ pub trait Hint {

pub trait HierarchicalTree {
fn build_message_tree() -> DebugMessageTree;

fn message_handler_data_str() -> Vec<String> {
Vec::new()
}
}
4 changes: 4 additions & 0 deletions proc-macros/src/hierarchical_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pub fn generate_hierarchical_tree(input: TokenStream) -> syn::Result<TokenStream
fn build_message_tree() -> DebugMessageTree {
let mut message_tree = DebugMessageTree::new(stringify!(#input_type));
#(#build_message_tree)*
let data_str = #input_type::message_handler_data_str();
if data_str.len() > 0 {
message_tree.add_data_field(format!("{}Data", stringify!(#input_type)), data_str);
}
message_tree
}
}
Expand Down
9 changes: 8 additions & 1 deletion proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod helper_structs;
mod helpers;
mod hierarchical_tree;
mod hint;
mod message_handler_data_attr;
mod transitive_child;
mod widget_builder;

Expand All @@ -16,10 +17,11 @@ use crate::combined_message_attrs::combined_message_attrs_impl;
use crate::discriminant::derive_discriminant_impl;
use crate::extract_fields::derive_extract_field_impl;
use crate::helper_structs::AttrInnerSingleString;
use crate::hierarchical_tree::generate_hierarchical_tree;
use crate::hint::derive_hint_impl;
use crate::message_handler_data_attr::message_handler_data_attr_impl;
use crate::transitive_child::derive_transitive_child_impl;
use crate::widget_builder::derive_widget_builder_impl;
use hierarchical_tree::generate_hierarchical_tree;
use proc_macro::TokenStream;

/// Derive the `ToDiscriminant` trait and create a `<Type Name>Discriminant` enum
Expand Down Expand Up @@ -295,6 +297,11 @@ pub fn derive_extract_field(input_item: TokenStream) -> TokenStream {
TokenStream::from(derive_extract_field_impl(input_item.into()).unwrap_or_else(|err| err.to_compile_error()))
}

#[proc_macro_attribute]
pub fn message_handler_data(attr: TokenStream, input_item: TokenStream) -> TokenStream {
TokenStream::from(message_handler_data_attr_impl(attr.into(), input_item.into()).unwrap_or_else(|err| err.to_compile_error()))
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading