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
75 changes: 31 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ if(NOT PROJECT_NAME)
add_compile_definitions(FLOW_UI_EXPORT)
endif()

project(flow-ui VERSION 1.0.1 LANGUAGES CXX)
project(Flow VERSION 1.0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${CONFIG} CONFIG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
endforeach(CONFIG CMAKE_CONFIGURATION_TYPES)

if(APPLE)
enable_language(OBJC)
elseif(MSVC)
Expand All @@ -29,8 +39,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(cmake/CPM.cmake)

CPMAddPackage("gh:InFlowStructure/flow-core@1.2.0")
CPMAddPackage("gh:btzy/nativefiledialog-extended@1.2.1")
CPMAddPackage("gh:InFlowStructure/flow-core#7253c7d")
CPMAddPackage("gh:btzy/nativefiledialog-extended#29e3bcb")

FetchContent_Declare(
imgui
Expand Down Expand Up @@ -88,7 +98,7 @@ list(APPEND flow-ui_HEADERS
${flow-ui_WINDOW_HEADERS}
)

add_library(${PROJECT_NAME} SHARED
add_library(flow-ui SHARED
# Main source files
src/Config.cpp
src/Core.cpp
Expand All @@ -107,6 +117,7 @@ add_library(${PROJECT_NAME} SHARED
# Window source files
src/windows/GraphWindow.cpp
src/windows/ModuleManagerWindow.cpp
src/windows/NewModuleWindow.cpp
src/windows/NodeExplorerWindow.cpp
src/windows/PropertyWindow.cpp
src/windows/ShortcutsWindow.cpp
Expand All @@ -124,14 +135,14 @@ add_library(${PROJECT_NAME} SHARED
${flow-ui_HEADERS}
)

add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
add_library(flow-ui::flow-ui ALIAS flow-ui)

if(MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
target_compile_options(flow-ui PRIVATE /W4 /MP)
endif()

target_include_directories(${PROJECT_NAME}
target_include_directories(flow-ui
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Expand All @@ -145,57 +156,33 @@ target_include_directories(${PROJECT_NAME}
${PROJECT_SOURCE_DIR}/include/flow/ui/widgets
)

target_link_libraries(${PROJECT_NAME} PUBLIC
target_link_libraries(flow-ui PUBLIC
flow-core::flow-core
nlohmann_json::nlohmann_json
spdlog::spdlog
)

target_link_libraries(${PROJECT_NAME} PRIVATE
target_link_libraries(flow-ui PRIVATE
imgui
imgui_node_editor
hello_imgui
nfd
)
target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_DEFINE_MATH_OPERATORS)
target_compile_definitions(flow-ui PUBLIC IMGUI_DEFINE_MATH_OPERATORS)

add_subdirectory(programs/editor)

# -----------------------------------------------------------------------------
# Install
# -----------------------------------------------------------------------------
install(TARGETS flow-ui flow-core
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ${flow-core_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ${CPM_PACKAGE_json_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ${CPM_PACKAGE_thread-pool_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

if(flow-ui_INSTALL)
set(export_destination "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS ${PROJECT_NAME} imgui hello_imgui imgui_node_editor
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT ${PROJECT_NAME}Targets
DESTINATION ${export_destination}
NAMESPACE ${PROJECT_NAME}::
FILE "${PROJECT_NAME}Targets.cmake")

include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${export_destination}
)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION ${export_destination}
)

write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY SameMajorVersion)
endif()

# -----------------------------------------------------------------------------
# Examples
Expand Down
1 change: 1 addition & 0 deletions cmake/add_modules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions examples/simple_module/include/Example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <flow/core/Node.hpp>
#include <flow/core/NodeData.hpp>
#include <nlohmann/json.hpp>

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions include/flow/ui/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ FLOW_UI_NAMESPACE_END
* Specialization to avoid trying to cleanup Fonts as they are unowned.
*/
template<>
struct std::default_delete<FLOW_UI_NAMESPACE::Font>
struct std::default_delete<flow::ui::Font>
{
void operator()(FLOW_UI_NAMESPACE::Font*) const {}
void operator()(flow::ui::Font*) const {}
};

FLOW_UI_NAMESPACE_START
Expand Down
22 changes: 7 additions & 15 deletions include/flow/ui/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@

#include <memory>

#define FLOW_UI_NAMESPACE FLOW_NAMESPACE::ui
#define FLOW_UI_NAMESPACE_START \
/** The UI namespace. */ \
namespace FLOW_UI_NAMESPACE \
{
#define FLOW_UI_SUBNAMESPACE_START(n) \
namespace FLOW_UI_NAMESPACE \
{ \
namespace n \
{
// 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_END }
#define FLOW_UI_SUBNAMESPACE_END \
} \
}
#define FLOW_UI_SUBNAMESPACE_END } }
// clang-format on

FLOW_UI_NAMESPACE_START

Expand All @@ -29,9 +21,9 @@ class EditorContext;
FLOW_UI_NAMESPACE_END

template<>
struct std::default_delete<FLOW_UI_NAMESPACE::EditorContext>
struct std::default_delete<flow::ui::EditorContext>
{
void operator()(FLOW_UI_NAMESPACE::EditorContext*) const {}
void operator()(flow::ui::EditorContext*) const {}
};

FLOW_UI_NAMESPACE_START
Expand Down
10 changes: 5 additions & 5 deletions include/flow/ui/views/NodeView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class NodeView : public GraphItemView
* @param node The node to represent.
* @param header_colour The colour of the node header.
*/
NodeView(flow::SharedNode node, Colour header_colour = Colour(40, 75, 99));
NodeView(const flow::SharedNode& node, Colour header_colour = Colour(40, 75, 99));

virtual ~NodeView() = default;

Expand All @@ -86,6 +86,9 @@ class NodeView : public GraphItemView
void ShowConnectables(const std::shared_ptr<PortView>& port) override;

public:
/// The ID of the node this view is for.
UUID NodeID;

/// The name of the Node.
std::string Name;

Expand All @@ -98,9 +101,6 @@ class NodeView : public GraphItemView
/// The colour of the header.
Colour HeaderColour;

/// The node that is being represented.
flow::SharedNode Node;

protected:
std::shared_ptr<utility::NodeBuilder> _builder;
bool _received_error = false;
Expand All @@ -116,7 +116,7 @@ class SimpleNodeView : public NodeView
* @brief Constructs a simple node view.
* @param node The node being represented.
*/
SimpleNodeView(flow::SharedNode node);
SimpleNodeView(const flow::SharedNode& node);

virtual ~SimpleNodeView() = default;

Expand Down
11 changes: 4 additions & 7 deletions include/flow/ui/views/PortView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ class PortView
*/
const flow::IndexableName& Key() const noexcept { return _port->GetKey(); }

/**
* @brief Gets the name/label of the port.
* @returns The port's name.
*/
std::string_view Name() const noexcept { return _port->GetVarName(); }

/**
* @brief Gets the caption/description of the port.
* @returns The port's caption.
Expand Down Expand Up @@ -148,14 +142,17 @@ class PortView
std::uint64_t ID;

/// The owning NodeView ID.
const std::uint64_t& NodeID;
const std::uint64_t& NodeViewID;

/// The type of port.
PortType Kind = PortType::Input;

/// Event run on setting a new value in the input field.
InputEvent OnSetInput;

/// The name of the port.
std::string Name;

private:
std::shared_ptr<Port> _port;
std::shared_ptr<widgets::InputInterface> _input_field;
Expand Down
2 changes: 2 additions & 0 deletions include/flow/ui/widgets/Table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Table : public Widget
*/
void AddEntry(std::shared_ptr<Widget> widget);

const std::shared_ptr<Widget>& GetEntry(std::size_t i) const { return _widgets.at(i); }

private:
std::string _name;
std::size_t _columns = 0;
Expand Down
8 changes: 5 additions & 3 deletions include/flow/ui/windows/GraphWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <flow/core/Graph.hpp>
#include <flow/core/NodeFactory.hpp>
#include <nlohmann/json.hpp>

#include <algorithm>
#include <memory>
Expand All @@ -19,6 +20,8 @@

FLOW_UI_NAMESPACE_START

using json = nlohmann::json;

class ContextMenu : public Widget
{
public:
Expand Down Expand Up @@ -209,6 +212,7 @@ class GraphWindow : public Window
flow::SharedNode CreateNode(const std::string& class_name, const std::string& display_name);

private:
mutable std::mutex _mutex;
std::unique_ptr<EditorContext> _editor_ctx;
std::shared_ptr<flow::Graph> _graph;

Expand All @@ -221,9 +225,7 @@ class GraphWindow : public Window
std::shared_ptr<PortView> _new_node_link_pin = nullptr;
std::shared_ptr<PortView> _new_link_pin = nullptr;

std::string node_lookup;

ContextMenu node_creation_context_menu;
ContextMenu _node_creation_context_menu;

struct
{
Expand Down
2 changes: 2 additions & 0 deletions include/flow/ui/windows/ModuleManagerWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "flow/ui/Core.hpp"
#include "flow/ui/Widget.hpp"
#include "flow/ui/Window.hpp"
#include "flow/ui/windows/NewModuleWindow.hpp"

#include <flow/core/Env.hpp>

Expand Down Expand Up @@ -36,6 +37,7 @@ class ModuleManagerWindow : public Window
std::shared_ptr<Env> _env;
std::filesystem::path _modules_path;
std::map<std::string, std::shared_ptr<Widget>> _widgets;
std::unique_ptr<NewModuleWindow> _new_module_window;
};

FLOW_UI_NAMESPACE_END
32 changes: 32 additions & 0 deletions include/flow/ui/windows/NewModuleWindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "flow/ui/Core.hpp"
#include "flow/ui/Window.hpp"
#include "widgets/InputField.hpp"
#include "widgets/Table.hpp"

FLOW_UI_NAMESPACE_START

class NewModuleWindow : public Window
{
public:
NewModuleWindow();
virtual ~NewModuleWindow() = default;

bool DrawAndCreate();

public:
static inline const std::string Name = "Create New Module";

private:
void Clear();

private:
std::shared_ptr<widgets::Input<std::string>> name_input;
std::shared_ptr<widgets::Input<std::string>> version_input;
std::shared_ptr<widgets::Input<std::string>> author_input;
std::shared_ptr<widgets::Input<std::string>> description_input;
std::shared_ptr<widgets::Table> dependencies;
};

FLOW_UI_NAMESPACE_END
Loading