Close menu with button

This commit is contained in:
Riku Isokoski 2021-11-13 13:02:00 +02:00
parent 18e3cc7038
commit 39157f2f19
5 changed files with 35 additions and 16 deletions

View File

@ -249,10 +249,10 @@ void DisplayApp::Refresh() {
}
} break;
case Messages::ButtonPushed:
if (!currentScreen->OnButtonPushed()) {
if (currentApp == Apps::Clock) {
PushMessageToSystemTask(System::Messages::GoToSleep);
} else {
if (!currentScreen->OnButtonPushed()) {
LoadApp(returnToApp, returnDirection);
brightnessController.Set(settingsController.GetBrightness());
brightnessController.Backup();

View File

@ -54,6 +54,10 @@ bool Clock::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return screen->OnTouchEvent(event);
}
bool Clock::OnButtonPushed() {
return screen->OnButtonPushed();
}
std::unique_ptr<Screen> Clock::WatchFaceDigitalScreen() {
return std::make_unique<Screens::WatchFaceDigital>(app,
dateTimeController,

View File

@ -32,6 +32,7 @@ namespace Pinetime {
~Clock() override;
bool OnTouchEvent(TouchEvents event) override;
bool OnButtonPushed() override;
private:
Controllers::DateTime& dateTimeController;

View File

@ -316,6 +316,27 @@ bool PineTimeStyle::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return false;
}
void PineTimeStyle::CloseMenu() {
settingsController.SaveSettings();
lv_obj_set_hidden(btnNextTime, true);
lv_obj_set_hidden(btnPrevTime, true);
lv_obj_set_hidden(btnNextBar, true);
lv_obj_set_hidden(btnPrevBar, true);
lv_obj_set_hidden(btnNextBG, true);
lv_obj_set_hidden(btnPrevBG, true);
lv_obj_set_hidden(btnReset, true);
lv_obj_set_hidden(btnRandom, true);
lv_obj_set_hidden(btnClose, true);
}
bool PineTimeStyle::OnButtonPushed() {
if (!lv_obj_get_hidden(btnClose)) {
CloseMenu();
return true;
}
return false;
}
void PineTimeStyle::SetBatteryIcon() {
auto batteryPercent = batteryPercentRemaining.Get();
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
@ -532,16 +553,7 @@ void PineTimeStyle::UpdateSelected(lv_obj_t* object, lv_event_t event) {
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(valueBG));
}
if (object == btnClose) {
settingsController.SaveSettings();
lv_obj_set_hidden(btnNextTime, true);
lv_obj_set_hidden(btnPrevTime, true);
lv_obj_set_hidden(btnNextBar, true);
lv_obj_set_hidden(btnPrevBar, true);
lv_obj_set_hidden(btnNextBG, true);
lv_obj_set_hidden(btnPrevBG, true);
lv_obj_set_hidden(btnReset, true);
lv_obj_set_hidden(btnRandom, true);
lv_obj_set_hidden(btnClose, true);
CloseMenu();
}
if (object == btnSet) {
lv_obj_set_hidden(btnSet, true);

View File

@ -31,6 +31,7 @@ namespace Pinetime {
~PineTimeStyle() override;
bool OnTouchEvent(TouchEvents event) override;
bool OnButtonPushed() override;
void Refresh() override;
@ -96,6 +97,7 @@ namespace Pinetime {
Controllers::MotionController& motionController;
void SetBatteryIcon();
void CloseMenu();
lv_task_t* taskRefresh;
};