Imgui::InputText with std::string

2,117 views
Skip to first unread message

role...@gmail.com

unread,
Jun 8, 2021, 6:30:19 AM6/8/21
to vsg-users : VulkanSceneGraph Developer Discussion Group
Hi Robert,

Imgui has an ImGui::InputText element that uses char* to store the string. If you're using c++11 or higher then you can pull in a couple of extra files to use a std:string instead of char* (much more convenient). As this is everyone using vsgImGui I thought we could include it as standard. 

Most of the update is easy, but I'm not very good at cmake and can't see how to copy the header file over. The two changes I know of are:

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9f0c9e0..00efa48 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -14,6 +14,7 @@ set(HEADERS
    imgui/imstb_rectpack.h
    imgui/imstb_textedit.h
    imgui/imstb_truetype.h
+    imgui/misc/cpp/imgui_stdlib.h
 )
 
set(SOURCES
@@ -25,6 +26,7 @@ set(SOURCES
    imgui/backends/imgui_impl_vulkan.cpp
    vsgImGui/RenderImGui.cpp
    vsgImGui/SendEventsToImGui.cpp
+    imgui/misc/cpp/imgui_stdlib.cpp
)

You then have to copy imgui_stdlib.h to the vsgImGui install include directory - can you help with this please? If I copy it manually and include the header in my code then std:strings work.

Thanks for your help.

Regards,
Roland


Robert Osfield

unread,
Jun 8, 2021, 7:09:05 AM6/8/21
to vsg-...@googlegroups.com
Hi Roland,

On Tue, 8 Jun 2021 at 11:30, role...@gmail.com <role...@gmail.com> wrote:
You then have to copy imgui_stdlib.h to the vsgImGui install include directory - can you help with this please? If I copy it manually and include the header in my code then std:strings work.

In vsgImGui/CMakeLists.txt there is the following for copying/syncing the imgui.h file, it sounds like the imgui_stdlib.h could be treated the same way:

execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/include/vsgImGui/imgui.h ${CMAKE_SOURCE_DIR}/src/imgui/imgui.h RESULT_VARIABLE compare_result)
if (compare_result EQUAL 0)
else()
    file(COPY ${CMAKE_SOURCE_DIR}/src/imgui/imgui.h DESTINATION ${CMAKE_SOURCE_DIR}/include/vsgImGui/)
    message("copied imgui.h")
endif()

Cheers,
Robert.

 

role...@gmail.com

unread,
Jun 23, 2021, 6:44:32 AM6/23/21
to vsg-users : VulkanSceneGraph Developer Discussion Group
Thanks, Robert. PR sent.

I was also getting errors because imgui.h couldn't find imconfig.h, so I've copied that to the install directory as well.

Regards,
Roland
Reply all
Reply to author
Forward
0 new messages