From fb60cd6ec834afc25f076fcb5f1368bf21885b35 Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Sat, 30 May 2026 17:11:49 +0200 Subject: [PATCH 1/5] Use nullptr, not NULL, in modern C++ --- examples/main-GLFW_GLES2.cpp | 2 +- examples/main-GLFW_OPENGL3.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/main-GLFW_GLES2.cpp b/examples/main-GLFW_GLES2.cpp index 913948427..e9c611fc1 100644 --- a/examples/main-GLFW_GLES2.cpp +++ b/examples/main-GLFW_GLES2.cpp @@ -58,7 +58,7 @@ int main() glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - GLFWwindow* window = glfwCreateWindow(800, 600, "TGUI example (GLFW-GLES2)", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(800, 600, "TGUI example (GLFW-GLES2)", nullptr, nullptr); glfwMakeContextCurrent(window); glfwSwapInterval(1); diff --git a/examples/main-GLFW_OPENGL3.cpp b/examples/main-GLFW_OPENGL3.cpp index dcf35f844..801bf1402 100644 --- a/examples/main-GLFW_OPENGL3.cpp +++ b/examples/main-GLFW_OPENGL3.cpp @@ -59,7 +59,7 @@ int main() glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); // Required for macOS - GLFWwindow* window = glfwCreateWindow(800, 600, "TGUI example (GLFW-OpenGL3)", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(800, 600, "TGUI example (GLFW-OpenGL3)", nullptr, nullptr); glfwMakeContextCurrent(window); glfwSwapInterval(1); From c18c37953b1c0e7fa7482bb8c79a6d9609bb926b Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Sat, 30 May 2026 17:28:32 +0200 Subject: [PATCH 2/5] Add [[nodiscard]] to a few functions If you don't use the return value then calling these functions makes no sense. --- include/TGUI/Backend/Window/Backend.hpp | 2 +- include/TGUI/Global.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/TGUI/Backend/Window/Backend.hpp b/include/TGUI/Backend/Window/Backend.hpp index 5084df1f3..522516f2f 100644 --- a/include/TGUI/Backend/Window/Backend.hpp +++ b/include/TGUI/Backend/Window/Backend.hpp @@ -53,7 +53,7 @@ namespace tgui /// @brief Checks whether the backend differs from a nullptr /// @return Has setBackend been called with a valid backend? //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TGUI_API bool isBackendSet(); + [[nodiscard]] TGUI_API bool isBackendSet(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @brief Changes the global backend diff --git a/include/TGUI/Global.hpp b/include/TGUI/Global.hpp index b435be80c..a3be3770f 100644 --- a/include/TGUI/Global.hpp +++ b/include/TGUI/Global.hpp @@ -84,7 +84,7 @@ namespace tgui /// /// @since TGUI 1.13 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TGUI_API bool getTextInputUsesTextCursorByDefault(); + [[nodiscard]] TGUI_API bool getTextInputUsesTextCursorByDefault(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @brief Sets the default text size for all widgets created after calling the function From a71998004c206fa518bfefa25caceaddfd3b3f79 Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Sat, 30 May 2026 17:47:15 +0200 Subject: [PATCH 3/5] All our supported compilers define __has_include so there's no need to explicitly test --- include/TGUI/Config.hpp.in | 2 +- src/FileDialogIconLoaderLinux.cpp | 8 +++----- src/FileDialogIconLoaderWindows.cpp | 16 +++++++--------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/TGUI/Config.hpp.in b/include/TGUI/Config.hpp.in index e9f328b3a..117301425 100644 --- a/include/TGUI/Config.hpp.in +++ b/include/TGUI/Config.hpp.in @@ -131,7 +131,7 @@ // Include the version header when C++20 is available to use the library feature-testing macros #if TGUI_COMPILED_WITH_CPP_VER >= 20 #include -#elif defined(__has_include) +#else // Try including the header even when TGUI itself wasn't compiled with C++20 #if __has_include() #include diff --git a/src/FileDialogIconLoaderLinux.cpp b/src/FileDialogIconLoaderLinux.cpp index 8ee858cb8..1d5aafa1c 100644 --- a/src/FileDialogIconLoaderLinux.cpp +++ b/src/FileDialogIconLoaderLinux.cpp @@ -33,11 +33,9 @@ #include #include - #if defined(__has_include) - #if __has_include() - #define TGUI_MAGIC_HEADER_INCLUDED - #include - #endif + #if __has_include() + #define TGUI_MAGIC_HEADER_INCLUDED + #include #endif #if !defined(TGUI_MAGIC_HEADER_INCLUDED) diff --git a/src/FileDialogIconLoaderWindows.cpp b/src/FileDialogIconLoaderWindows.cpp index 7c46b192d..4b5c861d6 100644 --- a/src/FileDialogIconLoaderWindows.cpp +++ b/src/FileDialogIconLoaderWindows.cpp @@ -28,15 +28,13 @@ #include - #if defined(__has_include) - #if __has_include() - #define TGUI_SHELL_API_HEADER_INCLUDED - #include - - // MinGW.org based TDM-GCC doesn't define SHGFI_ADDOVERLAYS - #ifndef SHGFI_ADDOVERLAYS - #define SHGFI_ADDOVERLAYS 0x000000020 - #endif + #if __has_include() + #define TGUI_SHELL_API_HEADER_INCLUDED + #include + + // MinGW.org based TDM-GCC doesn't define SHGFI_ADDOVERLAYS + #ifndef SHGFI_ADDOVERLAYS + #define SHGFI_ADDOVERLAYS 0x000000020 #endif #endif From 69002d427d5e3feb8da2aed6fc141b2f3d6b1d3f Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Sat, 30 May 2026 18:09:31 +0200 Subject: [PATCH 4/5] Remove a pointless 'else' after an explicit return --- src/DefaultBackendWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DefaultBackendWindow.cpp b/src/DefaultBackendWindow.cpp index 949c3ae4f..f8b712bdc 100644 --- a/src/DefaultBackendWindow.cpp +++ b/src/DefaultBackendWindow.cpp @@ -634,8 +634,8 @@ namespace tgui event.type = Event::Type::Closed; return true; } - else // This is the second attempt to close the window (this should not happen), just close it - close(); + // This is the second attempt to close the window (this should not happen), just close it + close(); } } From 0de84d42804850289051342dd37a8dbb3799f807 Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Sat, 30 May 2026 18:19:02 +0200 Subject: [PATCH 5/5] Remove a few blank lines after preprocessor directives These don't match the common style of the code. There's usually no blank line after #if, #elif etc, so remove these to match the common style. --- src/DefaultBackendWindow.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/DefaultBackendWindow.cpp b/src/DefaultBackendWindow.cpp index f8b712bdc..46e90dd1b 100644 --- a/src/DefaultBackendWindow.cpp +++ b/src/DefaultBackendWindow.cpp @@ -64,7 +64,6 @@ namespace tgui { #if TGUI_HAS_BACKEND_SFML_GRAPHICS || TGUI_HAS_BACKEND_SFML_OPENGL3 - class BackendWindowSFML : public DefaultBackendWindow { public: @@ -383,7 +382,6 @@ namespace tgui }; #elif TGUI_HAS_BACKEND_GLFW_OPENGL3 || TGUI_HAS_BACKEND_GLFW_GLES2 - class BackendWindowGLFW : public DefaultBackendWindow { public: @@ -568,7 +566,6 @@ namespace tgui }; #elif TGUI_HAS_BACKEND_RAYLIB - class BackendWindowRaylib : public DefaultBackendWindow { public: