Skip to content

Commit 59bdd0d

Browse files
amcolashclaude
andcommitted
fw/apps/system/settings: Apply dark mode to settings and add toggle
Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrew McOlash <amcolash@gmail.com>
1 parent f54cfd4 commit 59bdd0d

9 files changed

Lines changed: 103 additions & 31 deletions

File tree

src/fw/apps/system/settings/activity_tracker.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ static Window *prv_init(void) {
240240
option_menu_init(&data->option_menu);
241241
// Not using option_menu_configure because prv_reload_menu_data already sets
242242
// icons_enabled and chosen row index
243-
option_menu_set_status_colors(&data->option_menu, GColorWhite, GColorBlack);
244-
GColor highlight_bg = shell_prefs_get_theme_highlight_color();
245-
option_menu_set_highlight_colors(&data->option_menu, highlight_bg, gcolor_legible_over(highlight_bg));
246243
option_menu_set_title(&data->option_menu, i18n_get("Background App", data));
247244
option_menu_set_content_type(&data->option_menu, OptionMenuContentType_SingleLine);
248245
option_menu_set_callbacks(&data->option_menu, &option_menu_callbacks, data);

src/fw/apps/system/settings/display.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ enum SettingsDisplayItem {
455455
#endif
456456
#if CAPABILITY_HAS_APP_SCALING
457457
SettingsDisplayLegacyAppMode,
458+
#endif
459+
#if !CAPABILITY_HAS_THEMING
460+
SettingsDisplayDarkMode,
458461
#endif
459462
NumSettingsDisplayItems
460463
};
@@ -486,6 +489,11 @@ static void prv_display_select_click_cb(SettingsCallbacks *context, uint16_t row
486489
case SettingsDisplayLegacyAppMode:
487490
prv_legacy_app_mode_menu_push((SettingsDisplayData*)context);
488491
break;
492+
#endif
493+
#if !CAPABILITY_HAS_THEMING
494+
case SettingsDisplayDarkMode:
495+
shell_prefs_set_dark_mode((shell_prefs_get_dark_mode() + 1) % DarkModeCount);
496+
break;
489497
#endif
490498
default:
491499
WTF;
@@ -530,6 +538,20 @@ static void prv_display_draw_row_cb(SettingsCallbacks *context, GContext *ctx,
530538
subtitle = (shell_prefs_get_legacy_app_render_mode() >= LegacyAppRenderMode_ScalingNearest) ?
531539
i18n_noop("Scaled") : i18n_noop("Centered");
532540
break;
541+
#endif
542+
#if !CAPABILITY_HAS_THEMING
543+
case SettingsDisplayDarkMode: {
544+
title = i18n_noop("Dark Mode");
545+
static const char * const s_dark_mode_labels[] = {
546+
[DarkModeOff] = i18n_noop("Off"),
547+
[DarkModeOn] = i18n_noop("On"),
548+
#if CAPABILITY_HAS_AMBIENT_LIGHT_SENSOR
549+
[DarkModeAuto] = i18n_noop("Auto"),
550+
#endif
551+
};
552+
subtitle = s_dark_mode_labels[shell_prefs_get_dark_mode()];
553+
break;
554+
}
533555
#endif
534556
default:
535557
WTF;

src/fw/apps/system/settings/option_menu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ OptionMenu *settings_option_menu_create(
4242
.title = i18n_get(i18n_title_key, option_menu),
4343
.content_type = content_type,
4444
.choice = choice,
45-
.status_colors = { GColorWhite, GColorBlack },
45+
.status_colors = { system_theme_get_bg_color(), system_theme_get_fg_color() },
4646
.highlight_colors = { highlight_bg, gcolor_legible_over(highlight_bg) },
4747
.icons_enabled = icons_enabled,
4848
};

src/fw/apps/system/settings/quick_launch_app_menu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void quick_launch_app_menu_window_push(ButtonId button, bool is_tap) {
158158
const OptionMenuConfig config = {
159159
.title = i18n_get(i18n_noop("Quick Launch"), data),
160160
.choice = (install_id == INSTALL_ID_INVALID) ? 0 : (app_index + NUM_CUSTOM_CELLS),
161-
.status_colors = { GColorWhite, GColorBlack, },
161+
.status_colors = { system_theme_get_bg_color(), system_theme_get_fg_color() },
162162
.highlight_colors = { highlight_bg, gcolor_legible_over(highlight_bg) },
163163
.icons_enabled = true,
164164
};

src/fw/apps/system/settings/quick_launch_setup_menu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static void prv_push_first_use_dialog(void) {
5656
const char *text = i18n_get("Open favorite apps quickly with a long button press from your "
5757
"watchface.", i18n_owner);
5858
ExpandableDialog *expandable_dialog = expandable_dialog_create_with_params(
59-
WINDOW_NAME("Quick Launch First Use"), RESOURCE_ID_SUNNY_DAY_TINY, text, GColorBlack,
60-
GColorWhite, NULL, RESOURCE_ID_ACTION_BAR_ICON_CHECK, prv_handle_quick_launch_confirm);
59+
WINDOW_NAME("Quick Launch First Use"), RESOURCE_ID_SUNNY_DAY_TINY, text, system_theme_get_fg_color(),
60+
system_theme_get_bg_color(), NULL, RESOURCE_ID_ACTION_BAR_ICON_CHECK, prv_handle_quick_launch_confirm);
6161
expandable_dialog_set_header(expandable_dialog, header);
6262
#if PBL_ROUND
6363
expandable_dialog_set_header_font(expandable_dialog,

src/fw/apps/system/settings/settings.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "pbl/services/i18n/i18n.h"
1414
#include "system/passert.h"
1515
#include "shell/prefs.h"
16+
#include "shell/system_theme.h"
1617
#include "util/size.h"
1718

1819
#define SETTINGS_CATEGORY_MENU_CELL_UNFOCUSED_ROUND_VERTICAL_PADDING 14
@@ -135,13 +136,6 @@ static void prv_window_load(Window *window) {
135136
.select_click = prv_select_callback,
136137
.get_separator_height = prv_get_separator_height_callback
137138
});
138-
GColor highlight_bg = shell_prefs_get_theme_highlight_color();
139-
menu_layer_set_normal_colors(menu_layer,
140-
PBL_IF_COLOR_ELSE(GColorBlack, GColorWhite),
141-
PBL_IF_COLOR_ELSE(GColorWhite, GColorBlack));
142-
menu_layer_set_highlight_colors(menu_layer,
143-
highlight_bg,
144-
gcolor_legible_over(highlight_bg));
145139
menu_layer_set_click_config_onto_window(menu_layer, &data->window);
146140
menu_layer_set_scroll_wrap_around(menu_layer, shell_prefs_get_menu_scroll_wrap_around_enable());
147141
menu_layer_set_scroll_vibe_on_wrap(menu_layer, shell_prefs_get_menu_scroll_vibe_behavior() == MenuScrollVibeOnWrapAround);
@@ -150,6 +144,15 @@ static void prv_window_load(Window *window) {
150144
layer_add_child(&data->window.layer, menu_layer_get_layer(menu_layer));
151145
}
152146

147+
static void prv_window_appear(Window *window) {
148+
SettingsAppData *data = window_get_user_data(window);
149+
// Refresh background and menu colors in case dark mode changed while away
150+
window_set_background_color(window, system_theme_get_bg_color());
151+
menu_layer_set_normal_colors(&data->menu_layer, system_theme_get_bg_color(),
152+
system_theme_get_fg_color());
153+
layer_mark_dirty(menu_layer_get_layer(&data->menu_layer));
154+
}
155+
153156
static void prv_window_unload(Window *window) {
154157
SettingsAppData *data = window_get_user_data(window);
155158

@@ -174,9 +177,10 @@ static void handle_init(void) {
174177
window_set_user_data(window, data);
175178
window_set_window_handlers(window, &(WindowHandlers){
176179
.load = prv_window_load,
180+
.appear = prv_window_appear,
177181
.unload = prv_window_unload,
178182
});
179-
window_set_background_color(window, PBL_IF_COLOR_ELSE(GColorBlack, GColorWhite));
183+
window_set_background_color(window, system_theme_get_bg_color());
180184
app_window_stack_push(window, true);
181185
}
182186

src/fw/apps/system/settings/system.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ static void prv_init_status_bar(StatusBarLayer *status_layer, Window *window, co
176176
status_bar_layer_init(status_layer);
177177
status_bar_layer_set_title(status_layer, text, false, false);
178178
status_bar_layer_set_separator_mode(status_layer, OPTION_MENU_STATUS_SEPARATOR_MODE);
179-
status_bar_layer_set_colors(status_layer, GColorWhite, GColorBlack);
180179
layer_add_child(&window->layer, status_bar_layer_get_layer(status_layer));
181180
}
182181

@@ -881,7 +880,9 @@ static void prv_draw_fcc_cell_round(
881880
const uint8_t fcc_number_subtitle_height = fonts_get_font_height(fcc_number_subtitle_font);
882881
const GTextOverflowMode text_overflow_mode = GTextOverflowModeFill;
883882

884-
graphics_context_set_text_color(ctx, cell_is_highlighted ? GColorWhite : GColorBlack);
883+
graphics_context_set_text_color(ctx, cell_is_highlighted ?
884+
system_theme_get_bg_color() :
885+
system_theme_get_fg_color());
885886

886887
// Calculate the container of the FCC cell content and center it within the cell
887888
const int16_t title_and_icon_width = 50;
@@ -1324,15 +1325,15 @@ static void prv_kcc_window_load(Window *window) {
13241325
- title_text_internal_padding;
13251326
text_layer_init_with_parameters(&data->title_text, &title_text_frame,
13261327
title, title_text_font,
1327-
GColorBlack, GColorClear, GTextAlignmentCenter,
1328+
system_theme_get_fg_color(), GColorClear, GTextAlignmentCenter,
13281329
GTextOverflowModeTrailingEllipsis);
13291330
layer_add_child(window_layer, text_layer_get_layer(&data->title_text));
13301331

13311332
GRect info_text_frame = (GRect) { .size = info_text_size };
13321333
info_text_frame.origin.y = title_text_frame.origin.y + title_text_size.h + vertical_spacing;
13331334
text_layer_init_with_parameters(&data->info_text, &info_text_frame,
13341335
prv_get_korea_kcc_id(), info_text_font,
1335-
GColorBlack, GColorClear, GTextAlignmentCenter,
1336+
system_theme_get_fg_color(), GColorClear, GTextAlignmentCenter,
13361337
GTextOverflowModeTrailingEllipsis);
13371338
layer_add_child(window_layer, text_layer_get_layer(&data->info_text));
13381339
}

src/fw/apps/system/settings/themes.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static OptionMenu *prv_push_color_menu(void) {
117117
PBL_LOG_WRN("Invalid menu color, using default");
118118
selected = 0;
119119
}
120-
OptionMenu * const option_menu = settings_option_menu_create(
120+
OptionMenu * const option_menu = settings_option_menu_push(
121121
title, OptionMenuContentType_SingleLine, selected, &callbacks,
122122
ARRAY_LENGTH(s_color_definitions), true /* icons_enabled */, color_names, NULL);
123123

@@ -133,12 +133,52 @@ static OptionMenu *prv_push_color_menu(void) {
133133

134134
return option_menu;
135135
}
136+
137+
static const char * const s_dark_mode_labels[] = {
138+
i18n_noop("Off"), i18n_noop("On"), i18n_noop("Auto"),
139+
};
140+
141+
static void prv_select_click_cb(SettingsCallbacks *context, uint16_t row) {
142+
if (row == 0) shell_prefs_set_dark_mode((shell_prefs_get_dark_mode() + 1) % DarkModeCount);
143+
else prv_push_color_menu();
144+
settings_menu_reload_data(SettingsMenuItemThemes);
145+
settings_menu_mark_dirty(SettingsMenuItemThemes);
146+
}
147+
148+
static void prv_draw_row_cb(SettingsCallbacks *context, GContext *ctx,
149+
const Layer *cell_layer, uint16_t row, bool selected) {
150+
const char *title, *subtitle;
151+
if (row == 0) {
152+
title = i18n_noop("Dark Mode");
153+
subtitle = s_dark_mode_labels[shell_prefs_get_dark_mode()];
154+
} else {
155+
int idx = prv_color_to_index(shell_prefs_get_theme_highlight_color(),
156+
DEFAULT_THEME_HIGHLIGHT_COLOR);
157+
title = i18n_noop("Accent Color");
158+
subtitle = s_color_definitions[idx < 0 ? 0 : idx].name;
159+
}
160+
menu_cell_basic_draw(ctx, cell_layer, i18n_get(title, context),
161+
i18n_get(subtitle, context), NULL);
162+
}
163+
164+
static uint16_t prv_num_rows_cb(SettingsCallbacks *context) { return 2; }
165+
static void prv_deinit_cb(SettingsCallbacks *context) {
166+
i18n_free_all(context);
167+
app_free(context);
168+
}
169+
136170
#endif // CAPABILITY_HAS_THEMING
137171

138172
static Window *prv_create_color_menu(void) {
139173
#if CAPABILITY_HAS_THEMING
140-
OptionMenu *option_menu = prv_push_color_menu();
141-
return option_menu ? &option_menu->window : NULL;
174+
SettingsCallbacks *callbacks = app_malloc_check(sizeof(*callbacks));
175+
*callbacks = (SettingsCallbacks){
176+
.deinit = prv_deinit_cb,
177+
.draw_row = prv_draw_row_cb,
178+
.select_click = prv_select_click_cb,
179+
.num_rows = prv_num_rows_cb,
180+
};
181+
return settings_window_create(SettingsMenuItemThemes, callbacks);
142182
#else
143183
WTF;
144184
return NULL;

src/fw/apps/system/settings/window.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "pbl/services/i18n/i18n.h"
3030
#include "pbl/services/system_task.h"
3131
#include "system/bootbits.h"
32+
#include "shell/system_theme.h"
3233
#include "system/passert.h"
3334
#include "shell/prefs.h"
3435

@@ -62,10 +63,18 @@ typedef struct SettingsData {
6263
// Pref change handler
6364
///////////////////////
6465

66+
static void prv_refresh_theme_colors(SettingsData *data) {
67+
const GColor bg = system_theme_get_bg_color();
68+
const GColor fg = system_theme_get_fg_color();
69+
window_set_background_color(&data->window, bg);
70+
status_bar_layer_set_colors(&data->status_layer, bg, fg);
71+
menu_layer_set_normal_colors(&data->menu_layer, bg, fg);
72+
layer_mark_dirty(menu_layer_get_layer(&data->menu_layer));
73+
}
74+
6575
static void prv_pref_change_handler(PebbleEvent *event, void *context) {
6676
SettingsData *data = context;
67-
// Refresh the menu when any pref changes
68-
layer_mark_dirty(menu_layer_get_layer(&data->menu_layer));
77+
prv_refresh_theme_colors(data);
6978
}
7079

7180
// Filter category helpers
@@ -85,8 +94,8 @@ static void prv_set_sub_menu_colors(GContext *ctx, const Layer *cell_layer, bool
8594
graphics_context_set_fill_color(ctx, highlight_bg);
8695
graphics_context_set_text_color(ctx, gcolor_legible_over(highlight_bg));
8796
} else {
88-
graphics_context_set_fill_color(ctx, GColorWhite);
89-
graphics_context_set_text_color(ctx, GColorBlack);
97+
graphics_context_set_fill_color(ctx, system_theme_get_bg_color());
98+
graphics_context_set_text_color(ctx, system_theme_get_fg_color());
9099
}
91100
graphics_fill_rect(ctx, &cell_layer->bounds);
92101
}
@@ -183,7 +192,7 @@ static void prv_settings_window_load(Window *window) {
183192
? data->title_override
184193
: settings_menu_get_status_name(data->current_category);
185194
status_bar_layer_set_title(status_layer, i18n_get(title, data), false, false);
186-
status_bar_layer_set_colors(status_layer, GColorWhite, GColorBlack);
195+
status_bar_layer_set_colors(status_layer, system_theme_get_bg_color(), system_theme_get_fg_color());
187196
status_bar_layer_set_separator_mode(status_layer, OPTION_MENU_STATUS_SEPARATOR_MODE);
188197
layer_add_child(&data->window.layer, status_bar_layer_get_layer(status_layer));
189198

@@ -203,9 +212,6 @@ static void prv_settings_window_load(Window *window) {
203212
.selection_changed = prv_selection_changed_callback,
204213
.selection_will_change = prv_selection_will_change_callback,
205214
});
206-
menu_layer_set_normal_colors(menu_layer, GColorWhite, GColorBlack);
207-
GColor highlight_bg = shell_prefs_get_theme_highlight_color();
208-
menu_layer_set_highlight_colors(menu_layer, highlight_bg, gcolor_legible_over(highlight_bg));
209215
menu_layer_set_click_config_onto_window(menu_layer, &data->window);
210216
menu_layer_set_scroll_wrap_around(menu_layer, shell_prefs_get_menu_scroll_wrap_around_enable());
211217
menu_layer_set_scroll_vibe_on_wrap(menu_layer, shell_prefs_get_menu_scroll_vibe_behavior() == MenuScrollVibeOnWrapAround);
@@ -234,6 +240,8 @@ static void prv_settings_window_load(Window *window) {
234240

235241
static void prv_settings_window_appear(Window *window) {
236242
SettingsData *data = window_get_user_data(window);
243+
// Refresh colors in case the theme changed while this window was hidden
244+
prv_refresh_theme_colors(data);
237245
SettingsCallbacks *callbacks = prv_get_current_callbacks(data);
238246
if (callbacks->appear) {
239247
callbacks->appear(data->callbacks);
@@ -312,7 +320,7 @@ void settings_window_destroy(Window *window) {
312320
void settings_menu_mark_dirty(SettingsMenuItem category) {
313321
SettingsData *data = app_state_get_user_data();
314322
if (data->current_category == category) {
315-
layer_mark_dirty(menu_layer_get_layer(&data->menu_layer));
323+
prv_refresh_theme_colors(data);
316324
}
317325
}
318326

0 commit comments

Comments
 (0)