Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move UI Code to the Engine #594

Merged
merged 7 commits into from
Sep 27, 2023
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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
[submodule "core/lib/spdlog"]
path = core/lib/spdlog
url = https://github.com/gabime/spdlog
[submodule "core/lib/imgui"]
path = core/lib/imgui
url = https://github.com/ocornut/imgui.git
[submodule "core/lib/fmt"]
path = core/lib/fmt
url = https://github.com/fmtlib/fmt.git
Expand All @@ -25,3 +22,6 @@
[submodule "docs/css/m.css"]
path = docs/css
url = https://github.com/mosra/m.css
[submodule "engine/lib/imgui"]
path = engine/lib/imgui
url = https://github.com/ocornut/imgui.git
17 changes: 1 addition & 16 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ set(CUBOS_CORE_SOURCE
"src/cubos/core/al/oal_audio_device.cpp"
"src/cubos/core/al/oal_audio_device.hpp"

"src/cubos/core/ui/imgui.cpp"
"src/cubos/core/ui/serialization.cpp"
"src/cubos/core/ui/ecs.cpp"

"src/cubos/core/ecs/entity_manager.cpp"
"src/cubos/core/ecs/component_manager.cpp"
"src/cubos/core/ecs/commands.cpp"
Expand Down Expand Up @@ -154,25 +150,14 @@ endif ()

add_subdirectory(lib/json)

add_library(imgui STATIC
"lib/imgui/imgui.cpp"
"lib/imgui/imgui_draw.cpp"
"lib/imgui/imgui_tables.cpp"
"lib/imgui/imgui_widgets.cpp"
"lib/imgui/imgui_demo.cpp"
"lib/imgui/misc/cpp/imgui_stdlib.cpp"
)

target_include_directories(imgui PUBLIC "lib/imgui" "lib/imgui/misc/cpp/imgui_stdlib.hpp")

add_subdirectory(lib/stduuid)
target_link_libraries(cubos-core PUBLIC stduuid)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

target_compile_definitions(cubos-core PUBLIC GLM_FORCE_SILENT_WARNINGS) # Needed for compilation to succeed on MSVC
target_link_libraries(cubos-core PUBLIC glm::glm spdlog imgui fmt::fmt json ${CMAKE_DL_LIBS})
target_link_libraries(cubos-core PUBLIC glm::glm spdlog fmt::fmt json ${CMAKE_DL_LIBS})
target_link_libraries(cubos-core PRIVATE glad Threads::Threads)

# Add core tests
Expand Down
25 changes: 0 additions & 25 deletions core/include/cubos/core/ui/ecs.hpp

This file was deleted.

16 changes: 0 additions & 16 deletions core/include/cubos/core/ui/module.dox

This file was deleted.

1 change: 0 additions & 1 deletion core/lib/imgui
Submodule imgui deleted from 075f4a
1 change: 0 additions & 1 deletion core/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ make_sample(DIR "ecs/general")
make_sample(DIR "gl/compute")
make_sample(DIR "gl/debug_renderer")
make_sample(DIR "gl/quad")
make_sample(DIR "ui")
95 changes: 0 additions & 95 deletions core/samples/ui/main.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions core/src/cubos/core/ui/ecs.cpp

This file was deleted.

14 changes: 14 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ set(CUBOS_ENGINE_SOURCE
"src/cubos/engine/window/plugin.cpp"

"src/cubos/engine/imgui/plugin.cpp"
"src/cubos/engine/imgui/imgui.cpp"
"src/cubos/engine/imgui/serialization.cpp"

"src/cubos/engine/tools/asset_explorer/plugin.cpp"
"src/cubos/engine/tools/settings_inspector/plugin.cpp"
Expand Down Expand Up @@ -67,6 +69,18 @@ target_include_directories(cubos-engine PUBLIC "include" PRIVATE "src")
target_link_libraries(cubos-engine PUBLIC cubos-core)
cubos_common_target_options(cubos-engine)

add_library(imgui STATIC
"lib/imgui/imgui.cpp"
"lib/imgui/imgui_draw.cpp"
"lib/imgui/imgui_tables.cpp"
"lib/imgui/imgui_widgets.cpp"
"lib/imgui/imgui_demo.cpp"
"lib/imgui/misc/cpp/imgui_stdlib.cpp"
)

target_include_directories(imgui PUBLIC "lib/imgui" "lib/imgui/misc/cpp/imgui_stdlib.hpp")
target_link_libraries(cubos-engine PUBLIC imgui)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(cubos-engine PUBLIC -Wno-attributes)
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// @file
/// @brief Functions for showing and editing serializable objects in the UI.
/// @ingroup core-ui
/// @ingroup imgui-plugin

#pragma once

#include <cubos/core/data/package.hpp>

namespace cubos::core::ui
namespace cubos::engine
{
/// @brief Shows a packaged object's properties in the UI. Should be called inside a
/// `ImGui::BeginTable(2)` and `ImGui::EndTable()` block.
Expand All @@ -16,8 +16,8 @@ namespace cubos::core::ui
///
/// @param pkg Packaged object to show.
/// @param name Name of the object.
/// @ingroup core-ui
void showPackage(const data::Package& pkg, const std::string& name);
/// @ingroup imgui-plugin
void imguiShowPackage(const core::data::Package& pkg, const std::string& name);

/// @brief Shows a packaged object's properties in the UI, allowing the user to edit the
/// object. Should be called inside a `ImGui::BeginTable(3)` and `ImGui::EndTable()` block.
Expand All @@ -29,8 +29,8 @@ namespace cubos::core::ui
/// @param pkg Packaged object to edit.
/// @param name Name of the object.
/// @return True if the object was modified, false otherwise.
/// @ingroup core-ui
bool editPackage(data::Package& pkg, const std::string& name);
/// @ingroup imgui-plugin
bool imguiEditPackage(core::data::Package& pkg, const std::string& name);

/// @brief Shows a serializable object's properties in the UI. Should be called inside a
/// `ImGui::BeginTable(2)` and `ImGui::EndTable()` block.
Expand All @@ -40,12 +40,12 @@ namespace cubos::core::ui
/// @tparam T Type of the serializable object.
/// @param object Object to show.
/// @param name Name of the object.
/// @ingroup core-ui
/// @ingroup imgui-plugin
template <typename T>
inline void show(const T& object, const std::string& name)
inline void imguiShow(const T& object, const std::string& name)
{
auto pkg = data::Package::from(object);
showPackage(pkg, name);
auto pkg = core::data::Package::from(object);
imguiShowPackage(pkg, name);
}

/// @brief Shows a serializable object's properties in the UI. Should be called inside a
Expand All @@ -58,17 +58,17 @@ namespace cubos::core::ui
/// @param object Object to edit.
/// @param name Name of the object.
/// @return True if the object was edited, false otherwise.
/// @ingroup core-ui
/// @ingroup imgui-plugin
template <typename T>
inline bool edit(T& object, const std::string& name)
inline bool imguiEdit(T& object, const std::string& name)
{
auto pkg = data::Package::from(object);
if (editPackage(pkg, name))
auto pkg = core::data::Package::from(object);
if (imguiEditPackage(pkg, name))
{
pkg.into(object);
return true;
}

return false;
}
} // namespace cubos::core::ui
} // namespace cubos::engine
1 change: 1 addition & 0 deletions engine/lib/imgui
Submodule imgui added at 94da58
Loading
Loading