Skip to content
Merged
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ add_library(${PROJECT_NAME} SHARED
# Window source files
src/windows/GraphWindow.cpp
src/windows/ModuleManagerWindow.cpp
src/windows/NodeExplorerWindow.cpp

# Widget source files
src/widgets/InputField.cpp
Expand Down
3 changes: 2 additions & 1 deletion include/flow/ui/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
FLOW_UI_NAMESPACE_START

/// Default name of the main dockspace.
static inline const std::string DefaultDockspace = "MainDockSpace";
static inline const std::string DefaultDockspace = "MainDockSpace";
static inline const std::string PropertyDockspace = "PropertySpace";

/**
* @brief Base Windows class.
Expand Down
27 changes: 24 additions & 3 deletions include/flow/ui/windows/GraphWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include "flow/ui/Core.hpp"
#include "flow/ui/Widget.hpp"
#include "flow/ui/Window.hpp"
#include "flow/ui/views/NodeView.hpp"

Expand All @@ -18,6 +19,27 @@

FLOW_UI_NAMESPACE_START

class ContextMenu : public Widget
{
public:
ContextMenu(std::shared_ptr<NodeFactory> factory) : _factory(std::move(factory)) {}

virtual ~ContextMenu() = default;

virtual void operator()() noexcept override;

private:
void DrawPopupCategory(const std::string& category, const flow::CategoryMap& registered_nodes);

public:
Event<const std::string&, const std::string&> OnSelection;

private:
std::shared_ptr<NodeFactory> _factory;
std::string node_lookup;
bool is_focused = false;
};

/**
* @brief Graph editor window for creating flows.
*/
Expand Down Expand Up @@ -180,15 +202,12 @@ class GraphWindow : public Window

void CreateItems();
void CleanupDeadItems();
void ShowNodeContextMenu();

void OnLoadNode(const flow::SharedNode& node, const json& position_json);
void OnLoadConnection(const flow::SharedConnection& connection);

flow::SharedNode CreateNode(const std::string& class_name, const std::string& display_name);

void DrawPopupCategory(const std::string& category, const flow::CategoryMap& registered_nodes);

private:
std::unique_ptr<EditorContext> _editor_ctx;
std::shared_ptr<flow::Graph> _graph;
Expand All @@ -204,6 +223,8 @@ class GraphWindow : public Window

std::string node_lookup;

ContextMenu node_context_menu;

struct
{
float x = 0.f;
Expand Down
37 changes: 37 additions & 0 deletions include/flow/ui/windows/NodeExplorerWindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "Core.hpp"
#include "Window.hpp"

#include <flow/core/Env.hpp>
#include <flow/core/Event.hpp>
#include <flow/core/Graph.hpp>
#include <flow/core/NodeFactory.hpp>

FLOW_UI_NAMESPACE_START

class NodeExplorerWindow : public Window
{
public:
NodeExplorerWindow(std::shared_ptr<Env> env);
virtual ~NodeExplorerWindow() = default;

virtual void Draw() override;

void SetActiveGraph(std::shared_ptr<Graph> graph) { _active_graph = std::move(graph); }

private:
void DrawPopupCategory(const std::string& category, const flow::CategoryMap& registered_nodes);

private:
std::shared_ptr<Env> _env;
std::shared_ptr<Graph> _active_graph;
std::string node_lookup;
struct
{
std::string class_name;
std::string display_name;
} drag_drop_payload;
};

FLOW_UI_NAMESPACE_END
10 changes: 9 additions & 1 deletion src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Window.hpp"
#include "utilities/Conversions.hpp"
#include "windows/ModuleManagerWindow.hpp"
#include "windows/NodeExplorerWindow.hpp"

#include <flow/core/Node.hpp>
#include <flow/core/NodeFactory.hpp>
Expand Down Expand Up @@ -146,7 +147,14 @@ void Editor::Init(const std::string& initial_file)
_factory->RegisterInputType<std::chrono::months>(std::chrono::months::zero());
_factory->RegisterInputType<std::chrono::years>(std::chrono::years::zero());

AddWindow(std::make_shared<ModuleManagerWindow>(_env, default_modules_path), DefaultDockspace);
auto node_explorer = std::make_shared<NodeExplorerWindow>(_env);
OnActiveGraphChanged.Bind("NodeExplorer", [window = node_explorer](const auto& g) { window->SetActiveGraph(g); });

AddDockspace(PropertyDockspace, DefaultDockspace, 0.25f, DockspaceSplitDirection::Left);
AddDockspace("PropertySubSpace", PropertyDockspace, 0.5f, DockspaceSplitDirection::Down);

AddWindow(std::move(node_explorer), "PropertySubSpace");
AddWindow(std::make_shared<ModuleManagerWindow>(_env, default_modules_path), "PropertySubSpace");

if (!initial_file.empty())
{
Expand Down
Loading
Loading