From c3c842b975f8aebab8c50c30919d89d0746985f5 Mon Sep 17 00:00:00 2001 From: frysee Date: Wed, 27 May 2026 22:06:32 +0200 Subject: [PATCH] feat: font style is now configurable (fixes #748) --- workspace/all/common/api.c | 10 +-- workspace/all/common/config.c | 100 ++++++++++++++++++++++++++++ workspace/all/common/config.h | 5 ++ workspace/all/settings/settings.cpp | 4 ++ 4 files changed, 114 insertions(+), 5 deletions(-) diff --git a/workspace/all/common/api.c b/workspace/all/common/api.c index 91661f39c..25b4998e9 100644 --- a/workspace/all/common/api.c +++ b/workspace/all/common/api.c @@ -311,11 +311,11 @@ int GFX_loadSystemFont(const char *fontPath) font.tiny = TTF_OpenFont(fontPath, SCALE1(FONT_TINY)); font.micro = TTF_OpenFont(fontPath, SCALE1(FONT_MICRO)); - TTF_SetFontStyle(font.large, TTF_STYLE_BOLD); - TTF_SetFontStyle(font.medium, TTF_STYLE_BOLD); - TTF_SetFontStyle(font.small, TTF_STYLE_BOLD); - TTF_SetFontStyle(font.tiny, TTF_STYLE_BOLD); - TTF_SetFontStyle(font.micro, TTF_STYLE_BOLD); + TTF_SetFontStyle(font.large, CFG_getFontStyle()); + TTF_SetFontStyle(font.medium, CFG_getFontStyle()); + TTF_SetFontStyle(font.small, CFG_getFontStyle()); + TTF_SetFontStyle(font.tiny, CFG_getFontStyle()); + TTF_SetFontStyle(font.micro, CFG_getFontStyle()); return 0; } diff --git a/workspace/all/common/config.c b/workspace/all/common/config.c index 2d9f5ebf7..ff5af1a62 100644 --- a/workspace/all/common/config.c +++ b/workspace/all/common/config.c @@ -31,6 +31,7 @@ void CFG_defaults(NextUISettings *cfg) NextUISettings defaults = { .fontFile = CFG_DEFAULT_FONT_FILE, + .fontStyle = CFG_DEFAULT_FONT_STYLE, .color1_255 = CFG_DEFAULT_COLOR1, .color2_255 = CFG_DEFAULT_COLOR2, .color3_255 = CFG_DEFAULT_COLOR3, @@ -414,6 +415,11 @@ void CFG_init(FontLoad_callback_t cb, ColorSet_callback_t ccb) CFG_setRAAchievementSortOrder(temp_value); continue; } + if (sscanf(line, "fontStyle=%i", &temp_value) == 1) + { + CFG_setFontStyle(temp_value); + continue; + } } fclose(file); } @@ -1086,6 +1092,19 @@ void CFG_setRAAchievementSortOrder(int sortOrder) CFG_sync(); } +int CFG_getFontStyle(void) +{ + return settings.fontStyle; +} + +void CFG_setFontStyle(int style) +{ + settings.fontStyle = clamp(style, 0x00, 0x01); + CFG_sync(); + // reload the font to apply the new style (if the font supports it) + CFG_setFontFile(CFG_getFontFile()); +} + void CFG_get(const char *key, char *value) { if (strcmp(key, "font") == 0) @@ -1245,6 +1264,70 @@ void CFG_get(const char *key, char *value) { sprintf(value, "%i", CFG_getCurrentTimezone()); } + else if (strcmp(key, "notifyManualSave") == 0) + { + sprintf(value, "%i", (int)(CFG_getNotifyManualSave())); + } + else if (strcmp(key, "notifyLoad") == 0) + { + sprintf(value, "%i", (int)(CFG_getNotifyLoad())); + } + else if (strcmp(key, "notifyScreenshot") == 0) + { + sprintf(value, "%i", (int)(CFG_getNotifyScreenshot())); + } + else if (strcmp(key, "notifyAdjustments") == 0) + { + sprintf(value, "%i", (int)(CFG_getNotifyAdjustments())); + } + else if (strcmp(key, "notifyDuration") == 0) + { + sprintf(value, "%i", CFG_getNotifyDuration()); + } + else if (strcmp(key, "raEnable") == 0) + { + sprintf(value, "%i", (int)(CFG_getRAEnable())); + } + else if (strcmp(key, "raUsername") == 0) + { + sprintf(value, "%s", CFG_getRAUsername()); + } + else if (strcmp(key, "raHardcoreMode") == 0) + { + sprintf(value, "%i", (int)(CFG_getRAHardcoreMode())); + } + else if (strcmp(key, "raToken") == 0) + { + sprintf(value, "%s", CFG_getRAToken()); + } + else if (strcmp(key, "raServerUsername") == 0) + { + sprintf(value, "%s", CFG_getRAServerUsername()); + } + else if (strcmp(key, "raAuthenticated") == 0) + { + sprintf(value, "%i", (int)(CFG_getRAAuthenticated())); + } + else if (strcmp(key, "raShowNotifications") == 0) + { + sprintf(value, "%i", (int)(CFG_getRAShowNotifications())); + } + else if (strcmp(key, "raNotificationDuration") == 0) + { + sprintf(value, "%i", CFG_getRANotificationDuration()); + } + else if (strcmp(key, "raProgressNotificationDuration") == 0) + { + sprintf(value, "%i", CFG_getRAProgressNotificationDuration()); + } + else if (strcmp(key, "raAchievementSortOrder") == 0) + { + sprintf(value, "%i", CFG_getRAAchievementSortOrder()); + } + else if (strcmp(key, "fontStyle") == 0) + { + sprintf(value, "%i", CFG_getFontStyle()); + } // meta, not a real setting else if (strcmp(key, "fontpath") == 0) @@ -1338,6 +1421,7 @@ void CFG_sync(void) fprintf(file, "raNotificationDuration=%i\n", settings.raNotificationDuration); fprintf(file, "raProgressNotificationDuration=%i\n", settings.raProgressNotificationDuration); fprintf(file, "raAchievementSortOrder=%i\n", settings.raAchievementSortOrder); + fprintf(file, "fontStyle=%i\n", settings.fontStyle); fclose(file); } @@ -1388,6 +1472,22 @@ void CFG_print(void) printf("\t\"btMaxRate\": %i,\n", settings.bluetoothSamplerateLimit); printf("\t\"ntp\": %i,\n", settings.ntp); printf("\t\"currentTimezone\": %i,\n", settings.currentTimezone); + printf("\t\"notifyManualSave\": %i,\n", settings.notifyManualSave); + printf("\t\"notifyLoad\": %i,\n", settings.notifyLoad); + printf("\t\"notifyScreenshot\": %i,\n", settings.notifyScreenshot); + printf("\t\"notifyAdjustments\": %i,\n", settings.notifyAdjustments); + printf("\t\"notifyDuration\": %i,\n", settings.notifyDuration); + printf("\t\"raEnable\": %i,\n", settings.raEnable); + printf("\t\"raUsername\": \"%s\",\n", settings.raUsername); + printf("\t\"raHardcoreMode\": %i,\n", settings.raHardcoreMode); + printf("\t\"raToken\": \"%s\",\n", settings.raToken); + printf("\t\"raServerUsername\": \"%s\",\n", settings.raServerUsername); + printf("\t\"raAuthenticated\": %i,\n", settings.raAuthenticated); + printf("\t\"raShowNotifications\": %i,\n", settings.raShowNotifications); + printf("\t\"raNotificationDuration\": %i,\n", settings.raNotificationDuration); + printf("\t\"raProgressNotificationDuration\": %i,\n", settings.raProgressNotificationDuration); + printf("\t\"raAchievementSortOrder\": %i,\n", settings.raAchievementSortOrder); + printf("\t\"fontStyle\": %i,\n", settings.fontStyle); // meta, not a real setting printf("\t\"fontpath\": \"%s/%s\"\n", RES_PATH, CFG_getFontFile()); diff --git a/workspace/all/common/config.h b/workspace/all/common/config.h index 50952b5b1..d2c56b94b 100644 --- a/workspace/all/common/config.h +++ b/workspace/all/common/config.h @@ -86,6 +86,7 @@ typedef struct { // Theme char fontFile[256]; + int fontStyle; // 0x00 = TTF_STYLE_NORMAL, 0x01 = TTF_STYLE_BOLD, etc. uint32_t color1_255; // not screen mapped uint32_t color2_255; // not screen mapped uint32_t color3_255; // not screen mapped @@ -171,6 +172,7 @@ typedef struct #define TRANSITION_COMFY 2 #define CFG_DEFAULT_FONT_FILE "font1.ttf" // Next +#define CFG_DEFAULT_FONT_STYLE 0x01 // TTF_STYLE_BOLD (MinUI default) #define CFG_DEFAULT_COLOR1 0xffffffU #define CFG_DEFAULT_COLOR2 0x9b2257U #define CFG_DEFAULT_COLOR3 0x1e2329U @@ -252,6 +254,9 @@ void CFG_get(const char *key, char * value); // Custom fonts go in RES_PATH alongside built-in fonts. const char* CFG_getFontFile(void); void CFG_setFontFile(const char* filename); +// The font style to use for the UI font. +int CFG_getFontStyle(void); +void CFG_setFontStyle(int style); // The colors to use for the UI. These are 0xRRGGBB values. // 0 - Color1 (primary hint/asset colour) // 1 - Color2 (accent colour) diff --git a/workspace/all/settings/settings.cpp b/workspace/all/settings/settings.cpp index 8f54e379e..53fc6b7a6 100644 --- a/workspace/all/settings/settings.cpp +++ b/workspace/all/settings/settings.cpp @@ -403,6 +403,10 @@ int main(int argc, char *argv[]) []() -> std::any { return std::string(CFG_getFontFile()); }, [](const std::any &value) { CFG_setFontFile(std::any_cast(value).c_str()); }, []() { CFG_setFontFile(CFG_DEFAULT_FONT_FILE); }}); + appearanceItems.push_back(new MenuItem{ListItemType::Generic, "Font style", "The style to render the UI font (e.g. bold)", std::vector{0, 1}, std::vector{"Normal", "Bold"}, + []() -> std::any { return CFG_getFontStyle(); }, + [](const std::any &value) { CFG_setFontStyle(std::any_cast(value)); }, + []() { CFG_setFontStyle(CFG_DEFAULT_FONT_STYLE); }}); for (auto *item : colorMenuItems) appearanceItems.push_back(item); appearanceItems.push_back(new MenuItem{ListItemType::Generic, "Show battery percentage", "Show battery level as percent in the status pill", {false, true}, on_off,