diff --git a/source/utils/ConfigUtils.cpp b/source/utils/ConfigUtils.cpp index 45a6af7..f17db0c 100644 --- a/source/utils/ConfigUtils.cpp +++ b/source/utils/ConfigUtils.cpp @@ -367,7 +367,7 @@ void ConfigUtils::displayMenu() { // draw top bar DrawUtils::setFontSize(24); - DrawUtils::print(16, 6 + 24, currentConfig->config->getName().c_str()); + DrawUtils::print(16, 6 + 24, StringTools::truncate(currentConfig->config->getName(), 45).c_str()); DrawUtils::setFontSize(18); DrawUtils::print(SCREEN_WIDTH - 16, 8 + 24, currentConfig->version.c_str(), true); DrawUtils::drawRectFilled(8, 8 + 24 + 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK); @@ -490,7 +490,7 @@ void ConfigUtils::displayMenu() { auto headline = string_format("%s - %s", currentConfig->config->getName().c_str(), currentCategory->getName().c_str()); // draw top bar DrawUtils::setFontSize(24); - DrawUtils::print(16, 6 + 24, headline.c_str()); + DrawUtils::print(16, 6 + 24, StringTools::truncate(headline, 45).c_str()); DrawUtils::drawRectFilled(8, 8 + 24 + 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_BLACK); DrawUtils::setFontSize(18); DrawUtils::print(SCREEN_WIDTH - 16, 8 + 24, currentConfig->version.c_str(), true); diff --git a/source/utils/StringTools.cpp b/source/utils/StringTools.cpp index 3fa643a..79d5721 100644 --- a/source/utils/StringTools.cpp +++ b/source/utils/StringTools.cpp @@ -30,6 +30,17 @@ #include #include +std::string StringTools::truncate(const std::string &str, size_t width, bool show_ellipsis) { + if (str.length() > width - 3) { + if (show_ellipsis) { + return str.substr(0, width - 3) + "..."; + } else { + return str.substr(0, width - 3); + } + } + return str; +} + int32_t StringTools::strtokcmp(const char *string, const char *compare, const char *separator) { if (!string || !compare) return -1; diff --git a/source/utils/StringTools.h b/source/utils/StringTools.h index c64de2c..f657937 100644 --- a/source/utils/StringTools.h +++ b/source/utils/StringTools.h @@ -50,8 +50,9 @@ std::string string_format(const std::string &format, Args... args) { class StringTools { public: - static int32_t strtokcmp(const char *string, const char *compare, const char *separator); + static std::string truncate(const std::string &str, size_t width, bool show_ellipsis = true); + static int32_t strtokcmp(const char *string, const char *compare, const char *separator); static const char *FullpathToFilename(const char *path) { if (!path)