Skip to content

Commit a78caa0

Browse files
Removed submodules and added flow editor into this repo instead. (#18)
* Removed submodules and added flow editor into this repo instead. * Fix mac and linux builds. Trying to fix linux build for spdlog. Ading position independent code for hello_imgui as well. Explicitly add fPIC to compile options. * Updating flow core version.
1 parent 04dd94d commit a78caa0

File tree

20 files changed

+505
-111
lines changed

20 files changed

+505
-111
lines changed

.gitmodules

Lines changed: 0 additions & 20 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,56 @@ elseif(MSVC)
1515
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
1616
endif()
1717

18-
# -----------------------------------------------------------------------------
19-
# Options
20-
# -----------------------------------------------------------------------------
21-
22-
option(flow-ui_USE_EXTERNAL_FLOW_CORE "Use an external Flow Core library" OFF)
23-
2418
# -----------------------------------------------------------------------------
2519
# Dependencies
2620
# -----------------------------------------------------------------------------
2721

22+
if(flow-ui_INSTALL)
23+
set(flow-core_INSTALL ON CACHE BOOL "" FORCE)
24+
set(SPDLOG_INSTALL ON CACHE BOOL "" FORCE)
25+
set(NFD_INSTALL ON CACHE BOOL "" FORCE)
26+
endif()
27+
2828
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2929

30-
find_package(nlohmann_json CONFIG QUIET)
31-
if (NOT nlohmann_json_FOUND)
32-
include(FetchContent)
33-
FetchContent_Declare(
34-
nlohmann_json OVERRIDE_FIND_PACKAGE
35-
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
36-
)
37-
FetchContent_MakeAvailable(nlohmann_json)
38-
endif()
30+
include(cmake/CPM.cmake)
3931

40-
if (flow-ui_USE_EXTERNAL_FLOW_CORE)
41-
find_package(flow-core REQUIRED)
42-
endif()
32+
CPMAddPackage("gh:InFlowStructure/flow-core@1.2.0")
33+
CPMAddPackage("gh:btzy/nativefiledialog-extended@1.2.1")
4334

44-
if(flow-ui_INSTALL)
45-
if (NOT flow-ui_USE_EXTERNAL_FLOW_CORE)
46-
set(flow-core_INSTALL ON CACHE BOOL "" FORCE)
47-
endif()
48-
set(SPDLOG_INSTALL ON CACHE BOOL "" FORCE)
49-
set(NFD_INSTALL ON CACHE BOOL "" FORCE)
35+
FetchContent_Declare(
36+
imgui
37+
GIT_REPOSITORY https://github.com/pthom/imgui.git
38+
GIT_TAG imgui_bundle
39+
)
40+
FetchContent_Declare(
41+
imgui_node_editor
42+
GIT_REPOSITORY https://github.com/pthom/imgui-node-editor.git
43+
GIT_TAG imgui_bundle
44+
)
45+
FetchContent_MakeAvailable(imgui imgui_node_editor)
46+
47+
set(HELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED OFF CACHE BOOL "")
48+
set(HELLOIMGUI_USE_FREETYPE OFF CACHE BOOL "")
49+
set(HELLOIMGUI_USE_EXTERNAL_JSON ON CACHE BOOL "")
50+
set(HELLOIMGUI_BUILD_IMGUI OFF CACHE BOOL "" FORCE)
51+
set(HELLOIMGUI_IMGUI_SOURCE_DIR ${imgui_SOURCE_DIR} CACHE STRING "" FORCE)
52+
53+
if (UNIX)
54+
add_compile_options(-fPIC)
5055
endif()
5156

52-
add_subdirectory(third_party)
57+
CPMAddPackage("gh:GhostofCookie/hello_imgui#0e0adb7")
58+
59+
include(FetchContent)
60+
include(cmake/add_libs.cmake)
61+
include(${hello_imgui_SOURCE_DIR}/hello_imgui_cmake/msvc/msvc_target_group.cmake)
62+
63+
add_imgui(${imgui_SOURCE_DIR})
64+
add_simple_external_library_with_sources(imgui_node_editor ${imgui_node_editor_SOURCE_DIR})
65+
66+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
67+
CPMAddPackage("gh:gabime/spdlog@1.15.1")
5368

5469
# -----------------------------------------------------------------------------
5570
# Library
@@ -93,6 +108,7 @@ add_library(${PROJECT_NAME} SHARED
93108
src/windows/GraphWindow.cpp
94109
src/windows/ModuleManagerWindow.cpp
95110
src/windows/NodeExplorerWindow.cpp
111+
src/windows/PropertyWindow.cpp
96112
src/windows/ShortcutsWindow.cpp
97113

98114
# Widget source files
@@ -143,6 +159,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
143159
)
144160
target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_DEFINE_MATH_OPERATORS)
145161

162+
add_subdirectory(programs/editor)
163+
146164
# -----------------------------------------------------------------------------
147165
# Install
148166
# -----------------------------------------------------------------------------

cmake/CPM.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: MIT
2+
#
3+
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
4+
5+
set(CPM_DOWNLOAD_VERSION 0.40.5)
6+
set(CPM_HASH_SUM "c46b876ae3b9f994b4f05a4c15553e0485636862064f1fcc9d8b4f832086bc5d")
7+
8+
if(CPM_SOURCE_CACHE)
9+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
10+
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
11+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
12+
else()
13+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
14+
endif()
15+
16+
# Expand relative path. This is important if the provided path contains a tilde (~)
17+
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
18+
19+
file(DOWNLOAD
20+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
21+
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
22+
)
23+
24+
include(${CPM_DOWNLOAD_LOCATION})

cmake/add_libs.cmake

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,14 @@ function(add_imgui imgui_dir)
1919
target_compile_options(imgui PRIVATE "/wd4297")
2020
endif()
2121

22-
if(PROJECT_IS_TOP_LEVEL AND NOT SKBUILD)
23-
install(TARGETS imgui DESTINATION ./lib/)
24-
endif()
25-
26-
if(IMGUI_BUNDLE_BUILD_PYTHON)
27-
target_compile_definitions(imgui PUBLIC ImTextureID=int)
28-
endif()
29-
3022
if (UNIX)
3123
target_compile_options(imgui PUBLIC -fPIC)
3224
endif()
33-
hello_imgui_msvc_target_group_sources(imgui)
34-
endif()
35-
endfunction()
3625

37-
function (add_hello_imgui)
38-
if (UNIX)
39-
add_compile_options(-fPIC)
40-
endif()
41-
42-
set(BUILD_SHARED_LIBS OFF)
43-
set(imgui_dir ${CMAKE_CURRENT_LIST_DIR}/imgui)
44-
add_imgui(${imgui_dir})
45-
46-
set(HELLOIMGUI_BUILD_IMGUI OFF CACHE BOOL "" FORCE)
47-
set(HELLOIMGUI_IMGUI_SOURCE_DIR ${imgui_dir} CACHE STRING "" FORCE)
48-
49-
add_subdirectory(hello_imgui)
50-
51-
if (WIN32)
52-
set_target_properties(hello_imgui PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
26+
hello_imgui_msvc_target_group_sources(imgui)
5327
endif()
5428
endfunction()
5529

56-
5730
function(add_simple_external_library_with_sources lib_target_name lib_folder)
5831
file(GLOB lib_sources ${lib_folder}/*.cpp ${lib_folder}/*.h)
5932

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2024, Cisco Systems, Inc.
2+
// All rights reserved.
3+
4+
#pragma once
5+
6+
#include "flow/ui/Core.hpp"
7+
#include "flow/ui/Window.hpp"
8+
9+
#include <flow/core/Env.hpp>
10+
#include <flow/core/Graph.hpp>
11+
12+
#include <memory>
13+
#include <string>
14+
15+
FLOW_UI_NAMESPACE_START
16+
17+
class PropertyWindow : public Window
18+
{
19+
public:
20+
PropertyWindow(std::shared_ptr<flow::Env> env);
21+
virtual ~PropertyWindow() = default;
22+
23+
virtual void Draw() override;
24+
25+
void SetCurrentGraph(std::shared_ptr<flow::Graph> graph) { _graph = graph; }
26+
27+
static inline const std::string Name = "Properties";
28+
29+
private:
30+
std::weak_ptr<flow::Env> _env;
31+
std::weak_ptr<flow::Graph> _graph;
32+
};
33+
34+
FLOW_UI_NAMESPACE_END

programs/editor/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(FlowEditor VERSION 1.0.1 LANGUAGES CXX)
4+
5+
set(CMAKE_CXX_STANDARD 20)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
# -----------------------------------------------------------------------------
9+
# Dependencies
10+
# -----------------------------------------------------------------------------
11+
12+
CPMAddPackage("gh:jarro2783/cxxopts@3.2.0")
13+
14+
# -----------------------------------------------------------------------------
15+
# Executable
16+
# -----------------------------------------------------------------------------
17+
18+
if(MSVC)
19+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
20+
endif()
21+
22+
hello_imgui_add_app(${PROJECT_NAME}
23+
src/main.cpp
24+
25+
ASSETS_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/assets/
26+
)
27+
target_link_libraries(${PROJECT_NAME} PUBLIC
28+
flow-ui::flow-ui
29+
cxxopts
30+
imgui_node_editor
31+
)
32+
33+
if(MSVC)
34+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
35+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
36+
$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}>
37+
$<TARGET_FILE_DIR:${PROJECT_NAME}>
38+
COMMAND_EXPAND_LISTS
39+
)
40+
endif()

programs/editor/src/main.cpp

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#include <cxxopts.hpp>
2+
#include <flow/ui/Config.hpp>
3+
#include <flow/ui/Editor.hpp>
4+
#include <spdlog/spdlog.h>
5+
6+
#include <algorithm>
7+
#include <csignal>
8+
#include <fstream>
9+
#include <iostream>
10+
11+
int main(int argc, char** argv)
12+
{
13+
std::string filename;
14+
15+
#ifndef FLOW_WINDOWS
16+
// clang-format off
17+
cxxopts::Options options("FlowEditor");
18+
options.add_options()
19+
("f,flow", "Flow file to open", cxxopts::value<std::string>())
20+
("l,log_level", "Logging level [trace = 0, debug = 1, info = 2, warn = 3, err = 4, critical = 5, off = 6]", cxxopts::value<int>())
21+
("h,help", "Print usage");
22+
// clang-format on
23+
24+
cxxopts::ParseResult result;
25+
26+
try
27+
{
28+
result = options.parse(argc, argv);
29+
}
30+
catch (const cxxopts::exceptions::exception& e)
31+
{
32+
std::cerr << "Caught exception while parsing arguments: " << e.what() << std::endl;
33+
return EXIT_FAILURE;
34+
}
35+
36+
if (result.count("help"))
37+
{
38+
std::cerr << options.help() << std::endl;
39+
return EXIT_SUCCESS;
40+
}
41+
42+
if (result.count("flow"))
43+
{
44+
filename = result["flow"].as<std::string>();
45+
}
46+
47+
if (result.count("log_level"))
48+
{
49+
spdlog::set_level(static_cast<spdlog::level::level_enum>(result["log_level"].as<int>()));
50+
}
51+
#endif
52+
53+
flow::ui::Editor app(filename);
54+
55+
app.LoadFonts = [](flow::ui::Config& config) {
56+
config.DefaultFont = flow::ui::LoadFont("fonts/DroidSans.ttf", 18.f);
57+
config.NodeHeaderFont = flow::ui::LoadFont("fonts/DroidSans.ttf", 20.f);
58+
config.IconFont = flow::ui::LoadFont("fonts/fontawesome-webfont.ttf", 18.f);
59+
};
60+
61+
app.SetupStyle = [](flow::ui::Style& style) {
62+
style.WindowBorderSize = 5.f;
63+
style.FrameBorderSize = 2.f;
64+
style.TabRounding = 8.f;
65+
style.TabBarBorderSize = 0.f;
66+
style.CellPadding = {.Width = 7.f, .Height = 7.f};
67+
68+
auto& imgui_colours = style.Colours.BaseColours;
69+
using BaseColour = flow::ui::Style::BaseColour;
70+
71+
imgui_colours[BaseColour::WindowBg] = flow::ui::Colour(21, 21, 21);
72+
imgui_colours[BaseColour::PopupBg] = flow::ui::Colour(15, 15, 15, 175);
73+
imgui_colours[BaseColour::Border] = flow::ui::Colour(15, 15, 15);
74+
imgui_colours[BaseColour::PopupBg] = imgui_colours[BaseColour::WindowBg];
75+
imgui_colours[BaseColour::FrameBg] = flow::ui::Colour(15, 15, 15);
76+
imgui_colours[BaseColour::MenuBarBg] = flow::ui::Colour(21, 21, 21);
77+
imgui_colours[BaseColour::TitleBg] = flow::ui::Colour(21, 21, 21);
78+
imgui_colours[BaseColour::TitleBgActive] = imgui_colours[BaseColour::TitleBg];
79+
imgui_colours[BaseColour::Tab] = flow::ui::Colour(21, 21, 21);
80+
imgui_colours[BaseColour::TabDimmed] = flow::ui::Colour(21, 21, 21);
81+
imgui_colours[BaseColour::TabHovered] = flow::ui::Colour(47, 47, 47);
82+
imgui_colours[BaseColour::TabSelected] = flow::ui::Colour(3, 98, 195);
83+
imgui_colours[BaseColour::TabDimmedSelected] = imgui_colours[BaseColour::TabSelected];
84+
imgui_colours[BaseColour::Button] = flow::ui::Colour(32, 32, 32);
85+
imgui_colours[BaseColour::ButtonHovered] = flow::ui::Colour(3, 98, 195);
86+
imgui_colours[BaseColour::ButtonActive] = flow::ui::Colour(13, 39, 77);
87+
imgui_colours[BaseColour::ScrollbarBg] = flow::ui::Colour(21, 21, 21);
88+
imgui_colours[BaseColour::ScrollbarGrab] = flow::ui::Colour(86, 86, 86);
89+
imgui_colours[BaseColour::TableBorderLight] = flow::ui::Colour(21, 21, 21);
90+
imgui_colours[BaseColour::TableBorderStrong] = flow::ui::Colour(21, 21, 21);
91+
imgui_colours[BaseColour::TableRowBg] = flow::ui::Colour(36, 36, 36);
92+
imgui_colours[BaseColour::TableRowBgAlt] = flow::ui::Colour(36, 36, 36);
93+
imgui_colours[BaseColour::Header] = flow::ui::Colour(47, 47, 47);
94+
imgui_colours[BaseColour::HeaderHovered] = flow::ui::Colour(50, 50, 50);
95+
imgui_colours[BaseColour::CheckMark] = flow::ui::Colour(3, 98, 195);
96+
97+
auto& colours = style.Colours.EditorColours;
98+
using EditorColour = flow::ui::Style::EditorColour;
99+
100+
colours[EditorColour::Bg] = flow::ui::Colour(38, 38, 38);
101+
colours[EditorColour::Grid] = flow::ui::Colour(52, 52, 52);
102+
colours[EditorColour::NodeBg] = flow::ui::Colour(15, 17, 15, 240);
103+
colours[EditorColour::NodeBorder] = flow::ui::Colour(0, 0, 0);
104+
colours[EditorColour::SelNodeBorder] = flow::ui::Colour(255, 255, 255);
105+
colours[EditorColour::Flow] = flow::ui::Colour(32, 191, 85);
106+
colours[EditorColour::FlowMarker] = flow::ui::Colour(32, 191, 85);
107+
colours[EditorColour::HighlightLinkBorder] = flow::ui::Colour(0, 188, 235);
108+
colours[EditorColour::SelLinkBorder] = flow::ui::Colour(0, 188, 235);
109+
};
110+
111+
try
112+
{
113+
app.Run();
114+
}
115+
catch (const std::exception& e)
116+
{
117+
SPDLOG_CRITICAL("Exiting with error: {0}", e.what());
118+
return EXIT_FAILURE;
119+
}
120+
catch (...)
121+
{
122+
SPDLOG_CRITICAL("Exiting with unknown error");
123+
return EXIT_FAILURE;
124+
}
125+
126+
return EXIT_SUCCESS;
127+
}

0 commit comments

Comments
 (0)