diff --git a/include/TGUI/Backend/Font/BackendFont.hpp b/include/TGUI/Backend/Font/BackendFont.hpp index f783f67c9..1f40b3c06 100644 --- a/include/TGUI/Backend/Font/BackendFont.hpp +++ b/include/TGUI/Backend/Font/BackendFont.hpp @@ -275,7 +275,7 @@ namespace tgui /// /// Calling this function with the same parameters results in the same id, while other parameters result in another id. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TGUI_NODISCARD std::uint64_t constructGlyphKey(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness) const; + TGUI_NODISCARD static std::uint64_t constructGlyphKey(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected: diff --git a/include/TGUI/Backend/Renderer/BackendText.hpp b/include/TGUI/Backend/Renderer/BackendText.hpp index 63ee2238a..bfadebf7c 100644 --- a/include/TGUI/Backend/Renderer/BackendText.hpp +++ b/include/TGUI/Backend/Renderer/BackendText.hpp @@ -175,14 +175,14 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Helper function used by updateVertices to add vertices for a glyph ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - void addGlyphQuad(std::vector& vertices, Vector2f position, const Vertex::Color& color, - const FontGlyph& glyph, float fontScale, float italicShear); + static void addGlyphQuad(std::vector& vertices, Vector2f position, const Vertex::Color& color, + const FontGlyph& glyph, float fontScale, float italicShear); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Helper function used by updateVertices to add vertices for a line ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - void addLine(std::vector& vertices, float lineLength, float lineTop, const Vertex::Color& color, - float offset, float thickness, float outlineThickness, float fontScale); + static void addLine(std::vector& vertices, float lineLength, float lineTop, const Vertex::Color& color, + float offset, float thickness, float outlineThickness, float fontScale); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected: diff --git a/include/TGUI/Backend/Window/BackendGui.hpp b/include/TGUI/Backend/Window/BackendGui.hpp index 8ba69ffa6..cce136ee2 100644 --- a/include/TGUI/Backend/Window/BackendGui.hpp +++ b/include/TGUI/Backend/Window/BackendGui.hpp @@ -663,7 +663,7 @@ namespace tgui // The key parameter should be a value from Numpad0 to Numpad9 and the output is the key code that corresponds to the // wanted functionality (e.g. for Numpad0 we return the Insert key). Unknown is returned for Numpad5. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Event::KeyboardKey translateKeypadKey(Event::KeyboardKey key); + static Event::KeyboardKey translateKeypadKey(Event::KeyboardKey key); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public: diff --git a/include/TGUI/Backend/Window/SFML/BackendSFML.hpp b/include/TGUI/Backend/Window/SFML/BackendSFML.hpp index f3f8ef9ef..23c049cba 100644 --- a/include/TGUI/Backend/Window/SFML/BackendSFML.hpp +++ b/include/TGUI/Backend/Window/SFML/BackendSFML.hpp @@ -156,7 +156,7 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Helper function to create a system cursor ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TGUI_NODISCARD std::unique_ptr createSystemCursor(Cursor::Type type); + TGUI_NODISCARD static std::unique_ptr createSystemCursor(Cursor::Type type); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Helper function to update the mouse cursors on all attached guis diff --git a/include/TGUI/Container.hpp b/include/TGUI/Container.hpp index e058c42eb..df6b1d99e 100644 --- a/include/TGUI/Container.hpp +++ b/include/TGUI/Container.hpp @@ -603,7 +603,7 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Transform the mouse position for the child widget based its origin, rotation and scaling. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TGUI_NODISCARD Vector2f transformMousePos(const Widget::Ptr& widget, Vector2f mousePos) const; + TGUI_NODISCARD static Vector2f transformMousePos(const Widget::Ptr& widget, Vector2f mousePos) ; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Finishes adding a widget to the container diff --git a/include/TGUI/RendererDefines.hpp b/include/TGUI/RendererDefines.hpp index ec8c2afcd..84ef2983b 100644 --- a/include/TGUI/RendererDefines.hpp +++ b/include/TGUI/RendererDefines.hpp @@ -35,8 +35,7 @@ const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \ if (it != m_data->propertyValuePairs.end()) \ return it->second.getOutline(); \ - else \ - return {}; \ + return {}; \ } \ void CLASS::set##NAME(const tgui::Outline& outline) \ { \ @@ -51,8 +50,7 @@ const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \ if (it != m_data->propertyValuePairs.end()) \ return it->second.getColor(); \ - else \ - return DEFAULT; \ + return DEFAULT; \ } \ void CLASS::set##NAME(tgui::Color color) \ { \ @@ -67,8 +65,7 @@ const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \ if (it != m_data->propertyValuePairs.end()) \ return it->second.getTextStyle(); \ - else \ - return DEFAULT; \ + return DEFAULT; \ } \ void CLASS::set##NAME(tgui::TextStyles style) \ { \ @@ -83,8 +80,7 @@ const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \ if (it != m_data->propertyValuePairs.end()) \ return it->second.getNumber(); \ - else \ - return DEFAULT; \ + return DEFAULT; \ } #define TGUI_RENDERER_PROPERTY_NUMBER(CLASS, NAME, DEFAULT) \ @@ -102,8 +98,7 @@ const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \ if (it != m_data->propertyValuePairs.end()) \ return it->second.getBool(); \ - else \ - return DEFAULT; \ + return DEFAULT; \ } #define TGUI_RENDERER_PROPERTY_BOOL(CLASS, NAME, DEFAULT) \ @@ -121,11 +116,8 @@ const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \ if (it != m_data->propertyValuePairs.end()) \ return it->second.getTexture(); \ - else \ - { \ - m_data->propertyValuePairs[tgui::String(#NAME)] = {tgui::Texture{}}; \ - return m_data->propertyValuePairs[tgui::String(#NAME)].getTexture(); \ - } \ + m_data->propertyValuePairs[tgui::String(#NAME)] = {tgui::Texture{}}; \ + return m_data->propertyValuePairs[tgui::String(#NAME)].getTexture(); \ } \ void CLASS::set##NAME(const tgui::Texture& texture) \ { \ @@ -140,12 +132,9 @@ const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \ if (it != m_data->propertyValuePairs.end()) \ return it->second.getRenderer(); \ - else \ - { \ - const auto& renderer = tgui::Theme::getDefault()->getRendererNoThrow(RENDERER); \ - m_data->propertyValuePairs[tgui::String(#NAME)] = {renderer ? renderer : (DEFAULT)}; \ - return renderer; \ - } \ + const auto& renderer = tgui::Theme::getDefault()->getRendererNoThrow(RENDERER); \ + m_data->propertyValuePairs[tgui::String(#NAME)] = {renderer ? renderer : (DEFAULT)}; \ + return renderer; \ } \ void CLASS::set##NAME(std::shared_ptr renderer) \ { \ diff --git a/include/TGUI/SignalManager.hpp b/include/TGUI/SignalManager.hpp index 941d873e4..f9cbf9aec 100644 --- a/include/TGUI/SignalManager.hpp +++ b/include/TGUI/SignalManager.hpp @@ -177,12 +177,12 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @internal ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TGUI_NODISCARD std::pair makeSignal(const Delegate&); + TGUI_NODISCARD static std::pair makeSignal(const Delegate&); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @internal ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TGUI_NODISCARD std::pair makeSignalEx(const DelegateEx&); + TGUI_NODISCARD static std::pair makeSignalEx(const DelegateEx&); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @brief Function that is called each time new signal is created with it id diff --git a/include/TGUI/String.hpp b/include/TGUI/String.hpp index 064b2ea93..f8457509d 100644 --- a/include/TGUI/String.hpp +++ b/include/TGUI/String.hpp @@ -754,7 +754,7 @@ namespace tgui void resize(std::size_t count, char16_t ch); void resize(std::size_t count, char32_t ch); - void swap(String& other); + void swap(String& other) noexcept; TGUI_NODISCARD bool contains(char c) const noexcept; TGUI_NODISCARD bool contains(wchar_t c) const noexcept; diff --git a/src/Backend/Font/BackendFont.cpp b/src/Backend/Font/BackendFont.cpp index d11809c94..9badf33b5 100644 --- a/src/Backend/Font/BackendFont.cpp +++ b/src/Backend/Font/BackendFont.cpp @@ -116,7 +116,7 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - std::uint64_t BackendFont::constructGlyphKey(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness) const + std::uint64_t BackendFont::constructGlyphKey(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness) { // Create a unique key for every character. // Technically it would be possible to specify character sizes and outline thicknesses that can't uniquely be mapped diff --git a/src/Backend/Renderer/BackendRenderTarget.cpp b/src/Backend/Renderer/BackendRenderTarget.cpp index 2e06aeeb8..5f14fdf42 100644 --- a/src/Backend/Renderer/BackendRenderTarget.cpp +++ b/src/Backend/Renderer/BackendRenderTarget.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -455,10 +456,7 @@ namespace tgui float radius, const Borders& borders, const Color& borderColor) { // Radius can never be larger than half the width or height - if (radius > size.x / 2) - radius = size.x / 2; - if (radius > size.y / 2) - radius = size.y / 2; + radius = std::min({radius, size.x / 2, size.y / 2}); const unsigned int nrCornerPoints = std::max(1u, static_cast(std::ceil(radius * 2))); const std::vector& outerPoints = drawRoundedRectHelperGetPoints(nrCornerPoints, size, radius, 0); @@ -468,10 +466,7 @@ namespace tgui { radius = std::max(0.f, radius - borderWidth); const Vector2f innerSize = {std::max(0.f, size.x - 2*borderWidth), std::max(0.f, size.y - 2*borderWidth)}; - if (radius > innerSize.x / 2) - radius = innerSize.x / 2; - if (radius > innerSize.y / 2) - radius = innerSize.y / 2; + radius = std::min({radius, innerSize.x / 2, innerSize.y / 2}); const std::vector& innerPoints = drawRoundedRectHelperGetPoints(nrCornerPoints, innerSize, radius, borderWidth); diff --git a/src/Backend/Renderer/BackendText.cpp b/src/Backend/Renderer/BackendText.cpp index 5409105f0..c6de2c12b 100644 --- a/src/Backend/Renderer/BackendText.cpp +++ b/src/Backend/Renderer/BackendText.cpp @@ -24,6 +24,7 @@ #include +#include #include ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -193,8 +194,7 @@ namespace tgui if (!m_font) return {}; - if (index > m_string.length()) - index = m_string.length(); + index = std::min(index, m_string.length()); const bool isBold = static_cast(m_style) & TextStyle::Bold; const float whitespaceWidth = m_font->getGlyph(U' ', m_characterSize, isBold).advance; @@ -376,8 +376,8 @@ namespace tgui { const auto& glyph = m_font->getGlyph(curChar, m_characterSize, isBold, m_outlineThickness); - float top = glyph.bounds.top; - float right = glyph.bounds.left + glyph.bounds.width; + const float top = glyph.bounds.top; + const float right = glyph.bounds.left + glyph.bounds.width; // Add the outline glyph to the vertices addGlyphQuad(*m_outlineVertices, {x, y}, vertexOutlineColor, glyph, fontScale, italicShear); diff --git a/src/Backend/Renderer/SFML-Graphics/BackendRenderTargetSFML.cpp b/src/Backend/Renderer/SFML-Graphics/BackendRenderTargetSFML.cpp index e010b1ba1..2a2b8bf53 100644 --- a/src/Backend/Renderer/SFML-Graphics/BackendRenderTargetSFML.cpp +++ b/src/Backend/Renderer/SFML-Graphics/BackendRenderTargetSFML.cpp @@ -109,7 +109,7 @@ namespace tgui if (clippingRequired) addClippingLayer(transformedStates, {{visibleRect.left, visibleRect.top}, {visibleRect.width, visibleRect.height}}); - std::shared_ptr texture = sprite.getTexture().getData()->backendTexture; + const std::shared_ptr texture = sprite.getTexture().getData()->backendTexture; sf::RenderStates sfStates = convertRenderStates(transformedStates, texture); TGUI_ASSERT(std::dynamic_pointer_cast(sprite.getTexture().getData()->backendTexture), "BackendRenderTargetSFML::drawSprite requires backend texture of type BackendTextureSFML"); diff --git a/src/Backend/Renderer/SFML-Graphics/CanvasSFML.cpp b/src/Backend/Renderer/SFML-Graphics/CanvasSFML.cpp index 3d98eb8ee..786e15aa4 100644 --- a/src/Backend/Renderer/SFML-Graphics/CanvasSFML.cpp +++ b/src/Backend/Renderer/SFML-Graphics/CanvasSFML.cpp @@ -114,8 +114,7 @@ namespace tgui { if (canvas) return std::static_pointer_cast(canvas->clone()); - else - return nullptr; + return nullptr; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Backend/Window/Backend.cpp b/src/Backend/Window/Backend.cpp index 368847d83..c27195e7a 100644 --- a/src/Backend/Window/Backend.cpp +++ b/src/Backend/Window/Backend.cpp @@ -109,8 +109,7 @@ namespace tgui { if (m_fontBackend) return {static_cast(defaultFontBytes), sizeof(defaultFontBytes)}; - else - return {}; + return {}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -131,9 +130,9 @@ namespace tgui sprite->updateVertices(); // Update the size of all texts in all widgets - for (auto& gui : m_guis) + for (const auto& gui : m_guis) { - for (auto& widget : gui->getWidgets()) + for (const auto& widget : gui->getWidgets()) widget->updateTextSize(); } } diff --git a/src/Backend/Window/BackendGui.cpp b/src/Backend/Window/BackendGui.cpp index 6234f597f..f3d77f347 100644 --- a/src/Backend/Window/BackendGui.cpp +++ b/src/Backend/Window/BackendGui.cpp @@ -147,7 +147,7 @@ namespace tgui if (event.type == Event::Type::MouseMoved) return m_container->processMouseMoveEvent(mouseCoords); - else if (event.type == Event::Type::MouseWheelScrolled) + if (event.type == Event::Type::MouseWheelScrolled) { if (m_container->processScrollEvent(event.mouseWheel.delta, mouseCoords, false)) return true; @@ -155,17 +155,15 @@ namespace tgui // Even if no scrollbar moved, we will still absorb the scroll event when the mouse is on top of a widget return m_container->getWidgetAtPos(mouseCoords, false) != nullptr; } - else if (event.type == Event::Type::MouseButtonPressed) + if (event.type == Event::Type::MouseButtonPressed) return m_container->processMousePressEvent(event.mouseButton.button, mouseCoords); - else // if (event.type == Event::Type::MouseButtonReleased) - { - const bool eventHandled = m_container->processMouseReleaseEvent(event.mouseButton.button, mouseCoords); - if (event.mouseButton.button == Event::MouseButton::Left) - m_container->leftMouseButtonNoLongerDown(); - else if (event.mouseButton.button == Event::MouseButton::Right) - m_container->rightMouseButtonNoLongerDown(); - return eventHandled; - } + // if (event.type == Event::Type::MouseButtonReleased) + const bool eventHandled = m_container->processMouseReleaseEvent(event.mouseButton.button, mouseCoords); + if (event.mouseButton.button == Event::MouseButton::Left) + m_container->leftMouseButtonNoLongerDown(); + else if (event.mouseButton.button == Event::MouseButton::Right) + m_container->rightMouseButtonNoLongerDown(); + return eventHandled; } case Event::Type::KeyPressed: { @@ -178,8 +176,7 @@ namespace tgui return true; } - else - return m_container->processKeyPressEvent(event.key); + return m_container->processKeyPressEvent(event.key); } case Event::Type::TextEntered: { @@ -271,8 +268,7 @@ namespace tgui { if (m_container->getInheritedFont()) return m_container->getInheritedFont(); - else - return Font::getGlobalFont(); + return Font::getGlobalFont(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -556,7 +552,7 @@ namespace tgui if (m_tooltipTime >= ToolTip::getInitialDelay()) { const Vector2f lastMousePos = mapPixelToCoords(m_lastMousePos); - Widget::Ptr tooltip = m_container->askToolTip(lastMousePos); + const Widget::Ptr tooltip = m_container->askToolTip(lastMousePos); if (tooltip) { m_visibleToolTip = tooltip; diff --git a/src/Backend/Window/SFML/BackendGuiSFML.cpp b/src/Backend/Window/SFML/BackendGuiSFML.cpp index b9ffbcd11..eb4a6fef7 100644 --- a/src/Backend/Window/SFML/BackendGuiSFML.cpp +++ b/src/Backend/Window/SFML/BackendGuiSFML.cpp @@ -258,8 +258,7 @@ namespace tgui Optional duration = Timer::getNextScheduledTime(); if (duration && (*duration < std::chrono::milliseconds(10))) return *duration; - else - return Duration{std::chrono::milliseconds(10)}; + return Duration{std::chrono::milliseconds(10)}; }; setDrawingUpdatesTime(false); diff --git a/src/Backend/Window/SFML/BackendSFML.cpp b/src/Backend/Window/SFML/BackendSFML.cpp index e8f3d7f70..1504fd0ef 100644 --- a/src/Backend/Window/SFML/BackendSFML.cpp +++ b/src/Backend/Window/SFML/BackendSFML.cpp @@ -314,8 +314,7 @@ namespace tgui auto cursor = sf::Cursor::createFromSystem(typeSFML); if (cursor) return std::make_unique(std::move(*cursor)); - else - return nullptr; + return nullptr; #else auto cursor = std::make_unique(); if (cursor->loadFromSystem(typeSFML)) diff --git a/src/Base64.cpp b/src/Base64.cpp index 41ee9aaaf..0a1899b2b 100644 --- a/src/Base64.cpp +++ b/src/Base64.cpp @@ -96,7 +96,7 @@ namespace tgui unsigned int val = 0; int valShift = -8; - for (char c : data) + for (const char c : data) { const std::uint8_t tableIndex = base64InverseCharactersTable[static_cast(c)]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index) diff --git a/src/Components.cpp b/src/Components.cpp index 17b88b8c7..02430590a 100644 --- a/src/Components.cpp +++ b/src/Components.cpp @@ -491,11 +491,10 @@ namespace dev { if ((pos.x < m_borders.getLeft()) || (pos.y < m_borders.getTop()) || (pos.x >= m_borders.getLeft() + m_clientSize.x) || (pos.y >= m_borders.getTop() + m_clientSize.y)) return false; - else - return m_sprite.isTransparentPixel(pos - m_borders.getOffset()); + return m_sprite.isTransparentPixel(pos - m_borders.getOffset()); } - else /// TODO: Perform check when using rounded corners - return false; + /// TODO: Perform check when using rounded corners + return false; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -849,8 +848,7 @@ namespace dev { if (transparentTexture && m_sprite.isSet()) /// TODO: transparentTexture should be option on Texture (similar to Smooth) instead of a parameter return m_sprite.isTransparentPixel(pos); - else - return false; + return false; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Container.cpp b/src/Container.cpp index 14cf59c8b..7aa50243c 100644 --- a/src/Container.cpp +++ b/src/Container.cpp @@ -64,7 +64,7 @@ namespace tgui if (child->getToolTip()) addRenderer(child->getToolTip()->getSharedRenderer()->getData().get(), child->getToolTip().get()); - Container* childContainer = dynamic_cast(child.get()); + const Container* const childContainer = dynamic_cast(child.get()); if (childContainer) getAllRenderers(orderedRenderers, rendererToWidgetsMap, childContainer); else @@ -101,7 +101,7 @@ namespace tgui } else { - String value = ObjectConverter{pair.second}.getString(); + const String value = ObjectConverter{pair.second}.getString(); // Skip empty values if (value.empty()) @@ -236,10 +236,10 @@ namespace tgui // They all need to be in m_widgets before setParent is called on the first widget, // which is why we can't just use call add(widget) for each widget. m_widgets.reserve(right.m_widgets.size()); - for (auto& widget : right.m_widgets) + for (const auto& widget : right.m_widgets) m_widgets.emplace_back(widget->clone()); - for (auto& widget : m_widgets) + for (const auto& widget : m_widgets) widgetAdded(widget); updateChildrenWithAutoLayout(); @@ -358,7 +358,7 @@ namespace tgui // If we still couldn't find it then check if there are any SubwidgetContainer widgets and search their subwidgets for (const auto& child : m_widgets) { - auto subWidgetContainer = dynamic_cast(child.get()); + const auto* const subWidgetContainer = dynamic_cast(child.get()); if (subWidgetContainer) { Widget::Ptr widget = subWidgetContainer->getContainer()->get(widgetName); @@ -547,7 +547,7 @@ namespace tgui if (replaceExisting) removeAllWidgets(); - if (rootNode->propertyValuePairs.size() != 0) + if (!rootNode->propertyValuePairs.empty()) Widget::load(rootNode, {}); std::vector>>> widgetsToLoad; @@ -571,7 +571,7 @@ namespace tgui const auto& constructor = WidgetFactory::getConstructFunction(widgetType); if (constructor) { - Widget::Ptr widget = constructor(); + const Widget::Ptr widget = constructor(); add(widget, objectName); // We delay loading of widgets until they have all been added to the container. @@ -586,7 +586,7 @@ namespace tgui for (auto& pair : widgetsToLoad) { - Widget::Ptr& widget = pair.first; + const Widget::Ptr& widget = pair.first; const auto& node = pair.second.get(); widget->load(node, availableRenderers); } @@ -724,7 +724,7 @@ namespace tgui // insert first to avoid the widget being destroyed before it is copied, but that could lead // to an unnecessary reallocation and we would still need to be careful with using the widget // reference in the lines below the erase. So we make a copy of the shared_ptr to avoid issues. - Widget::Ptr widgetToMove = widget; + const Widget::Ptr widgetToMove = widget; // Move the widget to the new index m_widgets.erase(m_widgets.begin() + static_cast(currentWidgetIndex)); @@ -802,7 +802,7 @@ namespace tgui // If the widget is a container then look inside it if we are looking for the leaf widget if (recursive && widget->isContainer()) { - Container::Ptr container = std::static_pointer_cast(widget); + const Container::Ptr container = std::static_pointer_cast(widget); auto childWidget = container->getWidgetAtPos(transformMousePos(widget, pos) - container->getPosition(), true); if (childWidget) return childWidget; @@ -1065,7 +1065,7 @@ namespace tgui mousePos -= getPosition() + getChildWidgetsOffset(); - Widget::Ptr widget = getWidgetBelowMouse(mousePos); + const Widget::Ptr widget = getWidgetBelowMouse(mousePos); if (widget && (widget->isEnabled() || ToolTip::getShowOnDisabledWidget())) { toolTip = widget->askToolTip(transformMousePos(widget, mousePos)); @@ -1131,7 +1131,7 @@ namespace tgui if (nameSeparator != String::npos) className = Deserializer::deserialize(ObjectConverter::Type::String, childNode->name.substr(nameSeparator + 1)).getString(); - Widget::Ptr childWidget = constructor(); + const Widget::Ptr childWidget = constructor(); add(childWidget, className); // We delay loading of widgets until they have all been added to the container. @@ -1143,9 +1143,9 @@ namespace tgui throw Exception{U"No construct function exists for widget type '" + widgetType + U"'."}; } - for (auto& pair : widgetsToLoad) + for (const auto& pair : widgetsToLoad) { - Widget::Ptr& childWidget = pair.first; + const Widget::Ptr& childWidget = pair.first; const auto& childNode = pair.second.get(); childWidget->load(childNode, renderers); } @@ -1162,10 +1162,10 @@ namespace tgui return true; } - const auto oldWidgetBelowMouse = m_widgetBelowMouse.get(); + const auto* const oldWidgetBelowMouse = m_widgetBelowMouse.get(); // Check if the mouse is on top of a widget - Widget::Ptr widget = updateWidgetBelowMouse(mousePos); + const Widget::Ptr widget = updateWidgetBelowMouse(mousePos); if (widget != nullptr) { // Send the event to the widget @@ -1187,7 +1187,7 @@ namespace tgui bool Container::processMousePressEvent(Event::MouseButton button, Vector2f mousePos) { // Check if the mouse is on top of a widget - Widget::Ptr widget = updateWidgetBelowMouse(mousePos); + const Widget::Ptr widget = updateWidgetBelowMouse(mousePos); if (widget) { if (button == Event::MouseButton::Left) @@ -1211,22 +1211,20 @@ namespace tgui return true; } - else // The mouse did not went down on a widget, so unfocus the focused child widget, but keep ourselves focused + // The mouse did not went down on a widget, so unfocus the focused child widget, but keep ourselves focused + if (button == Event::MouseButton::Left) { - if (button == Event::MouseButton::Left) - { - m_widgetWithLeftMouseDown = nullptr; - m_draggingWidget = false; - } - else if (button == Event::MouseButton::Right) - m_widgetWithRightMouseDown = nullptr; + m_widgetWithLeftMouseDown = nullptr; + m_draggingWidget = false; + } + else if (button == Event::MouseButton::Right) + m_widgetWithRightMouseDown = nullptr; - if (m_focusedWidget) - m_focusedWidget->setFocused(false); + if (m_focusedWidget) + m_focusedWidget->setFocused(false); - m_focusedWidget = nullptr; - setFocused(true); - } + m_focusedWidget = nullptr; + setFocused(true); return false; } @@ -1235,7 +1233,7 @@ namespace tgui bool Container::processMouseReleaseEvent(Event::MouseButton button, Vector2f mousePos) { - Widget::Ptr widgetBelowMouse = updateWidgetBelowMouse(mousePos); + const Widget::Ptr widgetBelowMouse = updateWidgetBelowMouse(mousePos); if (widgetBelowMouse != nullptr) widgetBelowMouse->mouseReleased(button, transformMousePos(widgetBelowMouse, mousePos)); @@ -1246,7 +1244,7 @@ namespace tgui m_draggingWidget = false; return true; } - else if ((button == Event::MouseButton::Right) && m_widgetWithRightMouseDown) + if ((button == Event::MouseButton::Right) && m_widgetWithRightMouseDown) { m_widgetWithRightMouseDown->rightMouseButtonNoLongerDown(); m_widgetWithRightMouseDown = nullptr; @@ -1261,7 +1259,7 @@ namespace tgui bool Container::processScrollEvent(float delta, Vector2f pos, bool touch) { // Send the event to the widget below the mouse - Widget::Ptr widget = updateWidgetBelowMouse(pos); + const Widget::Ptr widget = updateWidgetBelowMouse(pos); if (widget != nullptr) return widget->scrolled(delta, transformMousePos(widget, pos), touch); @@ -1290,17 +1288,17 @@ namespace tgui m_focusedWidget->getNavigationUp()->setFocused(true); return true; } - else if ((event.code == Event::KeyboardKey::Down) && m_focusedWidget->getNavigationDown()) + if ((event.code == Event::KeyboardKey::Down) && m_focusedWidget->getNavigationDown()) { m_focusedWidget->getNavigationDown()->setFocused(true); return true; } - else if ((event.code == Event::KeyboardKey::Left) && m_focusedWidget->getNavigationLeft()) + if ((event.code == Event::KeyboardKey::Left) && m_focusedWidget->getNavigationLeft()) { m_focusedWidget->getNavigationLeft()->setFocused(true); return true; } - else if ((event.code == Event::KeyboardKey::Right) && m_focusedWidget->getNavigationRight()) + if ((event.code == Event::KeyboardKey::Right) && m_focusedWidget->getNavigationRight()) { m_focusedWidget->getNavigationRight()->setFocused(true); return true; @@ -1565,7 +1563,7 @@ namespace tgui // Try to focus the first focusable widget in the container auto oldUnfocusedWidget = container->m_focusedWidget; container->m_focusedWidget = nullptr; - bool childFocused = reverseWidgetOrder ? container->focusPreviousWidget(true) : container->focusNextWidget(true); + const bool childFocused = reverseWidgetOrder ? container->focusPreviousWidget(true) : container->focusNextWidget(true); if (oldUnfocusedWidget && (oldUnfocusedWidget != container->m_focusedWidget)) oldUnfocusedWidget->setFocused(false); @@ -1587,7 +1585,7 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Vector2f Container::transformMousePos(const Widget::Ptr& widget, Vector2f mousePos) const + Vector2f Container::transformMousePos(const Widget::Ptr& widget, Vector2f mousePos) { const bool defaultOrigin = (widget->getOrigin().x == 0) && (widget->getOrigin().y == 0); const bool scaledOrRotated = (widget->getScale().x != 1) || (widget->getScale().y != 1) || (widget->getRotation() != 0); diff --git a/src/Font.cpp b/src/Font.cpp index 725fc8eae..0b68a5c62 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -137,11 +137,9 @@ namespace tgui { if (m_backendFont != nullptr) return m_backendFont->getGlyph(codePoint, characterSize, bold, outlineThickness); - else - { - TGUI_PRINT_WARNING("Font::getGlyph called on font that wasn't initialized"); - return {}; - } + + TGUI_PRINT_WARNING("Font::getGlyph called on font that wasn't initialized"); + return {}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -150,8 +148,7 @@ namespace tgui { if (m_backendFont) return m_backendFont->getKerning(first, second, characterSize, bold); - else - return 0; + return 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -160,8 +157,7 @@ namespace tgui { if (m_backendFont) return m_backendFont->getLineSpacing(characterSize); - else - return 0; + return 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -170,8 +166,7 @@ namespace tgui { if (m_backendFont) return m_backendFont->getFontHeight(characterSize); - else - return 0; + return 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -188,8 +183,7 @@ namespace tgui { if (m_backendFont) return m_backendFont->isSmooth(); - else - return true; + return true; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Global.cpp b/src/Global.cpp index f11b15ff6..2eb715fd1 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -174,7 +174,7 @@ namespace tgui return nullptr; auto closeFileFunc = [](FILE* fp){ fclose(fp); }; - std::unique_ptr file(rawFilePtr, closeFileFunc); + const std::unique_ptr file(rawFilePtr, closeFileFunc); if (fseek(file.get(), 0, SEEK_END) != 0) return nullptr; diff --git a/src/Layout.cpp b/src/Layout.cpp index 6f3bff4e5..22bde711d 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -189,21 +189,20 @@ namespace tgui *this = Layout{expression.substr(1, expression.size()-2)}; return; } - else if ((searchPos == 3) && (bracketPos == expression.size()-1) && (expression.substr(0, 3) == U"min")) + if ((searchPos == 3) && (bracketPos == expression.size()-1) && (expression.substr(0, 3) == U"min")) { const auto& minSubExpressions = parseMinMaxExpresssion(expression.substr(4, expression.size() - 5)); *this = Layout{Operation::Minimum, std::make_unique(minSubExpressions.first), std::make_unique(minSubExpressions.second)}; return; } - else if ((searchPos == 3) && (bracketPos == expression.size()-1) && (expression.substr(0, 3) == U"max")) + if ((searchPos == 3) && (bracketPos == expression.size()-1) && (expression.substr(0, 3) == U"max")) { const auto& maxSubExpressions = parseMinMaxExpresssion(expression.substr(4, expression.size() - 5)); *this = Layout{Operation::Maximum, std::make_unique(maxSubExpressions.first), std::make_unique(maxSubExpressions.second)}; return; } - else // The brackets form a sub-expression - searchPos = bracketPos; - + // The brackets form a sub-expression + searchPos = bracketPos; break; } @@ -215,12 +214,10 @@ namespace tgui TGUI_PRINT_WARNING("bracket mismatch while parsing layout string '" << expression << "'."); return; } - else - { - // Search for the next operator, starting from the closing bracket, but keeping prevSearchPos before the opening bracket - searchPos = expression.find_first_of("+-/*()", searchPos + 1); - continue; - } + + // Search for the next operator, starting from the closing bracket, but keeping prevSearchPos before the opening bracket + searchPos = expression.find_first_of("+-/*()", searchPos + 1); + continue; } case ')': TGUI_PRINT_WARNING("bracket mismatch while parsing layout string '" << expression << "'."); @@ -454,7 +451,7 @@ namespace tgui void Layout::replaceValue(const Layout& value) { // Copy the layout, but keep the original parent - const auto oldParent = m_parent; + auto* const oldParent = m_parent; *this = value; m_parent = oldParent; @@ -471,15 +468,13 @@ namespace tgui { return String::fromNumber(m_value); } - else if (m_operation == Operation::Minimum) + if (m_operation == Operation::Minimum) { return U"min(" + m_leftOperand->toString() + U", " + m_rightOperand->toString() + U")"; } - else if (m_operation == Operation::Maximum) - { + if (m_operation == Operation::Maximum) return U"max(" + m_leftOperand->toString() + U", " + m_rightOperand->toString() + U")"; - } - else if ((m_operation == Operation::Plus) || (m_operation == Operation::Minus) || (m_operation == Operation::Multiplies) || (m_operation == Operation::Divides)) + if ((m_operation == Operation::Plus) || (m_operation == Operation::Minus) || (m_operation == Operation::Multiplies) || (m_operation == Operation::Divides)) { char operatorChar; if (m_operation == Operation::Plus) @@ -507,66 +502,54 @@ namespace tgui if (subExpressionNeedsBrackets(m_leftOperand) && subExpressionNeedsBrackets(m_rightOperand)) return U"(" + m_leftOperand->toString() + U") " + operatorChar + U" (" + m_rightOperand->toString() + U")"; - else if (subExpressionNeedsBrackets(m_leftOperand)) + if (subExpressionNeedsBrackets(m_leftOperand)) return U"(" + m_leftOperand->toString() + U") " + operatorChar + U" " + m_rightOperand->toString(); - else if (subExpressionNeedsBrackets(m_rightOperand)) + if (subExpressionNeedsBrackets(m_rightOperand)) return m_leftOperand->toString() + U" " + operatorChar + U" (" + m_rightOperand->toString() + U")"; - else - { - if ((m_operation == Operation::Multiplies) && (m_leftOperand->m_operation == Operation::Value) && (m_rightOperand->toString() == U"100%")) - return String::fromNumber(m_leftOperand->getValue() * 100) + '%'; - else - return m_leftOperand->toString() + U" " + operatorChar + U" " + m_rightOperand->toString(); - } + if ((m_operation == Operation::Multiplies) && (m_leftOperand->m_operation == Operation::Value) && (m_rightOperand->toString() == U"100%")) + return String::fromNumber(m_leftOperand->getValue() * 100) + '%'; + return m_leftOperand->toString() + U" " + operatorChar + U" " + m_rightOperand->toString(); } - else - { - if (m_boundString == U"&.innersize") - return U"100%"; + if (m_boundString == U"&.innersize") + return U"100%"; - // Hopefully the expression is stored in the bound string, otherwise (i.e. when bind functions were used) it is infeasible to turn it into a string - if (!m_boundString.empty()) - return m_boundString; - else + // Hopefully the expression is stored in the bound string, otherwise (i.e. when bind functions were used) it is infeasible to turn it into a string + if (!m_boundString.empty()) + return m_boundString; + if ((m_operation == Operation::BindingPosX) || (m_operation == Operation::BindingPosY) + || (m_operation == Operation::BindingLeft) || (m_operation == Operation::BindingTop) + || (m_operation == Operation::BindingWidth) || (m_operation == Operation::BindingHeight) + || (m_operation == Operation::BindingInnerWidth) || (m_operation == Operation::BindingInnerHeight)) + { + TGUI_ASSERT(m_boundWidget != nullptr, "There has to be a bound widget with this operation type"); + const String boundWidgetName = m_boundWidget->getWidgetName(); + if (boundWidgetName.empty()) { - if ((m_operation == Operation::BindingPosX) || (m_operation == Operation::BindingPosY) - || (m_operation == Operation::BindingLeft) || (m_operation == Operation::BindingTop) - || (m_operation == Operation::BindingWidth) || (m_operation == Operation::BindingHeight) - || (m_operation == Operation::BindingInnerWidth) || (m_operation == Operation::BindingInnerHeight)) - { - TGUI_ASSERT(m_boundWidget != nullptr, "There has to be a bound widget with this operation type"); - const String boundWidgetName = m_boundWidget->getWidgetName(); - if (boundWidgetName.empty()) - { - TGUI_PRINT_WARNING("layout can't be correctly converted to string because the bound widget has no name"); - } - - if (m_operation == Operation::BindingPosX) - return boundWidgetName + U".x"; - else if (m_operation == Operation::BindingPosY) - return boundWidgetName + U".y"; - else if (m_operation == Operation::BindingLeft) - return boundWidgetName + U".left"; - else if (m_operation == Operation::BindingTop) - return boundWidgetName + U".top"; - else if (m_operation == Operation::BindingWidth) - return boundWidgetName + U".width"; - else if (m_operation == Operation::BindingHeight) - return boundWidgetName + U".height"; - else if (m_operation == Operation::BindingInnerWidth) - return boundWidgetName + U".innerwidth"; - else - { - TGUI_ASSERT(m_operation == Operation::BindingInnerHeight, "Operation can't be anything other than BindingInnerHeight here"); - return boundWidgetName + U".innerheight"; - } - } - - // The layout contains an empty string - TGUI_ASSERT(m_operation == Operation::BindingString, "All operation types should have been covered already"); - return m_boundString; + TGUI_PRINT_WARNING("layout can't be correctly converted to string because the bound widget has no name"); } + + if (m_operation == Operation::BindingPosX) + return boundWidgetName + U".x"; + if (m_operation == Operation::BindingPosY) + return boundWidgetName + U".y"; + if (m_operation == Operation::BindingLeft) + return boundWidgetName + U".left"; + if (m_operation == Operation::BindingTop) + return boundWidgetName + U".top"; + if (m_operation == Operation::BindingWidth) + return boundWidgetName + U".width"; + if (m_operation == Operation::BindingHeight) + return boundWidgetName + U".height"; + if (m_operation == Operation::BindingInnerWidth) + return boundWidgetName + U".innerwidth"; + + TGUI_ASSERT(m_operation == Operation::BindingInnerHeight, "Operation can't be anything other than BindingInnerHeight here"); + return boundWidgetName + U".innerheight"; } + + // The layout contains an empty string + TGUI_ASSERT(m_operation == Operation::BindingString, "All operation types should have been covered already"); + return m_boundString; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -836,22 +819,19 @@ namespace tgui { if (xAxis) return parseBindingString(U"width", widget, xAxis); - else - return parseBindingString(U"height", widget, xAxis); + return parseBindingString(U"height", widget, xAxis); } else if (expression == U"innersize") { if (xAxis) return parseBindingString(U"innerwidth", widget, xAxis); - else - return parseBindingString(U"innerheight", widget, xAxis); + return parseBindingString(U"innerheight", widget, xAxis); } else if ((expression == U"pos") || (expression == U"position")) { if (xAxis) return parseBindingString(U"x", widget, xAxis); - else - return parseBindingString(U"y", widget, xAxis); + return parseBindingString(U"y", widget, xAxis); } else { @@ -867,10 +847,10 @@ namespace tgui // If there is no parent yet then patiently wait until the widget is added to its parent return; } - else if (!widgetName.empty()) + if (!widgetName.empty()) { // If the widget is a container, search in its children first - Container* container = dynamic_cast(widget); + const Container* const container = dynamic_cast(widget); if (container != nullptr) { const auto& widgets = container->getWidgets(); diff --git a/src/Loading/DataIO.cpp b/src/Loading/DataIO.cpp index f2ae24899..8d1222c50 100644 --- a/src/Loading/DataIO.cpp +++ b/src/Loading/DataIO.cpp @@ -80,8 +80,7 @@ { \ if (ReturnErrorOnEOF) \ return "Unexpected EOF while parsing."; \ - else \ - return ""; \ + return ""; \ } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -106,7 +105,7 @@ namespace tgui stream.read(&c, 1); return word; } - else if (!std::isspace(static_cast(c)) && (c != '=') && (c != ';') && (c != ':') && (c != '{') && (c != '}')) + if (!std::isspace(static_cast(c)) && (c != '=') && (c != ';') && (c != ':') && (c != '{') && (c != '}')) { stream.read(&c, 1); @@ -150,10 +149,7 @@ namespace tgui if (c == '"' && !backslash) break; - if (c == '\\' && !backslash) - backslash = true; - else - backslash = false; + backslash = c == '\\' && !backslash; } } else @@ -228,10 +224,7 @@ namespace tgui if (c == '"' && !backslash) break; - if (c == '\\' && !backslash) - backslash = true; - else - backslash = false; + backslash = c == '\\' && !backslash; } if (stream.peek() == EOF) @@ -242,13 +235,13 @@ namespace tgui if ((c == '=') || (c == '{')) return ""; - else if ((c == ';') || (c == '}')) + if ((c == ';') || (c == '}')) { // Remove trailing whitespace before returning the line line.erase(line.find_last_not_of(" \n\r\t")+1); return line; } - else if (::isspace(c)) + if (::isspace(c)) { stream.read(&c, 1); if (!whitespaceFound) @@ -327,10 +320,7 @@ namespace tgui break; } - if (line[i] == '\\' && !backslash) - backslash = true; - else - backslash = false; + backslash = line[i] == '\\' && !backslash; i++; } @@ -349,21 +339,16 @@ namespace tgui node->propertyValuePairs[key] = std::move(valueNode); return ""; } - else - { - if (stream.peek() == EOF) - return "Found EOF while trying to read a value."; - else - { - chr = static_cast(stream.peek()); - if (chr == '=') - return "Found '=' while trying to read a value."; - else if (chr == '{') - return "Found '{' while trying to read a value."; - else - return "Found empty value."; - } - } + + if (stream.peek() == EOF) + return "Found EOF while trying to read a value."; + + chr = static_cast(stream.peek()); + if (chr == '=') + return "Found '=' while trying to read a value."; + if (chr == '{') + return "Found '{' while trying to read a value."; + return "Found empty value."; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -375,7 +360,7 @@ namespace tgui stream.read(&chr, 1); REMOVE_WHITESPACE_AND_COMMENTS(true) - String baseSectionName = readWord(stream); + const String baseSectionName = readWord(stream); if (baseSectionName.empty()) return "Expected name of base section to inherit from after ':'."; @@ -445,12 +430,12 @@ namespace tgui { REMOVE_WHITESPACE_AND_COMMENTS(true) - String word = readWord(stream); - if (word == U"") + const String word = readWord(stream); + if (word.empty()) { if (stream.peek() == EOF) return "Found EOF while trying to read property or nested section name."; - else if (stream.peek() == '}') + if (stream.peek() == '}') { node->children.push_back(std::move(sectionNode)); @@ -464,7 +449,7 @@ namespace tgui REMOVE_WHITESPACE_AND_COMMENTS(false) return ""; } - else if (stream.peek() != '{') + if (stream.peek() != '{') return "Expected property or nested section name, found '" + String(1, static_cast(stream.peek())) + "' instead."; } @@ -500,8 +485,8 @@ namespace tgui { REMOVE_WHITESPACE_AND_COMMENTS(false) - String word = readWord(stream); - if (word == U"") + const String word = readWord(stream); + if (word.empty()) { REMOVE_WHITESPACE_AND_COMMENTS(true) if (stream.peek() != '{') @@ -511,12 +496,11 @@ namespace tgui REMOVE_WHITESPACE_AND_COMMENTS(true) if (stream.peek() == '{') return parseSection(stream, root, word); - else if (stream.peek() == '=') + if (stream.peek() == '=') return parseKeyValue(stream, root, word); - else if (stream.peek() == ':') + if (stream.peek() == ':') return parseInheritance(stream, root, word); - else - return "Expected '{', '=' or ':', found '" + String(1, static_cast(stream.peek())) + "' instead."; + return "Expected '{', '=' or ':', found '" + String(1, static_cast(stream.peek())) + "' instead."; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -535,7 +519,7 @@ namespace tgui output.emplace_back(" " + pair.first + " = " + pair.second->value + ";"); } - if (node->propertyValuePairs.size() > 0 && node->children.size() > 0) + if (!node->propertyValuePairs.empty() && !node->children.empty()) output.emplace_back(""); if (!node->children.empty()) @@ -581,8 +565,7 @@ namespace tgui auto lineNumber = std::count(str.begin(), str.begin() + static_cast(position), U'\n') + 1; throw Exception{U"Error while parsing input at line " + String::fromNumber(lineNumber) + U". " + error}; } - else - throw Exception{U"Error while parsing input. " + error}; + throw Exception{U"Error while parsing input. " + error}; } } @@ -596,14 +579,14 @@ namespace tgui for (const auto& pair : rootNode->propertyValuePairs) stream << pair.first << " = " << pair.second->value << ";" << std::endl; - if (rootNode->propertyValuePairs.size() > 0 && rootNode->children.size() > 0) + if (!rootNode->propertyValuePairs.empty() && !rootNode->children.empty()) stream << std::endl; std::vector output; for (std::size_t i = 0; i < rootNode->children.size(); ++i) { for (const auto& line : convertNodesToLines(rootNode->children[i])) - output.emplace_back(std::move(line)); + output.emplace_back(line); if (i < rootNode->children.size()-1) output.emplace_back(""); diff --git a/src/Loading/Deserializer.cpp b/src/Loading/Deserializer.cpp index 7404b2ca0..9a14e214a 100644 --- a/src/Loading/Deserializer.cpp +++ b/src/Loading/Deserializer.cpp @@ -41,18 +41,18 @@ namespace tgui if (c == U'a') return 10; - else if (c == U'b') + if (c == U'b') return 11; - else if (c == U'c') + if (c == U'c') return 12; - else if (c == U'd') + if (c == U'd') return 13; - else if (c == U'e') + if (c == U'e') return 14; - else if (c == U'f') + if (c == U'f') return 15; - else // if (c >= U'0' && c <= U'9') - return static_cast(c - U'0'); + // if (c >= U'0' && c <= U'9') + return static_cast(c - U'0'); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -82,12 +82,12 @@ namespace tgui rect = {tokens[0].toUInt(), tokens[1].toUInt(), tokens[2].toUInt(), tokens[3].toUInt()}; return true; } - else if (!rectRequiresFourValues && (tokens.size() == 2)) + if (!rectRequiresFourValues && (tokens.size() == 2)) { rect = {tokens[0].toUInt(), tokens[1].toUInt(), 0, 0}; return true; } - else if (!rectRequiresFourValues && (tokens.size() == 1)) + if (!rectRequiresFourValues && (tokens.size() == 1)) { rect = {tokens[0].toUInt(), tokens[0].toUInt(), 0, 0}; return true; @@ -103,10 +103,10 @@ namespace tgui { if (viewEqualIgnoreCase(str, U"true") || viewEqualIgnoreCase(str, U"yes") || viewEqualIgnoreCase(str, U"on") || viewEqualIgnoreCase(str, U"1")) return {true}; - else if (viewEqualIgnoreCase(str, U"false") || viewEqualIgnoreCase(str, U"no") || viewEqualIgnoreCase(str, U"off") || viewEqualIgnoreCase(str, U"0")) + if (viewEqualIgnoreCase(str, U"false") || viewEqualIgnoreCase(str, U"no") || viewEqualIgnoreCase(str, U"off") || viewEqualIgnoreCase(str, U"0")) return {false}; - else - throw Exception{U"Failed to deserialize boolean from '" + str + U"'"}; + + throw Exception{U"Failed to deserialize boolean from '" + str + U"'"}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -159,7 +159,7 @@ namespace tgui // You can only have hex characters for (std::size_t i = 1; i < str.length(); ++i) { - if (!((str[i] >= '0' && str[i] <= '9') || (str[i] >= 'a' && str[i] <= 'f'))) + if ((str[i] < '0' || str[i] > '9') && (str[i] < 'a' || str[i] > 'f')) throw Exception{U"Failed to deserialize color '" + str + U"'. Value started but '#' but contained an invalid character afterwards."}; } @@ -170,35 +170,31 @@ namespace tgui static_cast(hexToDec(str[2]) * 16 + hexToDec(str[2])), static_cast(hexToDec(str[3]) * 16 + hexToDec(str[3]))}; } - else if (str.length() == 5) + if (str.length() == 5) { return Color{static_cast(hexToDec(str[1]) * 16 + hexToDec(str[1])), static_cast(hexToDec(str[2]) * 16 + hexToDec(str[2])), static_cast(hexToDec(str[3]) * 16 + hexToDec(str[3])), static_cast(hexToDec(str[4]) * 16 + hexToDec(str[4]))}; } - else if (str.length() == 7) + if (str.length() == 7) { return Color{static_cast(hexToDec(str[1]) * 16 + hexToDec(str[2])), static_cast(hexToDec(str[3]) * 16 + hexToDec(str[4])), static_cast(hexToDec(str[5]) * 16 + hexToDec(str[6]))}; } - else // if (str.length() == 9) - { - return Color{static_cast(hexToDec(str[1]) * 16 + hexToDec(str[2])), - static_cast(hexToDec(str[3]) * 16 + hexToDec(str[4])), - static_cast(hexToDec(str[5]) * 16 + hexToDec(str[6])), - static_cast(hexToDec(str[7]) * 16 + hexToDec(str[8]))}; - } + // if (str.length() == 9) + return Color{static_cast(hexToDec(str[1]) * 16 + hexToDec(str[2])), + static_cast(hexToDec(str[3]) * 16 + hexToDec(str[4])), + static_cast(hexToDec(str[5]) * 16 + hexToDec(str[6])), + static_cast(hexToDec(str[7]) * 16 + hexToDec(str[8]))}; } - else // Color doesn't start with '#' + // Color doesn't start with '#' + // Check if the color is represented by a string with its name + for (const auto& pair : Color::colorNamesMap) { - // Check if the color is represented by a string with its name - for (const auto& pair : Color::colorNamesMap) - { - if (str == pair.first) - return pair.second; - } + if (str == pair.first) + return pair.second; } // The string can optionally start with "rgb" or "rgba", but this is ignored @@ -249,8 +245,7 @@ namespace tgui return {result}; } - else - return {value}; + return {value}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -279,12 +274,12 @@ namespace tgui const std::vector tokens = Deserializer::split(str, ','); if (tokens.size() == 1) return {Outline{tokens[0]}}; - else if (tokens.size() == 2) + if (tokens.size() == 2) return {Outline{tokens[0], tokens[1]}}; - else if (tokens.size() == 4) + if (tokens.size() == 4) return {Outline{tokens[0], tokens[1], tokens[2], tokens[3]}}; - else - throw Exception{U"Failed to deserialize outline '" + value + U"'. Expected numbers separated with a comma."}; + + throw Exception{U"Failed to deserialize outline '" + value + U"'. Expected numbers separated with a comma."}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -348,13 +343,12 @@ namespace tgui smooth = true; break; } - else if (viewEqualIgnoreCase(smoothParam, U"nosmooth")) + if (viewEqualIgnoreCase(smoothParam, U"nosmooth")) { smooth = false; break; } - else - throw Exception{U"Failed to deserialize texture '" + value + U"'. Invalid text found behind filename."}; + throw Exception{U"Failed to deserialize texture '" + value + U"'. Invalid text found behind filename."}; } if (word.empty()) @@ -422,7 +416,7 @@ namespace tgui ObjectConverter deserializeTextStyle(const String& style) { unsigned int decodedStyle = TextStyle::Regular; - std::vector styles = Deserializer::split(style, '|'); + const std::vector styles = Deserializer::split(style, '|'); for (const auto& elem : styles) { if (viewEqualIgnoreCase(elem, U"bold")) diff --git a/src/Loading/Serializer.cpp b/src/Loading/Serializer.cpp index b89bae3da..fcec39827 100644 --- a/src/Loading/Serializer.cpp +++ b/src/Loading/Serializer.cpp @@ -44,18 +44,17 @@ namespace tgui if (c == 10) return 'A'; - else if (c == 11) + if (c == 11) return 'B'; - else if (c == 12) + if (c == 12) return 'C'; - else if (c == 13) + if (c == 13) return 'D'; - else if (c == 14) + if (c == 14) return 'E'; - else if (c == 15) + if (c == 15) return 'F'; - else - return static_cast(c + '0'); + return static_cast(c + '0'); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -78,8 +77,7 @@ namespace tgui { if (value.getBool()) return "true"; - else - return "false"; + return "false"; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -88,15 +86,14 @@ namespace tgui { if (value.getFont() && !value.getFont().getId().empty()) return Serializer::serialize({value.getFont().getId()}); - else - return "null"; + return "null"; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// String serializeColor(ObjectConverter&& value) { - Color color = value.getColor(); + const Color color = value.getColor(); if (!color.isSet()) return "None"; @@ -176,7 +173,7 @@ namespace tgui String serializeTexture(ObjectConverter&& value) { - Texture texture = value.getTexture(); + const Texture texture = value.getTexture(); if (!texture.getData()) return "None"; @@ -249,8 +246,8 @@ namespace tgui if (!encodedStyle.empty()) return encodedStyle.substr(3); - else // Something is wrong with the style parameter - return "Regular"; + // Something is wrong with the style parameter + return "Regular"; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Loading/Theme.cpp b/src/Loading/Theme.cpp index 9a275bcb3..266ffb8bc 100644 --- a/src/Loading/Theme.cpp +++ b/src/Loading/Theme.cpp @@ -682,7 +682,7 @@ namespace tgui for (const auto& property : properties) renderer->propertyValuePairs[property.first] = ObjectConverter(property.second); - for (auto& observer : renderer->observers) + for (const auto& observer : renderer->observers) observer->setRenderer(renderer); } } @@ -734,7 +734,7 @@ namespace tgui // We do this in a separate loop because all renderers need to be replaced before // we tell the observers (because e.g. an observer of the BitmapButton renderer might // want to access the Button renderer of the theme to inherit properties). - for (auto pair : m_renderers) + for (const auto& pair : m_renderers) { const auto& renderer = pair.second; @@ -772,7 +772,7 @@ namespace tgui m_renderers[id] = RendererData::create(); m_renderers[id]->connectedTheme = this; - auto& properties = m_themeLoader->load(m_primary, id); + const auto& properties = m_themeLoader->load(m_primary, id); for (const auto& property : properties) m_renderers[id]->propertyValuePairs[property.first] = ObjectConverter(property.second); @@ -808,8 +808,7 @@ namespace tgui auto propertyIt = m_globalProperties.find(property); if (propertyIt != m_globalProperties.end()) return propertyIt->second; - else - return {}; + return {}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -845,8 +844,7 @@ namespace tgui m_renderers.erase(it); return true; } - else - return false; + return false; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Loading/ThemeLoader.cpp b/src/Loading/ThemeLoader.cpp index 6de006b5b..7499a25de 100644 --- a/src/Loading/ThemeLoader.cpp +++ b/src/Loading/ThemeLoader.cpp @@ -148,7 +148,7 @@ namespace tgui void DefaultThemeLoader::flushCache(const String& filename) { - if (filename != U"") + if (!filename.empty()) { m_propertiesCache.erase(filename); m_globalPropertiesCache.erase(filename); @@ -164,7 +164,7 @@ namespace tgui void DefaultThemeLoader::preload(const String& filename) { - if (filename == U"") + if (filename.empty()) return; // Load the file when not already in cache @@ -240,8 +240,7 @@ namespace tgui { if (filename.empty()) return true; - else - return m_propertiesCache[filename].find(section) != m_propertiesCache[filename].end(); + return m_propertiesCache[filename].find(section) != m_propertiesCache[filename].end(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Loading/WidgetFactory.cpp b/src/Loading/WidgetFactory.cpp index a0bb3afd1..33c6bec1a 100644 --- a/src/Loading/WidgetFactory.cpp +++ b/src/Loading/WidgetFactory.cpp @@ -93,8 +93,7 @@ namespace tgui auto it = m_constructFunctions.find(type); if (it != m_constructFunctions.end()) return it->second; - else - return nullptr; + return nullptr; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Renderers/BoxLayoutRenderer.cpp b/src/Renderers/BoxLayoutRenderer.cpp index 332121865..8c378da17 100644 --- a/src/Renderers/BoxLayoutRenderer.cpp +++ b/src/Renderers/BoxLayoutRenderer.cpp @@ -43,17 +43,13 @@ namespace tgui auto it = m_data->propertyValuePairs.find("SpaceBetweenWidgets"); if (it != m_data->propertyValuePairs.end()) return it->second.getNumber(); - else + it = m_data->propertyValuePairs.find("Padding"); + if (it != m_data->propertyValuePairs.end()) { - it = m_data->propertyValuePairs.find("Padding"); - if (it != m_data->propertyValuePairs.end()) - { - const Padding padding = it->second.getOutline(); - return std::max(std::min(padding.getLeft(), padding.getRight()), std::min(padding.getTop(), padding.getBottom())); - } - else - return 0; + const Padding padding = it->second.getOutline(); + return std::max(std::min(padding.getLeft(), padding.getRight()), std::min(padding.getTop(), padding.getBottom())); } + return 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Renderers/ChildWindowRenderer.cpp b/src/Renderers/ChildWindowRenderer.cpp index 18bed4535..c1e7cb5b0 100644 --- a/src/Renderers/ChildWindowRenderer.cpp +++ b/src/Renderers/ChildWindowRenderer.cpp @@ -59,14 +59,11 @@ namespace tgui auto it = m_data->propertyValuePairs.find("TitleBarHeight"); if (it != m_data->propertyValuePairs.end()) return it->second.getNumber(); - else - { - it = m_data->propertyValuePairs.find("TextureTitleBar"); - if (it != m_data->propertyValuePairs.end() && it->second.getTexture().getData()) - return static_cast(it->second.getTexture().getImageSize().y); - else - return 20; - } + + it = m_data->propertyValuePairs.find("TextureTitleBar"); + if (it != m_data->propertyValuePairs.end() && it->second.getTexture().getData()) + return static_cast(it->second.getTexture().getImageSize().y); + return 20; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Renderers/WidgetRenderer.cpp b/src/Renderers/WidgetRenderer.cpp index 60dbc18e1..671f72471 100644 --- a/src/Renderers/WidgetRenderer.cpp +++ b/src/Renderers/WidgetRenderer.cpp @@ -154,8 +154,7 @@ namespace tgui auto it = m_data->propertyValuePairs.find("Font"); if (it != m_data->propertyValuePairs.end()) return it->second.getFont(); - else - return {}; + return {}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -172,8 +171,7 @@ namespace tgui auto it = m_data->propertyValuePairs.find("TextSize"); if (it != m_data->propertyValuePairs.end()) return static_cast(it->second.getNumber()); - else - return 0; + return 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -205,8 +203,7 @@ namespace tgui auto it = m_data->propertyValuePairs.find(property); if (it != m_data->propertyValuePairs.end()) return it->second; - else - return {}; + return {}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/SignalManager.cpp b/src/SignalManager.cpp index a24b315cd..db76592c3 100644 --- a/src/SignalManager.cpp +++ b/src/SignalManager.cpp @@ -68,10 +68,8 @@ namespace tgui m_signals.erase(it); return true; } - else - { - return false; - } + + return false; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Sprite.cpp b/src/Sprite.cpp index 8e82928f6..ab13aab8c 100644 --- a/src/Sprite.cpp +++ b/src/Sprite.cpp @@ -293,8 +293,8 @@ namespace tgui // Find out on which pixel the mouse is standing Vector2f pixel; - FloatRect middleRect = FloatRect{m_texture.getMiddleRect()}; - Vector2u imageSize = m_texture.getImageSize(); + const FloatRect middleRect = FloatRect{m_texture.getMiddleRect()}; + const Vector2u imageSize = m_texture.getImageSize(); switch (m_scalingType) { case ScalingType::Normal: diff --git a/src/String.cpp b/src/String.cpp index 288106704..ebc1d2e53 100644 --- a/src/String.cpp +++ b/src/String.cpp @@ -46,10 +46,9 @@ namespace tgui TGUI_NODISCARD static inline bool compareCharIgnoreCase(char32_t char1, char32_t char2) { if (char1 == char2) return true; - else if ((char1 < 128) && (char2 < 128)) + if ((char1 < 128) && (char2 < 128)) return std::tolower(static_cast(char1)) == std::tolower(static_cast(char2)); - else - return false; + return false; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -167,8 +166,7 @@ namespace tgui int result; if (attemptToInt(result)) return result; - else - return defaultValue; + return defaultValue; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -178,8 +176,7 @@ namespace tgui unsigned int result; if (attemptToUInt(result)) return result; - else - return defaultValue; + return defaultValue; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -189,8 +186,7 @@ namespace tgui float result; if (attemptToFloat(result)) return result; - else - return defaultValue; + return defaultValue; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -348,7 +344,7 @@ namespace tgui } else // When the delimeter is empty, each character is put in its own part { - for (char32_t c : m_string) + for (const char32_t c : m_string) substrings.push_back(c); } @@ -1808,7 +1804,7 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - void String::swap(String& other) + void String::swap(String& other) noexcept { m_string.swap(other.m_string); } diff --git a/src/SubwidgetContainer.cpp b/src/SubwidgetContainer.cpp index a06f2f8aa..fc0662191 100644 --- a/src/SubwidgetContainer.cpp +++ b/src/SubwidgetContainer.cpp @@ -57,7 +57,7 @@ namespace tgui { Widget::setEnabled(enabled); - for (auto& widget : m_container->getWidgets()) + for (const auto& widget : m_container->getWidgets()) widget->setEnabled(enabled); } diff --git a/src/SvgImage.cpp b/src/SvgImage.cpp index 83a9c0e65..487cf500d 100644 --- a/src/SvgImage.cpp +++ b/src/SvgImage.cpp @@ -84,8 +84,7 @@ namespace tgui { if (m_data->svg) return {static_cast(m_data->svg->width), static_cast(m_data->svg->height)}; - else - return {0, 0}; + return {0, 0}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Text.cpp b/src/Text.cpp index 72b204ee6..6e6574dd7 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -291,9 +291,9 @@ namespace tgui float charWidth; if (curChar == '\n') break; - else if (curChar == U'\r') + if (curChar == U'\r') continue; // Skip carriage return characters which aren't rendered (we only use line feed characters to indicate a new line) - else if (curChar == '\t') + if (curChar == '\t') charWidth = font.getGlyph(' ', characterSize, bold).advance * 4.0f; else charWidth = font.getGlyph(curChar, characterSize, bold).advance; @@ -335,15 +335,13 @@ namespace tgui if (fit < 0) return *low; - else if (fit > 0) + if (fit > 0) return *high; - else - { - if (std::abs(height - lowLineSpacing) < std::abs(height - highLineSpacing)) - return *low; - else - return *high; - } + + if (std::abs(height - lowLineSpacing) < std::abs(height - highLineSpacing)) + return *low; + + return *high; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -371,13 +369,13 @@ namespace tgui index++; break; } - else if (curChar == U'\r') + if (curChar == U'\r') { // Skip carriage return characters which aren't rendered (we only use line feed characters to indicate a new line) index++; continue; } - else if (curChar == U'\t') + if (curChar == U'\t') charWidth = font.getGlyph(U' ', textSize, bold).advance * 4; else charWidth = font.getGlyph(curChar, textSize, bold).advance; diff --git a/src/Texture.cpp b/src/Texture.cpp index 37dafc410..e02bd9f58 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -293,8 +293,7 @@ TGUI_IGNORE_DEPRECATED_WARNINGS_END if (m_data->svgImage) return Vector2u{m_data->svgImage->getSize()}; - else - return getPartRect().getSize(); + return getPartRect().getSize(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -310,8 +309,7 @@ TGUI_IGNORE_DEPRECATED_WARNINGS_END { if (m_data && m_data->backendTexture) return m_data->backendTexture->isSmooth(); - else - return true; + return true; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/TextureManager.cpp b/src/TextureManager.cpp index 36f4b26bf..3e6596b1d 100644 --- a/src/TextureManager.cpp +++ b/src/TextureManager.cpp @@ -83,7 +83,7 @@ namespace tgui else // Not an svg { data->backendTexture = getBackend()->createTexture(); - if (texture.getBackendTextureLoader()(*data->backendTexture, filename, smooth)) + if (tgui::Texture::getBackendTextureLoader()(*data->backendTexture, filename, smooth)) return data; } diff --git a/src/Transform.cpp b/src/Transform.cpp index e4da0bf69..5a7e3e6c3 100644 --- a/src/Transform.cpp +++ b/src/Transform.cpp @@ -90,8 +90,7 @@ namespace tgui -(m_matrix[7] * m_matrix[0] - m_matrix[3] * m_matrix[4]) / det, (m_matrix[5] * m_matrix[0] - m_matrix[1] * m_matrix[4]) / det}; } - else - return {}; + return {}; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Widget.cpp b/src/Widget.cpp index 14dc394d5..20debb2ac 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -148,10 +148,10 @@ namespace tgui if (m_renderer) m_renderer->unsubscribe(this); - for (auto& layout : m_boundPositionLayouts) + for (const auto& layout : m_boundPositionLayouts) layout->unbindWidget(); - for (auto& layout : m_boundSizeLayouts) + for (const auto& layout : m_boundSizeLayouts) layout->unbindWidget(); SignalManager::getSignalManager()->remove(this); @@ -495,7 +495,7 @@ namespace tgui rendererData->themePropertiesInherited = true; } - std::shared_ptr oldData = m_renderer->getData(); + const std::shared_ptr oldData = m_renderer->getData(); // Update the data m_renderer->unsubscribe(this); @@ -652,8 +652,7 @@ namespace tgui if (m_parent) return m_parent->getAbsolutePosition(pos + m_parent->getChildWidgetsOffset()); - else - return pos; + return pos; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -708,8 +707,7 @@ namespace tgui { if (m_scaleOrigin) return *m_scaleOrigin; - else - return m_origin; + return m_origin; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -734,8 +732,7 @@ namespace tgui { if (m_rotationOrigin) return *m_rotationOrigin; - else - return m_origin; + return m_origin; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1472,10 +1469,7 @@ namespace tgui // This behavior can be disabled by calling gui.setKeyboardNavigationEnabled(true). // TGUI_NEXT: Always return false here, irrelevant of whether keyboard navigation is enabled. // TGUI_NEXT: Deprecate or remove this function and let keyPressed return a bool value. - if (m_parentGui && m_parentGui->isKeyboardNavigationEnabled()) - return false; - else - return true; + return !(m_parentGui && m_parentGui->isKeyboardNavigationEnabled()); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1518,8 +1512,7 @@ namespace tgui { if (m_toolTip && isMouseOnWidget(mousePos)) return getToolTip(); - else - return nullptr; + return nullptr; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1556,19 +1549,19 @@ namespace tgui { if (signalName == onPositionChange.getName()) return onPositionChange; - else if (signalName == onSizeChange.getName()) + if (signalName == onSizeChange.getName()) return onSizeChange; - else if (signalName == onFocus.getName()) + if (signalName == onFocus.getName()) return onFocus; - else if (signalName == onUnfocus.getName()) + if (signalName == onUnfocus.getName()) return onUnfocus; - else if (signalName == onMouseEnter.getName()) + if (signalName == onMouseEnter.getName()) return onMouseEnter; - else if (signalName == onMouseLeave.getName()) + if (signalName == onMouseLeave.getName()) return onMouseLeave; - else if (signalName == onAnimationFinish.getName()) + if (signalName == onAnimationFinish.getName()) return onAnimationFinish; - else if (signalName == onShowEffectFinish.getName()) + if (signalName == onShowEffectFinish.getName()) return onShowEffectFinish; throw Exception{U"No signal exists with name '" + std::move(signalName) + U"'."}; @@ -1798,7 +1791,7 @@ namespace tgui if (node->propertyValuePairs[U"MouseCursor"]) { - String cursorStr = node->propertyValuePairs[U"MouseCursor"]->value.trim(); + const String cursorStr = node->propertyValuePairs[U"MouseCursor"]->value.trim(); if (cursorStr == U"Text") m_mouseCursor = Cursor::Type::Text; else if (cursorStr == U"Hand") @@ -1870,7 +1863,7 @@ namespace tgui const auto& constructor = WidgetFactory::getConstructFunction(toolTipWidgetNode->name); if (constructor) { - Widget::Ptr toolTip = constructor(); + const Widget::Ptr toolTip = constructor(); toolTip->load(toolTipWidgetNode, renderers); setToolTip(toolTip); } diff --git a/src/Widgets/BitmapButton.cpp b/src/Widgets/BitmapButton.cpp index 959c01bda..320aa578f 100644 --- a/src/Widgets/BitmapButton.cpp +++ b/src/Widgets/BitmapButton.cpp @@ -119,8 +119,7 @@ namespace tgui { if (button) return std::static_pointer_cast(button->clone()); - else - return nullptr; + return nullptr; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Widgets/BoxLayout.cpp b/src/Widgets/BoxLayout.cpp index b183c66df..5d1396d32 100644 --- a/src/Widgets/BoxLayout.cpp +++ b/src/Widgets/BoxLayout.cpp @@ -124,8 +124,7 @@ namespace tgui { if (index < m_widgets.size()) return m_widgets[index]; - else - return nullptr; + return nullptr; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Widgets/BoxLayoutRatios.cpp b/src/Widgets/BoxLayoutRatios.cpp index 49bced51d..117c025ee 100644 --- a/src/Widgets/BoxLayoutRatios.cpp +++ b/src/Widgets/BoxLayoutRatios.cpp @@ -154,7 +154,7 @@ namespace tgui { auto node = BoxLayout::save(renderers); - if (m_widgets.size() > 0) + if (!m_widgets.empty()) { String ratioList = "[" + Serializer::serialize(m_ratios[0]); for (std::size_t i = 1; i < m_widgets.size(); ++i) diff --git a/src/Widgets/Button.cpp b/src/Widgets/Button.cpp index ed877a790..5674701f4 100644 --- a/src/Widgets/Button.cpp +++ b/src/Widgets/Button.cpp @@ -57,8 +57,7 @@ namespace tgui { if (button) return std::static_pointer_cast