Skip to content
Closed
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: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ if (EMSCRIPTEN)
endif()



#------------------------------------------------------------------------------
# Advanced build options / ImPlot
#------------------------------------------------------------------------------
option(HELLOIMGUI_USE_IMPLOT "Enable ImPlot support" ON)
option(HELLOIMGUI_DOWNLOAD_IMPLOT_IF_NEEDED "Download ImPlot if not found" ON)
#------------------------------------------------------------------------------
# Advanced build options / HelloImGui
#------------------------------------------------------------------------------
Expand Down
59 changes: 58 additions & 1 deletion hello_imgui_cmake/hello_imgui_build_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,60 @@ function(him_add_hello_imgui)
else()
target_link_libraries(${HELLOIMGUI_TARGET} PUBLIC imgui)
endif()

if (HELLOIMGUI_USE_IMPLOT)
target_link_libraries(${HELLOIMGUI_TARGET} PUBLIC implot)
target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_USE_IMPLOT)
endif()
add_library(hello-imgui::hello_imgui ALIAS hello_imgui)
him_add_installable_dependency(${HELLOIMGUI_TARGET})
endfunction()
###################################################################################################
# Build implot: API = him_build_implot
###################################################################################################
function(him_build_implot)
if (NOT HELLOIMGUI_USE_IMPLOT)
return()
endif()

# Попробовать найти системный пакет
find_package(implot CONFIG QUIET)
if (implot_FOUND)
message(STATUS "HelloImGui: using ImPlot from find_package")
return()
endif()

if (HELLOIMGUI_FETCH_FORBIDDEN OR NOT HELLOIMGUI_DOWNLOAD_IMPLOT_IF_NEEDED)
message(FATAL_ERROR "ImPlot not found and fetching is forbidden")
endif()

message(STATUS "HelloImGui: downloading and building ImPlot")

include(FetchContent)
FetchContent_Declare(
implot
GIT_REPOSITORY https://github.com/epezent/implot.git
GIT_TAG v0.17
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(implot)

add_library(implot
${implot_SOURCE_DIR}/implot.cpp
${implot_SOURCE_DIR}/implot_items.cpp
)

target_include_directories(implot PUBLIC
$<BUILD_INTERFACE:${implot_SOURCE_DIR}>
)

target_link_libraries(implot PUBLIC imgui)

add_library(implot::implot ALIAS implot)

him_add_installable_dependency(implot)

hello_imgui_msvc_target_set_folder(implot ${HELLOIMGUI_SOLUTIONFOLDER}/external)
endfunction()
###################################################################################################
# Build imgui: API = him_build_imgui + him_install_imgui (to be called at the end)
###################################################################################################
Expand Down Expand Up @@ -324,6 +372,14 @@ function(him_install_imgui)
if(HELLOIMGUI_USE_FREETYPE)
install(FILES ${HELLOIMGUI_IMGUI_SOURCE_DIR}/misc/freetype/imgui_freetype.h DESTINATION include)
endif()
if(TARGET implot)
install(TARGETS implot DESTINATION ./lib/)
install(FILES
${implot_SOURCE_DIR}/implot.h
${implot_SOURCE_DIR}/implot_internal.h
DESTINATION include
)
endif()
endif()
endfunction()

Expand Down Expand Up @@ -1319,6 +1375,7 @@ function(him_main_add_hello_imgui_library)
him_sanity_checks()
him_add_stb_image()
him_build_imgui()
him_build_implot()
him_add_hello_imgui()
him_add_nlohmann_json()

Expand Down
26 changes: 25 additions & 1 deletion src/hello_imgui_demos/hello_world/hello_world.main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
#include "hello_imgui/hello_imgui.h"
#include <implot.h>
int main(int , char *[])
{
float a[]= {1.0,2,3};
float b[]= {1.0,2,3};
HelloImGui::Run(
[]{ ImGui::Text("Hello, world!"); }, // Gui code
[&a, &b]
{
static bool init = false;
if (!init)
{
ImPlot::CreateContext();
init = true;
}
ImGui::Text("Hello, world!");
if (ImPlot::BeginPlot("Plot"))
{
ImPlot::PlotLine("Line", a, b, 3);
ImPlot::EndPlot();
}

if (ImPlot::BeginPlot("Plot 2 "))
{
ImPlot::PlotLine("Line 2", a, b, 3);
ImPlot::EndPlot();
}

}, // Gui code
"Hello!", // Window title
true // Window size auto
);
Expand Down