1+ /* Copyright (C) 2021 JF, Adam Pigg, Avamander
2+ This file is part of InfiniTime.
3+ InfiniTime is free software: you can redistribute it and/or modify
4+ it under the terms of the GNU General Public License as published
5+ by the Free Software Foundation, either version 3 of the License, or
6+ (at your option) any later version.
7+ InfiniTime is distributed in the hope that it will be useful,
8+ but WITHOUT ANY WARRANTY; without even the implied warranty of
9+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+ GNU General Public License for more details.
11+ You should have received a copy of the GNU General Public License
12+ along with this program. If not, see <https://www.gnu.org/licenses/>.
13+ */
114#include " Alarm.h"
215#include " Screen.h"
316#include " Symbols.h"
@@ -21,66 +34,61 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController)
2134 alarmMinutes = alarmController.Minutes ();
2235 lv_label_set_text_fmt (time, " %02lu:%02lu" , alarmHours, alarmMinutes);
2336
24- lv_obj_align (time, lv_scr_act (), LV_ALIGN_IN_LEFT_MID , 0 , -20 );
37+ lv_obj_align (time, lv_scr_act (), LV_ALIGN_CENTER , 0 , -25 );
2538
2639 btnHoursUp = lv_btn_create (lv_scr_act (), nullptr );
2740 btnHoursUp->user_data = this ;
2841 lv_obj_set_event_cb (btnHoursUp, btnEventHandler);
29- lv_obj_align (btnHoursUp, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 20 , -80 );
30- lv_obj_set_height (btnHoursUp, 40 );
31- lv_obj_set_width (btnHoursUp, 60 );
42+ lv_obj_set_size (btnHoursUp, 60 , 40 );
43+ lv_obj_align (btnHoursUp, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 20 , -85 );
3244 txtHrUp = lv_label_create (btnHoursUp, nullptr );
3345 lv_label_set_text (txtHrUp, " +" );
3446
3547 btnHoursDown = lv_btn_create (lv_scr_act (), nullptr );
3648 btnHoursDown->user_data = this ;
3749 lv_obj_set_event_cb (btnHoursDown, btnEventHandler);
38- lv_obj_align (btnHoursDown, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 20 , +40 );
39- lv_obj_set_height (btnHoursDown, 40 );
40- lv_obj_set_width (btnHoursDown, 60 );
50+ lv_obj_set_size (btnHoursDown, 60 , 40 );
51+ lv_obj_align (btnHoursDown, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 20 , 35 );
4152 txtHrDown = lv_label_create (btnHoursDown, nullptr );
4253 lv_label_set_text (txtHrDown, " -" );
4354
4455 btnMinutesUp = lv_btn_create (lv_scr_act (), nullptr );
4556 btnMinutesUp->user_data = this ;
4657 lv_obj_set_event_cb (btnMinutesUp, btnEventHandler);
47- lv_obj_align (btnMinutesUp, lv_scr_act (), LV_ALIGN_IN_RIGHT_MID, 10 , -80 );
48- lv_obj_set_height (btnMinutesUp, 40 );
49- lv_obj_set_width (btnMinutesUp, 60 );
58+ lv_obj_set_size (btnMinutesUp, 60 , 40 );
59+ lv_obj_align (btnMinutesUp, lv_scr_act (), LV_ALIGN_IN_RIGHT_MID, -20 , -85 );
5060 txtMinUp = lv_label_create (btnMinutesUp, nullptr );
5161 lv_label_set_text (txtMinUp, " +" );
5262
5363 btnMinutesDown = lv_btn_create (lv_scr_act (), nullptr );
5464 btnMinutesDown->user_data = this ;
5565 lv_obj_set_event_cb (btnMinutesDown, btnEventHandler);
56- lv_obj_align (btnMinutesDown, lv_scr_act (), LV_ALIGN_IN_RIGHT_MID, 10 , +40 );
57- lv_obj_set_height (btnMinutesDown, 40 );
58- lv_obj_set_width (btnMinutesDown, 60 );
66+ lv_obj_set_size (btnMinutesDown, 60 , 40 );
67+ lv_obj_align (btnMinutesDown, lv_scr_act (), LV_ALIGN_IN_RIGHT_MID, -20 , 35 );
5968 txtMinDown = lv_label_create (btnMinutesDown, nullptr );
6069 lv_label_set_text (txtMinDown, " -" );
6170
6271 btnEnable = lv_btn_create (lv_scr_act (), nullptr );
6372 btnEnable->user_data = this ;
6473 lv_obj_set_event_cb (btnEnable, btnEventHandler);
65- lv_obj_align (btnEnable, lv_scr_act (), LV_ALIGN_IN_BOTTOM_LEFT, 3 , - 10 );
66- lv_obj_set_height (btnEnable, 40 );
74+ lv_obj_set_size (btnEnable, 115 , 50 );
75+ lv_obj_align (btnEnable, lv_scr_act (), LV_ALIGN_IN_BOTTOM_LEFT, 0 , 0 );
6776 txtEnable = lv_label_create (btnEnable, nullptr );
68- setEnableButtonState ();
77+ SetEnableButtonState ();
6978
7079 btnRecur = lv_btn_create (lv_scr_act (), nullptr );
7180 btnRecur->user_data = this ;
7281 lv_obj_set_event_cb (btnRecur, btnEventHandler);
73- lv_obj_align (btnRecur, lv_scr_act (), LV_ALIGN_IN_BOTTOM_RIGHT, - 3 , - 10 );
74- lv_obj_set_height (btnRecur, 40 );
82+ lv_obj_set_size (btnRecur, 115 , 50 );
83+ lv_obj_align (btnRecur, lv_scr_act (), LV_ALIGN_IN_BOTTOM_RIGHT, 0 , 0 );
7584 txtRecur = lv_label_create (btnRecur, nullptr );
76- setRecurButtonState ();
85+ SetRecurButtonState ();
7786
7887 btnInfo = lv_btn_create (lv_scr_act (), nullptr );
7988 btnInfo->user_data = this ;
8089 lv_obj_set_event_cb (btnInfo, btnEventHandler);
81- lv_obj_align (btnInfo, lv_scr_act (), LV_ALIGN_CENTER, 30 , -80 );
82- lv_obj_set_height (btnInfo, 40 );
83- lv_obj_set_width (btnInfo, 30 );
90+ lv_obj_set_size (btnInfo, 50 , 40 );
91+ lv_obj_align (btnInfo, lv_scr_act (), LV_ALIGN_CENTER, 0 , -85 );
8492 txtInfo = lv_label_create (btnInfo, nullptr );
8593 lv_label_set_text (txtInfo, " i" );
8694}
@@ -100,11 +108,11 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
100108 } else {
101109 alarmController.SetAlarm (alarmHours, alarmMinutes);
102110 }
103- setEnableButtonState ();
111+ SetEnableButtonState ();
104112 return ;
105113 }
106114 if (obj == btnInfo) {
107- showInfo ();
115+ ShowInfo ();
108116 return ;
109117 }
110118 if (obj == btnMessage) {
@@ -120,7 +128,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
120128 // can just do it once when the alarm is re-enabled
121129 if (alarmController.State () == AlarmController::AlarmState::Set) {
122130 alarmController.DisableAlarm ();
123- setEnableButtonState ();
131+ SetEnableButtonState ();
124132 }
125133 if (obj == btnMinutesUp) {
126134 if (alarmMinutes >= 59 ) {
@@ -159,17 +167,16 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
159167 return ;
160168 }
161169 if (obj == btnRecur) {
162- alarmController.ToggleRecurrence ();
163- setRecurButtonState ();
170+ ToggleRecurrence ();
164171 }
165172 }
166173}
167174
168175void Alarm::SetAlerting () {
169- setEnableButtonState ();
176+ SetEnableButtonState ();
170177}
171178
172- void Alarm::setEnableButtonState () {
179+ void Alarm::SetEnableButtonState () {
173180 switch (alarmController.State ()) {
174181 case AlarmController::AlarmState::Set:
175182 lv_label_set_text (txtEnable, " ON" );
@@ -185,7 +192,7 @@ void Alarm::setEnableButtonState() {
185192 }
186193}
187194
188- void Alarm::showInfo () {
195+ void Alarm::ShowInfo () {
189196 btnMessage = lv_btn_create (lv_scr_act (), nullptr );
190197 btnMessage->user_data = this ;
191198 lv_obj_set_event_cb (btnMessage, btnEventHandler);
@@ -210,7 +217,7 @@ void Alarm::showInfo() {
210217 }
211218}
212219
213- void Alarm::setRecurButtonState () {
220+ void Alarm::SetRecurButtonState () {
214221 using Pinetime::Controllers::AlarmController;
215222 switch (alarmController.Recurrence ()) {
216223 case AlarmController::RecurType::None:
@@ -220,6 +227,21 @@ void Alarm::setRecurButtonState() {
220227 lv_label_set_text (txtRecur, " DAILY" );
221228 break ;
222229 case AlarmController::RecurType::Weekdays:
223- lv_label_set_text (txtRecur, " WKDAYS " );
230+ lv_label_set_text (txtRecur, " MON-FRI " );
224231 }
225- }
232+ }
233+
234+ void Alarm::ToggleRecurrence () {
235+ using Pinetime::Controllers::AlarmController;
236+ switch (alarmController.Recurrence ()) {
237+ case AlarmController::RecurType::None:
238+ alarmController.SetRecurrence (AlarmController::RecurType::Daily);
239+ break ;
240+ case AlarmController::RecurType::Daily:
241+ alarmController.SetRecurrence (AlarmController::RecurType::Weekdays);
242+ break ;
243+ case AlarmController::RecurType::Weekdays:
244+ alarmController.SetRecurrence (AlarmController::RecurType::None);
245+ }
246+ SetRecurButtonState ();
247+ }
0 commit comments