Skip to content

Commit 3c4ad8b

Browse files
committed
Refactor the WidgetLayout struct to remove SubLayout and avoid sending LayoutTarget to frontend
1 parent 4581689 commit 3c4ad8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+207
-247
lines changed

desktop/wrapper/src/intercept_frontend_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD
120120
[
121121
WidgetDiff {
122122
widget_path,
123-
new_value: DiffUpdate::SubLayout(layout),
123+
new_value: DiffUpdate::WidgetLayout(layout),
124124
},
125125
] if widget_path.is_empty() => {
126126
let entries = crate::utils::menu::convert_menu_bar_layout_to_menu_items(layout);

desktop/wrapper/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ pub(crate) mod menu {
66
use graphite_editor::messages::input_mapper::utility_types::input_keyboard::{Key, LabeledKey, LabeledShortcut};
77
use graphite_editor::messages::input_mapper::utility_types::misc::ActionShortcut;
88
use graphite_editor::messages::layout::LayoutMessage;
9-
use graphite_editor::messages::tool::tool_messages::tool_prelude::{LayoutGroup, LayoutTarget, MenuListEntry, SubLayout, Widget, WidgetId};
9+
use graphite_editor::messages::tool::tool_messages::tool_prelude::{LayoutGroup, LayoutTarget, MenuListEntry, Widget, WidgetId, WidgetLayout};
1010

1111
use crate::messages::{EditorMessage, KeyCode, MenuItem, Modifiers, Shortcut};
1212

13-
pub(crate) fn convert_menu_bar_layout_to_menu_items(layout: &SubLayout) -> Vec<MenuItem> {
13+
pub(crate) fn convert_menu_bar_layout_to_menu_items(layout: &WidgetLayout) -> Vec<MenuItem> {
1414
let layout_group = match layout.as_slice() {
1515
[layout_group] => layout_group,
1616
_ => panic!("Menu bar layout is supposed to have exactly one layout group"),

editor/src/dispatcher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,9 @@ mod test {
547547

548548
for response in responses {
549549
// Check for the existence of the file format incompatibility warning dialog after opening the test file
550-
if let FrontendMessage::UpdateDialogColumn1 { layout_target: _, diff } = response {
551-
if let DiffUpdate::SubLayout(sub_layout) = &diff[0].new_value {
552-
if let LayoutGroup::Row { widgets } = &sub_layout[0] {
550+
if let FrontendMessage::UpdateDialogColumn1 { diff } = response {
551+
if let DiffUpdate::WidgetLayout(sub_layout) = &diff[0].new_value {
552+
if let LayoutGroup::Row { widgets } = &sub_layout.0[0] {
553553
if let Widget::TextLabel(TextLabel { value, .. }) = &widgets[0].widget {
554554
print_problem_to_terminal_on_failure(value);
555555
}

editor/src/messages/dialog/export_dialog/export_dialog_message_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl DialogLayoutHolder for ExportDialogMessageHandler {
7676
TextButton::new("Cancel").on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance(),
7777
];
7878

79-
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
79+
Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }]))
8080
}
8181
}
8282

@@ -160,7 +160,7 @@ impl LayoutHolder for ExportDialogMessageHandler {
160160
.widget_instance(),
161161
];
162162

163-
Layout::WidgetLayout(WidgetLayout::new(vec![
163+
Layout::WidgetLayout(WidgetLayout(vec![
164164
LayoutGroup::Row { widgets: export_type },
165165
LayoutGroup::Row { widgets: resolution },
166166
LayoutGroup::Row { widgets: export_area },

editor/src/messages/dialog/new_document_dialog/new_document_dialog_message_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl DialogLayoutHolder for NewDocumentDialogMessageHandler {
6666
TextButton::new("Cancel").on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance(),
6767
];
6868

69-
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
69+
Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }]))
7070
}
7171
}
7272

@@ -117,7 +117,7 @@ impl LayoutHolder for NewDocumentDialogMessageHandler {
117117
.widget_instance(),
118118
];
119119

120-
Layout::WidgetLayout(WidgetLayout::new(vec![
120+
Layout::WidgetLayout(WidgetLayout(vec![
121121
LayoutGroup::Row { widgets: name },
122122
LayoutGroup::Row { widgets: infinite },
123123
LayoutGroup::Row { widgets: scale },

editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl PreferencesDialogMessageHandler {
224224
.widget_instance(),
225225
];
226226

227-
Layout::WidgetLayout(WidgetLayout::new(vec![
227+
Layout::WidgetLayout(WidgetLayout(vec![
228228
LayoutGroup::Row { widgets: navigation_header },
229229
LayoutGroup::Row { widgets: zoom_rate_label },
230230
LayoutGroup::Row { widgets: zoom_rate },
@@ -272,7 +272,7 @@ impl PreferencesDialogMessageHandler {
272272
TextButton::new("Reset to Defaults").on_update(|_| PreferencesMessage::ResetToDefaults.into()).widget_instance(),
273273
];
274274

275-
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
275+
Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }]))
276276
}
277277

278278
fn send_layout_buttons(&self, responses: &mut VecDeque<Message>, layout_target: LayoutTarget) {

editor/src/messages/dialog/simple_dialogs/about_graphite_dialog.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl DialogLayoutHolder for AboutGraphiteDialog {
1515
fn layout_buttons(&self) -> Layout {
1616
let widgets = vec![TextButton::new("OK").emphasized(true).on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance()];
1717

18-
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
18+
Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }]))
1919
}
2020

2121
fn layout_column_2(&self) -> Layout {
@@ -51,13 +51,13 @@ impl DialogLayoutHolder for AboutGraphiteDialog {
5151
.widget_instance(),
5252
);
5353

54-
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Column { widgets }]))
54+
Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Column { widgets }]))
5555
}
5656
}
5757

5858
impl LayoutHolder for AboutGraphiteDialog {
5959
fn layout(&self) -> Layout {
60-
Layout::WidgetLayout(WidgetLayout::new(vec![
60+
Layout::WidgetLayout(WidgetLayout(vec![
6161
LayoutGroup::Row {
6262
widgets: vec![TextLabel::new("About this release").bold(true).widget_instance()],
6363
},

editor/src/messages/dialog/simple_dialogs/close_all_documents_dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ impl DialogLayoutHolder for CloseAllDocumentsDialog {
2424
TextButton::new("Cancel").on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance(),
2525
];
2626

27-
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
27+
Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }]))
2828
}
2929
}
3030

3131
impl LayoutHolder for CloseAllDocumentsDialog {
3232
fn layout(&self) -> Layout {
3333
let unsaved_list = "• ".to_string() + &self.unsaved_document_names.join("\n• ");
3434

35-
Layout::WidgetLayout(WidgetLayout::new(vec![
35+
Layout::WidgetLayout(WidgetLayout(vec![
3636
LayoutGroup::Row {
3737
widgets: vec![TextLabel::new("Save documents before closing them?").bold(true).multiline(true).widget_instance()],
3838
},

editor/src/messages/dialog/simple_dialogs/close_document_dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl DialogLayoutHolder for CloseDocumentDialog {
3535
TextButton::new("Cancel").on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance(),
3636
];
3737

38-
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
38+
Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }]))
3939
}
4040
}
4141

@@ -51,7 +51,7 @@ impl LayoutHolder for CloseDocumentDialog {
5151

5252
let break_lines = if self.document_name.len() > max_one_line_length { '\n' } else { ' ' };
5353

54-
Layout::WidgetLayout(WidgetLayout::new(vec![
54+
Layout::WidgetLayout(WidgetLayout(vec![
5555
LayoutGroup::Row {
5656
widgets: vec![TextLabel::new("Save document before closing it?").bold(true).widget_instance()],
5757
},

editor/src/messages/dialog/simple_dialogs/coming_soon_dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl DialogLayoutHolder for ComingSoonDialog {
1313
fn layout_buttons(&self) -> Layout {
1414
let widgets = vec![TextButton::new("OK").emphasized(true).on_update(|_| FrontendMessage::DisplayDialogDismiss.into()).widget_instance()];
1515

16-
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
16+
Layout::WidgetLayout(WidgetLayout(vec![LayoutGroup::Row { widgets }]))
1717
}
1818
}
1919

@@ -43,6 +43,6 @@ impl LayoutHolder for ComingSoonDialog {
4343
rows.push(LayoutGroup::Row { widgets: row3 });
4444
}
4545

46-
Layout::WidgetLayout(WidgetLayout::new(rows))
46+
Layout::WidgetLayout(WidgetLayout(rows))
4747
}
4848
}

0 commit comments

Comments
 (0)