Created
February 7, 2014 10:19
-
-
Save vprus/8860225 to your computer and use it in GitHub Desktop.
Pebble normal vs. text layers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pebble.h> | |
#include <pebble_fonts.h> | |
static Window *window; | |
static Layer *left; | |
static TextLayer *right; | |
static GFont font; | |
static void draw_left(Layer *layer, GContext *ctx) { | |
graphics_context_set_text_color(ctx, GColorBlack); | |
graphics_draw_text(ctx, "T", font, (GRect) { .origin = {0, 0}, .size = {72, 84} }, | |
GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL); | |
} | |
static void window_load(Window *window) { | |
Layer *window_layer = window_get_root_layer(window); | |
font = fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD); | |
left = layer_create(GRect(0, 0, 72, 168)); | |
layer_set_bounds(left, (GRect) { .origin = { 0, 20 }, .size = { 72, 84 } } ); | |
layer_set_update_proc(left, draw_left); | |
layer_add_child(window_layer, left); | |
right = text_layer_create(GRect(72, 0, 72, 168)); | |
layer_set_bounds(text_layer_get_layer(right), (GRect) { .origin = { 0, 20 }, .size = { 72, 84 } } ); | |
text_layer_set_font(right, font); | |
text_layer_set_text(right, "T"); | |
text_layer_set_text_alignment(right, GTextAlignmentLeft); | |
layer_add_child(window_layer, text_layer_get_layer(right)); | |
} | |
static void window_unload(Window *window) { | |
layer_destroy(left); | |
text_layer_destroy(right); | |
} | |
static void init(void) { | |
window = window_create(); | |
window_set_window_handlers(window, (WindowHandlers) { | |
.load = window_load, | |
.unload = window_unload, | |
}); | |
window_stack_push(window, true); | |
} | |
static void deinit(void) { | |
window_destroy(window); | |
} | |
int main(void) { | |
init(); | |
app_event_loop(); | |
deinit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment