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
20 changes: 0 additions & 20 deletions .gitmodules

This file was deleted.

68 changes: 43 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,56 @@ elseif(MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()

# -----------------------------------------------------------------------------
# Options
# -----------------------------------------------------------------------------

option(flow-ui_USE_EXTERNAL_FLOW_CORE "Use an external Flow Core library" OFF)

# -----------------------------------------------------------------------------
# Dependencies
# -----------------------------------------------------------------------------

if(flow-ui_INSTALL)
set(flow-core_INSTALL ON CACHE BOOL "" FORCE)
set(SPDLOG_INSTALL ON CACHE BOOL "" FORCE)
set(NFD_INSTALL ON CACHE BOOL "" FORCE)
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

find_package(nlohmann_json CONFIG QUIET)
if (NOT nlohmann_json_FOUND)
include(FetchContent)
FetchContent_Declare(
nlohmann_json OVERRIDE_FIND_PACKAGE
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
)
FetchContent_MakeAvailable(nlohmann_json)
endif()
include(cmake/CPM.cmake)

if (flow-ui_USE_EXTERNAL_FLOW_CORE)
find_package(flow-core REQUIRED)
endif()
CPMAddPackage("gh:InFlowStructure/flow-core@1.2.0")
CPMAddPackage("gh:btzy/nativefiledialog-extended@1.2.1")

if(flow-ui_INSTALL)
if (NOT flow-ui_USE_EXTERNAL_FLOW_CORE)
set(flow-core_INSTALL ON CACHE BOOL "" FORCE)
endif()
set(SPDLOG_INSTALL ON CACHE BOOL "" FORCE)
set(NFD_INSTALL ON CACHE BOOL "" FORCE)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/pthom/imgui.git
GIT_TAG imgui_bundle
)
FetchContent_Declare(
imgui_node_editor
GIT_REPOSITORY https://github.com/pthom/imgui-node-editor.git
GIT_TAG imgui_bundle
)
FetchContent_MakeAvailable(imgui imgui_node_editor)

set(HELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED OFF CACHE BOOL "")
set(HELLOIMGUI_USE_FREETYPE OFF CACHE BOOL "")
set(HELLOIMGUI_USE_EXTERNAL_JSON ON CACHE BOOL "")
set(HELLOIMGUI_BUILD_IMGUI OFF CACHE BOOL "" FORCE)
set(HELLOIMGUI_IMGUI_SOURCE_DIR ${imgui_SOURCE_DIR} CACHE STRING "" FORCE)

if (UNIX)
add_compile_options(-fPIC)
endif()

add_subdirectory(third_party)
CPMAddPackage("gh:GhostofCookie/hello_imgui#0e0adb7")

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

add_imgui(${imgui_SOURCE_DIR})
add_simple_external_library_with_sources(imgui_node_editor ${imgui_node_editor_SOURCE_DIR})

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
CPMAddPackage("gh:gabime/spdlog@1.15.1")

# -----------------------------------------------------------------------------
# Library
Expand Down Expand Up @@ -93,6 +108,7 @@ add_library(${PROJECT_NAME} SHARED
src/windows/GraphWindow.cpp
src/windows/ModuleManagerWindow.cpp
src/windows/NodeExplorerWindow.cpp
src/windows/PropertyWindow.cpp
src/windows/ShortcutsWindow.cpp

# Widget source files
Expand Down Expand Up @@ -143,6 +159,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
)
target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_DEFINE_MATH_OPERATORS)

add_subdirectory(programs/editor)

# -----------------------------------------------------------------------------
# Install
# -----------------------------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.40.5)
set(CPM_HASH_SUM "c46b876ae3b9f994b4f05a4c15553e0485636862064f1fcc9d8b4f832086bc5d")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
29 changes: 1 addition & 28 deletions cmake/add_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,14 @@ function(add_imgui imgui_dir)
target_compile_options(imgui PRIVATE "/wd4297")
endif()

if(PROJECT_IS_TOP_LEVEL AND NOT SKBUILD)
install(TARGETS imgui DESTINATION ./lib/)
endif()

if(IMGUI_BUNDLE_BUILD_PYTHON)
target_compile_definitions(imgui PUBLIC ImTextureID=int)
endif()

if (UNIX)
target_compile_options(imgui PUBLIC -fPIC)
endif()
hello_imgui_msvc_target_group_sources(imgui)
endif()
endfunction()

function (add_hello_imgui)
if (UNIX)
add_compile_options(-fPIC)
endif()

set(BUILD_SHARED_LIBS OFF)
set(imgui_dir ${CMAKE_CURRENT_LIST_DIR}/imgui)
add_imgui(${imgui_dir})

set(HELLOIMGUI_BUILD_IMGUI OFF CACHE BOOL "" FORCE)
set(HELLOIMGUI_IMGUI_SOURCE_DIR ${imgui_dir} CACHE STRING "" FORCE)

add_subdirectory(hello_imgui)

if (WIN32)
set_target_properties(hello_imgui PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
hello_imgui_msvc_target_group_sources(imgui)
endif()
endfunction()


function(add_simple_external_library_with_sources lib_target_name lib_folder)
file(GLOB lib_sources ${lib_folder}/*.cpp ${lib_folder}/*.h)

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

#pragma once

#include "flow/ui/Core.hpp"
#include "flow/ui/Window.hpp"

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

#include <memory>
#include <string>

FLOW_UI_NAMESPACE_START

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

virtual void Draw() override;

void SetCurrentGraph(std::shared_ptr<flow::Graph> graph) { _graph = graph; }

static inline const std::string Name = "Properties";

private:
std::weak_ptr<flow::Env> _env;
std::weak_ptr<flow::Graph> _graph;
};

FLOW_UI_NAMESPACE_END
40 changes: 40 additions & 0 deletions programs/editor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.10)

project(FlowEditor VERSION 1.0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# -----------------------------------------------------------------------------
# Dependencies
# -----------------------------------------------------------------------------

CPMAddPackage("gh:jarro2783/cxxopts@3.2.0")

# -----------------------------------------------------------------------------
# Executable
# -----------------------------------------------------------------------------

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
endif()

hello_imgui_add_app(${PROJECT_NAME}
src/main.cpp

ASSETS_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/assets/
)
target_link_libraries(${PROJECT_NAME} PUBLIC
flow-ui::flow-ui
cxxopts
imgui_node_editor
)

if(MSVC)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}>
$<TARGET_FILE_DIR:${PROJECT_NAME}>
COMMAND_EXPAND_LISTS
)
endif()
127 changes: 127 additions & 0 deletions programs/editor/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include <cxxopts.hpp>
#include <flow/ui/Config.hpp>
#include <flow/ui/Editor.hpp>
#include <spdlog/spdlog.h>

#include <algorithm>
#include <csignal>
#include <fstream>
#include <iostream>

int main(int argc, char** argv)
{
std::string filename;

#ifndef FLOW_WINDOWS
// clang-format off
cxxopts::Options options("FlowEditor");
options.add_options()
("f,flow", "Flow file to open", cxxopts::value<std::string>())
("l,log_level", "Logging level [trace = 0, debug = 1, info = 2, warn = 3, err = 4, critical = 5, off = 6]", cxxopts::value<int>())
("h,help", "Print usage");
// clang-format on

cxxopts::ParseResult result;

try
{
result = options.parse(argc, argv);
}
catch (const cxxopts::exceptions::exception& e)
{
std::cerr << "Caught exception while parsing arguments: " << e.what() << std::endl;
return EXIT_FAILURE;
}

if (result.count("help"))
{
std::cerr << options.help() << std::endl;
return EXIT_SUCCESS;
}

if (result.count("flow"))
{
filename = result["flow"].as<std::string>();
}

if (result.count("log_level"))
{
spdlog::set_level(static_cast<spdlog::level::level_enum>(result["log_level"].as<int>()));
}
#endif

flow::ui::Editor app(filename);

app.LoadFonts = [](flow::ui::Config& config) {
config.DefaultFont = flow::ui::LoadFont("fonts/DroidSans.ttf", 18.f);
config.NodeHeaderFont = flow::ui::LoadFont("fonts/DroidSans.ttf", 20.f);
config.IconFont = flow::ui::LoadFont("fonts/fontawesome-webfont.ttf", 18.f);
};

app.SetupStyle = [](flow::ui::Style& style) {
style.WindowBorderSize = 5.f;
style.FrameBorderSize = 2.f;
style.TabRounding = 8.f;
style.TabBarBorderSize = 0.f;
style.CellPadding = {.Width = 7.f, .Height = 7.f};

auto& imgui_colours = style.Colours.BaseColours;
using BaseColour = flow::ui::Style::BaseColour;

imgui_colours[BaseColour::WindowBg] = flow::ui::Colour(21, 21, 21);
imgui_colours[BaseColour::PopupBg] = flow::ui::Colour(15, 15, 15, 175);
imgui_colours[BaseColour::Border] = flow::ui::Colour(15, 15, 15);
imgui_colours[BaseColour::PopupBg] = imgui_colours[BaseColour::WindowBg];
imgui_colours[BaseColour::FrameBg] = flow::ui::Colour(15, 15, 15);
imgui_colours[BaseColour::MenuBarBg] = flow::ui::Colour(21, 21, 21);
imgui_colours[BaseColour::TitleBg] = flow::ui::Colour(21, 21, 21);
imgui_colours[BaseColour::TitleBgActive] = imgui_colours[BaseColour::TitleBg];
imgui_colours[BaseColour::Tab] = flow::ui::Colour(21, 21, 21);
imgui_colours[BaseColour::TabDimmed] = flow::ui::Colour(21, 21, 21);
imgui_colours[BaseColour::TabHovered] = flow::ui::Colour(47, 47, 47);
imgui_colours[BaseColour::TabSelected] = flow::ui::Colour(3, 98, 195);
imgui_colours[BaseColour::TabDimmedSelected] = imgui_colours[BaseColour::TabSelected];
imgui_colours[BaseColour::Button] = flow::ui::Colour(32, 32, 32);
imgui_colours[BaseColour::ButtonHovered] = flow::ui::Colour(3, 98, 195);
imgui_colours[BaseColour::ButtonActive] = flow::ui::Colour(13, 39, 77);
imgui_colours[BaseColour::ScrollbarBg] = flow::ui::Colour(21, 21, 21);
imgui_colours[BaseColour::ScrollbarGrab] = flow::ui::Colour(86, 86, 86);
imgui_colours[BaseColour::TableBorderLight] = flow::ui::Colour(21, 21, 21);
imgui_colours[BaseColour::TableBorderStrong] = flow::ui::Colour(21, 21, 21);
imgui_colours[BaseColour::TableRowBg] = flow::ui::Colour(36, 36, 36);
imgui_colours[BaseColour::TableRowBgAlt] = flow::ui::Colour(36, 36, 36);
imgui_colours[BaseColour::Header] = flow::ui::Colour(47, 47, 47);
imgui_colours[BaseColour::HeaderHovered] = flow::ui::Colour(50, 50, 50);
imgui_colours[BaseColour::CheckMark] = flow::ui::Colour(3, 98, 195);

auto& colours = style.Colours.EditorColours;
using EditorColour = flow::ui::Style::EditorColour;

colours[EditorColour::Bg] = flow::ui::Colour(38, 38, 38);
colours[EditorColour::Grid] = flow::ui::Colour(52, 52, 52);
colours[EditorColour::NodeBg] = flow::ui::Colour(15, 17, 15, 240);
colours[EditorColour::NodeBorder] = flow::ui::Colour(0, 0, 0);
colours[EditorColour::SelNodeBorder] = flow::ui::Colour(255, 255, 255);
colours[EditorColour::Flow] = flow::ui::Colour(32, 191, 85);
colours[EditorColour::FlowMarker] = flow::ui::Colour(32, 191, 85);
colours[EditorColour::HighlightLinkBorder] = flow::ui::Colour(0, 188, 235);
colours[EditorColour::SelLinkBorder] = flow::ui::Colour(0, 188, 235);
};

try
{
app.Run();
}
catch (const std::exception& e)
{
SPDLOG_CRITICAL("Exiting with error: {0}", e.what());
return EXIT_FAILURE;
}
catch (...)
{
SPDLOG_CRITICAL("Exiting with unknown error");
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}
Loading