Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions editor/src/messages/layout/utility_types/layout_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub enum LayoutGroup {
description: String,
visible: bool,
pinned: bool,
expanded: bool,
id: u64,
layout: Layout,
},
Expand Down Expand Up @@ -439,6 +440,7 @@ impl Diffable for LayoutGroup {
description: current_description,
visible: current_visible,
pinned: current_pinned,
expanded: current_expanded,
id: current_id,
layout: current_layout,
},
Expand All @@ -447,6 +449,7 @@ impl Diffable for LayoutGroup {
description: new_description,
visible: new_visible,
pinned: new_pinned,
expanded: new_expanded,
id: new_id,
layout: new_layout,
},
Expand All @@ -458,13 +461,15 @@ impl Diffable for LayoutGroup {
|| *current_description != new_description
|| *current_visible != new_visible
|| *current_pinned != new_pinned
|| *current_expanded != new_expanded
|| *current_id != new_id
{
// Update self to reflect new changes
current_name.clone_from(&new_name);
current_description.clone_from(&new_description);
*current_visible = new_visible;
*current_pinned = new_pinned;
*current_expanded = new_expanded;
*current_id = new_id;
current_layout.clone_from(&new_layout);

Expand All @@ -474,6 +479,7 @@ impl Diffable for LayoutGroup {
description: new_description,
visible: new_visible,
pinned: new_pinned,
expanded: new_expanded,
id: new_id,
layout: new_layout,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl<'a> ModifyInputsContext<'a> {
pub fn create_layer(&mut self, new_id: NodeId) -> LayerNodeIdentifier {
let new_merge_node = resolve_network_node_type("Merge").expect("Merge node").default_node_template();
self.network_interface.insert_node(new_id, new_merge_node, &[]);
self.responses.add(PropertiesPanelMessage::SetSectionExpanded { node_id: new_id.0, expanded: false });
LayerNodeIdentifier::new(new_id, self.network_interface)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct NodePropertiesContext<'a> {
pub network_interface: &'a mut NodeNetworkInterface,
pub selection_network_path: &'a [NodeId],
pub document_name: &'a str,
pub section_expanded: &'a HashMap<u64, bool>,
}

impl NodePropertiesContext<'_> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1843,12 +1843,20 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper

let visible = context.network_interface.is_visible(&node_id, context.selection_network_path);
let pinned = context.network_interface.is_pinned(&node_id, context.selection_network_path);
let expanded = context.section_expanded.get(&node_id.0).copied().unwrap_or_else(|| {
!context
.network_interface
.reference(&node_id, context.selection_network_path)
.as_ref()
.is_some_and(|id| id.implementation_name_from_identifier() == "Merge")
});

LayoutGroup::Section {
name,
description,
visible,
pinned,
expanded,
id: node_id.0,
layout: Layout(layout),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ pub enum PropertiesPanelMessage {
// Messages
Clear,
Refresh,
SetAllSectionsExpanded { expanded: bool },
SetSectionExpanded { node_id: u64, expanded: bool },
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use graphene_std::uuid::NodeId;

use crate::messages::layout::utility_types::widget_prelude::*;
Expand All @@ -18,7 +20,9 @@ pub struct PropertiesPanelMessageContext<'a> {
}

#[derive(Debug, Clone, Default, ExtractField)]
pub struct PropertiesPanelMessageHandler {}
pub struct PropertiesPanelMessageHandler {
pub section_expanded: HashMap<u64, bool>,
}
Comment on lines 22 to +25

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation of SetAllSectionsExpanded has a flaw where it only affects sections that have been individually toggled. To fix this, I suggest adding a field to track a global expansion state. I'll leave another comment on the message handlers with more details.

Suggested change
#[derive(Debug, Clone, Default, ExtractField)]
pub struct PropertiesPanelMessageHandler {}
pub struct PropertiesPanelMessageHandler {
pub section_expanded: HashMap<u64, bool>,
}
#[derive(Debug, Clone, Default, ExtractField)]
pub struct PropertiesPanelMessageHandler {
pub section_expanded: HashMap<u64, bool>,
pub all_sections_expanded: Option<bool>,
}


#[message_handler_data]
impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> for PropertiesPanelMessageHandler {
Expand Down Expand Up @@ -52,6 +56,7 @@ impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> f
selection_network_path,
document_name,
executor,
section_expanded: &self.section_expanded,
};
let layout = Layout(NodeGraphMessageHandler::collate_properties(&mut node_properties_context));

Expand All @@ -60,10 +65,64 @@ impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> f
layout_target: LayoutTarget::PropertiesPanel,
});
}
PropertiesPanelMessage::SetAllSectionsExpanded { expanded } => {
let mut layout = {
let mut node_properties_context = NodePropertiesContext {
persistent_data,
responses,
network_interface,
selection_network_path,
document_name,
executor,
section_expanded: &self.section_expanded,
};
Layout(NodeGraphMessageHandler::collate_properties(&mut node_properties_context))
};

Self::update_all_section_expansion_recursive(&mut layout.0, expanded, &mut self.section_expanded, network_interface, selection_network_path);

responses.add(LayoutMessage::SendLayout {
layout,
layout_target: LayoutTarget::PropertiesPanel,
});
}
PropertiesPanelMessage::SetSectionExpanded { node_id, expanded } => {
self.section_expanded.insert(node_id, expanded);
responses.add(PropertiesPanelMessage::Refresh);
}
}
}

fn actions(&self) -> ActionList {
actions!(PropertiesMessageDiscriminant;)
}
}

impl PropertiesPanelMessageHandler {
fn update_all_section_expansion_recursive(
layout: &mut [LayoutGroup],
expanded: bool,
section_expanded: &mut HashMap<u64, bool>,
network_interface: &NodeNetworkInterface,
selection_network_path: &[NodeId],
) {
for group in layout {
if let LayoutGroup::Section {
id, layout, expanded: group_expanded, ..
} = group
{
let is_merge_node = network_interface
.reference(&NodeId(*id), selection_network_path)
.as_ref()
.is_some_and(|id| id.implementation_name_from_identifier() == "Merge");

if !is_merge_node {
*group_expanded = expanded;
section_expanded.insert(*id, expanded);
}

Self::update_all_section_expansion_recursive(&mut layout.0, expanded, section_expanded, network_interface, selection_network_path);
}
}
}
}
15 changes: 12 additions & 3 deletions frontend/src/components/widgets/WidgetSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@
export { className as class };
export let classes: Record<string, boolean> = {};

let expanded = true;
$: expanded = widgetData.expanded;

const editor = getContext<Editor>("editor");
</script>

<!-- TODO: Implement collapsable sections with properties system -->
<LayoutCol class={`widget-section ${className}`.trim()} {classes}>
<button class="header" class:expanded on:click|stopPropagation={() => (expanded = !expanded)} tabindex="0">
<button
class="header"
class:expanded
on:click|stopPropagation={(e) => {
if (e.altKey) {
editor.handle.setAllSectionsExpanded(!expanded);
} else {
editor.handle.setSectionExpanded(widgetData.id, !expanded);
}
}}
>
<div class="expand-arrow"></div>
<TextLabel tooltipLabel={widgetData.name} tooltipDescription={widgetData.description} bold={true}>{widgetData.name}</TextLabel>
<IconButton
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ export function isWidgetTable(layoutTable: LayoutGroup): layoutTable is WidgetTa
return Boolean((layoutTable as WidgetTable)?.tableWidgets);
}

export type WidgetSection = { name: string; description: string; visible: boolean; pinned: boolean; id: bigint; layout: Layout };
export type WidgetSection = { name: string; description: string; visible: boolean; pinned: boolean; expanded: boolean; id: bigint; layout: Layout };
export function isWidgetSection(layoutRow: LayoutGroup): layoutRow is WidgetSection {
return Boolean((layoutRow as WidgetSection)?.layout);
}
Expand All @@ -1612,6 +1612,7 @@ function createLayoutGroup(layoutGroup: any): LayoutGroup {
description: layoutGroup.section.description,
visible: layoutGroup.section.visible,
pinned: layoutGroup.section.pinned,
expanded: layoutGroup.section.expanded,
id: layoutGroup.section.id,
layout: layoutGroup.section.layout.map(createLayoutGroup),
};
Expand Down
14 changes: 14 additions & 0 deletions frontend/wasm/src/editor_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,20 @@ impl EditorHandle {
self.dispatch(message);
}

/// Set section expanded state in the Properties panel
#[wasm_bindgen(js_name = setSectionExpanded)]
pub fn set_section_expanded(&self, node_id: u64, expanded: bool) {
let message = DocumentMessage::PropertiesPanel(PropertiesPanelMessage::SetSectionExpanded { node_id, expanded });
self.dispatch(message);
}

/// Set all sections expanded state in the Properties panel
#[wasm_bindgen(js_name = setAllSectionsExpanded)]
pub fn set_all_sections_expanded(&self, expanded: bool) {
let message = DocumentMessage::PropertiesPanel(PropertiesPanelMessage::SetAllSectionsExpanded { expanded });
self.dispatch(message);
}

/// Set the active panel to the most recently clicked panel
#[wasm_bindgen(js_name = setActivePanel)]
pub fn set_active_panel(&self, panel: String) {
Expand Down
Loading