Skip to content

Commit a4a12b0

Browse files
committed
Improvements including simplifying panic dialog code
1 parent bcff14e commit a4a12b0

22 files changed

+174
-160
lines changed

editor/src/communication/build_metadata.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use serde::{Deserialize, Serialize};
2-
use std::fmt::Display;
32

43
/// Provides metadata about the build environment.
54
///
@@ -23,11 +22,24 @@ impl Default for BuildMetadata {
2322
}
2423
}
2524

26-
impl Display for BuildMetadata {
27-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28-
f.write_fmt(format_args!(
29-
"Release Series: {}\n\nDate: {}\nHash:{}\nBranch: {}",
30-
self.release, self.timestamp, self.hash, self.branch
31-
))
25+
impl BuildMetadata {
26+
pub fn release_series(&self) -> String {
27+
format!("Release Series: {}", self.release)
28+
}
29+
30+
pub fn commit_info(&self) -> String {
31+
format!("{}\n{}\n{}", self.commit_timestamp(), self.commit_hash(), self.commit_branch())
32+
}
33+
34+
pub fn commit_timestamp(&self) -> String {
35+
format!("Date: {}", self.timestamp)
36+
}
37+
38+
pub fn commit_hash(&self) -> String {
39+
format!("Hash: {}", self.hash)
40+
}
41+
42+
pub fn commit_branch(&self) -> String {
43+
format!("Branch: {}", self.branch)
3244
}
3345
}

editor/src/communication/dispatcher.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,12 @@ mod test {
455455
if let crate::layout::widgets::Widget::TextLabel(crate::layout::widgets::TextLabel { value, .. }) = &widgets[0].widget {
456456
println!();
457457
println!("-------------------------------------------------");
458-
println!("Failed test due to receiving a DisplayDialogError while loading the graphite sample file!");
458+
println!("Failed test due to receiving a DisplayDialogError while loading the Graphite sample file!");
459459
println!("This is most likely caused by forgetting to bump the `GRAPHITE_DOCUMENT_VERSION` in `editor/src/consts.rs`");
460-
println!("Once bumping this version number please replace the `graphite-test-document.graphite` with a valid file");
460+
println!("Once bumping this version number please replace the `graphite-test-document.graphite` with a valid file.");
461461
println!("DisplayDialogError details:");
462-
println!("description: {}", value);
462+
println!();
463+
println!("Description: {}", value);
463464
println!("-------------------------------------------------");
464465
println!();
465466
panic!()

editor/src/dialog/dialog_message_handler.rs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,28 @@ impl MessageHandler<DialogMessage, (&BuildMetadata, &PortfolioMessageHandler)> f
2121
DialogMessage::CloseAllDocumentsWithConfirmation => {
2222
let dialog = dialogs::CloseAllDocuments;
2323
dialog.register_properties(responses, LayoutTarget::DialogDetails);
24-
responses.push_back(
25-
FrontendMessage::DisplayDialog {
26-
icon: "Copy".to_string(),
27-
heading: "Close all documents?".to_string(),
28-
}
29-
.into(),
30-
);
24+
responses.push_back(FrontendMessage::DisplayDialog { icon: "Copy".to_string() }.into());
3125
}
3226
DialogMessage::CloseDialogAndThen { followup } => {
3327
responses.push_back(FrontendMessage::DisplayDialogDismiss.into());
3428
responses.push_back(*followup);
3529
}
3630
DialogMessage::DisplayDialogError { title, description } => {
37-
let dialog = dialogs::Error { description };
31+
let dialog = dialogs::Error { title, description };
3832
dialog.register_properties(responses, LayoutTarget::DialogDetails);
39-
responses.push_back(
40-
FrontendMessage::DisplayDialog {
41-
icon: "Warning".to_string(),
42-
heading: title,
43-
}
44-
.into(),
45-
);
33+
responses.push_back(FrontendMessage::DisplayDialog { icon: "Warning".to_string() }.into());
4634
}
4735
DialogMessage::RequestAboutGraphiteDialog => {
4836
let about_graphite = AboutGraphite {
4937
build_metadata: build_metadata.clone(),
5038
};
5139
about_graphite.register_properties(responses, LayoutTarget::DialogDetails);
52-
responses.push_back(
53-
FrontendMessage::DisplayDialog {
54-
icon: "GraphiteLogo".to_string(),
55-
heading: "Graphite".to_string(),
56-
}
57-
.into(),
58-
);
40+
responses.push_back(FrontendMessage::DisplayDialog { icon: "GraphiteLogo".to_string() }.into());
5941
}
6042
DialogMessage::RequestComingSoonDialog { issue } => {
6143
let coming_soon = ComingSoon { issue };
6244
coming_soon.register_properties(responses, LayoutTarget::DialogDetails);
63-
responses.push_back(
64-
FrontendMessage::DisplayDialog {
65-
icon: "Warning".to_string(),
66-
heading: "Coming soon".to_string(),
67-
}
68-
.into(),
69-
);
45+
responses.push_back(FrontendMessage::DisplayDialog { icon: "Warning".to_string() }.into());
7046
}
7147
DialogMessage::RequestNewDocumentDialog => {
7248
self.new_document_dialog = NewDocument {
@@ -75,13 +51,7 @@ impl MessageHandler<DialogMessage, (&BuildMetadata, &PortfolioMessageHandler)> f
7551
dimensions: glam::UVec2::new(1920, 1080),
7652
};
7753
self.new_document_dialog.register_properties(responses, LayoutTarget::DialogDetails);
78-
responses.push_back(
79-
FrontendMessage::DisplayDialog {
80-
icon: "File".to_string(),
81-
heading: "New document".to_string(),
82-
}
83-
.into(),
84-
);
54+
responses.push_back(FrontendMessage::DisplayDialog { icon: "File".to_string() }.into());
8555
}
8656
}
8757
}

editor/src/dialog/dialogs/about_dialog.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ impl PropertyHolder for AboutGraphite {
2626
WidgetLayout::new(vec![
2727
LayoutRow::Row {
2828
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
29-
value: self.build_metadata.to_string(),
30-
preserve_whitespace: true,
29+
value: "Graphite".to_string(),
30+
bold: true,
3131
..Default::default()
3232
}))],
3333
},
3434
LayoutRow::Row {
35-
widgets: vec![WidgetHolder::new(Widget::Separator(Separator {
36-
direction: SeparatorDirection::Vertical,
37-
separator_type: SeparatorType::Unrelated,
35+
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
36+
value: self.build_metadata.release_series(),
37+
..Default::default()
38+
}))],
39+
},
40+
LayoutRow::Row {
41+
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
42+
value: self.build_metadata.commit_info(),
43+
multiline: true,
44+
..Default::default()
3845
}))],
3946
},
4047
LayoutRow::Row { widgets: link_widgets },

editor/src/dialog/dialogs/close_all_documents_dialog.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ impl PropertyHolder for CloseAllDocuments {
2929
WidgetLayout::new(vec![
3030
LayoutRow::Row {
3131
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
32-
value: "Unsaved work will be lost!".to_string(),
33-
preserve_whitespace: true,
32+
value: "Close all documents?".to_string(),
33+
bold: true,
3434
..Default::default()
3535
}))],
3636
},
3737
LayoutRow::Row {
38-
widgets: vec![WidgetHolder::new(Widget::Separator(Separator {
39-
direction: SeparatorDirection::Vertical,
40-
separator_type: SeparatorType::Unrelated,
38+
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
39+
value: "Unsaved work will be lost!".to_string(),
40+
multiline: true,
41+
..Default::default()
4142
}))],
4243
},
4344
LayoutRow::Row { widgets: button_widgets },

editor/src/dialog/dialogs/close_document_dialog.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ impl PropertyHolder for CloseDocument {
4646
WidgetLayout::new(vec![
4747
LayoutRow::Row {
4848
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
49-
value: self.document_name.clone(),
50-
preserve_whitespace: true,
49+
value: "Save changes before closing?".to_string(),
50+
bold: true,
5151
..Default::default()
5252
}))],
5353
},
5454
LayoutRow::Row {
55-
widgets: vec![WidgetHolder::new(Widget::Separator(Separator {
56-
direction: SeparatorDirection::Vertical,
57-
separator_type: SeparatorType::Unrelated,
55+
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
56+
value: self.document_name.clone(),
57+
multiline: true,
58+
..Default::default()
5859
}))],
5960
},
6061
LayoutRow::Row { widgets: button_widgets },

editor/src/dialog/dialogs/coming_soon_dialog.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ impl PropertyHolder for ComingSoon {
3232
WidgetLayout::new(vec![
3333
LayoutRow::Row {
3434
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
35-
value: details,
36-
preserve_whitespace: true,
35+
value: "Coming soon".to_string(),
36+
bold: true,
3737
..Default::default()
3838
}))],
3939
},
4040
LayoutRow::Row {
41-
widgets: vec![WidgetHolder::new(Widget::Separator(Separator {
42-
direction: SeparatorDirection::Vertical,
43-
separator_type: SeparatorType::Unrelated,
41+
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
42+
value: details,
43+
multiline: true,
44+
..Default::default()
4445
}))],
4546
},
4647
LayoutRow::Row { widgets: buttons },

editor/src/dialog/dialogs/error_dialog.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{layout::widgets::*, message_prelude::FrontendMessage};
22

33
/// A dialog to notify users of a non-fatal error.
44
pub struct Error {
5+
pub title: String,
56
pub description: String,
67
}
78

@@ -10,15 +11,16 @@ impl PropertyHolder for Error {
1011
WidgetLayout::new(vec![
1112
LayoutRow::Row {
1213
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
13-
value: self.description.clone(),
14-
preserve_whitespace: true,
14+
value: self.title.clone(),
15+
bold: true,
1516
..Default::default()
1617
}))],
1718
},
1819
LayoutRow::Row {
19-
widgets: vec![WidgetHolder::new(Widget::Separator(Separator {
20-
direction: SeparatorDirection::Vertical,
21-
separator_type: SeparatorType::Unrelated,
20+
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
21+
value: self.description.clone(),
22+
multiline: true,
23+
..Default::default()
2224
}))],
2325
},
2426
LayoutRow::Row {

editor/src/dialog/dialogs/new_document_dialog.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ pub struct NewDocument {
1515

1616
impl PropertyHolder for NewDocument {
1717
fn properties(&self) -> WidgetLayout {
18+
let title = vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
19+
value: "New document".into(),
20+
bold: true,
21+
..Default::default()
22+
}))];
23+
1824
let name = vec![
1925
WidgetHolder::new(Widget::TextLabel(TextLabel {
2026
value: "Name".into(),
@@ -107,15 +113,10 @@ impl PropertyHolder for NewDocument {
107113
];
108114

109115
WidgetLayout::new(vec![
116+
LayoutRow::Row { widgets: title },
110117
LayoutRow::Row { widgets: name },
111118
LayoutRow::Row { widgets: infinite },
112119
LayoutRow::Row { widgets: scale },
113-
LayoutRow::Row {
114-
widgets: vec![WidgetHolder::new(Widget::Separator(Separator {
115-
direction: SeparatorDirection::Vertical,
116-
separator_type: SeparatorType::Unrelated,
117-
}))],
118-
},
119120
LayoutRow::Row { widgets: button_widgets },
120121
])
121122
}

editor/src/document/portfolio_message_handler.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
223223
document_id,
224224
};
225225
dialog.register_properties(responses, LayoutTarget::DialogDetails);
226-
responses.push_back(
227-
FrontendMessage::DisplayDialog {
228-
icon: "File".to_string(),
229-
heading: "Save changes before closing?".to_string(),
230-
}
231-
.into(),
232-
);
226+
responses.push_back(FrontendMessage::DisplayDialog { icon: "File".to_string() }.into());
233227

234228
// Select the document being closed
235229
responses.push_back(PortfolioMessage::SelectDocument { document_id }.into());

editor/src/frontend/frontend_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
1313
#[derive(PartialEq, Clone, Deserialize, Serialize, Debug)]
1414
pub enum FrontendMessage {
1515
// Display prefix: make the frontend show something, like a dialog
16-
DisplayDialog { icon: String, heading: String },
16+
DisplayDialog { icon: String },
1717
DisplayDialogDismiss,
1818
DisplayDialogPanic { panic_info: String, title: String, description: String },
1919
DisplayDocumentLayerTreeStructure { data_buffer: RawBuffer },

editor/src/layout/widgets.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ pub struct TextLabel {
373373
pub value: String,
374374
pub bold: bool,
375375
pub italic: bool,
376-
#[serde(rename = "preserveWhitespace")]
377-
pub preserve_whitespace: bool,
376+
pub multiline: bool,
378377
#[serde(rename = "tableAlign")]
379378
pub table_align: bool,
380379
}

frontend/src/components/panels/Document.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ export default defineComponent({
528528
const loadBuildMetadata = (): void => {
529529
const release = process.env.VUE_APP_RELEASE_SERIES;
530530
let timestamp = "";
531-
const hash = (process.env.VUE_APP_COMMIT_HASH || "").substring(0, 12);
531+
const hash = (process.env.VUE_APP_COMMIT_HASH || "").substring(0, 8);
532532
const branch = process.env.VUE_APP_COMMIT_BRANCH;
533533
{
534534
const date = new Date(process.env.VUE_APP_COMMIT_DATE || "");

frontend/src/components/panels/Properties.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<LayoutCol class="properties">
33
<LayoutRow class="options-bar">
4-
<WidgetLayout :layout="propertiesOptionsLayout"></WidgetLayout>
4+
<WidgetLayout :layout="propertiesOptionsLayout" />
55
</LayoutRow>
66
<LayoutRow class="sections" :scrollableY="true">
7-
<WidgetLayout :layout="propertiesSectionsLayout"></WidgetLayout>
7+
<WidgetLayout :layout="propertiesSectionsLayout" />
88
</LayoutRow>
99
</LayoutCol>
1010
</template>

frontend/src/components/widgets/WidgetRow.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<TextAreaInput v-if="component.kind === 'TextAreaInput'" v-bind="component.props" @commitText="(value: string) => updateLayout(component.widget_id, value)" />
2929
<TextButton v-if="component.kind === 'TextButton'" v-bind="component.props" :action="() => updateLayout(component.widget_id, null)" />
3030
<TextInput v-if="component.kind === 'TextInput'" v-bind="component.props" @commitText="(value: string) => updateLayout(component.widget_id, value)" />
31-
<TextLabel v-if="component.kind === 'TextLabel'" v-bind="component.props">{{ component.props.value }}</TextLabel>
31+
<TextLabel v-if="component.kind === 'TextLabel'" v-bind="withoutValue(component.props)">{{ component.props.value }}</TextLabel>
3232
</template>
3333
</div>
3434
</template>
@@ -37,12 +37,16 @@
3737
.widget-row {
3838
flex: 0 0 auto;
3939
display: flex;
40+
min-height: 32px;
4041
4142
> * {
4243
--widget-height: 24px;
43-
min-height: var(--widget-height);
44-
line-height: var(--widget-height);
4544
margin: calc((24px - var(--widget-height)) / 2 + 4px) 0;
45+
min-height: var(--widget-height);
46+
47+
&:not(.multiline) {
48+
line-height: var(--widget-height);
49+
}
4650
4751
&.icon-label.size-12 {
4852
--widget-height: 12px;
@@ -85,6 +89,10 @@ export default defineComponent({
8589
updateLayout(widgetId: BigInt, value: unknown) {
8690
this.editor.instance.update_layout(this.layoutTarget, widgetId, value);
8791
},
92+
withoutValue(props: Record<string, unknown>): Record<string, unknown> {
93+
const { value: _, ...rest } = props;
94+
return rest;
95+
},
8896
},
8997
components: {
9098
Separator,

0 commit comments

Comments
 (0)