From 783ea0b43762931c5c3473620ee562092d56ce6b Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Thu, 4 Dec 2025 15:24:40 -0800 Subject: [PATCH] Unwrap the Layout enum to replace it with the WidgetLayout struct now called Layout (#3448) --- .../wrapper/src/intercept_frontend_message.rs | 2 +- desktop/wrapper/src/utils.rs | 4 +- editor/src/dispatcher.rs | 2 +- .../export_dialog_message_handler.rs | 6 +- .../new_document_dialog_message_handler.rs | 8 +-- .../preferences_dialog_message_handler.rs | 6 +- .../simple_dialogs/about_graphite_dialog.rs | 8 +-- .../close_all_documents_dialog.rs | 6 +- .../simple_dialogs/close_document_dialog.rs | 6 +- .../simple_dialogs/coming_soon_dialog.rs | 4 +- .../simple_dialogs/demo_artwork_dialog.rs | 4 +- .../dialog/simple_dialogs/error_dialog.rs | 6 +- .../dialog/simple_dialogs/licenses_dialog.rs | 8 +-- .../licenses_third_party_dialog.rs | 6 +- .../messages/layout/layout_message_handler.rs | 57 +++++++--------- .../layout/utility_types/layout_widget.rs | 31 +++------ .../utility_types/widgets/button_widgets.rs | 2 +- .../data_panel/data_panel_message_handler.rs | 17 ++--- .../document/document_message_handler.rs | 36 +++++----- .../node_graph/node_graph_message_handler.rs | 6 +- .../document/node_graph/node_properties.rs | 2 +- .../properties_panel_message_handler.rs | 6 +- .../menu_bar/menu_bar_message_handler.rs | 2 +- .../portfolio/portfolio_message_handler.rs | 2 +- .../tool/tool_messages/artboard_tool.rs | 2 +- .../messages/tool/tool_messages/brush_tool.rs | 2 +- .../tool/tool_messages/eyedropper_tool.rs | 2 +- .../messages/tool/tool_messages/fill_tool.rs | 2 +- .../tool/tool_messages/freehand_tool.rs | 2 +- .../tool/tool_messages/gradient_tool.rs | 2 +- .../tool/tool_messages/navigate_tool.rs | 2 +- .../messages/tool/tool_messages/path_tool.rs | 4 +- .../messages/tool/tool_messages/pen_tool.rs | 2 +- .../tool/tool_messages/select_tool.rs | 4 +- .../messages/tool/tool_messages/shape_tool.rs | 2 +- .../tool/tool_messages/spline_tool.rs | 2 +- .../messages/tool/tool_messages/text_tool.rs | 2 +- editor/src/messages/tool/utility_types.rs | 10 +-- frontend/src/components/panels/Data.svelte | 6 +- frontend/src/components/panels/Layers.svelte | 16 ++--- .../src/components/panels/Properties.svelte | 6 +- frontend/src/components/panels/Welcome.svelte | 8 +-- .../components/widgets/WidgetLayout.svelte | 4 +- .../src/components/widgets/WidgetSpan.svelte | 6 +- .../window/status-bar/StatusBar.svelte | 8 +-- .../window/title-bar/TitleBar.svelte | 8 +-- frontend/src/messages.ts | 68 ++++++++----------- frontend/src/state-providers/dialog.ts | 24 +++---- frontend/src/state-providers/document.ts | 28 ++++---- 49 files changed, 205 insertions(+), 254 deletions(-) diff --git a/desktop/wrapper/src/intercept_frontend_message.rs b/desktop/wrapper/src/intercept_frontend_message.rs index 4905109d10..24ee4c5b1b 100644 --- a/desktop/wrapper/src/intercept_frontend_message.rs +++ b/desktop/wrapper/src/intercept_frontend_message.rs @@ -120,7 +120,7 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD [ WidgetDiff { widget_path, - new_value: DiffUpdate::WidgetLayout(layout), + new_value: DiffUpdate::Layout(layout), }, ] if widget_path.is_empty() => { let entries = crate::utils::menu::convert_menu_bar_layout_to_menu_items(layout); diff --git a/desktop/wrapper/src/utils.rs b/desktop/wrapper/src/utils.rs index 3ae13b9b9f..73a49960a1 100644 --- a/desktop/wrapper/src/utils.rs +++ b/desktop/wrapper/src/utils.rs @@ -6,11 +6,11 @@ pub(crate) mod menu { use graphite_editor::messages::input_mapper::utility_types::input_keyboard::{Key, LabeledKey, LabeledShortcut}; use graphite_editor::messages::input_mapper::utility_types::misc::ActionShortcut; use graphite_editor::messages::layout::LayoutMessage; - use graphite_editor::messages::tool::tool_messages::tool_prelude::{LayoutGroup, LayoutTarget, MenuListEntry, Widget, WidgetId, WidgetLayout}; + use graphite_editor::messages::tool::tool_messages::tool_prelude::{Layout, LayoutGroup, LayoutTarget, MenuListEntry, Widget, WidgetId}; use crate::messages::{EditorMessage, KeyCode, MenuItem, Modifiers, Shortcut}; - pub(crate) fn convert_menu_bar_layout_to_menu_items(layout: &WidgetLayout) -> Vec { + pub(crate) fn convert_menu_bar_layout_to_menu_items(layout: &Layout) -> Vec { let layout_group = match layout.as_slice() { [layout_group] => layout_group, _ => panic!("Menu bar layout is supposed to have exactly one layout group"), diff --git a/editor/src/dispatcher.rs b/editor/src/dispatcher.rs index 64d4c45cd1..a6c1816322 100644 --- a/editor/src/dispatcher.rs +++ b/editor/src/dispatcher.rs @@ -548,7 +548,7 @@ mod test { for response in responses { // Check for the existence of the file format incompatibility warning dialog after opening the test file if let FrontendMessage::UpdateDialogColumn1 { diff } = response { - if let DiffUpdate::WidgetLayout(sub_layout) = &diff[0].new_value { + if let DiffUpdate::Layout(sub_layout) = &diff[0].new_value { if let LayoutGroup::Row { widgets } = &sub_layout.0[0] { if let Widget::TextLabel(TextLabel { value, .. }) = &widgets[0].widget { print_problem_to_terminal_on_failure(value); diff --git a/editor/src/messages/dialog/export_dialog/export_dialog_message_handler.rs b/editor/src/messages/dialog/export_dialog/export_dialog_message_handler.rs index 8562e63305..32593b80c4 100644 --- a/editor/src/messages/dialog/export_dialog/export_dialog_message_handler.rs +++ b/editor/src/messages/dialog/export_dialog/export_dialog_message_handler.rs @@ -76,7 +76,7 @@ impl DialogLayoutHolder for ExportDialogMessageHandler { TextButton::new("Cancel").on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } @@ -160,11 +160,11 @@ impl LayoutHolder for ExportDialogMessageHandler { .widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![ + Layout(vec![ LayoutGroup::Row { widgets: export_type }, LayoutGroup::Row { widgets: resolution }, LayoutGroup::Row { widgets: export_area }, LayoutGroup::Row { widgets: transparent_background }, - ])) + ]) } } diff --git a/editor/src/messages/dialog/new_document_dialog/new_document_dialog_message_handler.rs b/editor/src/messages/dialog/new_document_dialog/new_document_dialog_message_handler.rs index f4c448147c..9fae872331 100644 --- a/editor/src/messages/dialog/new_document_dialog/new_document_dialog_message_handler.rs +++ b/editor/src/messages/dialog/new_document_dialog/new_document_dialog_message_handler.rs @@ -66,7 +66,7 @@ impl DialogLayoutHolder for NewDocumentDialogMessageHandler { TextButton::new("Cancel").on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } @@ -117,10 +117,6 @@ impl LayoutHolder for NewDocumentDialogMessageHandler { .widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![ - LayoutGroup::Row { widgets: name }, - LayoutGroup::Row { widgets: infinite }, - LayoutGroup::Row { widgets: scale }, - ])) + Layout(vec![LayoutGroup::Row { widgets: name }, LayoutGroup::Row { widgets: infinite }, LayoutGroup::Row { widgets: scale }]) } } diff --git a/editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs b/editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs index d5840a97f1..35e27cfbaf 100644 --- a/editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs +++ b/editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs @@ -224,7 +224,7 @@ impl PreferencesDialogMessageHandler { .widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![ + Layout(vec![ LayoutGroup::Row { widgets: navigation_header }, LayoutGroup::Row { widgets: zoom_rate_label }, LayoutGroup::Row { widgets: zoom_rate }, @@ -237,7 +237,7 @@ impl PreferencesDialogMessageHandler { LayoutGroup::Row { widgets: graph_wire_style }, LayoutGroup::Row { widgets: use_vello }, LayoutGroup::Row { widgets: vector_meshes }, - ])) + ]) } pub fn send_layout(&self, responses: &mut VecDeque, layout_target: LayoutTarget, preferences: &PreferencesMessageHandler) { @@ -272,7 +272,7 @@ impl PreferencesDialogMessageHandler { TextButton::new("Reset to Defaults").on_update(|_| PreferencesMessage::ResetToDefaults.into()).widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } fn send_layout_buttons(&self, responses: &mut VecDeque, layout_target: LayoutTarget) { diff --git a/editor/src/messages/dialog/simple_dialogs/about_graphite_dialog.rs b/editor/src/messages/dialog/simple_dialogs/about_graphite_dialog.rs index eb45174ea5..0b770c61fd 100644 --- a/editor/src/messages/dialog/simple_dialogs/about_graphite_dialog.rs +++ b/editor/src/messages/dialog/simple_dialogs/about_graphite_dialog.rs @@ -15,7 +15,7 @@ impl DialogLayoutHolder for AboutGraphiteDialog { fn layout_buttons(&self) -> Layout { let widgets = vec![TextButton::new("OK").emphasized(true).on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance()]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } fn layout_column_2(&self) -> Layout { @@ -51,13 +51,13 @@ impl DialogLayoutHolder for AboutGraphiteDialog { .widget_instance(), ); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Column { widgets }])) + Layout(vec![LayoutGroup::Column { widgets }]) } } impl LayoutHolder for AboutGraphiteDialog { fn layout(&self) -> Layout { - Layout::WidgetLayout(WidgetLayout(vec![ + Layout(vec![ LayoutGroup::Row { widgets: vec![TextLabel::new("About this release").bold(true).widget_instance()], }, @@ -67,6 +67,6 @@ impl LayoutHolder for AboutGraphiteDialog { LayoutGroup::Row { widgets: vec![TextLabel::new(format!("Copyright © {} Graphite contributors", self.localized_commit_year)).widget_instance()], }, - ])) + ]) } } diff --git a/editor/src/messages/dialog/simple_dialogs/close_all_documents_dialog.rs b/editor/src/messages/dialog/simple_dialogs/close_all_documents_dialog.rs index 583dd48d35..545f764cc5 100644 --- a/editor/src/messages/dialog/simple_dialogs/close_all_documents_dialog.rs +++ b/editor/src/messages/dialog/simple_dialogs/close_all_documents_dialog.rs @@ -24,7 +24,7 @@ impl DialogLayoutHolder for CloseAllDocumentsDialog { TextButton::new("Cancel").on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } @@ -32,13 +32,13 @@ impl LayoutHolder for CloseAllDocumentsDialog { fn layout(&self) -> Layout { let unsaved_list = "• ".to_string() + &self.unsaved_document_names.join("\n• "); - Layout::WidgetLayout(WidgetLayout(vec![ + Layout(vec![ LayoutGroup::Row { widgets: vec![TextLabel::new("Save documents before closing them?").bold(true).multiline(true).widget_instance()], }, LayoutGroup::Row { widgets: vec![TextLabel::new(format!("Documents with unsaved changes:\n{unsaved_list}")).multiline(true).widget_instance()], }, - ])) + ]) } } diff --git a/editor/src/messages/dialog/simple_dialogs/close_document_dialog.rs b/editor/src/messages/dialog/simple_dialogs/close_document_dialog.rs index 4248a9bede..d535acbaa3 100644 --- a/editor/src/messages/dialog/simple_dialogs/close_document_dialog.rs +++ b/editor/src/messages/dialog/simple_dialogs/close_document_dialog.rs @@ -35,7 +35,7 @@ impl DialogLayoutHolder for CloseDocumentDialog { TextButton::new("Cancel").on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } @@ -51,13 +51,13 @@ impl LayoutHolder for CloseDocumentDialog { let break_lines = if self.document_name.len() > max_one_line_length { '\n' } else { ' ' }; - Layout::WidgetLayout(WidgetLayout(vec![ + Layout(vec![ LayoutGroup::Row { widgets: vec![TextLabel::new("Save document before closing it?").bold(true).widget_instance()], }, LayoutGroup::Row { widgets: vec![TextLabel::new(format!("\"{name}{ellipsis}\"{break_lines}has unsaved changes")).multiline(true).widget_instance()], }, - ])) + ]) } } diff --git a/editor/src/messages/dialog/simple_dialogs/coming_soon_dialog.rs b/editor/src/messages/dialog/simple_dialogs/coming_soon_dialog.rs index 6e00c7336b..f27b756e22 100644 --- a/editor/src/messages/dialog/simple_dialogs/coming_soon_dialog.rs +++ b/editor/src/messages/dialog/simple_dialogs/coming_soon_dialog.rs @@ -13,7 +13,7 @@ impl DialogLayoutHolder for ComingSoonDialog { fn layout_buttons(&self) -> Layout { let widgets = vec![TextButton::new("OK").emphasized(true).on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance()]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } @@ -43,6 +43,6 @@ impl LayoutHolder for ComingSoonDialog { rows.push(LayoutGroup::Row { widgets: row3 }); } - Layout::WidgetLayout(WidgetLayout(rows)) + Layout(rows) } } diff --git a/editor/src/messages/dialog/simple_dialogs/demo_artwork_dialog.rs b/editor/src/messages/dialog/simple_dialogs/demo_artwork_dialog.rs index fe381225d6..e30a96ab1e 100644 --- a/editor/src/messages/dialog/simple_dialogs/demo_artwork_dialog.rs +++ b/editor/src/messages/dialog/simple_dialogs/demo_artwork_dialog.rs @@ -22,7 +22,7 @@ impl DialogLayoutHolder for DemoArtworkDialog { fn layout_buttons(&self) -> Layout { let widgets = vec![TextButton::new("Close").emphasized(true).on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance()]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } @@ -59,6 +59,6 @@ impl LayoutHolder for DemoArtworkDialog { .collect(); let _ = rows_of_images_with_buttons.pop(); - Layout::WidgetLayout(WidgetLayout(rows_of_images_with_buttons)) + Layout(rows_of_images_with_buttons) } } diff --git a/editor/src/messages/dialog/simple_dialogs/error_dialog.rs b/editor/src/messages/dialog/simple_dialogs/error_dialog.rs index 94e759a226..9ef98916d4 100644 --- a/editor/src/messages/dialog/simple_dialogs/error_dialog.rs +++ b/editor/src/messages/dialog/simple_dialogs/error_dialog.rs @@ -14,19 +14,19 @@ impl DialogLayoutHolder for ErrorDialog { fn layout_buttons(&self) -> Layout { let widgets = vec![TextButton::new("OK").emphasized(true).on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance()]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } impl LayoutHolder for ErrorDialog { fn layout(&self) -> Layout { - Layout::WidgetLayout(WidgetLayout(vec![ + Layout(vec![ LayoutGroup::Row { widgets: vec![TextLabel::new(&self.title).bold(true).widget_instance()], }, LayoutGroup::Row { widgets: vec![TextLabel::new(&self.description).multiline(true).widget_instance()], }, - ])) + ]) } } diff --git a/editor/src/messages/dialog/simple_dialogs/licenses_dialog.rs b/editor/src/messages/dialog/simple_dialogs/licenses_dialog.rs index 93f56315a7..6a8683050c 100644 --- a/editor/src/messages/dialog/simple_dialogs/licenses_dialog.rs +++ b/editor/src/messages/dialog/simple_dialogs/licenses_dialog.rs @@ -12,7 +12,7 @@ impl DialogLayoutHolder for LicensesDialog { fn layout_buttons(&self) -> Layout { let widgets = vec![TextButton::new("OK").emphasized(true).on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance()]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } fn layout_column_2(&self) -> Layout { @@ -43,7 +43,7 @@ impl DialogLayoutHolder for LicensesDialog { .map(|&(icon, label, message_factory)| TextButton::new(label).icon(Some((icon).into())).flush(true).on_update(move |_| message_factory()).widget_instance()) .collect(); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Column { widgets }])) + Layout(vec![LayoutGroup::Column { widgets }]) } } @@ -63,13 +63,13 @@ impl LayoutHolder for LicensesDialog { ); let description = description.trim(); - Layout::WidgetLayout(WidgetLayout(vec![ + Layout(vec![ LayoutGroup::Row { widgets: vec![TextLabel::new("Graphite is free, open source software").bold(true).widget_instance()], }, LayoutGroup::Row { widgets: vec![TextLabel::new(description).multiline(true).widget_instance()], }, - ])) + ]) } } diff --git a/editor/src/messages/dialog/simple_dialogs/licenses_third_party_dialog.rs b/editor/src/messages/dialog/simple_dialogs/licenses_third_party_dialog.rs index 16f985018d..e891ed2051 100644 --- a/editor/src/messages/dialog/simple_dialogs/licenses_third_party_dialog.rs +++ b/editor/src/messages/dialog/simple_dialogs/licenses_third_party_dialog.rs @@ -12,7 +12,7 @@ impl DialogLayoutHolder for LicensesThirdPartyDialog { fn layout_buttons(&self) -> Layout { let widgets = vec![TextButton::new("OK").emphasized(true).on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance()]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } @@ -31,7 +31,7 @@ impl LayoutHolder for LicensesThirdPartyDialog { // Two characters (one before, one after) the sequence of underscore characters, plus one additional column to provide a space between the text and the scrollbar let non_wrapping_column_width = license_text.split('\n').map(|line| line.chars().filter(|&c| c == '_').count()).max().unwrap_or(0) + 2 + 1; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { + Layout(vec![LayoutGroup::Row { widgets: vec![ TextLabel::new(license_text) .monospace(true) @@ -39,6 +39,6 @@ impl LayoutHolder for LicensesThirdPartyDialog { .min_width(format!("{non_wrapping_column_width}ch")) .widget_instance(), ], - }])) + }]) } } diff --git a/editor/src/messages/layout/layout_message_handler.rs b/editor/src/messages/layout/layout_message_handler.rs index e6c58e2b25..f9bf381d12 100644 --- a/editor/src/messages/layout/layout_message_handler.rs +++ b/editor/src/messages/layout/layout_message_handler.rs @@ -24,12 +24,10 @@ impl MessageHandler> for LayoutMessageHa match message { LayoutMessage::ResendActiveWidget { layout_target, widget_id } => { // Find the updated diff based on the specified layout target - let Some(diff) = (match &self.layouts[layout_target as usize] { - Layout::WidgetLayout(layout) => Self::get_widget_path(layout, widget_id).map(|(widget, widget_path)| { - // Create a widget update diff for the relevant id - let new_value = DiffUpdate::Widget(widget.clone()); - WidgetDiff { widget_path, new_value } - }), + let Some(diff) = Self::get_widget_path(&self.layouts[layout_target as usize], widget_id).map(|(widget, widget_path)| { + // Create a widget update diff for the relevant id + let new_value = DiffUpdate::Widget(widget.clone()); + WidgetDiff { widget_path, new_value } }) else { return; }; @@ -41,7 +39,7 @@ impl MessageHandler> for LayoutMessageHa } LayoutMessage::DestroyLayout { layout_target } => { if let Some(layout) = self.layouts.get_mut(layout_target as usize) { - *layout = Default::default(); + *layout = Layout::default(); } } LayoutMessage::WidgetValueCommit { layout_target, widget_id, value } => { @@ -61,7 +59,7 @@ impl MessageHandler> for LayoutMessageHa impl LayoutMessageHandler { /// Get the widget path for the widget with the specified id - fn get_widget_path(widget_layout: &WidgetLayout, widget_id: WidgetId) -> Option<(&WidgetInstance, Vec)> { + fn get_widget_path(widget_layout: &Layout, widget_id: WidgetId) -> Option<(&WidgetInstance, Vec)> { let mut stack = widget_layout.0.iter().enumerate().map(|(index, val)| (vec![index], val)).collect::>(); while let Some((mut widget_path, layout_group)) = stack.pop() { match layout_group { @@ -124,10 +122,7 @@ impl LayoutMessageHandler { return; }; - let mut layout_iter = match layout { - Layout::WidgetLayout(widget_layout) => widget_layout.iter_mut(), - }; - let Some(widget_instance) = layout_iter.find(|widget| widget.widget_id == widget_id) else { + let Some(widget_instance) = layout.iter_mut().find(|widget| widget.widget_id == widget_id) else { warn!("handle_widget_callback was called referencing an invalid widget ID, although the layout target was valid. `widget_id: {widget_id}`, `layout_target: {layout_target:?}`",); return; }; @@ -479,31 +474,25 @@ impl LayoutMessageHandler { responses: &mut VecDeque, action_input_mapping: &impl Fn(&MessageDiscriminant) -> Option, ) { - match new_layout { - Layout::WidgetLayout(_) => { - let mut widget_diffs = Vec::new(); + let mut widget_diffs = Vec::new(); - let Layout::WidgetLayout(current) = &mut self.layouts[layout_target as usize]; - let Layout::WidgetLayout(new) = new_layout; - current.diff(new, &mut Vec::new(), &mut widget_diffs); + 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; - } - - // On Mac we need the full MenuBar layout to construct the native menu - #[cfg(target_os = "macos")] - if layout_target == LayoutTarget::MenuBar { - widget_diffs = vec![WidgetDiff { - widget_path: Vec::new(), - new_value: DiffUpdate::WidgetLayout(current.layout.clone()), - }]; - } - - self.send_diff(widget_diffs, layout_target, responses, action_input_mapping); - } + // Skip sending if no diff + if widget_diffs.is_empty() { + return; } + + // On Mac we need the full MenuBar layout to construct the native menu + #[cfg(target_os = "macos")] + if layout_target == LayoutTarget::MenuBar { + widget_diffs = vec![WidgetDiff { + widget_path: Vec::new(), + new_value: DiffUpdate::Layout(current.layout.clone()), + }]; + } + + self.send_diff(widget_diffs, layout_target, responses, action_input_mapping); } /// Send a diff to the frontend based on the layout target. diff --git a/editor/src/messages/layout/utility_types/layout_widget.rs b/editor/src/messages/layout/utility_types/layout_widget.rs index d3141c76d9..907aaff43c 100644 --- a/editor/src/messages/layout/utility_types/layout_widget.rs +++ b/editor/src/messages/layout/utility_types/layout_widget.rs @@ -103,24 +103,11 @@ pub trait DialogLayoutHolder: LayoutHolder { } } -// TODO: Unwrap this enum -/// Wraps a choice of layout type. The chosen layout contains an arrangement of widgets mounted somewhere specific in the frontend. -#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)] -pub enum Layout { - WidgetLayout(WidgetLayout), -} - -impl Default for Layout { - fn default() -> Self { - Self::WidgetLayout(WidgetLayout::default()) - } -} - -// TODO: Unwrap this struct +/// Contains an arrangement of widgets mounted somewhere specific in the frontend. #[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, PartialEq, specta::Type)] -pub struct WidgetLayout(pub Vec); +pub struct Layout(pub Vec); -impl WidgetLayout { +impl Layout { pub fn iter(&self) -> WidgetIter<'_> { WidgetIter { stack: self.0.iter().collect(), @@ -144,7 +131,7 @@ impl WidgetLayout { self.0.clone_from(&new.0); // Push an update sublayout to the diff - let new = DiffUpdate::WidgetLayout(new); + let new = DiffUpdate::Layout(new); widget_diffs.push(WidgetDiff { widget_path: widget_path.to_vec(), new_value: new, @@ -285,7 +272,7 @@ pub enum LayoutGroup { visible: bool, pinned: bool, id: u64, - layout: WidgetLayout, + layout: Layout, }, } @@ -588,12 +575,10 @@ pub struct WidgetDiff { } /// The new value of the UI, sent as part of a diff. -/// -/// An update can represent a single widget or an entire WidgetLayout, or just a single layout group. #[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)] pub enum DiffUpdate { - #[serde(rename = "widgetLayout")] - WidgetLayout(WidgetLayout), + #[serde(rename = "layout")] + Layout(Layout), #[serde(rename = "layoutGroup")] LayoutGroup(LayoutGroup), #[serde(rename = "widget")] @@ -675,7 +660,7 @@ impl DiffUpdate { }; match self { - Self::WidgetLayout(widget_layout) => widget_layout.0.iter_mut().flat_map(|layout_group| layout_group.iter_mut()).for_each(|widget_instance| { + Self::Layout(layout) => layout.0.iter_mut().flat_map(|layout_group| layout_group.iter_mut()).for_each(|widget_instance| { convert_tooltip(widget_instance); convert_menu_lists(widget_instance); }), diff --git a/editor/src/messages/layout/utility_types/widgets/button_widgets.rs b/editor/src/messages/layout/utility_types/widgets/button_widgets.rs index 4f3c4c8963..3f8f59b8a1 100644 --- a/editor/src/messages/layout/utility_types/widgets/button_widgets.rs +++ b/editor/src/messages/layout/utility_types/widgets/button_widgets.rs @@ -63,7 +63,7 @@ pub struct PopoverButton { pub tooltip_shortcut: Option, #[serde(rename = "popoverLayout")] - pub popover_layout: WidgetLayout, + pub popover_layout: Layout, #[serde(rename = "popoverMinWidth")] pub popover_min_width: Option, diff --git a/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs b/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs index a4ea7d5a86..004b3cc485 100644 --- a/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs +++ b/editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs @@ -1,5 +1,5 @@ use super::VectorTableTab; -use crate::messages::layout::utility_types::layout_widget::{Layout, LayoutGroup, LayoutTarget, WidgetLayout}; +use crate::messages::layout::utility_types::layout_widget::{Layout, LayoutGroup, LayoutTarget}; use crate::messages::portfolio::document::data_panel::DataPanelMessage; use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface; use crate::messages::prelude::*; @@ -83,11 +83,12 @@ impl DataPanelMessageHandler { }; // Main data visualization - let mut layout = self - .introspected_data - .as_ref() - .map(|instrospected_data| generate_layout(instrospected_data, &mut layout_data).unwrap_or_else(|| label("Visualization of this data type is not yet supported"))) - .unwrap_or_default(); + let mut layout = Layout( + self.introspected_data + .as_ref() + .map(|instrospected_data| generate_layout(instrospected_data, &mut layout_data).unwrap_or_else(|| label("Visualization of this data type is not yet supported"))) + .unwrap_or_default(), + ); let mut widgets = Vec::new(); @@ -127,11 +128,11 @@ impl DataPanelMessageHandler { } if !widgets.is_empty() { - layout.insert(0, LayoutGroup::Row { widgets }); + layout.0.insert(0, LayoutGroup::Row { widgets }); } responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(WidgetLayout(layout)), + layout, layout_target: LayoutTarget::DataPanel, }); } diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 34b1e290fa..ac360321d4 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -323,17 +323,17 @@ impl MessageHandler> for DocumentMes // Clear the control bar responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(Default::default()), + layout: Layout::default(), layout_target: LayoutTarget::LayersPanelControlLeftBar, }); responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(Default::default()), + layout: Layout::default(), layout_target: LayoutTarget::LayersPanelControlRightBar, }); // Clear the bottom bar responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(Default::default()), + layout: Layout::default(), layout_target: LayoutTarget::LayersPanelBottomBar, }); } @@ -2175,7 +2175,7 @@ impl DocumentMessageHandler { pub fn update_document_widgets(&self, responses: &mut VecDeque, animation_is_playing: bool, time: Duration) { // Document mode (dropdown menu at the left of the bar above the viewport, before the tool options) - let document_mode_layout = WidgetLayout(vec![LayoutGroup::Row { + let layout = Layout(vec![LayoutGroup::Row { widgets: vec![ // DropdownInput::new( // vec![vec![ @@ -2200,7 +2200,7 @@ impl DocumentMessageHandler { }]); responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(document_mode_layout), + layout, layout_target: LayoutTarget::DocumentMode, }); @@ -2235,7 +2235,7 @@ impl DocumentMessageHandler { }) .widget_instance(), PopoverButton::new() - .popover_layout(WidgetLayout(vec![ + .popover_layout(Layout(vec![ LayoutGroup::Row { widgets: vec![TextLabel::new("Overlays").bold(true).widget_instance()], }, @@ -2484,7 +2484,7 @@ impl DocumentMessageHandler { }) .widget_instance(), PopoverButton::new() - .popover_layout(WidgetLayout( + .popover_layout(Layout( [ LayoutGroup::Row { widgets: vec![TextLabel::new("Snapping").bold(true).widget_instance()], @@ -2548,7 +2548,7 @@ impl DocumentMessageHandler { .on_update(|optional_input: &CheckboxInput| DocumentMessage::GridVisibility { visible: optional_input.checked }.into()) .widget_instance(), PopoverButton::new() - .popover_layout(WidgetLayout(overlay_options(&self.snapping_state.grid))) + .popover_layout(Layout(overlay_options(&self.snapping_state.grid))) .popover_min_width(Some(320)) .widget_instance(), Separator::new(SeparatorType::Unrelated).widget_instance(), @@ -2574,7 +2574,7 @@ impl DocumentMessageHandler { .narrow(true) .widget_instance(), // PopoverButton::new().popover_layout( - // WidgetLayout(vec![ + // Layout(vec![ // LayoutGroup::Row { // widgets: vec![TextLabel::new("Render Mode").bold(true).widget_instance()], // }, @@ -2632,10 +2632,8 @@ impl DocumentMessageHandler { .widget_instance(), ]); - let document_bar_layout = WidgetLayout(vec![LayoutGroup::Row { widgets }]); - responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(document_bar_layout), + layout: Layout(vec![LayoutGroup::Row { widgets }]), layout_target: LayoutTarget::DocumentBar, }); responses.add(NodeGraphMessage::RunDocumentGraph); @@ -2773,7 +2771,7 @@ impl DocumentMessageHandler { .tooltip_label("Fill") .widget_instance(), ]; - let layers_panel_control_bar_left = WidgetLayout(vec![LayoutGroup::Row { widgets }]); + let layers_panel_control_bar_left = Layout(vec![LayoutGroup::Row { widgets }]); let widgets = vec![ IconButton::new(if selection_all_locked { "PadlockLocked" } else { "PadlockUnlocked" }, 24) @@ -2791,14 +2789,14 @@ impl DocumentMessageHandler { .disabled(!has_selection) .widget_instance(), ]; - let layers_panel_control_bar_right = WidgetLayout(vec![LayoutGroup::Row { widgets }]); + let layers_panel_control_bar_right = Layout(vec![LayoutGroup::Row { widgets }]); responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(layers_panel_control_bar_left), + layout: layers_panel_control_bar_left, layout_target: LayoutTarget::LayersPanelControlLeftBar, }); responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(layers_panel_control_bar_right), + layout: layers_panel_control_bar_right, layout_target: LayoutTarget::LayersPanelControlRightBar, }); } @@ -2845,7 +2843,7 @@ impl DocumentMessageHandler { } }) .widget_instance(); - WidgetLayout(vec![LayoutGroup::Row { widgets: vec![node_chooser] }]) + Layout(vec![LayoutGroup::Row { widgets: vec![node_chooser] }]) }) .widget_instance(), Separator::new(SeparatorType::Unrelated).widget_instance(), @@ -2870,10 +2868,8 @@ impl DocumentMessageHandler { .disabled(!has_selection) .widget_instance(), ]; - let layers_panel_bottom_bar = WidgetLayout(vec![LayoutGroup::Row { widgets }]); - responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(layers_panel_bottom_bar), + layout: Layout(vec![LayoutGroup::Row { widgets }]), layout_target: LayoutTarget::LayersPanelBottomBar, }); } diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs index ddd7a348e8..8825fbb0bb 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs @@ -2069,7 +2069,7 @@ impl NodeGraphMessageHandler { /// Send the cached layout to the frontend for the control bar at the top of the node panel fn send_node_bar_layout(&self, responses: &mut VecDeque) { responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(WidgetLayout(self.widgets.to_vec())), + layout: Layout(self.widgets.to_vec()), layout_target: LayoutTarget::NodeGraphControlBar, }); } @@ -2145,7 +2145,7 @@ impl NodeGraphMessageHandler { } }) .widget_instance(); - WidgetLayout(vec![LayoutGroup::Row { widgets: vec![node_chooser] }]) + Layout(vec![LayoutGroup::Row { widgets: vec![node_chooser] }]) }) .widget_instance(), // @@ -2443,7 +2443,7 @@ impl NodeGraphMessageHandler { .into() }) .widget_instance(); - WidgetLayout(vec![LayoutGroup::Row { widgets: vec![node_chooser] }]) + Layout(vec![LayoutGroup::Row { widgets: vec![node_chooser] }]) }) .widget_instance(), Separator::new(SeparatorType::Related).widget_instance(), diff --git a/editor/src/messages/portfolio/document/node_graph/node_properties.rs b/editor/src/messages/portfolio/document/node_graph/node_properties.rs index cab0f0dfb2..7786cfb32a 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_properties.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_properties.rs @@ -1699,7 +1699,7 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper visible, pinned, id: node_id.0, - layout: WidgetLayout(layout), + layout: Layout(layout), } } diff --git a/editor/src/messages/portfolio/document/properties_panel/properties_panel_message_handler.rs b/editor/src/messages/portfolio/document/properties_panel/properties_panel_message_handler.rs index fad48342b5..b5706ec1e5 100644 --- a/editor/src/messages/portfolio/document/properties_panel/properties_panel_message_handler.rs +++ b/editor/src/messages/portfolio/document/properties_panel/properties_panel_message_handler.rs @@ -35,7 +35,7 @@ impl MessageHandler> f match message { PropertiesPanelMessage::Clear => { responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(WidgetLayout(vec![])), + layout: Layout::default(), layout_target: LayoutTarget::PropertiesPanel, }); } @@ -53,10 +53,10 @@ impl MessageHandler> f document_name, executor, }; - let properties_sections = NodeGraphMessageHandler::collate_properties(&mut node_properties_context); + let layout = Layout(NodeGraphMessageHandler::collate_properties(&mut node_properties_context)); node_properties_context.responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(WidgetLayout(properties_sections)), + layout, layout_target: LayoutTarget::PropertiesPanel, }); } diff --git a/editor/src/messages/portfolio/menu_bar/menu_bar_message_handler.rs b/editor/src/messages/portfolio/menu_bar/menu_bar_message_handler.rs index 336155d4ea..ca3b9f3c3e 100644 --- a/editor/src/messages/portfolio/menu_bar/menu_bar_message_handler.rs +++ b/editor/src/messages/portfolio/menu_bar/menu_bar_message_handler.rs @@ -736,6 +736,6 @@ impl LayoutHolder for MenuBarMessageHandler { .widget_instance(), ]; - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets: menu_bar_buttons }])) + Layout(vec![LayoutGroup::Row { widgets: menu_bar_buttons }]) } } diff --git a/editor/src/messages/portfolio/portfolio_message_handler.rs b/editor/src/messages/portfolio/portfolio_message_handler.rs index 6cb246a5c5..7ba591bb0f 100644 --- a/editor/src/messages/portfolio/portfolio_message_handler.rs +++ b/editor/src/messages/portfolio/portfolio_message_handler.rs @@ -924,7 +924,7 @@ impl MessageHandler> for Portfolio layout_target: LayoutTarget::WelcomeScreenButtons, }); responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(WidgetLayout(vec![table])), + layout: Layout(vec![table]), layout_target: LayoutTarget::WelcomeScreenButtons, }); } diff --git a/editor/src/messages/tool/tool_messages/artboard_tool.rs b/editor/src/messages/tool/tool_messages/artboard_tool.rs index 7289d68147..e257dc359c 100644 --- a/editor/src/messages/tool/tool_messages/artboard_tool.rs +++ b/editor/src/messages/tool/tool_messages/artboard_tool.rs @@ -75,7 +75,7 @@ impl<'a> MessageHandler> for Artb impl LayoutHolder for ArtboardTool { fn layout(&self) -> Layout { - Layout::WidgetLayout(WidgetLayout::default()) + Layout::default() } } diff --git a/editor/src/messages/tool/tool_messages/brush_tool.rs b/editor/src/messages/tool/tool_messages/brush_tool.rs index 72de4c6384..17da7b23a1 100644 --- a/editor/src/messages/tool/tool_messages/brush_tool.rs +++ b/editor/src/messages/tool/tool_messages/brush_tool.rs @@ -220,7 +220,7 @@ impl LayoutHolder for BrushTool { .widget_instance(), ); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } diff --git a/editor/src/messages/tool/tool_messages/eyedropper_tool.rs b/editor/src/messages/tool/tool_messages/eyedropper_tool.rs index 3ff5f37487..c976047153 100644 --- a/editor/src/messages/tool/tool_messages/eyedropper_tool.rs +++ b/editor/src/messages/tool/tool_messages/eyedropper_tool.rs @@ -35,7 +35,7 @@ impl ToolMetadata for EyedropperTool { impl LayoutHolder for EyedropperTool { fn layout(&self) -> Layout { - Layout::WidgetLayout(WidgetLayout::default()) + Layout::default() } } diff --git a/editor/src/messages/tool/tool_messages/fill_tool.rs b/editor/src/messages/tool/tool_messages/fill_tool.rs index f32b07b945..f29d73d1b7 100644 --- a/editor/src/messages/tool/tool_messages/fill_tool.rs +++ b/editor/src/messages/tool/tool_messages/fill_tool.rs @@ -37,7 +37,7 @@ impl ToolMetadata for FillTool { impl LayoutHolder for FillTool { fn layout(&self) -> Layout { - Layout::WidgetLayout(WidgetLayout::default()) + Layout::default() } } diff --git a/editor/src/messages/tool/tool_messages/freehand_tool.rs b/editor/src/messages/tool/tool_messages/freehand_tool.rs index 5fc79675db..a74635f391 100644 --- a/editor/src/messages/tool/tool_messages/freehand_tool.rs +++ b/editor/src/messages/tool/tool_messages/freehand_tool.rs @@ -151,7 +151,7 @@ impl LayoutHolder for FreehandTool { widgets.push(Separator::new(SeparatorType::Unrelated).widget_instance()); widgets.push(create_weight_widget(self.options.line_weight)); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } diff --git a/editor/src/messages/tool/tool_messages/gradient_tool.rs b/editor/src/messages/tool/tool_messages/gradient_tool.rs index 2a05bc79d3..fa5b3f38a4 100644 --- a/editor/src/messages/tool/tool_messages/gradient_tool.rs +++ b/editor/src/messages/tool/tool_messages/gradient_tool.rs @@ -107,7 +107,7 @@ impl LayoutHolder for GradientTool { .selected_index(Some((self.selected_gradient().unwrap_or(self.options.gradient_type) == GradientType::Radial) as u32)) .widget_instance(); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets: vec![gradient_type] }])) + Layout(vec![LayoutGroup::Row { widgets: vec![gradient_type] }]) } } diff --git a/editor/src/messages/tool/tool_messages/navigate_tool.rs b/editor/src/messages/tool/tool_messages/navigate_tool.rs index 0f997a84d6..8809ccdebd 100644 --- a/editor/src/messages/tool/tool_messages/navigate_tool.rs +++ b/editor/src/messages/tool/tool_messages/navigate_tool.rs @@ -34,7 +34,7 @@ impl ToolMetadata for NavigateTool { impl LayoutHolder for NavigateTool { fn layout(&self) -> Layout { - Layout::WidgetLayout(WidgetLayout::default()) + Layout::default() } } diff --git a/editor/src/messages/tool/tool_messages/path_tool.rs b/editor/src/messages/tool/tool_messages/path_tool.rs index fdde7798a9..be300ebe5c 100644 --- a/editor/src/messages/tool/tool_messages/path_tool.rs +++ b/editor/src/messages/tool/tool_messages/path_tool.rs @@ -342,7 +342,7 @@ impl LayoutHolder for PathTool { let _pin_pivot = pin_pivot_widget(self.tool_data.pivot_gizmo.pin_active(), false, PivotToolSource::Path); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { + Layout(vec![LayoutGroup::Row { widgets: vec![ x_location, related_seperator.clone(), @@ -367,7 +367,7 @@ impl LayoutHolder for PathTool { // related_seperator.clone(), // pin_pivot, ], - }])) + }]) } } diff --git a/editor/src/messages/tool/tool_messages/pen_tool.rs b/editor/src/messages/tool/tool_messages/pen_tool.rs index 7a5b87a898..8cb1bfeecb 100644 --- a/editor/src/messages/tool/tool_messages/pen_tool.rs +++ b/editor/src/messages/tool/tool_messages/pen_tool.rs @@ -238,7 +238,7 @@ impl LayoutHolder for PenTool { .widget_instance(), ); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } diff --git a/editor/src/messages/tool/tool_messages/select_tool.rs b/editor/src/messages/tool/tool_messages/select_tool.rs index e2c344cddd..17af28d2bb 100644 --- a/editor/src/messages/tool/tool_messages/select_tool.rs +++ b/editor/src/messages/tool/tool_messages/select_tool.rs @@ -252,7 +252,7 @@ impl LayoutHolder for SelectTool { widgets.extend(self.alignment_widgets(disabled)); // widgets.push( // PopoverButton::new() - // .popover_layout(WidgetLayout(vec![ + // .popover_layout(Layout(vec![ // LayoutGroup::Row { // widgets: vec![TextLabel::new("Align").bold(true).widget_instance()], // }, @@ -277,7 +277,7 @@ impl LayoutHolder for SelectTool { widgets.push(Separator::new(SeparatorType::Unrelated).widget_instance()); widgets.extend(self.boolean_widgets(self.tool_data.selected_layers_count)); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } diff --git a/editor/src/messages/tool/tool_messages/shape_tool.rs b/editor/src/messages/tool/tool_messages/shape_tool.rs index 2abe9f3835..7edbb73a33 100644 --- a/editor/src/messages/tool/tool_messages/shape_tool.rs +++ b/editor/src/messages/tool/tool_messages/shape_tool.rs @@ -335,7 +335,7 @@ impl LayoutHolder for ShapeTool { widgets.push(Separator::new(SeparatorType::Unrelated).widget_instance()); widgets.push(create_weight_widget(self.options.line_weight)); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } diff --git a/editor/src/messages/tool/tool_messages/spline_tool.rs b/editor/src/messages/tool/tool_messages/spline_tool.rs index ae125b30f0..55c8352abb 100644 --- a/editor/src/messages/tool/tool_messages/spline_tool.rs +++ b/editor/src/messages/tool/tool_messages/spline_tool.rs @@ -158,7 +158,7 @@ impl LayoutHolder for SplineTool { widgets.push(Separator::new(SeparatorType::Unrelated).widget_instance()); widgets.push(create_weight_widget(self.options.line_weight)); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } diff --git a/editor/src/messages/tool/tool_messages/text_tool.rs b/editor/src/messages/tool/tool_messages/text_tool.rs index 782a60c17a..3bdbc479d0 100644 --- a/editor/src/messages/tool/tool_messages/text_tool.rs +++ b/editor/src/messages/tool/tool_messages/text_tool.rs @@ -203,7 +203,7 @@ impl LayoutHolder for TextTool { }, )); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } } diff --git a/editor/src/messages/tool/utility_types.rs b/editor/src/messages/tool/utility_types.rs index 8ccf824849..21b2b22108 100644 --- a/editor/src/messages/tool/utility_types.rs +++ b/editor/src/messages/tool/utility_types.rs @@ -117,7 +117,7 @@ pub struct DocumentToolData { impl DocumentToolData { pub fn update_working_colors(&self, responses: &mut VecDeque) { - let layout = WidgetLayout(vec![ + let layout = Layout(vec![ LayoutGroup::Row { widgets: vec![WorkingColorsInput::new(self.primary_color.to_gamma_srgb(), self.secondary_color.to_gamma_srgb()).widget_instance()], }, @@ -138,7 +138,7 @@ impl DocumentToolData { ]); responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(layout), + layout, layout_target: LayoutTarget::WorkingColors, }); @@ -290,7 +290,7 @@ impl LayoutHolder for ToolData { .skip(1) .collect(); - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets: tool_groups_layout }])) + Layout(vec![LayoutGroup::Row { widgets: tool_groups_layout }]) } } @@ -545,7 +545,7 @@ impl HintData { } } - Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }])) + Layout(vec![LayoutGroup::Row { widgets }]) } pub fn send_layout(&self, responses: &mut VecDeque) { @@ -557,7 +557,7 @@ impl HintData { pub fn clear_layout(responses: &mut VecDeque) { responses.add(LayoutMessage::SendLayout { - layout: Layout::WidgetLayout(WidgetLayout(vec![])), + layout: Layout::default(), layout_target: LayoutTarget::StatusBarHints, }); } diff --git a/frontend/src/components/panels/Data.svelte b/frontend/src/components/panels/Data.svelte index 6d85da3f8a..f1cbafb82f 100644 --- a/frontend/src/components/panels/Data.svelte +++ b/frontend/src/components/panels/Data.svelte @@ -2,18 +2,18 @@ import { getContext, onMount, onDestroy } from "svelte"; import type { Editor } from "@graphite/editor"; - import { patchWidgetLayout, UpdateDataPanelLayout, type LayoutGroup } from "@graphite/messages"; + import { patchLayout, UpdateDataPanelLayout, type Layout } from "@graphite/messages"; import LayoutCol from "@graphite/components/layout/LayoutCol.svelte"; import WidgetLayout from "@graphite/components/widgets/WidgetLayout.svelte"; const editor = getContext("editor"); - let dataPanelLayout: LayoutGroup[] = []; + let dataPanelLayout: Layout = []; onMount(() => { editor.subscriptions.subscribeJsMessage(UpdateDataPanelLayout, (updateDataPanelLayout) => { - patchWidgetLayout(dataPanelLayout, updateDataPanelLayout); + patchLayout(dataPanelLayout, updateDataPanelLayout); dataPanelLayout = dataPanelLayout; }); }); diff --git a/frontend/src/components/panels/Layers.svelte b/frontend/src/components/panels/Layers.svelte index 04165215d7..9ed0e20674 100644 --- a/frontend/src/components/panels/Layers.svelte +++ b/frontend/src/components/panels/Layers.svelte @@ -4,14 +4,14 @@ import { shortcutAltClick } from "@graphite/../wasm/pkg/graphite_wasm"; import type { Editor } from "@graphite/editor"; import { - patchWidgetLayout, + patchLayout, UpdateDocumentLayerDetails, UpdateDocumentLayerStructureJs, UpdateLayersPanelControlBarLeftLayout, UpdateLayersPanelControlBarRightLayout, UpdateLayersPanelBottomBarLayout, } from "@graphite/messages"; - import type { ActionShortcut, DataBuffer, LayerPanelEntry, LayoutGroup } from "@graphite/messages"; + import type { ActionShortcut, DataBuffer, LayerPanelEntry, Layout } from "@graphite/messages"; import type { NodeGraphState } from "@graphite/state-providers/node-graph"; import { operatingSystem } from "@graphite/utility-functions/platform"; import { extractPixelData } from "@graphite/utility-functions/rasterization"; @@ -69,25 +69,25 @@ let layerToClipAltKeyPressed = false; // Layouts - let layersPanelControlBarLeftLayout: LayoutGroup[] = []; - let layersPanelControlBarRightLayout: LayoutGroup[] = []; - let layersPanelBottomBarLayout: LayoutGroup[] = []; + let layersPanelControlBarLeftLayout: Layout = []; + let layersPanelControlBarRightLayout: Layout = []; + let layersPanelBottomBarLayout: Layout = []; const altClickKeys: ActionShortcut = shortcutAltClick(); onMount(() => { editor.subscriptions.subscribeJsMessage(UpdateLayersPanelControlBarLeftLayout, (updateLayersPanelControlBarLeftLayout) => { - patchWidgetLayout(layersPanelControlBarLeftLayout, updateLayersPanelControlBarLeftLayout); + patchLayout(layersPanelControlBarLeftLayout, updateLayersPanelControlBarLeftLayout); layersPanelControlBarLeftLayout = layersPanelControlBarLeftLayout; }); editor.subscriptions.subscribeJsMessage(UpdateLayersPanelControlBarRightLayout, (updateLayersPanelControlBarRightLayout) => { - patchWidgetLayout(layersPanelControlBarRightLayout, updateLayersPanelControlBarRightLayout); + patchLayout(layersPanelControlBarRightLayout, updateLayersPanelControlBarRightLayout); layersPanelControlBarRightLayout = layersPanelControlBarRightLayout; }); editor.subscriptions.subscribeJsMessage(UpdateLayersPanelBottomBarLayout, (updateLayersPanelBottomBarLayout) => { - patchWidgetLayout(layersPanelBottomBarLayout, updateLayersPanelBottomBarLayout); + patchLayout(layersPanelBottomBarLayout, updateLayersPanelBottomBarLayout); layersPanelBottomBarLayout = layersPanelBottomBarLayout; }); diff --git a/frontend/src/components/panels/Properties.svelte b/frontend/src/components/panels/Properties.svelte index 234e081fd5..387541288d 100644 --- a/frontend/src/components/panels/Properties.svelte +++ b/frontend/src/components/panels/Properties.svelte @@ -2,18 +2,18 @@ import { getContext, onMount, onDestroy } from "svelte"; import type { Editor } from "@graphite/editor"; - import { patchWidgetLayout, UpdatePropertiesPanelLayout, type LayoutGroup } from "@graphite/messages"; + import { patchLayout, UpdatePropertiesPanelLayout, type Layout } from "@graphite/messages"; import LayoutCol from "@graphite/components/layout/LayoutCol.svelte"; import WidgetLayout from "@graphite/components/widgets/WidgetLayout.svelte"; const editor = getContext("editor"); - let propertiesPanelLayout: LayoutGroup[] = []; + let propertiesPanelLayout: Layout = []; onMount(() => { editor.subscriptions.subscribeJsMessage(UpdatePropertiesPanelLayout, (updatePropertiesPanelLayout) => { - patchWidgetLayout(propertiesPanelLayout, updatePropertiesPanelLayout); + patchLayout(propertiesPanelLayout, updatePropertiesPanelLayout); propertiesPanelLayout = propertiesPanelLayout; }); }); diff --git a/frontend/src/components/panels/Welcome.svelte b/frontend/src/components/panels/Welcome.svelte index 9e9ab45ba0..bcad430ea1 100644 --- a/frontend/src/components/panels/Welcome.svelte +++ b/frontend/src/components/panels/Welcome.svelte @@ -2,8 +2,8 @@ import { getContext, onMount, onDestroy } from "svelte"; import type { Editor } from "@graphite/editor"; - import type { LayoutGroup } from "@graphite/messages"; - import { patchWidgetLayout, UpdateWelcomeScreenButtonsLayout } from "@graphite/messages"; + import type { Layout } from "@graphite/messages"; + import { patchLayout, UpdateWelcomeScreenButtonsLayout } from "@graphite/messages"; import { extractPixelData } from "@graphite/utility-functions/rasterization"; import LayoutCol from "@graphite/components/layout/LayoutCol.svelte"; @@ -14,11 +14,11 @@ const editor = getContext("editor"); - let welcomePanelButtonsLayout: LayoutGroup[] = []; + let welcomePanelButtonsLayout: Layout = []; onMount(() => { editor.subscriptions.subscribeJsMessage(UpdateWelcomeScreenButtonsLayout, (updateWelcomeScreenButtonsLayout) => { - patchWidgetLayout(welcomePanelButtonsLayout, updateWelcomeScreenButtonsLayout); + patchLayout(welcomePanelButtonsLayout, updateWelcomeScreenButtonsLayout); welcomePanelButtonsLayout = welcomePanelButtonsLayout; }); diff --git a/frontend/src/components/widgets/WidgetLayout.svelte b/frontend/src/components/widgets/WidgetLayout.svelte index 15c6370238..936cce20fd 100644 --- a/frontend/src/components/widgets/WidgetLayout.svelte +++ b/frontend/src/components/widgets/WidgetLayout.svelte @@ -1,11 +1,11 @@