Skip to content

Frontend rearrage tabs #1955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
// Rust Analyzer config
"rust-analyzer.cargo.allTargets": false,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.command": "",
// ESLint config
"eslint.format.enable": true,
"eslint.workingDirectories": ["./frontend", "./website/other/bezier-rs-demos", "./website"],
Expand Down
9 changes: 7 additions & 2 deletions editor/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct DispatcherMessageHandlers {
pub portfolio_message_handler: PortfolioMessageHandler,
preferences_message_handler: PreferencesMessageHandler,
tool_message_handler: ToolMessageHandler,
workspace_message_handler: WorkspaceMessageHandler,
pub workspace_message_handler: WorkspaceMessageHandler,
}

/// For optimization, these are messages guaranteed to be redundant when repeated.
Expand Down Expand Up @@ -99,6 +99,9 @@ impl Dispatcher {
// Display the menu bar at the top of the window
queue.add(MenuBarMessage::SendLayout);

// Init the dockspace
queue.add(WorkspaceMessage::SendLayout);

// Load the default font
let font = Font::new(graphene_core::consts::DEFAULT_FONT_FAMILY.into(), graphene_core::consts::DEFAULT_FONT_STYLE.into());
queue.add(FrontendMessage::TriggerFontLoad { font, is_default: true });
Expand Down Expand Up @@ -181,7 +184,9 @@ impl Dispatcher {
}
}
Message::Workspace(message) => {
self.message_handlers.workspace_message_handler.process_message(message, &mut queue, ());
self.message_handlers
.workspace_message_handler
.process_message(message, &mut queue, &self.message_handlers.portfolio_message_handler);
}
}

Expand Down
4 changes: 4 additions & 0 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::messages::portfolio::document::node_graph::utility_types::{
use crate::messages::portfolio::document::utility_types::nodes::{JsRawBuffer, LayerPanelEntry, RawBuffer};
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::HintData;
use crate::messages::workspace::FrontendDivisionOrPanel;

use graph_craft::document::NodeId;
use graphene_core::raster::color::Color;
Expand Down Expand Up @@ -164,6 +165,9 @@ pub enum FrontendMessage {
layout_target: LayoutTarget,
diff: Vec<WidgetDiff>,
},
UpdateDockspace {
root: FrontendDivisionOrPanel,
},
UpdateDocumentArtwork {
svg: String,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageData> for

match message {
InputPreprocessorMessage::BoundsOfViewports { bounds_of_viewports } => {
assert_eq!(bounds_of_viewports.len(), 1, "Only one viewport is currently supported");
// assert_eq!(bounds_of_viewports.len(), 1, "Only one viewport is currently supported");

for bounds in bounds_of_viewports {
// TODO: Extend this to multiple viewports instead of setting it to the value of this last loop iteration
Expand Down
10 changes: 10 additions & 0 deletions editor/src/messages/portfolio/document/utility_types/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize, specta::Type)]
pub struct DocumentId(pub u64);

#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize, specta::Type)]
pub struct DocumentViewId(pub u64);

impl From<u64> for DocumentViewId {
fn from(value: u64) -> Self {
Self(value)
}
}

#[derive(PartialEq, Eq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize, Hash)]
pub enum FlipAxis {
X,
Expand Down
29 changes: 29 additions & 0 deletions editor/src/messages/portfolio/portfolio_message_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::document::utility_types::document_metadata::LayerNodeIdentifier;
use super::document::utility_types::misc::DocumentViewId;
use super::document::utility_types::network_interface::{self, InputConnector, OutputConnector};
use super::utility_types::{PanelType, PersistentData};
use crate::application::generate_uuid;
Expand All @@ -10,6 +11,7 @@ use crate::messages::portfolio::document::utility_types::clipboards::{Clipboard,
use crate::messages::portfolio::document::DocumentMessageData;
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::{HintData, HintGroup};
use crate::messages::workspace::TabType;
use crate::node_graph_executor::{ExportConfig, NodeGraphExecutor};

use graph_craft::document::value::TaggedValue;
Expand All @@ -26,10 +28,16 @@ pub struct PortfolioMessageData<'a> {
pub preferences: &'a PreferencesMessageHandler,
}

#[derive(Debug)]
pub struct DocumentView {
pub document_id: DocumentId,
}

#[derive(Debug, Default)]
pub struct PortfolioMessageHandler {
menu_bar_message_handler: MenuBarMessageHandler,
pub documents: HashMap<DocumentId, DocumentMessageHandler>,
pub document_views: HashMap<DocumentViewId, DocumentView>,
document_ids: Vec<DocumentId>,
active_panel: PanelType,
pub(crate) active_document_id: Option<DocumentId>,
Expand Down Expand Up @@ -816,6 +824,16 @@ impl PortfolioMessageHandler {

self.documents.insert(document_id, new_document);

// TODO: remove this and allow users to add views in UI.
for _ in 0..3 {
let document_view_id = DocumentViewId(41);
self.document_views.insert(document_view_id, DocumentView { document_id });
responses.add(WorkspaceMessage::AddTab {
tab: TabType::document(document_view_id, document_id),
destination: None,
});
}

if self.active_document().is_some() {
responses.add(BroadcastEvent::ToolAbort);
responses.add(ToolMessage::DeactivateTools);
Expand Down Expand Up @@ -863,4 +881,15 @@ impl PortfolioMessageHandler {
}
result
}

pub fn frontend_document(&self, view_id: DocumentViewId) -> Option<FrontendDocumentDetails> {
let document_id = self.document_views.get(&view_id)?.document_id;
let document = self.documents.get(&document_id)?;
Some(FrontendDocumentDetails {
is_auto_saved: document.is_auto_saved(),
is_saved: document.is_saved(),
id: document_id,
name: document.name.clone(),
})
}
}
4 changes: 4 additions & 0 deletions editor/src/messages/workspace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
mod workspace_message;
mod workspace_message_handler;
mod workspace_types;

#[doc(inline)]
pub use workspace_message::{WorkspaceMessage, WorkspaceMessageDiscriminant};
#[doc(inline)]
pub use workspace_message_handler::WorkspaceMessageHandler;

#[doc(inline)]
pub use workspace_types::*;
14 changes: 10 additions & 4 deletions editor/src/messages/workspace/workspace_message.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use crate::messages::prelude::*;
pub use super::workspace_types::*;
pub use crate::messages::prelude::*;

#[impl_message(Message, Workspace)]
#[derive(PartialEq, Eq, Clone, Debug, serde::Serialize, serde::Deserialize)]
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub enum WorkspaceMessage {
// Messages
NodeGraphToggleVisibility,
AddTab { tab: TabType, destination: Option<TabDestination> },
DeleteTab { tab: TabPath },
MoveTab { source: TabPath, destination: TabDestination },
SelectTab { tab: TabPath },
ResizeDivision { division: PanelPath, start_size: f64, end_size: f64 },

SendLayout,
}
Loading
Loading