Ci-dessous, affichage de l’heure simple :
Pour le détail sur les layers : https://developer.getpebble.com/2/api-reference/group___text_layer.html
#include <pebble.h>
//*** Déclarations ***
//-- Layers
TextLayer *title_layer, *location_layer, *time_layer;
//-- Variables globales
char buffer[] = "00:00";
//-- Ecran
Window* window;
//*** Fonctions ***
//-- Définition Layers
static TextLayer* init_text_layer(GRect location, GColor colour, GColor background, const char *res_id, GTextAlignment alignment)
{
TextLayer *layer = text_layer_create(location);
text_layer_set_text_color(layer, colour);
text_layer_set_background_color(layer, background);
text_layer_set_font(layer, fonts_get_system_font(res_id));
text_layer_set_text_alignment(layer, alignment);
return layer;
}
//-- Update de l'affichage de l'heure
void tick_handler(struct tm *tick_time, TimeUnits units_changed)
{
//--Format the buffer string using tick_time as the time source
strftime(buffer, sizeof("00:00"), "%H:%M", tick_time);
//--Change the TextLayer text to show the new time!
text_layer_set_text(time_layer, buffer);
}
//-- affichage de la fenêtre
void window_load(Window *window)
{ time_layer = init_text_layer(GRect(0, 0, 144, 30),GColorClear ,GColorBlack , "RESOURCE_ID_GOTHIC_18", GTextAlignmentCenter);
layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));
location_layer = init_text_layer(GRect(5, 30, 144, 30), GColorBlack, GColorClear, "RESOURCE_ID_GOTHIC_18", GTextAlignmentLeft);
text_layer_set_text(location_layer, "Texte à afficher...");
layer_add_child(window_get_root_layer(window), text_layer_get_layer(location_layer));
}
//-- fermeture de la fenêtre
void window_unload(Window *window)
{//-- Désallocation des layers
text_layer_destroy(title_layer);
text_layer_destroy(location_layer);
}
//-- Initialisation de l'appli
void init()
{
//-- Init fenêtre affichage montre
window = window_create();
WindowHandlers handlers = {
.load = window_load,
.unload = window_unload
};
//-- Init des handlers
window_set_window_handlers(window, handlers);
window_stack_push(window, true);
//-- Init de l'affichage de l'heure
tick_timer_service_subscribe(MINUTE_UNIT, (TickHandler) tick_handler);
}
//-- Déseinstallation de l'appli
void deinit()
{
//-- Liberation des affectations
tick_timer_service_unsubscribe();
window_destroy(window);
}
//-- Lancement de l'application
int main(void)
{
init();
app_event_loop();
deinit();
}
Votre commentaire