diff --git a/src/Magnum/ImGuiIntegration/Integration.h b/src/Magnum/ImGuiIntegration/Integration.h index db0795b3..db67995a 100644 --- a/src/Magnum/ImGuiIntegration/Integration.h +++ b/src/Magnum/ImGuiIntegration/Integration.h @@ -57,11 +57,27 @@ Example usage: #include "Magnum/ImGuiIntegration/visibility.h" /* defines IMGUI_API */ #include +#include #include #include -/* Don't list (useless) Magnum and Math namespaces without anything else */ +/* Don't list (useless) Corrade and Magnum and Math namespaces without anything else */ #ifndef DOXYGEN_GENERATING_OUTPUT + +/* Currently present only in the features/string_view branch of ImGui */ +#ifdef IMGUI_HAS_IMSTR +namespace Corrade { namespace Containers { namespace Implementation { + +template<> struct StringViewConverter { + static StringView from(const ImStrv& other) { + return StringView{other.Begin, other.length()}; + } + static ImStrv to(StringView other) { return ImStrv{other.begin(), other.end()}; } +}; + +}}} +#endif + namespace Magnum { namespace Math { namespace Implementation { /* ImVec2 */ diff --git a/src/Magnum/ImGuiIntegration/Test/IntegrationTest.cpp b/src/Magnum/ImGuiIntegration/Test/IntegrationTest.cpp index 745c937b..318419c9 100644 --- a/src/Magnum/ImGuiIntegration/Test/IntegrationTest.cpp +++ b/src/Magnum/ImGuiIntegration/Test/IntegrationTest.cpp @@ -35,6 +35,7 @@ namespace Magnum { namespace ImGuiIntegration { namespace Test { namespace { struct IntegrationTest: TestSuite::Tester { explicit IntegrationTest(); + void stringView(); void vector2(); void vector4(); void color(); @@ -42,12 +43,25 @@ struct IntegrationTest: TestSuite::Tester { }; IntegrationTest::IntegrationTest() { - addTests({&IntegrationTest::vector2, + addTests({&IntegrationTest::stringView, + &IntegrationTest::vector2, &IntegrationTest::vector4, &IntegrationTest::color, &IntegrationTest::colorLiterals}); } +void IntegrationTest::stringView() { +#ifdef IMGUI_HAS_IMSTR + ImStrv imStrv{"Hello World!"}; + StringView stringView("Hello World!"); + + CORRADE_COMPARE(StringView(imVec2), vec2); + + ImStrv c(stringView); + CORRADE_COMPARE(c, stringView); +#endif +} + void IntegrationTest::vector2() { ImVec2 imVec2{1.1f, 1.2f}; Vector2 vec2(1.1f, 1.2f);