diff --git a/changelog.md b/changelog.md index 16b33803f..25b258f9f 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ TGUI 1.7 (TBD) --------------- - New widgets: GrowHorizontalLayout and GrowVerticalLayout +- Fixed some issues with font scale in SFML font backend TGUI 1.6.1 (8 October 2024) diff --git a/include/TGUI/Backend/Font/SFML-Graphics/BackendFontSFML.hpp b/include/TGUI/Backend/Font/SFML-Graphics/BackendFontSFML.hpp index 72abf28a2..3482bf985 100644 --- a/include/TGUI/Backend/Font/SFML-Graphics/BackendFontSFML.hpp +++ b/include/TGUI/Backend/Font/SFML-Graphics/BackendFontSFML.hpp @@ -218,6 +218,10 @@ TGUI_MODULE_EXPORT namespace tgui // from breaking since sf::Font does the same. std::map> m_textures; std::map m_textureVersions; + + // We use a single version that is unique across all text sizes. Otherwise switching from size by changing the font scale + // can result in the same version being accidentally returned and the text not realizing that the texture changed. + unsigned int m_lastTextureVersion = 0; }; } diff --git a/src/Backend/Font/SFML-Graphics/BackendFontSFML.cpp b/src/Backend/Font/SFML-Graphics/BackendFontSFML.cpp index d1d34d9fb..2bf87040b 100644 --- a/src/Backend/Font/SFML-Graphics/BackendFontSFML.cpp +++ b/src/Backend/Font/SFML-Graphics/BackendFontSFML.cpp @@ -243,7 +243,8 @@ namespace tgui } m_textures[scaledTextSize] = texture; - textureVersion = ++m_textureVersions[scaledTextSize]; + textureVersion = ++m_lastTextureVersion; + m_textureVersions[scaledTextSize] = textureVersion; return texture; } diff --git a/tests/Widget.cpp b/tests/Widget.cpp index c0a418d28..a813db207 100644 --- a/tests/Widget.cpp +++ b/tests/Widget.cpp @@ -639,6 +639,28 @@ TEST_CASE("[Widget]") TEST_DRAW("OriginScaleRotation.png") } + + SECTION("Font scale") + { + auto button = tgui::Button::create(); + button->setSize(150, 50); + button->setText("Scaling"); + button->setTextSize(32); + button->setPosition(5, 10); + + TEST_DRAW_INIT(400, 175, button) + + auto oldView = gui.getView(); + gui.setAbsoluteView({0, 0, 160, 70}); + + TEST_DRAW("FontScale_Unscaled.png") + + tgui::getBackend()->setFontScale(2.5f); + TEST_DRAW("FontScale_Scaled.png") + + tgui::getBackend()->setFontScale(1); + gui.setAbsoluteView(oldView.getRect()); + } } SECTION("Bug Fixes") diff --git a/tests/expected/FontScale_Scaled.png b/tests/expected/FontScale_Scaled.png new file mode 100644 index 000000000..24186e234 Binary files /dev/null and b/tests/expected/FontScale_Scaled.png differ diff --git a/tests/expected/FontScale_Unscaled.png b/tests/expected/FontScale_Unscaled.png new file mode 100644 index 000000000..f622a8637 Binary files /dev/null and b/tests/expected/FontScale_Unscaled.png differ