@ -9,6 +9,37 @@ using namespace Pinetime::Applications::Screens;
constexpr const char * SettingWatchFace : : title ;
constexpr const char * SettingWatchFace : : title ;
constexpr const char * SettingWatchFace : : symbol ;
constexpr const char * SettingWatchFace : : symbol ;
namespace {
uint32_t IndexOf ( const std : : array < Pinetime : : Applications : : Screens : : SettingWatchFace : : Item ,
Pinetime : : Applications : : UserWatchFaceTypes : : Count > & watchfaces ,
Pinetime : : Applications : : WatchFace watchface ) {
size_t index = 0 ;
auto found = std : : find_if ( watchfaces . begin ( ) ,
watchfaces . end ( ) ,
[ & index , & watchface ] ( const Pinetime : : Applications : : Screens : : SettingWatchFace : : Item & item ) {
const bool result = item . watchface = = watchface ;
if ( ! result ) {
index + + ;
}
return result ;
} ) ;
if ( found = = watchfaces . end ( ) ) {
index = 0 ;
}
return index ;
}
Pinetime : : Applications : : WatchFace IndexToWatchFace ( const std : : array < Pinetime : : Applications : : Screens : : SettingWatchFace : : Item ,
Pinetime : : Applications : : UserWatchFaceTypes : : Count > & watchfaces ,
size_t index ) {
if ( index > = watchfaces . size ( ) ) {
return watchfaces [ 0 ] . watchface ;
}
return watchfaces [ index ] . watchface ;
}
}
auto SettingWatchFace : : CreateScreenList ( ) const {
auto SettingWatchFace : : CreateScreenList ( ) const {
std : : array < std : : function < std : : unique_ptr < Screen > ( ) > , nScreens > screens ;
std : : array < std : : function < std : : unique_ptr < Screen > ( ) > , nScreens > screens ;
for ( size_t i = 0 ; i < screens . size ( ) ; i + + ) {
for ( size_t i = 0 ; i < screens . size ( ) ; i + + ) {
@ -20,7 +51,7 @@ auto SettingWatchFace::CreateScreenList() const {
}
}
SettingWatchFace : : SettingWatchFace ( Pinetime : : Applications : : DisplayApp * app ,
SettingWatchFace : : SettingWatchFace ( Pinetime : : Applications : : DisplayApp * app ,
std : : array < Screens : : CheckboxList : : Item , UserWatchFaceTypes : : Count > & & watchfaceItems ,
std : : array < Screens : : SettingWatchFace : : Item , UserWatchFaceTypes : : Count > & & watchfaceItems ,
Pinetime : : Controllers : : Settings & settingsController ,
Pinetime : : Controllers : : Settings & settingsController ,
Pinetime : : Controllers : : FS & filesystem )
Pinetime : : Controllers : : FS & filesystem )
: app { app } ,
: app { app } ,
@ -44,7 +75,8 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen(unsigned int screenNum) c
if ( i + ( screenNum * settingsPerScreen ) > = watchfaceItems . size ( ) ) {
if ( i + ( screenNum * settingsPerScreen ) > = watchfaceItems . size ( ) ) {
watchfacesOnThisScreen [ i ] = { " " , false } ;
watchfacesOnThisScreen [ i ] = { " " , false } ;
} else {
} else {
watchfacesOnThisScreen [ i ] = watchfaceItems [ i + ( screenNum * settingsPerScreen ) ] ;
auto & item = watchfaceItems [ i + ( screenNum * settingsPerScreen ) ] ;
watchfacesOnThisScreen [ i ] = Screens : : CheckboxList : : Item { item . name , item . enabled } ;
}
}
}
}
@ -53,9 +85,9 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen(unsigned int screenNum) c
nScreens ,
nScreens ,
title ,
title ,
symbol ,
symbol ,
static_cast < uint32_t > ( settingsController. GetWatchFace ( ) ) ,
static_cast < uint32_t > ( IndexOf( watchfaceItems , settingsController. GetWatchFace ( ) ) ) ,
[ & settings = settingsController ] ( uint32_t index ) {
[ this , & settings = settingsController ] ( uint32_t index ) {
settings . SetWatchFace ( static_cast < WatchFace > ( index ) ) ;
settings . SetWatchFace ( IndexToWatchFace ( watchfaceItems , index ) ) ;
settings . SaveSettings ( ) ;
settings . SaveSettings ( ) ;
} ,
} ,
watchfacesOnThisScreen ) ;
watchfacesOnThisScreen ) ;