summaryrefslogtreecommitdiff
path: root/apps/menus/time_menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/menus/time_menu.c')
-rw-r--r--apps/menus/time_menu.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/apps/menus/time_menu.c b/apps/menus/time_menu.c
index cb0e4aac5b..bc08374ba0 100644
--- a/apps/menus/time_menu.c
+++ b/apps/menus/time_menu.c
@@ -46,11 +46,9 @@
46 46
47static int timedate_set(void) 47static int timedate_set(void)
48{ 48{
49 struct tm tm;
50 int result;
51
52 /* Make a local copy of the time struct */ 49 /* Make a local copy of the time struct */
53 memcpy(&tm, get_time(), sizeof(struct tm)); 50 struct tm tm = *get_time();
51 int result;
54 52
55 /* do some range checks */ 53 /* do some range checks */
56 /* This prevents problems with time/date setting after a power loss */ 54 /* This prevents problems with time/date setting after a power loss */
@@ -160,21 +158,6 @@ static void talk_timedate(void)
160 } 158 }
161} 159}
162 160
163static void vp_puts_center(struct viewport *vp, struct screen *display,
164 int line, const char *str)
165{
166 int w, offset;
167
168 display->getstringsize(str, &w, NULL);
169 if (w > vp->width)
170 display->puts_scroll(0, line, str);
171 else
172 {
173 offset = (vp->width - w)/2;
174 display->putsxy(offset, line * font_get(vp->font)->height, str);
175 }
176}
177
178static void draw_timedate(struct viewport *vp, struct screen *display) 161static void draw_timedate(struct viewport *vp, struct screen *display)
179{ 162{
180 struct tm *tm = get_time(); 163 struct tm *tm = get_time();
@@ -210,13 +193,14 @@ static void draw_timedate(struct viewport *vp, struct screen *display)
210 d = str(LANG_UNKNOWN); 193 d = str(LANG_UNKNOWN);
211 } 194 }
212 195
213 vp_puts_center(vp, display, line, t); 196 display->puts_scroll(0, line++, time);
214 line++; 197 display->puts_scroll(0, line, date);
215 vp_puts_center(vp, display, line, d);
216 198
217 display->update_viewport(); 199 display->update_viewport();
200 display->set_viewport(NULL);
218} 201}
219 202
203
220static struct viewport clock[NB_SCREENS], menu[NB_SCREENS]; 204static struct viewport clock[NB_SCREENS], menu[NB_SCREENS];
221static bool menu_was_pressed; 205static bool menu_was_pressed;
222static int time_menu_callback(int action, 206static int time_menu_callback(int action,
@@ -281,7 +265,11 @@ int time_screen(void* ignored)
281 } 265 }
282#endif 266#endif
283 nb_lines = viewport_get_nb_lines(&clock[i]); 267 nb_lines = viewport_get_nb_lines(&clock[i]);
268
284 menu[i] = clock[i]; 269 menu[i] = clock[i];
270 /* force time to be drawn centered */
271 clock[i].flags |= VP_FLAG_CENTER_ALIGN;
272
285 font_h = font_get(clock[i].font)->height; 273 font_h = font_get(clock[i].font)->height;
286 if (nb_lines > 3) 274 if (nb_lines > 3)
287 { 275 {
@@ -302,6 +290,7 @@ int time_screen(void* ignored)
302 menu[i].height -= clock[i].height; 290 menu[i].height -= clock[i].height;
303 draw_timedate(&clock[i], &screens[i]); 291 draw_timedate(&clock[i], &screens[i]);
304 } 292 }
293
305 ret = do_menu(&time_menu, NULL, menu, false); 294 ret = do_menu(&time_menu, NULL, menu, false);
306 /* see comments above in the button callback */ 295 /* see comments above in the button callback */
307 if (!menu_was_pressed && ret == GO_TO_PREVIOUS) 296 if (!menu_was_pressed && ret == GO_TO_PREVIOUS)