-
Notifications
You must be signed in to change notification settings - Fork 46
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
ImGuiIntegration: Add conversion between ImStrv and StringView #96
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -57,11 +57,27 @@ Example usage: | |||||||
#include "Magnum/ImGuiIntegration/visibility.h" /* defines IMGUI_API */ | ||||||||
|
||||||||
#include <imgui.h> | ||||||||
#include <Corrade/Containers/StringView.h> | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would ideally be also wrapped in Alternatively I was thinking of deinlining the conversion into a new |
||||||||
#include <Magnum/Types.h> | ||||||||
#include <Magnum/Math/Vector.h> | ||||||||
|
||||||||
/* 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 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
... or something like that, to make it clear why the ifdef is there. |
||||||||
namespace Corrade { namespace Containers { namespace Implementation { | ||||||||
|
||||||||
template<> struct StringViewConverter<const char, ImStrv> { | ||||||||
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 */ | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -35,19 +35,40 @@ namespace Magnum { namespace ImGuiIntegration { namespace Test { namespace { | |||||||||||||
struct IntegrationTest: TestSuite::Tester { | ||||||||||||||
explicit IntegrationTest(); | ||||||||||||||
|
||||||||||||||
#ifdef IMGUI_HAS_IMSTR | ||||||||||||||
void stringView(); | ||||||||||||||
#endif | ||||||||||||||
Comment on lines
+38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Indent preprocessor same as other code. Same below :) |
||||||||||||||
void vector2(); | ||||||||||||||
void vector4(); | ||||||||||||||
void color(); | ||||||||||||||
void colorLiterals(); | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
IntegrationTest::IntegrationTest() { | ||||||||||||||
addTests({&IntegrationTest::vector2, | ||||||||||||||
addTests({ | ||||||||||||||
#ifdef IMGUI_HAS_IMSTR | ||||||||||||||
&IntegrationTest::stringView, | ||||||||||||||
#endif | ||||||||||||||
&IntegrationTest::vector2, | ||||||||||||||
&IntegrationTest::vector4, | ||||||||||||||
&IntegrationTest::color, | ||||||||||||||
&IntegrationTest::colorLiterals}); | ||||||||||||||
&IntegrationTest::colorLiterals | ||||||||||||||
}); | ||||||||||||||
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unneeded change. |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#ifdef IMGUI_HAS_IMSTR | ||||||||||||||
void IntegrationTest::stringView() { | ||||||||||||||
using Containers::StringView; | ||||||||||||||
StringView stringView("Hello World!"); | ||||||||||||||
ImStrv imStrv{"Hello World!"}; | ||||||||||||||
|
||||||||||||||
CORRADE_COMPARE(StringView(imStrv), stringView); | ||||||||||||||
|
||||||||||||||
ImStrv c(stringView); | ||||||||||||||
CORRADE_COMPARE(c, stringView); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, as far as I can see, this would convert Instead, isn't there something like |
||||||||||||||
} | ||||||||||||||
#endif | ||||||||||||||
|
||||||||||||||
void IntegrationTest::vector2() { | ||||||||||||||
ImVec2 imVec2{1.1f, 1.2f}; | ||||||||||||||
Vector2 vec2(1.1f, 1.2f); | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the docs above to mention the string conversion, please ;)
Also feel free to add yourself to the copyright header in the license block above the file.