Created
May 30, 2013 10:44
-
-
Save Katharine/5677054 to your computer and use it in GitHub Desktop.
Demo program that breaks text. Move it left and right with the up and down keys.
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_os.h" | |
#include "pebble_app.h" | |
#include "pebble_fonts.h" | |
#define MY_UUID { 0xFC, 0xF3, 0xC3, 0xF1, 0xBC, 0xE4, 0x48, 0x3D, 0x92, 0x48, 0x79, 0x97, 0xAC, 0xC7, 0x2F, 0x7F } | |
PBL_APP_INFO_SIMPLE(MY_UUID, "Text Rendering Error", "Demo Corp", 1 /* App version */); | |
Window window; | |
Layer layer; | |
int8_t offset; | |
// Modify these common button handlers | |
void up_single_click_handler(ClickRecognizerRef recognizer, Window *window) { | |
++offset; | |
layer_mark_dirty(&layer); | |
} | |
void down_single_click_handler(ClickRecognizerRef recognizer, Window *window) { | |
--offset; | |
layer_mark_dirty(&layer); | |
} | |
void click_config_provider(ClickConfig **config, Window *window) { | |
config[BUTTON_ID_UP]->click.handler = (ClickHandler) up_single_click_handler; | |
config[BUTTON_ID_UP]->click.repeat_interval_ms = 100; | |
config[BUTTON_ID_DOWN]->click.handler = (ClickHandler) down_single_click_handler; | |
config[BUTTON_ID_DOWN]->click.repeat_interval_ms = 100; | |
} | |
void update_proc(Layer* layer, GContext* context) { | |
static char str[] = "Test"; | |
GFont font = fonts_get_system_font(FONT_KEY_GOTHAM_30_BLACK); | |
graphics_context_set_text_color(context, GColorBlack); | |
graphics_text_draw(context, str, font, GRect(offset, 0, 100, 40), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); | |
} | |
void handle_init(AppContextRef ctx) { | |
window_init(&window, "Debug"); | |
window_stack_push(&window, true /* Animated */); | |
layer_init(&layer, GRect(10,10,124,40)); | |
layer.update_proc = update_proc; | |
layer_add_child(&window.layer, &layer); | |
// Attach our desired button functionality | |
window_set_click_config_provider(&window, (ClickConfigProvider) click_config_provider); | |
} | |
void pbl_main(void *params) { | |
PebbleAppHandlers handlers = { | |
.init_handler = &handle_init | |
}; | |
app_event_loop(params, &handlers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment