1414 * limitations under the License.
1515 */
1616
17-
1817#include "settings_themes.h"
1918#include "settings_menu.h"
2019#include "settings_option_menu.h"
2120#include "settings_window.h"
2221
2322#include "applib/ui/dialogs/dialog.h"
2423#include "applib/ui/dialogs/expandable_dialog.h"
24+ #include "applib/graphics/gtypes.h"
2525#include "applib/graphics/graphics.h"
2626#include "applib/ui/menu_layer.h"
2727#include "kernel/pbl_malloc.h"
@@ -77,21 +77,10 @@ static void prv_draw_row_cb(SettingsCallbacks *context, GContext *ctx,
7777 menu_cell_basic_draw (ctx , cell_layer , i18n_get (title , data ), i18n_get (subtitle , data ), NULL );
7878}
7979
80- static const char * color_names_short [ARRAY_LENGTH (s_color_definitions_short )];
81- static bool color_names_short_initialized = false;
8280static const char * color_names [ARRAY_LENGTH (s_color_definitions )];
8381static bool color_names_initialized = false;
8482
8583static const char * * prv_get_color_names (bool short_list ) {
86- if (short_list ) {
87- if (!color_names_short_initialized ) {
88- for (size_t i = 0 ; i < ARRAY_LENGTH (s_color_definitions_short ); i ++ ) {
89- color_names_short [i ] = (char * )s_color_definitions_short [i ].name ;
90- }
91- color_names_short_initialized = true;
92- }
93- return color_names_short ;
94- }
9584 if (!color_names_initialized ) {
9685 for (size_t i = 0 ; i < ARRAY_LENGTH (s_color_definitions ); i ++ ) {
9786 color_names [i ] = (char * )s_color_definitions [i ].name ;
@@ -104,20 +93,13 @@ static const char** prv_get_color_names(bool short_list) {
10493
10594
10695
107- static int prv_color_to_index (GColor color , bool short_list , GColor default_color ) {
96+ static int prv_color_to_index (GColor color , bool is_light , GColor default_color ) {
10897 if (color .argb == GColorClear .argb || color .argb == default_color .argb ) {
10998 return 0 ;
11099 }
111- if (short_list ) {
112- for (size_t i = 0 ; i < ARRAY_LENGTH (s_color_definitions_short ); i ++ ) {
113- if ((uint8_t )(color .argb ) == (uint8_t )(s_color_definitions_short [i ].value .argb )) {
114- return i ;
115- }
116- }
117- return -1 ;
118- }
119100 for (size_t i = 0 ; i < ARRAY_LENGTH (s_color_definitions ); i ++ ) {
120- if ((uint8_t )(color .argb ) == (uint8_t )(s_color_definitions [i ].value .argb )) {
101+ GColor selected_color = is_light ? s_color_definitions [i ].light : s_color_definitions [i ].dark ;
102+ if ((uint8_t )(color .argb ) == (uint8_t )(selected_color .argb )) {
121103 return i ;
122104 }
123105 }
@@ -135,7 +117,7 @@ static void prv_apps_color_menu_select(OptionMenu *option_menu, int selection, v
135117 shell_prefs_set_apps_menu_highlight_color (DEFAULT_APPS_HIGHLIGHT_COLOR );
136118 }
137119 else {
138- shell_prefs_set_apps_menu_highlight_color (s_color_definitions [selection ].value );
120+ shell_prefs_set_apps_menu_highlight_color (s_color_definitions [selection ].light );
139121 }
140122 app_window_stack_remove (& option_menu -> window , true /* animated */ );
141123}
@@ -147,18 +129,18 @@ static void prv_option_apps_menu_selection_will_change(OptionMenu *option_menu,
147129 if (new_row == old_row ) {
148130 return ;
149131 }
150- GColor color = s_color_definitions [new_row ].value ;
132+ GColor color = s_color_definitions [new_row ].light ;
151133 if (color .argb != GColorClear .argb ) {
152- option_menu_set_highlight_colors (option_menu , color , PBL_IF_COLOR_ELSE ( GColorBlack , GColorWhite ) );
134+ option_menu_set_highlight_colors (option_menu , color , PBL_COLOR ? GColorBlack : GColorWhite );
153135 }
154136 else {
155- option_menu_set_highlight_colors (option_menu , DEFAULT_APPS_HIGHLIGHT_COLOR , PBL_IF_COLOR_ELSE ( GColorBlack , GColorWhite ) );
137+ option_menu_set_highlight_colors (option_menu , DEFAULT_APPS_HIGHLIGHT_COLOR , PBL_COLOR ? GColorBlack : GColorWhite );
156138 }
157139}
158140
159141static void prv_push_apps_color_menu (SettingsThemesData * data ) {
160142 const char * title = i18n_noop ("Apps Menu Accent" );
161- int selected = prv_color_to_index (shell_prefs_get_apps_menu_highlight_color (), false , DEFAULT_APPS_HIGHLIGHT_COLOR );
143+ int selected = prv_color_to_index (shell_prefs_get_apps_menu_highlight_color (), true , DEFAULT_APPS_HIGHLIGHT_COLOR );
162144 const char * * color_names = prv_get_color_names (false);
163145 const OptionMenuCallbacks callbacks = {
164146 .select = prv_apps_color_menu_select ,
@@ -174,99 +156,27 @@ static void prv_push_apps_color_menu(SettingsThemesData *data) {
174156 if (option_menu ) {
175157 const bool animated = true;
176158 if (selected == 0 ) {
177- option_menu_set_highlight_colors (option_menu , DEFAULT_APPS_HIGHLIGHT_COLOR , PBL_IF_COLOR_ELSE ( GColorBlack , GColorWhite ) );
159+ option_menu_set_highlight_colors (option_menu , DEFAULT_APPS_HIGHLIGHT_COLOR , PBL_COLOR ? GColorBlack : GColorWhite );
178160 }
179161 else {
180- option_menu_set_highlight_colors (option_menu , s_color_definitions [selected ].value , PBL_IF_COLOR_ELSE ( GColorBlack , GColorWhite ) );
162+ option_menu_set_highlight_colors (option_menu , s_color_definitions [selected ].light , PBL_COLOR ? GColorBlack : GColorWhite );
181163 }
182164 app_window_stack_push (& option_menu -> window , animated );
183165 }
184166}
185167
186-
187168/////////////////////////////
188- // Short Apps Accent Color Settings
169+ // Settings Accent Color Settings
189170/////////////////////////////
190171
191- static void prv_apps_color_menu_select_short (OptionMenu * option_menu , int selection , void * context ) {
192- if (selection == 0 ){
193- /* Default option selected -> restore default color. */
194- shell_prefs_set_apps_menu_highlight_color (DEFAULT_APPS_HIGHLIGHT_COLOR );
195- }
196- else if (selection == ARRAY_LENGTH (s_color_definitions_short ) - 1 ) {
197- /* "Show All..." -> open full color menu. */
198- prv_push_apps_color_menu ((SettingsThemesData * )context );
199- return ;
200- }
201- else {
202- shell_prefs_set_apps_menu_highlight_color (s_color_definitions [selection ].value );
203- }
204- app_window_stack_remove (& option_menu -> window , true /* animated */ );
205- }
206-
207- static void prv_option_apps_menu_selection_will_change_short (OptionMenu * option_menu ,
208- uint16_t new_row ,
209- uint16_t old_row ,
210- void * context ) {
211- if (new_row == old_row ) {
212- return ;
213- }
214- GColor color = s_color_definitions_short [new_row ].value ;
215- if (new_row >= ARRAY_LENGTH (s_color_definitions_short ) - 1 ) {
216- /* "Show All..." selected -> preview current saved color. */
217- option_menu_set_highlight_colors (option_menu , shell_prefs_get_apps_menu_highlight_color (), PBL_IF_COLOR_ELSE (GColorBlack , GColorWhite ));
218- }
219- else if (color .argb != GColorClear .argb ) {
220- option_menu_set_highlight_colors (option_menu , color , PBL_IF_COLOR_ELSE (GColorBlack , GColorWhite ));
221- }
222- else {
223- option_menu_set_highlight_colors (option_menu , DEFAULT_APPS_HIGHLIGHT_COLOR , PBL_IF_COLOR_ELSE (GColorBlack , GColorWhite ));
224- }
225- }
226-
227-
228- static void prv_push_apps_color_menu_short (SettingsThemesData * data ) {
229- const char * title = i18n_noop ("Apps Menu Accent" );
230- int selected = prv_color_to_index (shell_prefs_get_apps_menu_highlight_color (), true, DEFAULT_APPS_HIGHLIGHT_COLOR );
231- const char * * color_names = prv_get_color_names (true);
232- const OptionMenuCallbacks callbacks = {
233- .select = prv_apps_color_menu_select_short ,
234- .selection_will_change = prv_option_apps_menu_selection_will_change_short ,
235- };
236- if (selected < 0 ) {
237- selected = ARRAY_LENGTH (s_color_definitions_short ) - 1 ;
238- }
239- OptionMenu * const option_menu = settings_option_menu_create (
240- title , OptionMenuContentType_SingleLine , selected , & callbacks ,
241- ARRAY_LENGTH (s_color_definitions_short ), true /* icons_enabled */ , color_names , data );
242-
243- if (option_menu ) {
244- const bool animated = true;
245- if (selected == 0 ) {
246- option_menu_set_highlight_colors (option_menu , DEFAULT_APPS_HIGHLIGHT_COLOR , PBL_IF_COLOR_ELSE (GColorBlack , GColorWhite ));
247- }
248- else if (selected == ARRAY_LENGTH (s_color_definitions_short ) - 1 ) {
249- // "Show All..." option selected
250- option_menu_set_highlight_colors (option_menu , shell_prefs_get_apps_menu_highlight_color (), PBL_IF_COLOR_ELSE (GColorBlack , GColorWhite ));
251- }
252- else {
253- option_menu_set_highlight_colors (option_menu , s_color_definitions_short [selected ].value , PBL_IF_COLOR_ELSE (GColorBlack , GColorWhite ));
254- }
255- app_window_stack_push (& option_menu -> window , animated );
256- }
257- }
258-
259172
260- /////////////////////////////
261- // Settings Accent Color Settings
262- /////////////////////////////
263173static void prv_settings_color_menu_select (OptionMenu * option_menu , int selection , void * context ) {
264174 if (selection == 0 ){
265175 /* Default option selected -> restore default color. */
266176 shell_prefs_set_settings_menu_highlight_color (DEFAULT_SETTINGS_HIGHLIGHT_COLOR );
267177 }
268178 else {
269- shell_prefs_set_settings_menu_highlight_color (s_color_definitions [selection ].value );
179+ shell_prefs_set_settings_menu_highlight_color (s_color_definitions [selection ].dark );
270180 }
271181 app_window_stack_remove (& option_menu -> window , true /* animated */ );
272182}
@@ -278,17 +188,17 @@ static void prv_option_settings_menu_selection_will_change(OptionMenu *option_me
278188 if (new_row == old_row ) {
279189 return ;
280190 }
281- GColor color = s_color_definitions [new_row ].value ;
191+ GColor color = s_color_definitions [new_row ].dark ;
282192 if (color .argb != GColorClear .argb ) {
283- option_menu_set_highlight_colors (option_menu , color , GColorWhite );
193+ option_menu_set_highlight_colors (option_menu , color , PBL_COLOR ? GColorWhite : GColorBlack );
284194 }
285195 else {
286- option_menu_set_highlight_colors (option_menu , DEFAULT_SETTINGS_HIGHLIGHT_COLOR , GColorWhite );
196+ option_menu_set_highlight_colors (option_menu , DEFAULT_SETTINGS_HIGHLIGHT_COLOR , PBL_COLOR ? GColorWhite : GColorBlack );
287197 }
288198}
289199
290200static void prv_push_settings_color_menu (SettingsThemesData * data ) {
291- const char * title = i18n_noop ("Settings Accent" );
201+ const char * title = i18n_noop ("Settings Menu Accent" );
292202 int selected = prv_color_to_index (shell_prefs_get_settings_menu_highlight_color (), false, DEFAULT_SETTINGS_HIGHLIGHT_COLOR );
293203 const char * * color_names = prv_get_color_names (false);
294204 const OptionMenuCallbacks callbacks = {
@@ -305,102 +215,27 @@ static void prv_push_settings_color_menu(SettingsThemesData *data) {
305215 if (option_menu ) {
306216 const bool animated = true;
307217 option_menu_set_normal_colors (option_menu ,
308- PBL_IF_COLOR_ELSE ( GColorBlack , GColorWhite ) ,
309- PBL_IF_COLOR_ELSE ( GColorWhite , GColorBlack ) );
218+ PBL_COLOR ? GColorBlack : GColorWhite ,
219+ PBL_COLOR ? GColorWhite : GColorBlack );
310220 if (selected == 0 ) {
311- option_menu_set_highlight_colors (option_menu , DEFAULT_SETTINGS_HIGHLIGHT_COLOR , GColorWhite );
221+ option_menu_set_highlight_colors (option_menu , DEFAULT_SETTINGS_HIGHLIGHT_COLOR , PBL_COLOR ? GColorWhite : GColorBlack );
312222 }
313223 else {
314- option_menu_set_highlight_colors (option_menu , s_color_definitions [selected ].value , GColorWhite );
224+ option_menu_set_highlight_colors (option_menu , s_color_definitions [selected ].dark , PBL_COLOR ? GColorWhite : GColorBlack );
315225 }
316226 app_window_stack_push (& option_menu -> window , animated );
317227 }
318228}
319229
320-
321- /////////////////////////////
322- // Short Settings Accent Color Settings
323- /////////////////////////////
324- static void prv_settings_color_menu_select_short (OptionMenu * option_menu , int selection , void * context ) {
325- if (selection == 0 ){
326- /* Default option selected -> restore default color. */
327- shell_prefs_set_settings_menu_highlight_color (DEFAULT_SETTINGS_HIGHLIGHT_COLOR );
328- }
329- else if (selection == ARRAY_LENGTH (s_color_definitions_short ) - 1 ) {
330- prv_push_settings_color_menu ((SettingsThemesData * )context );
331- return ;
332- }
333- else {
334- shell_prefs_set_settings_menu_highlight_color (s_color_definitions [selection ].value );
335- }
336- }
337-
338- static void prv_option_settings_menu_selection_will_change_short (OptionMenu * option_menu ,
339- uint16_t new_row ,
340- uint16_t old_row ,
341- void * context ) {
342- if (new_row == old_row ) {
343- return ;
344- }
345- GColor color = s_color_definitions [new_row ].value ;
346- if (new_row >= ARRAY_LENGTH (s_color_definitions_short ) - 1 ) {
347- /* "Show All..." selected -> preview saved color. */
348- option_menu_set_highlight_colors (option_menu , shell_prefs_get_settings_menu_highlight_color (), GColorWhite );
349- }
350- else if (color .argb != GColorClear .argb ) {
351- option_menu_set_highlight_colors (option_menu , color , GColorWhite );
352- }
353- else {
354- option_menu_set_highlight_colors (option_menu , DEFAULT_SETTINGS_HIGHLIGHT_COLOR , GColorWhite );
355- }
356- }
357-
358-
359- static void prv_push_settings_color_menu_short (SettingsThemesData * data ) {
360- const char * title = i18n_noop ("Settings Accent" );
361- int selected = prv_color_to_index (shell_prefs_get_settings_menu_highlight_color (), true, DEFAULT_SETTINGS_HIGHLIGHT_COLOR );
362- const char * * color_names = prv_get_color_names (true);
363- const OptionMenuCallbacks callbacks = {
364- .select = prv_settings_color_menu_select_short ,
365- .selection_will_change = prv_option_settings_menu_selection_will_change_short ,
366- };
367- if (selected < 0 ) {
368- selected = ARRAY_LENGTH (s_color_definitions_short ) - 1 ;
369- }
370- OptionMenu * const option_menu = settings_option_menu_create (
371- title , OptionMenuContentType_SingleLine , selected , & callbacks ,
372- ARRAY_LENGTH (s_color_definitions_short ), true /* icons_enabled */ , color_names , data );
373-
374- if (option_menu ) {
375- const bool animated = true;
376- option_menu_set_normal_colors (option_menu ,
377- PBL_IF_COLOR_ELSE (GColorBlack , GColorWhite ),
378- PBL_IF_COLOR_ELSE (GColorWhite , GColorBlack ));
379- if (selected == 0 ) {
380- option_menu_set_highlight_colors (option_menu , DEFAULT_SETTINGS_HIGHLIGHT_COLOR , GColorWhite );
381- }
382- else if (selected == ARRAY_LENGTH (s_color_definitions_short ) - 1 ) {
383- // "Show All..." option selected
384- option_menu_set_highlight_colors (option_menu , shell_prefs_get_settings_menu_highlight_color (), GColorWhite );
385- }
386- else {
387- option_menu_set_highlight_colors (option_menu , s_color_definitions_short [selected ].value , GColorWhite );
388- }
389- app_window_stack_push (& option_menu -> window , animated );
390- }
391- }
392-
393-
394-
395230static void prv_select_click_cb (SettingsCallbacks * context , uint16_t row ) {
396231#if PBL_COLOR
397232 SettingsThemesData * data = (SettingsThemesData * )context ;
398233 switch ((ThemesMenuIndex )row ) {
399234 case ThemesMenuIndex_Apps :
400- prv_push_apps_color_menu_short (data );
235+ prv_push_apps_color_menu (data );
401236 goto done ;
402237 case ThemesMenuIndex_Settings :
403- prv_push_settings_color_menu_short (data );
238+ prv_push_settings_color_menu (data );
404239 goto done ;
405240 case ThemesMenuIndexCount :
406241 break ;
0 commit comments