Truncate the headline in config menu

This commit is contained in:
Maschell 2022-09-19 21:47:09 +02:00
parent 80d577b1dd
commit f6d8e850d2
3 changed files with 15 additions and 3 deletions

View File

@ -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);

View File

@ -30,6 +30,17 @@
#include <utils/StringTools.h>
#include <wut_types.h>
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;

View File

@ -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)