Skip to content

Commit c65de3c

Browse files
committed
Improve const correctness
1 parent 683792e commit c65de3c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

.clang-tidy

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Checks: >
2424
-cppcoreguidelines-pro-type-union-access,
2525
-cppcoreguidelines-special-member-functions,
2626
-misc-include-cleaner,
27+
-misc-misplaced-const,
2728
-misc-non-private-member-variables-in-classes,
2829
-modernize-avoid-c-arrays,
2930
-modernize-use-trailing-return-type,

imgui-SFML.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void setClipboardText(ImGuiContext* /*ctx*/, const char* text)
209209
{
210210
static std::string s_clipboardText;
211211

212-
auto tmp = sf::Clipboard::getString().toUtf8();
212+
const auto tmp = sf::Clipboard::getString().toUtf8();
213213
s_clipboardText.assign(tmp.begin(), tmp.end());
214214
return s_clipboardText.c_str();
215215
}
@@ -350,10 +350,10 @@ bool Init(sf::Window& window, const sf::Vector2f& displaySize, bool loadDefaultF
350350

351351
void SetCurrentWindow(const sf::Window& window)
352352
{
353-
auto found = std::find_if(s_windowContexts.begin(),
354-
s_windowContexts.end(),
355-
[&](std::unique_ptr<WindowContext>& ctx)
356-
{ return ctx->window->getNativeHandle() == window.getNativeHandle(); });
353+
const auto found = std::find_if(s_windowContexts.begin(),
354+
s_windowContexts.end(),
355+
[&](std::unique_ptr<WindowContext>& ctx)
356+
{ return ctx->window->getNativeHandle() == window.getNativeHandle(); });
357357
assert(found != s_windowContexts.end() &&
358358
"Failed to find the window. Forgot to call ImGui::SFML::Init for the window?");
359359
s_currWindowCtx = found->get();
@@ -590,18 +590,18 @@ void Shutdown(const sf::Window& window)
590590
const bool needReplacement = (s_currWindowCtx->window->getNativeHandle() == window.getNativeHandle());
591591

592592
// remove window's context
593-
auto found = std::find_if(s_windowContexts.begin(),
594-
s_windowContexts.end(),
595-
[&](std::unique_ptr<WindowContext>& ctx)
596-
{ return ctx->window->getNativeHandle() == window.getNativeHandle(); });
593+
const auto found = std::find_if(s_windowContexts.begin(),
594+
s_windowContexts.end(),
595+
[&](std::unique_ptr<WindowContext>& ctx)
596+
{ return ctx->window->getNativeHandle() == window.getNativeHandle(); });
597597
assert(found != s_windowContexts.end() &&
598598
"Window wasn't inited properly: forgot to call ImGui::SFML::Init(window)?");
599599
s_windowContexts.erase(found); // s_currWindowCtx can become invalid here!
600600

601601
// set current context to some window for convenience if needed
602602
if (needReplacement)
603603
{
604-
auto it = s_windowContexts.begin();
604+
const auto it = s_windowContexts.begin();
605605
if (it != s_windowContexts.end())
606606
{
607607
// set to some other window
@@ -809,7 +809,7 @@ void Image(const sf::Sprite& sprite, const sf::Color& tintColor, const sf::Color
809809

810810
void Image(const sf::Sprite& sprite, const sf::Vector2f& size, const sf::Color& tintColor, const sf::Color& borderColor)
811811
{
812-
auto [uv0, uv1, textureID] = getSpriteTextureData(sprite);
812+
const auto [uv0, uv1, textureID] = getSpriteTextureData(sprite);
813813
ImGui::Image(textureID, toImVec2(size), uv0, uv1, toImColor(tintColor), toImColor(borderColor));
814814
}
815815

@@ -850,7 +850,7 @@ bool ImageButton(const char* id,
850850

851851
bool ImageButton(const char* id, const sf::Sprite& sprite, const sf::Vector2f& size, const sf::Color& bgColor, const sf::Color& tintColor)
852852
{
853-
auto [uv0, uv1, textureID] = getSpriteTextureData(sprite);
853+
const auto [uv0, uv1, textureID] = getSpriteTextureData(sprite);
854854
return ImGui::ImageButton(id, textureID, toImVec2(size), uv0, uv1, toImColor(bgColor), toImColor(tintColor));
855855
}
856856

0 commit comments

Comments
 (0)