Add visibility and delete buttons to node sections in the Properties panel

This commit is contained in:
Keavon Chambers
2024-05-07 02:53:30 -07:00
parent 1ce3d59e0f
commit 07fd2c2782
10 changed files with 139 additions and 68 deletions

View File

@@ -309,30 +309,35 @@ impl LayoutMessageHandler {
responses: &mut VecDeque<Message>,
action_input_mapping: &impl Fn(&MessageDiscriminant) -> Vec<KeysGroup>,
) {
// We don't diff the menu bar layout yet.
if matches!(new_layout, Layout::MenuLayout(_)) {
// Skip update if the same
if self.layouts[layout_target as usize] == new_layout {
return;
match new_layout {
Layout::WidgetLayout(_) => {
let mut widget_diffs = Vec::new();
self.layouts[layout_target as usize].diff(new_layout, &mut Vec::new(), &mut widget_diffs);
// Skip sending if no diff.
if widget_diffs.is_empty() {
return;
}
self.send_diff(widget_diffs, layout_target, responses, action_input_mapping);
}
// Update the backend storage
self.layouts[layout_target as usize] = new_layout;
// Update the UI
responses.add(FrontendMessage::UpdateMenuBarLayout {
layout_target,
layout: self.layouts[layout_target as usize].clone().unwrap_menu_layout(action_input_mapping).layout,
});
return;
}
// We don't diff the menu bar layout yet.
Layout::MenuLayout(_) => {
// Skip update if the same
if self.layouts[layout_target as usize] == new_layout {
return;
}
let mut widget_diffs = Vec::new();
self.layouts[layout_target as usize].diff(new_layout, &mut Vec::new(), &mut widget_diffs);
// Skip sending if no diff.
if widget_diffs.is_empty() {
return;
}
// Update the backend storage
self.layouts[layout_target as usize] = new_layout;
self.send_diff(widget_diffs, layout_target, responses, action_input_mapping);
// Update the UI
responses.add(FrontendMessage::UpdateMenuBarLayout {
layout_target,
layout: self.layouts[layout_target as usize].clone().unwrap_menu_layout(action_input_mapping).layout,
});
}
}
}
/// Send a diff to the frontend based on the layout target.

View File

@@ -235,7 +235,7 @@ impl<'a> Iterator for WidgetIter<'a> {
self.current_slice = Some(widgets);
self.next()
}
Some(LayoutGroup::Section { name: _, layout }) => {
Some(LayoutGroup::Section { layout, .. }) => {
for layout_row in layout {
self.stack.push(layout_row);
}
@@ -276,7 +276,7 @@ impl<'a> Iterator for WidgetIterMut<'a> {
self.current_slice = Some(widgets);
self.next()
}
Some(LayoutGroup::Section { name: _, layout }) => {
Some(LayoutGroup::Section { layout, .. }) => {
for layout_row in layout {
self.stack.push(layout_row);
}
@@ -301,8 +301,9 @@ pub enum LayoutGroup {
#[serde(rename = "rowWidgets")]
widgets: Vec<WidgetHolder>,
},
// TODO: Move this from being a child of `enum LayoutGroup` to being a child of `enum Layout`
#[serde(rename = "section")]
Section { name: String, layout: SubLayout },
Section { name: String, visible: bool, id: u64, layout: SubLayout },
}
impl Default for LayoutGroup {
@@ -378,28 +379,43 @@ impl LayoutGroup {
(
Self::Section {
name: current_name,
visible: current_visible,
id: current_id,
layout: current_layout,
},
Self::Section { name: new_name, layout: new_layout },
Self::Section {
name: new_name,
visible: new_visible,
id: new_id,
layout: new_layout,
},
) => {
// If the lengths are different then resend the entire panel
// Resend the entire panel if the lengths, names, visibility, or node IDs are different
// TODO: Diff insersion and deletion of items
if *current_name != new_name || current_layout.len() != new_layout.len() {
if current_layout.len() != new_layout.len() || *current_name != new_name || *current_visible != new_visible || *current_id != new_id {
// Update self to reflect new changes
*current_name = new_name.clone();
*current_visible = new_visible;
*current_id = new_id;
*current_layout = new_layout.clone();
// Push an update layout group to the diff
let new_value = DiffUpdate::LayoutGroup(Self::Section { name: new_name, layout: new_layout });
let new_value = DiffUpdate::LayoutGroup(Self::Section {
name: new_name,
visible: new_visible,
id: new_id,
layout: new_layout,
});
let widget_path = widget_path.to_vec();
widget_diffs.push(WidgetDiff { widget_path, new_value });
return;
}
// Diff all of the children
for (index, (current_child, new_child)) in current_layout.iter_mut().zip(new_layout).enumerate() {
widget_path.push(index);
current_child.diff(new_child, widget_path, widget_diffs);
widget_path.pop();
else {
for (index, (current_child, new_child)) in current_layout.iter_mut().zip(new_layout).enumerate() {
widget_path.push(index);
current_child.diff(new_child, widget_path, widget_diffs);
widget_path.pop();
}
}
}
(current, new) => {

View File

@@ -666,8 +666,12 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
responses.add(NodeGraphMessage::RunDocumentGraph);
}
})();
document_metadata.load_structure(document_network, selected_nodes);
self.update_selection_action_buttons(document_network, document_metadata, selected_nodes, responses);
responses.add(PropertiesPanelMessage::Refresh);
}
NodeGraphMessage::ToggleSelectedLocked => {
responses.add(DocumentMessage::StartTransaction);

View File

@@ -2252,7 +2252,12 @@ pub fn generate_node_properties(document_node: &DocumentNode, node_id: NodeId, c
Some(document_node_type) => (document_node_type.properties)(document_node, node_id, context),
None => unknown_node_properties(document_node),
};
LayoutGroup::Section { name, layout }
LayoutGroup::Section {
name,
visible: document_node.visible,
id: node_id.0,
layout,
}
}
pub fn stroke_properties(document_node: &DocumentNode, node_id: NodeId, _context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {

View File

@@ -43,7 +43,7 @@ impl<'a> MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPane
let options_bar = vec![LayoutGroup::Row {
widgets: vec![
IconLabel::new("File").tooltip("Document").widget_holder(),
IconLabel::new("File").tooltip("Document name").widget_holder(),
Separator::new(SeparatorType::Related).widget_holder(),
TextInput::new(document_name)
.on_update(|text_input| DocumentMessage::RenameDocument { new_name: text_input.value.clone() }.into())