Skip to content

Commit 3dd4e62

Browse files
authored
Merge pull request #83 from baba-dev/codex/add-compile-time-constant-for-theme-option-count
fix: cache theme option count in settings page
2 parents 251b0c4 + 43c5228 commit 3dd4e62

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

custom/ui/pages/ui_page_settings.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ static const theme_option_t k_theme_options[] = {
6666
{"midnight", "Midnight"},
6767
};
6868

69+
static const size_t kThemeOptionCount = sizeof(k_theme_options) / sizeof(k_theme_options[0]);
70+
6971
static const char* k_theme_options_list = "System Default\nSolar\nMidnight";
7072

7173
static const struct
@@ -550,7 +552,7 @@ static void theme_state_async_cb(void* param)
550552

551553
if (ctx->theme_dropdown != NULL && payload->variant_id[0] != '\0')
552554
{
553-
for (uint32_t i = 0; i < LV_ARRAY_SIZE(k_theme_options); i++)
555+
for (uint32_t i = 0; i < kThemeOptionCount; i++)
554556
{
555557
if (strcmp(k_theme_options[i].id, payload->variant_id) == 0)
556558
{
@@ -678,7 +680,7 @@ static void theme_dropdown_cb(lv_event_t* event)
678680
if (ctx->actions_bound && ctx->actions.set_theme_variant != NULL)
679681
{
680682
uint16_t index = lv_dropdown_get_selected(lv_event_get_target(event));
681-
if (index < LV_ARRAY_SIZE(k_theme_options))
683+
if (index < kThemeOptionCount)
682684
{
683685
ctx->actions.set_theme_variant(k_theme_options[index].id, ctx->actions_user_data);
684686
}

0 commit comments

Comments
 (0)