Skip to content
Draft
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
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ include(cmake/CPM.cmake)
CPMAddPackage("gh:InFlowStructure/flow-core#7253c7d")
CPMAddPackage("gh:btzy/nativefiledialog-extended#29e3bcb")

include(FetchContent)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/pthom/imgui.git
GIT_TAG imgui_bundle
GIT_TAG bundle_20250323
)
FetchContent_Declare(
imgui_node_editor
Expand All @@ -66,7 +67,6 @@ endif()

CPMAddPackage("gh:pthom/hello_imgui#c985031")

include(FetchContent)
include(cmake/add_libs.cmake)
include(${hello_imgui_SOURCE_DIR}/hello_imgui_cmake/msvc/msvc_target_group.cmake)

Expand Down Expand Up @@ -104,10 +104,12 @@ add_library(flow-ui SHARED
src/Core.cpp
src/Editor.cpp
src/FileExplorer.cpp
src/CommandManager.cpp
src/Style.cpp
src/Texture.cpp
src/ViewFactory.cpp
src/Window.cpp
src/WindowManager.cpp

# View source files
src/views/ConnectionView.cpp
Expand All @@ -129,7 +131,7 @@ add_library(flow-ui SHARED
src/widgets/Text.cpp

# Utility files
src/utilities/Builders.cpp
src/utilities/NodeBuilder.cpp
src/utilities/Widgets.cpp

${flow-ui_HEADERS}
Expand Down
25 changes: 25 additions & 0 deletions include/flow/ui/CommandManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024, Cisco Systems, Inc.
// All rights reserved.

#pragma once

#include "Core.hpp"

#include <flow/core/Event.hpp>

#include <map>

FLOW_UI_NAMESPACE_BEGIN

class CommandManager
{
public:
void Handle();

void AddCommand(int key_chord, Event<>&& event);

private:
std::map<int, Event<>> _input_events;
};

FLOW_UI_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/flow/ui/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <string>
#include <unordered_map>

FLOW_UI_NAMESPACE_START
FLOW_UI_NAMESPACE_BEGIN
class Font;
FLOW_UI_NAMESPACE_END

Expand All @@ -22,7 +22,7 @@ struct std::default_delete<flow::ui::Font>
void operator()(flow::ui::Font*) const {}
};

FLOW_UI_NAMESPACE_START
FLOW_UI_NAMESPACE_BEGIN

/**
* @brief Flags for choosing dockspace splitting direction.
Expand Down
8 changes: 4 additions & 4 deletions include/flow/ui/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include <memory>

// clang-format off
#define FLOW_UI_NAMESPACE_START namespace flow::ui {
#define FLOW_UI_SUBNAMESPACE_START(nested) namespace flow::ui { namespace nested {
#define FLOW_UI_NAMESPACE_BEGIN namespace flow::ui {
#define FLOW_UI_SUBNAMESPACE_BEGIN(nested) namespace flow::ui { namespace nested {
#define FLOW_UI_NAMESPACE_END }
#define FLOW_UI_SUBNAMESPACE_END } }
// clang-format on

FLOW_UI_NAMESPACE_START
FLOW_UI_NAMESPACE_BEGIN

class EditorContext;

Expand All @@ -26,7 +26,7 @@ struct std::default_delete<flow::ui::EditorContext>
void operator()(flow::ui::EditorContext*) const {}
};

FLOW_UI_NAMESPACE_START
FLOW_UI_NAMESPACE_BEGIN

/**
* @brief Get the current context for the graph editor.
Expand Down
67 changes: 15 additions & 52 deletions include/flow/ui/Editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

#pragma once

#include "CommandManager.hpp"
#include "Config.hpp"
#include "FileExplorer.hpp"
#include "Style.hpp"
#include "ViewFactory.hpp"
#include "Window.hpp"
#include "views/ConnectionView.hpp"
#include "views/NodeView.hpp"
#include "views/PortView.hpp"
#include "WindowManager.hpp"
#include "windows/GraphWindow.hpp"

#include <flow/core/Env.hpp>
Expand All @@ -22,7 +19,7 @@
#include <string>
#include <vector>

FLOW_UI_NAMESPACE_START
FLOW_UI_NAMESPACE_BEGIN

/**
* @brief Main application class the holds and runs the graphs and other windows.
Expand All @@ -41,28 +38,6 @@ class Editor
*/
void Run();

/**
* @brief Add a new custom window to the editor.
*
* @param new_window The new window to add to the editor.
* @param dockspace The default dockspace to attach the window to.
* @param show Flag to show or hide the window by default.
*/
void AddWindow(std::shared_ptr<Window> new_window, const std::string& dockspace, bool show = true);

/**
* @brief Adds a new dockspace that windows can be docked to.
*
* @param name The name of the dockspace.
* @param initial_dockspace_name The dockspace to split off from.
* @param ratio How much of the original dockspace should be split off for the new dockspace.
* @param direction The direction for the new split.
*
* @note Should be called before adding windows.
*/
void AddDockspace(std::string name, std::string initial_dockspace_name, float ratio,
DockspaceSplitDirection direction);

/**
* @brief Get a reference to the shared environment.
* @returns THe shared ptr to the Env.
Expand All @@ -75,47 +50,35 @@ class Editor
*/
const std::shared_ptr<ViewFactory>& GetFactory() const noexcept { return _factory; }

/**
* @brief Get a reference to the current editor context.
* @returns The pointer to the current editor context.
*/
void* GetContext() const noexcept;

/**
* @brief Event that is run to load custom fonts for the editor.
*/
Event<Config&> LoadFonts = [](auto&) {};

/**
* @brief Event that is run to setup a custom appearance of the editor.
*/
Event<Style&> SetupStyle = [](auto&) {};

/**
* @brief Event dispatcher that is run every time a new graph is marked as the active graph.
*/
EventDispatcher<const std::shared_ptr<Graph>&> OnActiveGraphChanged;

protected:
void Init(const std::string& initial_file);

void Teardown();

void HandleInput();
void SetupParams(const std::string& initial_file);

void DrawMainMenuBar();
void RegisterInputs();

void RegisterNodes();

void RegisterInputFieldTypes();

const std::shared_ptr<GraphWindow>& CreateFlow(const std::string& name = "");

std::shared_ptr<GraphWindow>& CreateFlow(std::string name);
void LoadFlow(const std::filesystem::path& file = "");

void SaveFlow();

private:
std::shared_ptr<ViewFactory> _factory = std::make_shared<ViewFactory>();
std::shared_ptr<Env> _env = Env::Create(_factory);

std::vector<std::shared_ptr<Window>> _windows;
std::unordered_map<UUID, std::shared_ptr<GraphWindow>> _graph_windows;
EventDispatcher<> OnGraphWindowAdded;
EventDispatcher<> OnGraphWindowRemoved;
std::unique_ptr<WindowManager> _window_manager;
std::unique_ptr<CommandManager> _input_manager;
};

FLOW_UI_NAMESPACE_END
2 changes: 1 addition & 1 deletion include/flow/ui/FileExplorer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <filesystem>
#include <string>

FLOW_UI_NAMESPACE_START
FLOW_UI_NAMESPACE_BEGIN

/**
* @brief Native file dialog.
Expand Down
Loading
Loading