Migrate dialogs to Rust and add a New File dialog (#623)

* Migrate coming soon and about dialog to Rust

* Migrate confirm close and close all

* Migrate dialog error

* Improve keyboard navigation throughout UI

* Cleanup and fix panic dialog

* Reduce css spacing to better match old dialogs

* Add new document modal

* Fix crash when generating default name

* Populate rust about graphite data on startup

* Code review changes

* Move one more :focus CSS rule into App.vue

* Add a dialog message and move dialogs

* Split out keyboard input navigation from this branch

* Improvements including simplifying panic dialog code

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2022-05-07 01:59:52 -07:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent 7729b6219e
commit f177f63217
44 changed files with 1017 additions and 390 deletions
@@ -0,0 +1,45 @@
use serde::{Deserialize, Serialize};
/// Provides metadata about the build environment.
///
/// This data is viewable in the editor via the [`crate::dialog::AboutGraphite`] dialog.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BuildMetadata {
pub release: String,
pub timestamp: String,
pub hash: String,
pub branch: String,
}
impl Default for BuildMetadata {
fn default() -> Self {
Self {
release: "unknown".to_string(),
timestamp: "unknown".to_string(),
hash: "unknown".to_string(),
branch: "unknown".to_string(),
}
}
}
impl BuildMetadata {
pub fn release_series(&self) -> String {
format!("Release Series: {}", self.release)
}
pub fn commit_info(&self) -> String {
format!("{}\n{}\n{}", self.commit_timestamp(), self.commit_hash(), self.commit_branch())
}
pub fn commit_timestamp(&self) -> String {
format!("Date: {}", self.timestamp)
}
pub fn commit_hash(&self) -> String {
format!("Hash: {}", self.hash)
}
pub fn commit_branch(&self) -> String {
format!("Branch: {}", self.branch)
}
}
+32 -12
View File
@@ -7,16 +7,20 @@ use crate::viewport_tools::tool_message_handler::ToolMessageHandler;
use std::collections::VecDeque;
use super::BuildMetadata;
#[derive(Debug, Default)]
pub struct Dispatcher {
message_queue: VecDeque<Message>,
pub responses: Vec<FrontendMessage>,
message_handlers: DispatcherMessageHandlers,
build_metadata: BuildMetadata,
}
#[remain::sorted]
#[derive(Debug, Default)]
struct DispatcherMessageHandlers {
dialog_message_handler: DialogMessageHandler,
global_message_handler: GlobalMessageHandler,
input_mapper_message_handler: InputMapperMessageHandler,
input_preprocessor_message_handler: InputPreprocessorMessageHandler,
@@ -31,6 +35,9 @@ struct DispatcherMessageHandlers {
const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::RenderDocument)),
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::Overlays(OverlaysMessageDiscriminant::Rerender))),
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::Artboard(
ArtboardMessageDiscriminant::RenderArtboards,
))),
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::FolderChanged)),
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayer),
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::DisplayDocumentLayerTreeStructure),
@@ -63,6 +70,11 @@ impl Dispatcher {
match message {
#[remain::unsorted]
NoOp => {}
Dialog(message) => {
self.message_handlers
.dialog_message_handler
.process_action(message, (&self.build_metadata, &self.message_handlers.portfolio_message_handler), &mut self.message_queue);
}
Frontend(message) => {
// Image and font loading should be immediately handled
if let FrontendMessage::UpdateImageData { .. } | FrontendMessage::TriggerFontLoad { .. } = message {
@@ -101,6 +113,9 @@ impl Dispatcher {
&mut self.message_queue,
);
}
#[remain::unsorted]
PopulateBuildMetadata { new } => self.build_metadata = new,
}
}
}
@@ -108,6 +123,7 @@ impl Dispatcher {
pub fn collect_actions(&self) -> ActionList {
// TODO: Reduce the number of heap allocations
let mut list = Vec::new();
list.extend(self.message_handlers.dialog_message_handler.actions());
list.extend(self.message_handlers.input_preprocessor_message_handler.actions());
list.extend(self.message_handlers.input_mapper_message_handler.actions());
list.extend(self.message_handlers.global_message_handler.actions());
@@ -434,18 +450,22 @@ mod test {
});
for response in responses {
if let FrontendMessage::DisplayDialogError { title, description } = response {
println!();
println!("-------------------------------------------------");
println!("Failed test due to receiving a DisplayDialogError while loading the graphite sample file!");
println!("This is most likely caused by forgetting to bump the `GRAPHITE_DOCUMENT_VERSION` in `editor/src/consts.rs`");
println!("Once bumping this version number please replace the `graphite-test-document.graphite` with a valid file");
println!("DisplayDialogError details:");
println!("Title: {}", title);
println!("description: {}", description);
println!("-------------------------------------------------");
println!();
panic!()
if let FrontendMessage::UpdateDialogDetails { layout_target: _, layout } = response {
if let crate::layout::widgets::LayoutRow::Row { widgets } = &layout[0] {
if let crate::layout::widgets::Widget::TextLabel(crate::layout::widgets::TextLabel { value, .. }) = &widgets[0].widget {
println!();
println!("-------------------------------------------------");
println!("Failed test due to receiving a DisplayDialogError while loading the Graphite sample file!");
println!("This is most likely caused by forgetting to bump the `GRAPHITE_DOCUMENT_VERSION` in `editor/src/consts.rs`");
println!("Once bumping this version number please replace the `graphite-test-document.graphite` with a valid file.");
println!("DisplayDialogError details:");
println!();
println!("Description: {}", value);
println!("-------------------------------------------------");
println!();
panic!()
}
}
}
}
}
+6
View File
@@ -1,3 +1,4 @@
use super::BuildMetadata;
use crate::message_prelude::*;
use graphite_proc_macros::*;
@@ -23,6 +24,8 @@ pub enum Message {
#[remain::unsorted]
NoOp,
#[child]
Dialog(DialogMessage),
#[child]
Frontend(FrontendMessage),
#[child]
Global(GlobalMessage),
@@ -36,6 +39,9 @@ pub enum Message {
Portfolio(PortfolioMessage),
#[child]
Tool(ToolMessage),
#[remain::unsorted]
PopulateBuildMetadata { new: BuildMetadata },
}
impl Message {
+2
View File
@@ -1,9 +1,11 @@
mod build_metadata;
pub mod dispatcher;
pub mod message;
pub mod message_handler;
pub use crate::communication::dispatcher::*;
pub use crate::input::InputPreprocessorMessageHandler;
pub use build_metadata::BuildMetadata;
use rand_chacha::rand_core::{RngCore, SeedableRng};
use rand_chacha::ChaCha20Rng;