Commits

Trammell Hudson committed 018db16

Proper de-init handling of fonts

Comments (0)

Files changed (1)

hoelaat/src/nederlands.c

 #include "pebble_fonts.h"
 
 static Window window;
+static GFont font_thin;
+static GFont font_thick;
 
 static const char * min_text;
 static const char * rel_text;
 	int h
 )
 {
-	if (h == 0 || h == 24)
+	// only if it is actually midnight, not "before midnight"
+	if (h == 0)
 		return "midder-\nnacht";
 
 	if (h == 12)
 	hour_text = hour_string(hour);
 
 	// at midnight and noon do not display an am/pm notation
-	if (hour == 0 || hour == 12 || hour == 24)
+	// but don't say "before midnight"
+	if (hour == 0 || hour == 12)
 	{
 		// nothing to do
 		ampm_text = "";
 	} else
-	if (hour <= 6)
+	if (hour < 6)
 		ampm_text = "'s nachts";
 	else
 	if (hour <= 12)
 PBL_APP_INFO(
 	"Hoe laat is het?",
 	"hudson",
-	1, // Version
+	2, // Version
 	RESOURCE_ID_IMAGE_MENU_ICON,
 	APP_INFO_WATCH_FACE
 );
 text_layer(
 	TextLayer * layer,
 	GRect frame,
-	int font
+	GFont font
 )
 {
 	text_layer_init(layer, frame);
 	text_layer_set_text(layer, "");
 	text_layer_set_text_color(layer, GColorWhite);
 	text_layer_set_background_color(layer, GColorClear);
-	text_layer_set_font(layer, fonts_load_custom_font(resource_get_handle(font)));
+	text_layer_set_font(layer, font);
 
 	layer_add_child(&window.layer, &layer->layer);
 }
 	int y = 15;
 	int h = 30;
 
+	font_thin = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_28));
+	font_thick = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_BLACK_30));
+
 	// Stack top to bottom.  Note that the hour can take up
 	// two rows at midnight.
-	text_layer(&ampm_layer, GRect(4, y + 3*h, 144, h+8), RESOURCE_ID_FONT_ARIAL_28);
-	text_layer(&hour_layer, GRect(4, y + 2*h, 144, 2*h+8), RESOURCE_ID_FONT_ARIAL_BLACK_30);
-	text_layer(&rel_layer, GRect(4, y + 1*h, 144, h+8), RESOURCE_ID_FONT_ARIAL_28);
-	text_layer(&min_layer, GRect(4, y + 0*h, 144, h+8), RESOURCE_ID_FONT_ARIAL_28);
+	text_layer(&ampm_layer, GRect(4, y + 3*h, 144, h+8), font_thin);
+	text_layer(&hour_layer, GRect(4, y + 2*h, 144, 2*h+8), font_thin);
+	text_layer(&rel_layer, GRect(4, y + 1*h, 144, h+8), font_thick);
+	text_layer(&min_layer, GRect(4, y + 0*h, 144, h+8), font_thin);
+}
+
+
+static void
+handle_deinit(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	fonts_unload_custom_font(font_thin);
+	fonts_unload_custom_font(font_thick);
 }
 
 
 {
 	PebbleAppHandlers handlers = {
 		.init_handler	= &handle_init,
+		.deinit_handler = &handle_deinit,
 		.tick_info	= {
 			.tick_handler = &handle_tick,
 			.tick_units = MINUTE_UNIT,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.