void storyview_init(char *title, char *summary) { window = window_create(); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); GRect max_text_bounds = GRect(2, 0, bounds.size.w - 4, 2000); scroll_layer = scroll_layer_create(bounds); scroll_layer_set_click_config_onto_window(scroll_layer, window); title_layer = text_layer_create(max_text_bounds); text_layer_set_font(title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text(title_layer, title); GSize title_max_size = text_layer_get_content_size(title_layer); text_layer_set_size(title_layer, GSize(title_max_size.w, title_max_size.h + 14)); summary_layer = text_layer_create(GRect(2, title_max_size.h + 14, max_text_bounds.size.w, max_text_bounds.size.h - (title_max_size.h + 14))); text_layer_set_font(summary_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text(summary_layer, summary); GSize summary_max_size = text_layer_get_content_size(summary_layer); text_layer_set_size(summary_layer, GSize(summary_max_size.w, summary_max_size.h + 14)); scroll_layer_set_content_size(scroll_layer, GSize(bounds.size.w, title_max_size.h + 14 + summary_max_size.h + 8)); scroll_layer_add_child(scroll_layer, text_layer_get_layer(title_layer)); scroll_layer_add_child(scroll_layer, text_layer_get_layer(summary_layer)); layer_add_child(window_layer, scroll_layer_get_layer(scroll_layer)); }
static void update_time() { time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); static char s_buffer_h[3]; strftime(s_buffer_h, sizeof(s_buffer_h), clock_is_24h_style() ? "%H" : "%I", tick_time); text_layer_set_text(s_timehours_layer, s_buffer_h); static char s_buffer_m[3]; strftime(s_buffer_m, sizeof(s_buffer_m), "%M", tick_time); text_layer_set_text(s_timemins_layer, s_buffer_m); static char s_buffer_ampm[3]; strftime(s_buffer_ampm, sizeof(s_buffer_ampm), clock_is_24h_style() ? "": "%p", tick_time); text_layer_set_text(s_time_ampm_layer, s_buffer_ampm); // Resize to ceneter GSize hoursSize = text_layer_get_content_size(s_timehours_layer); GSize minSize = text_layer_get_content_size(s_timemins_layer); GSize ampmSize = text_layer_get_content_size(s_time_ampm_layer); int combinedWidth = hoursSize.w + minSize.w; int halfWidth = combinedWidth / 2; text_layer_set_size(s_timehours_layer, GSize(xHalf + halfWidth - minSize.w, 90)); text_layer_set_size(s_timemins_layer, GSize(xHalf + halfWidth, 68)); text_layer_set_size(s_time_ampm_layer, GSize(xHalf + halfWidth - (minSize.w - ampmSize.w) + 2, 68)); }
/** * Initializates the GUI Elements */ void about_window_load (Window *window) { GRect windowBounds = layer_get_frame(ui.windowLayer); GRect titleBounds = GRect(0, 0, windowBounds.size.w, 30); ui.titleLayer = text_layer_create(titleBounds); text_layer_set_text_color(ui.titleLayer, GColorWhite); text_layer_set_background_color(ui.titleLayer, GColorBlack); text_layer_set_text(ui.titleLayer, "About"); text_layer_set_font(ui.titleLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(ui.titleLayer, GTextAlignmentCenter); layer_add_child(ui.windowLayer, text_layer_get_layer(ui.titleLayer)); // Creates the Scroll GRect scrollBounds = GRect(0, 30, windowBounds.size.w, (windowBounds.size.h - 30)); ui.scroll = scroll_layer_create(scrollBounds); scroll_layer_set_click_config_onto_window(ui.scroll, ui.window); layer_add_child(ui.windowLayer, scroll_layer_get_layer(ui.scroll)); GRect textBounds = GRect(0, 0, scrollBounds.size.w, 2000); ui.textLayer = text_layer_create(textBounds); text_layer_set_text_color(ui.textLayer, GColorBlack); text_layer_set_background_color(ui.textLayer, GColorClear); text_layer_set_text(ui.textLayer, "Developer:\nYago Carballo ([email protected])\n\nGame By...\nameiga 2014\n\n"); text_layer_set_font(ui.textLayer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(ui.textLayer, GTextAlignmentCenter); GSize max_size = text_layer_get_content_size(ui.textLayer); text_layer_set_size(ui.textLayer, max_size); scroll_layer_set_content_size(ui.scroll, GSize(windowBounds.size.w, max_size.h + 5)); scroll_layer_add_child(ui.scroll, text_layer_get_layer(ui.textLayer)); }
// Setup the scroll layer on window load // We do this here in order to be able to get the max used text size static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(0, 0, bounds.size.w, 2000); // Initialize the scroll layer scroll_layer = scroll_layer_create(bounds); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(scroll_layer, window); // Initialize the text layer text_layer = text_layer_create(max_text_bounds); text_layer_set_text(text_layer, scroll_text); // Change the font to a nice readable one // This is system font; you can inspect pebble_fonts.h for all system fonts // or you can take a look at feature_custom_font to add your own font text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(text_layer); text_layer_set_size(text_layer, max_size); scroll_layer_set_content_size(scroll_layer, GSize(bounds.size.w, max_size.h + vert_scroll_text_padding)); // Add the layers for display scroll_layer_add_child(scroll_layer, text_layer_get_layer(text_layer)); // The inverter layer will highlight some text inverter_layer = inverter_layer_create(GRect(0, 28, bounds.size.w, 28)); scroll_layer_add_child(scroll_layer, inverter_layer_get_layer(inverter_layer)); layer_add_child(window_layer, scroll_layer_get_layer(scroll_layer)); }
static void detail_window_load(Window *window) { #ifdef PBL_COLOR window_colorize(window); #endif // set up text layer Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); int16_t content_width = bounds.size.w-10; // Initialize the text layers GRect max_title_bounds = GRect(5, 0, content_width, 2000); s_detail_title_text_layer = detail_text_layer_create(max_title_bounds, s_detail_title, true); GSize title_size = text_layer_get_content_size(s_detail_title_text_layer); title_size.w = content_width; GRect max_text_bounds = GRect(5, title_size.h+2, content_width, 2000); s_detail_text_layer = detail_text_layer_create(max_text_bounds, s_detail_text, false); // Initialize the scroll layer s_detail_scroll_layer = scroll_layer_create(bounds); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(s_detail_scroll_layer, window); // Add the layers for display scroll_layer_add_child(s_detail_scroll_layer, text_layer_get_layer(s_detail_text_layer)); scroll_layer_add_child(s_detail_scroll_layer, text_layer_get_layer(s_detail_title_text_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_detail_scroll_layer)); // Trim text layer and scroll content to fit text box // GSize title_size = text_layer_get_content_size(s_detail_title_text_layer); title_size.w = content_width; title_size.h += 5; GSize text_size = text_layer_get_content_size(s_detail_text_layer); text_size.h += title_size.h; text_size.w = content_width; text_layer_set_size(s_detail_title_text_layer, title_size); text_layer_set_size(s_detail_text_layer, text_size); scroll_layer_set_content_size(s_detail_scroll_layer, GSize(bounds.size.w, title_size.h + text_size.h)); }
static void changeText(int step, const char* font){ animation_unschedule_all(); text_layer_set_font(s_text_layer, fonts_get_system_font(font)); text_layer_set_text(s_text_layer, wikiData[step]); number_of_pixels = layer_get_bounds(window_get_root_layer(s_wiki_window)).size.h - text_layer_get_content_size(s_text_layer).h; if (number_of_pixels < 0) { animate_quote(number_of_pixels); } }
static int textWidth(char *str) { TextLayer *txtLyr = text_layer_create(GRect(0, 0, 1024, 50)); text_layer_set_text(txtLyr, str); text_layer_set_font(txtLyr, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); GSize size = text_layer_get_content_size(txtLyr); text_layer_destroy(txtLyr); APP_LOG(APP_LOG_LEVEL_DEBUG, "%d", (int)size.w); return size.w; }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_scroll_layer = scroll_layer_create(bounds); scroll_layer_set_click_config_onto_window(s_scroll_layer, window); scroll_layer_set_shadow_hidden(s_scroll_layer, true); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); // Get the ContentIndicator from the ScrollLayer s_indicator = scroll_layer_get_content_indicator(s_scroll_layer); // Create two Layers to draw the arrows s_indicator_up_layer = layer_create(GRect(bounds.origin.x, bounds.origin.y, bounds.size.w, STATUS_BAR_LAYER_HEIGHT)); s_indicator_down_layer = layer_create(GRect(0, bounds.size.h - STATUS_BAR_LAYER_HEIGHT, bounds.size.w, STATUS_BAR_LAYER_HEIGHT)); layer_add_child(window_layer, s_indicator_up_layer); layer_add_child(window_layer, s_indicator_down_layer); // Configure the properties of each indicator const ContentIndicatorConfig up_config = (ContentIndicatorConfig) { .layer = s_indicator_up_layer, .times_out = false, .alignment = GAlignCenter, .colors = { .foreground = GColorBlack, .background = GColorWhite } }; content_indicator_configure_direction(s_indicator, ContentIndicatorDirectionUp, &up_config); const ContentIndicatorConfig down_config = (ContentIndicatorConfig) { .layer = s_indicator_down_layer, .times_out = false, .alignment = GAlignCenter, .colors = { .foreground = GColorBlack, .background = GColorWhite } }; content_indicator_configure_direction(s_indicator, ContentIndicatorDirectionDown, &down_config); s_content_layer = text_layer_create(GRect(bounds.origin.x, bounds.origin.y, bounds.size.w, 2000)); text_layer_set_text(s_content_layer, s_content); text_layer_set_text_alignment(s_content_layer, GTextAlignmentCenter); text_layer_set_font(s_content_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_content_layer)); GSize text_size = text_layer_get_content_size(s_content_layer); layer_set_frame(text_layer_get_layer(s_content_layer), GRect(bounds.origin.x, bounds.origin.y, bounds.size.w, text_size.h)); scroll_layer_set_content_size(s_scroll_layer, text_size); }
void scroll_text_layer_set_text(ScrollTextLayer* layer, char* text) { if (layer == NULL) { return; } text_layer_set_text(layer->text_layer, text); GSize max_size = text_layer_get_content_size(layer->text_layer); text_layer_set_size(layer->text_layer, max_size); GRect bounds = layer_get_bounds(scroll_layer_get_layer(layer->scroll_layer)); scroll_layer_set_content_size(layer->scroll_layer, GSize(bounds.size.w, max_size.h + (PADDING_Y * 3))); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); s_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ICONO_PRINCIPAL); GRect bitmap_bounds = gbitmap_get_bounds(s_icon_bitmap); s_fondo_layer = bitmap_layer_create(GRect(0, 0, 144, 40)); bitmap_layer_set_background_color(s_fondo_layer, COLOR_CABECERA); layer_add_child(window_layer, bitmap_layer_get_layer(s_fondo_layer)); s_scroll_layer = scroll_layer_create(GRect(10, 10 + bitmap_bounds.size.h + 5, 124, 168 - (10 + bitmap_bounds.size.h + 10))); scroll_layer_set_click_config_onto_window(s_scroll_layer, window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(0, 0, 120, 2000); s_label_layer = text_layer_create(max_text_bounds); text_layer_set_text(s_label_layer, i_lineas); text_layer_set_text_color(s_label_layer, COLOR_TEXTO_CUERPO); text_layer_set_background_color(s_label_layer, GColorClear); if (i_total_lineas> 3) text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); else text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28)); //layer_add_child(window_layer, text_layer_get_layer(s_label_layer)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(s_label_layer); text_layer_set_size(s_label_layer, max_size); scroll_layer_set_content_size(s_scroll_layer, GSize(bounds.size.w, max_size.h + 4)); scroll_layer_set_shadow_hidden(s_scroll_layer, true); scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_label_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); // CAPA DE LA PARADA s_titulo_layer = text_layer_create(GRect(38, 0 , 101, 40)); text_layer_set_text(s_titulo_layer, string_parada); text_layer_set_background_color(s_titulo_layer, GColorClear ); text_layer_set_text_color(s_titulo_layer, COLOR_TEXTO_CABECERA ); text_layer_set_text_alignment(s_titulo_layer, GTextAlignmentCenter); text_layer_set_font(s_titulo_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); layer_add_child(window_layer, text_layer_get_layer(s_titulo_layer)); // FIN DE CAPA DE LA PARADA // CAPA DEL ICONO DEL BUS s_icon_layer = bitmap_layer_create(GRect(5, 5, bitmap_bounds.size.w, bitmap_bounds.size.h)); bitmap_layer_set_bitmap(s_icon_layer, s_icon_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_icon_layer)); // FIN DE LA CAPA }
// Setup the scroll layer on window load // We do this here in order to be able to get the max used text size static void traveltime_details_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(10, 90, bounds.size.w - 20, 60); GRect from_text_bounds = GRect(10, 10, bounds.size.w - 20, 30); GRect name_text_bounds = GRect(10, 30, bounds.size.w - 20, 40); GRect bkg_text_bounds = GRect(0, 70, bounds.size.w, bounds.size.h); // Initialize the scroll layer traveltime_details_scroll_layer = scroll_layer_create(bounds); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(traveltime_details_scroll_layer, window); // Initialize the text layers traveltime_from_text_layer = text_layer_create(from_text_bounds); text_layer_set_text(traveltime_from_text_layer, "Depuis"); text_layer_set_font(traveltime_from_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); traveltime_name_text_layer = text_layer_create(name_text_bounds); text_layer_set_text(traveltime_name_text_layer, traveltimes_menu_items[current_traveltime_idx].title); text_layer_set_font(traveltime_name_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); traveltime_details_text_layer = text_layer_create(max_text_bounds); text_layer_set_text(traveltime_details_text_layer, traveltimes_menu_items[current_traveltime_idx].subtitle); text_layer_set_font(traveltime_details_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(traveltime_details_text_layer); //text_layer_set_size(traveltime_details_text_layer, max_size); scroll_layer_set_content_size(traveltime_details_scroll_layer, GSize(bounds.size.w, max_size.h + 104)); traveltime_bkg_text_layer = text_layer_create(bkg_text_bounds); #ifdef PBL_COLOR text_layer_set_background_color(traveltime_bkg_text_layer, GColorBlack); text_layer_set_background_color(traveltime_from_text_layer, GColorIslamicGreen); text_layer_set_background_color(traveltime_name_text_layer, GColorIslamicGreen); text_layer_set_background_color(traveltime_details_text_layer, GColorBlack); text_layer_set_text_color(traveltime_from_text_layer, GColorWhite); text_layer_set_text_color(traveltime_name_text_layer, GColorWhite); text_layer_set_text_color(traveltime_details_text_layer, GColorYellow); #endif // Add the layers for display scroll_layer_add_child(traveltime_details_scroll_layer, text_layer_get_layer(traveltime_bkg_text_layer)); scroll_layer_add_child(traveltime_details_scroll_layer, text_layer_get_layer(traveltime_from_text_layer)); scroll_layer_add_child(traveltime_details_scroll_layer, text_layer_get_layer(traveltime_name_text_layer)); scroll_layer_add_child(traveltime_details_scroll_layer, text_layer_get_layer(traveltime_details_text_layer)); layer_add_child(window_layer, scroll_layer_get_layer(traveltime_details_scroll_layer)); }
/** * Called when a result item is selected * @param index * @param ctx */ static void result_select_callback(int index, void *ctx) { //Called when a caregory menu item is selected g_index=index; window_stack_push(d_window, animated); text_layer_set_text(d_text_layer, detail[index]); GSize max_size = text_layer_get_content_size(d_text_layer); scroll_layer_set_content_size (d_scroll_layer, max_size ); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); GRect max_text_bounds = GRect(0, 0, bounds.size.w, 2000); // Initialize the scroll layer s_scroll_layer = scroll_layer_create(GRect(0, 55, bounds.size.w, 98)); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(s_scroll_layer, window); // Initialize the social messages scrolling text layer s_text_layer = text_layer_create(max_text_bounds); text_layer_set_text(s_text_layer, s_scroll_text); text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(s_text_layer); text_layer_set_size(s_text_layer, max_size); scroll_layer_set_content_size(s_scroll_layer, GSize(bounds.size.w, max_size.h + 4)); // Add the layers for display scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_text_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); // Set the text of the application name layer text_layer_app_name = text_layer_create(GRect(0, 0, bounds.size.w, 20)); text_layer_set_text(text_layer_app_name, "UbiSwim.org"); text_layer_set_text_alignment(text_layer_app_name, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_layer_app_name)); // Set the text of the social likes layer text_layer_likes = text_layer_create(GRect(0, 20, bounds.size.w, 40)); text_layer_set_font(text_layer_likes, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text(text_layer_likes, "Likes:"); text_layer_set_text_alignment(text_layer_likes, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_layer_likes)); // Set the text of the info layer text_layer_msg = text_layer_create(GRect(0, 150, bounds.size.w, 30)); text_layer_set_text(text_layer_msg, "U:Prev M:Like D:Next"); text_layer_set_text_alignment(text_layer_msg, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_layer_msg)); // Set the click config provider for the scrolling text layer scroll_layer_set_callbacks(s_scroll_layer, (ScrollLayerCallbacks) { .click_config_provider = &click_config_provider_updown });
static void window_appear (Window* window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); if (basic_info == NULL) { return; } int16_t y_offset = 0; state_text_layer = text_layer_create(GRect(0, 0, bounds.size.w, bounds.size.h / 4)); if (basic_info->state == Closed) { text_layer_set_text(state_text_layer, "Your space is closed.\n\n"); } else if (basic_info->state == Open) { text_layer_set_text(state_text_layer, "Your space is open.\n\n"); } else { text_layer_set_text(state_text_layer, "Your space state is unknown.\n\n"); } text_layer_set_text_alignment(state_text_layer, GTextAlignmentCenter); y_offset += text_layer_get_content_size(state_text_layer).h; layer_add_child(window_layer, text_layer_get_layer(state_text_layer)); if (basic_info->lastchange) { last_change_info_text_layer = text_layer_create(GRect(0, y_offset, bounds.size.w, bounds.size.h / 4)); text_layer_set_text(last_change_info_text_layer, "The space state changed on : "); y_offset += text_layer_get_content_size(last_change_info_text_layer).h; layer_add_child(window_layer, text_layer_get_layer(last_change_info_text_layer)); last_change_text_layer = text_layer_create(GRect(0, y_offset, bounds.size.w, bounds.size.h / 4)); strftime(last_change_buffer, 64, "%m/%d %H:%M:%S", localtime((time_t*) &(basic_info->lastchange))); text_layer_set_text(last_change_text_layer, last_change_buffer); text_layer_set_text_alignment(last_change_text_layer, GTextAlignmentCenter); y_offset += text_layer_get_content_size(last_change_text_layer).h; layer_add_child(window_layer, text_layer_get_layer(last_change_text_layer)); } }
/* * Update the font window with the currently selected font. * * This is called: * - When the font_window is initialized * - When the user presses up/down/select in the font window */ static void show_selected_font_and_message() { PebbleFont *font = &pebble_fonts[current_font]; // Update the font and text for the demo message text_layer_set_font(text_layer, fonts_get_system_font(font->res)); text_layer_set_text(text_layer, messages[current_message]); // Update the font name and font variant at the bottom of the screen text_layer_set_text(font_name_layer, font->name); text_layer_set_text(font_variant_layer, font->variant); // Update Font Size Layer GSize textSize = text_layer_get_content_size(text_layer); snprintf(size_text, sizeof(size_text), "H: %d W: %d", textSize.h, textSize.w); text_layer_set_text(font_size_layer, size_text); }
static void canvas_update_proc(Layer *layer, GContext *ctx) { int rect_width = text_layer_get_content_size(s_date_layer).w + 10; GRect rect_bounds = GRect(((180 - rect_width) / 2), 110, rect_width, 25); graphics_context_set_fill_color(ctx, settings.SecondaryColor); int corner_radius = 5; graphics_fill_rect(ctx, rect_bounds, corner_radius, GCornersAll); GPoint circle_center = GPoint(90, 90); uint16_t circle_radius = 75; graphics_context_set_stroke_color(ctx, settings.SecondaryColor); graphics_context_set_stroke_width(ctx, 1); graphics_draw_circle(ctx, circle_center, circle_radius); graphics_context_set_stroke_width(ctx, 3); uint16_t outer_circle_radius = 80; graphics_draw_circle(ctx, circle_center, outer_circle_radius); }
static void history_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); history_scroller = scroll_layer_create(bounds); scroll_layer_set_click_config_onto_window(history_scroller, window); int items = current_history_batch * HISTORY_BATCH_SIZE + history[current_history_batch].last_event + 1; int width = 142; int margin = (bounds.size.w - width)/2; GSize max_size = GSize(bounds.size.w, (items + 9) * 19); // font size is 18, 5 newlines before and 4 after history_layer = text_layer_create(GRect(margin, 0, width, max_size.h)); if ((current_history_batch == 0) && (history[0].last_event < 0)) { strcpy(history_text, "No history recorded."); } else { // int history_events = current_history_batch * HISTORY_BATCH_SIZE + history[current_history_batch].last_event + 1; // APP_LOG(APP_LOG_LEVEL_DEBUG, "%d history events", history_events); strcpy(history_text, "\n\n\n\n\n"); for (int b=current_history_batch; b>=0; b--) { // APP_LOG(APP_LOG_LEVEL_DEBUG, "Processing batch %d", b); for (int e=history[b].last_event; e>=0; e--) { // APP_LOG(APP_LOG_LEVEL_DEBUG, "Feeling %d at %d (%d/%d)", history[b].mood[e], (int) history[b].event_time[e], e, b); struct tm *lt = localtime(&history[b].event_time[e]); strftime(timestr, sizeof(timestr), "%V %a %k:%M", lt); snprintf(event_text, sizeof(event_text), "%s %s\n", timestr, Moods[history[b].mood[e]]); strncat(history_text, event_text, sizeof(event_text)); } } } strncat(history_text, "\n\n\n\n", 5); text_layer_set_text(history_layer, history_text); text_layer_set_font(history_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_overflow_mode(history_layer, GTextOverflowModeWordWrap); text_layer_set_text_color(history_layer, GColorBlack); text_layer_set_background_color(history_layer, GColorWhite); max_size = text_layer_get_content_size(history_layer); max_size.w = bounds.size.w; text_layer_set_size(history_layer, max_size); scroll_layer_set_content_size(history_scroller, max_size); scroll_layer_add_child(history_scroller, text_layer_get_layer(history_layer)); scroll_layer_set_content_offset(history_scroller, GPoint(0, 40), true); layer_add_child(window_layer, scroll_layer_get_layer(history_scroller)); }
static void main_window_load(Window *window) { // Set window layer bounds Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); // Create sizing layer // The goal of this layer is to calculate the vertical center TextLayer *vertical_position_layer = text_layer_create(bounds); text_layer_set_font(vertical_position_layer, s_font36); text_layer_set_text_alignment(vertical_position_layer, GTextAlignmentRight); text_layer_set_text(vertical_position_layer, "14:00"); GSize vertical_position_size = text_layer_get_content_size(vertical_position_layer); // Create the TextLayer with specific bounds //s_time_layer = text_layer_create(GRect(0, (bounds.size.h / 2) - (vertical_position_size.h / 2), bounds.size.w-5, vertical_position_size.h + 10)); s_time_layer = text_layer_create(GRect(0, 0, bounds.size.w, vertical_position_size.h)); //s_step_layer = text_layer_create(GRect(0, (bounds.size.h / 2) + (vertical_position_size.h / 2), bounds.size.w-5, vertical_position_size.h + 10)); s_step_layer = text_layer_create(GRect(0, vertical_position_size.h, bounds.size.w, vertical_position_size.h)); s_date_layer = text_layer_create(GRect(0, (vertical_position_size.h * 2), bounds.size.w, vertical_position_size.h)); // Modify text layer text_layer_set_background_color(s_time_layer, GColorBlack); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_text_alignment(s_time_layer, GTextAlignmentRight); text_layer_set_font(s_time_layer, s_font36); text_layer_set_background_color(s_step_layer, GColorBlack); text_layer_set_text_color(s_step_layer, GColorWhite); text_layer_set_text_alignment(s_step_layer, GTextAlignmentRight); text_layer_set_font(s_step_layer, s_font18); text_layer_set_background_color(s_date_layer, GColorBlack); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight); text_layer_set_font(s_date_layer, s_font18); // Destroy the temporary layer text_layer_destroy(vertical_position_layer); // Add it as a child layer to the Window's root layer layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); layer_add_child(window_layer, text_layer_get_layer(s_step_layer)); layer_add_child(window_layer, text_layer_get_layer(s_date_layer)); }
static void load(Window *window) { Layer *rl = window_get_root_layer(window); user_data *ud; Layer *l; GRect f; GSize s; ud = (user_data*) malloc(sizeof(*ud)); if (!ud) return; *ud = (user_data) { .moving = {-1, -1} }; window_set_user_data(window, ud); ud->icon = gbitmap_create_with_resource(RESOURCE_ID_MOVE); ud->tl = text_layer_create(layer_get_bounds(rl)); text_layer_set_text(ud->tl, "Use FreeOTP on your mobile device to add tokens."); text_layer_set_text_alignment(ud->tl, GTextAlignmentCenter); text_layer_set_overflow_mode(ud->tl, GTextOverflowModeWordWrap); s = text_layer_get_content_size(ud->tl); l = text_layer_get_layer(ud->tl); f = layer_get_frame(l); f.origin.y = (f.size.h - s.h) / 2; f.size.h = s.h; layer_set_frame(l, f); layer_set_hidden(l, true); ud->ml = menu_layer_create(layer_get_bounds(rl)); layer_set_hidden(menu_layer_get_layer(ud->ml), false); menu_layer_set_click_config_onto_window(ud->ml, window); menu_layer_set_callbacks(ud->ml, ud, (MenuLayerCallbacks) { .draw_row = menu_draw_row, .get_num_rows = menu_get_num_rows, .select_click = menu_select_click, .select_long_click = menu_select_long_click, .selection_changed = menu_selection_changed });
/************************************ App *************************************/ static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_text_layer = text_layer_create(GRect(0, 0, bounds.size.w - 10, 2000)); text_layer_set_text_color(s_text_layer, GColorDarkGray); changeText(0, FONT_KEY_GOTHIC_28_BOLD); text_layer_set_text(s_text_layer, wikiData[0]); layer_add_child(window_layer, text_layer_get_layer(s_text_layer)); // if height of quote > height of window, initiate animation to scroll GSize text_size = text_layer_get_content_size(s_text_layer); number_of_pixels = bounds.size.h - text_size.h; printf("bound height: %d\n", bounds.size.h); printf("text height: %d\n", text_size.h); if (number_of_pixels < 0) { printf("%s\n", "ANIMATION FOR DAYS"); animate_quote(number_of_pixels); } }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_scroll_layer = scroll_layer_create(bounds); scroll_layer_set_click_config_onto_window(s_scroll_layer, window); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); s_text_layer = text_layer_create(GRect(bounds.origin.x, bounds.origin.y, bounds.size.w, 2000)); text_layer_set_text(s_text_layer, s_long_text); text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter); text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_text_layer)); scroll_layer_set_content_size(s_scroll_layer, text_layer_get_content_size(s_text_layer)); // Must be after added to the view heirachy text_layer_enable_screen_text_flow_and_paging(s_text_layer, 2); // Enable ScrollLayer paging scroll_layer_set_paging(s_scroll_layer, true); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(0, 0, bounds.size.w, 2000); // Initialize the scroll layer s_scroll_layer = scroll_layer_create(bounds); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(s_scroll_layer, window); // Initialize the text layer s_text_layer = text_layer_create(max_text_bounds); text_layer_set_text(s_text_layer, s_scroll_text); // Change the font to a nice readable one // This is system font; you can inspect pebble_fonts.h for all system fonts // or you can take a look at feature_custom_font to add your own font text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_background_color(s_text_layer, GColorClear); #if defined(PBL_PLATFORM_APLITE) text_layer_set_text_color(s_text_layer, GColorBlack); #else text_layer_set_text_color(s_text_layer, GColorWhite); #endif // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(s_text_layer); text_layer_set_size(s_text_layer, max_size); scroll_layer_set_content_size(s_scroll_layer, GSize(bounds.size.w, max_size.h + 4)); // Add the layers for display scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_text_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); }
static void window_load(Window *window) { current_question = QA[4]; window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect inner = GRect(0,0,112,168); s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_background); s_background_layer = bitmap_layer_create(bounds); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); prompt_layer = text_layer_create(inner); text_layer_set_text_color(prompt_layer, GColorBlack); text_layer_set_background_color(prompt_layer, GColorClear); text_layer_set_font(prompt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(prompt_layer, GTextAlignmentCenter); layer_set_frame( text_layer_get_layer(prompt_layer), GRect(0, ((168 - (text_layer_get_content_size(prompt_layer).h)) / 2) - 4, 112, text_layer_get_content_size(prompt_layer).h) ); layer_add_child(window_layer, text_layer_get_layer(prompt_layer)); }
// Make a text layer half the height of the screen, // and set its font as big as possible that still // keeps the text visible TextLayer* make_text(const char* text, bool is_front) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); //APP_LOG(APP_LOG_LEVEL_ERROR, "bounds of window: x=%d, y=%d, w=%d, h=%d", // bounds.origin.x, bounds.origin.y, bounds.size.w, bounds.size.h); int16_t screen_height = bounds.size.h; int16_t half_screen_height = screen_height/2; TextLayer* layer = text_layer_create(GRect(0, is_front ? 0 : half_screen_height, 144, screen_height)); text_layer_set_text(layer, text); text_layer_set_text_alignment(layer, GTextAlignmentLeft); // step down font size until the text fits in half a screen height for (int i = 0; i < num_fonts; ++i) { text_layer_set_font(layer, fonts_get_system_font(fonts[i])); GSize size = text_layer_get_content_size(layer); //APP_LOG(APP_LOG_LEVEL_ERROR, "%s occupies h=%d w=%d", fonts[i], size.h, size.w); if (size.h <= half_screen_height) break; } // if we finished the loop without finding a small enough font, just live with it text_layer_set_background_color(layer, is_front ? GColorWhite : GColorBlack); text_layer_set_text_color(layer, is_front ? GColorBlack : GColorWhite); return layer; }
#endif window_stack_push(s_window, true); GRect bounds = layer_get_frame(window_get_root_layer(s_window)); GRect max_text_bounds = GRect(0, 0, bounds.size.w, 10000); scroll_layer = scroll_layer_create(bounds); scroll_layer_set_click_config_onto_window(scroll_layer, s_window); text_layer = text_layer_create(max_text_bounds); text_layer_set_text(text_layer, scroll_text); text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); GSize max_size = text_layer_get_content_size(text_layer); max_size = GSize(max_size.w, max_size.h + 10); text_layer_set_size(text_layer, max_size); scroll_layer_set_content_size(scroll_layer, GSize(bounds.size.w, max_size.h)); scroll_layer_add_child(scroll_layer, text_layer_get_layer(text_layer)); layer_add_child(window_get_root_layer(s_window), scroll_layer_get_layer(scroll_layer)); #ifdef PBL_COLOR text_layer_set_background_color(text_layer, GColorPastelYellow); #endif text_layer_set_text_color(text_layer, GColorBlack); layer_mark_dirty(text_layer_get_layer(text_layer)); text_layer_enable_screen_text_flow_and_paging(text_layer, 8);
static void result_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); RestaurantInformation *ptr; uint8_t status; bool valid_result = false; // create action bar and bind key pressing only when valid result is displayed #ifdef PBL_ROUND // no need for the following variables #else GSize max_size, sub_max_size; int title_height; TextLayer *temp; #endif APP_LOG(APP_LOG_LEVEL_DEBUG, "Result window load"); status = search_result.query_status; switch(status){ case QUERY_STATUS_SUCCESS: valid_result = true; // Randomly pick up the restaurant search_result.random_result = rand()%search_result.num_of_restaurant; // Collect required fields ptr = &(search_result.restaurant_info[search_result.random_result]); strncpy(title_text, ptr->name, sizeof(title_text)); if(user_setting.unit == 0){ snprintf(sub_text, sizeof(sub_text), "%s %u %s", direction_name[ptr->direction], (unsigned int)(ptr->distance), setting_unit_option_text[user_setting.unit]); } else{ snprintf(sub_text, sizeof(sub_text), "%s %u.%u %s", direction_name[ptr->direction], (unsigned int)(ptr->distance/100), (unsigned int)(ptr->distance%100), setting_unit_option_text[user_setting.unit]); } break; case QUERY_STATUS_NO_RESULT: case QUERY_STATUS_GPS_TIMEOUT: // Set corresponding error messages to title and subtitle strncpy(title_text, query_status_error_message[status], sizeof(title_text)); strncpy(sub_text, query_status_error_sub_message[status], sizeof(sub_text)); break; case QUERY_STATUS_GOOGLE_API_ERROR: // Collect error message from returned information strncpy(title_text, query_status_error_message[status], sizeof(title_text)); strncpy(sub_text, search_result.api_error_message, sizeof(sub_text)); break; default: // Other query status = unknown error strncpy(title_text, unknown_error_message, sizeof(title_text)); snprintf(sub_text, sizeof(sub_text), "%s %s%d", unknown_error_sub_message, "Incorrect query status:",status); break; } #ifdef PBL_ROUND // action bar part if(valid_result == true){ icon_agenda_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_AGENDA); text_layer_width = bounds.size.w - ACTION_BAR_WIDTH; s_result_action_bar_layer = action_bar_layer_create(); #ifdef PBL_COLOR action_bar_layer_set_background_color(s_result_action_bar_layer, highlight_alt_bg_color); #endif } else{ text_layer_width = bounds.size.w; } // title part s_result_title_layer = layer_create(bounds); layer_set_update_proc(s_result_title_layer, result_title_layer_update_proc); // subtitle part s_result_sub_layer = layer_create(GRect(bounds.origin.x, bounds.origin.y+120, bounds.size.w, bounds.size.h-100)); layer_set_update_proc(s_result_sub_layer, result_sub_layer_update_proc); layer_add_child(window_layer, s_result_title_layer); layer_add_child(window_layer, s_result_sub_layer); action_bar_layer_add_to_window(s_result_action_bar_layer, window); action_bar_layer_set_icon(s_result_action_bar_layer, BUTTON_ID_SELECT, icon_agenda_bitmap); action_bar_layer_set_click_config_provider(s_result_action_bar_layer, result_click_config_provider); #else // #ifdef PBL_ROUND // action bar part if(valid_result == true){ icon_agenda_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_AGENDA); text_layer_width = bounds.size.w - ACTION_BAR_WIDTH; s_result_action_bar_layer = action_bar_layer_create(); #ifdef PBL_COLOR action_bar_layer_set_background_color(s_result_action_bar_layer, highlight_alt_bg_color); #endif action_bar_layer_add_to_window(s_result_action_bar_layer, window); action_bar_layer_set_icon(s_result_action_bar_layer, BUTTON_ID_SELECT, icon_agenda_bitmap); } else{ text_layer_width = bounds.size.w; } // compute require height for sub-title temp = text_layer_create(GRect(bounds.origin.x, bounds.origin.y, text_layer_width, bounds.size.h)); text_layer_set_font(temp, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text(temp, sub_text); sub_max_size = text_layer_get_content_size(temp); text_layer_destroy(temp); // title part s_result_title_text_layer = text_layer_create(GRect(bounds.origin.x, bounds.origin.y, text_layer_width, 2000)); text_layer_set_font(s_result_title_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text_alignment(s_result_title_text_layer, GTextAlignmentLeft); text_layer_set_overflow_mode(s_result_title_text_layer, GTextOverflowModeWordWrap); text_layer_set_background_color(s_result_title_text_layer, bg_color); text_layer_set_text_color(s_result_title_text_layer, text_color); text_layer_set_text(s_result_title_text_layer, title_text); max_size = text_layer_get_content_size(s_result_title_text_layer); // adjust title height. Always have 10px padding for certain characters to display if(max_size.h > (bounds.size.h - sub_max_size.h + 10)) title_height = (bounds.size.h - sub_max_size.h + 10); // title is very long: leave some space for sub-title. else if(max_size.h < (bounds.size.h/2 + 10)) title_height = (bounds.size.h/2 + 10); // title is short: make it half part else title_height = max_size.h + 10; // title is long, but not very long: use current size // create scroll layer s_result_scroll_layer = scroll_layer_create(GRect(bounds.origin.x, bounds.origin.y, text_layer_width, title_height)); if(valid_result == true){ scroll_layer_set_click_config_onto_window(s_result_scroll_layer, window); scroll_layer_set_callbacks(s_result_scroll_layer, (ScrollLayerCallbacks){.click_config_provider=result_click_config_provider});
int get_text_height() { text_layer_set_font(messagetext_layer, fonts_get_system_font(fontid2resource(fontmessage))); text_layer_set_text(messagetext_layer, chunk_buffer); return text_layer_get_content_size(messagetext_layer).h + 4; }
int get_header_height() { text_layer_set_font(messageheader_layer, fonts_get_system_font(fontid2resource(fontmessage))); text_layer_set_text(messageheader_layer, item_names[selected_item_id]); return text_layer_get_content_size(messageheader_layer).h + 4; }
static void trim_text_frame(void *callback_data) { ConnectionStatusComponent *c = callback_data; resize_text_frame(c, text_layer_get_content_size(c->staleness_text).w); }
//Initialize the TextLayer that will contain the drug information. GRect bounds = layer_get_frame(window_get_root_layer(window)); s_ind_drug_info_text_layer = text_layer_create(GRect(0,0,bounds.size.w,2000)); text_layer_set_font(s_ind_drug_info_text_layer,fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text(s_ind_drug_info_text_layer,s_drug_information); //Create the scroll layer. s_ind_drug_info_scroll_layer = scroll_layer_create(layer_get_frame(window_get_root_layer(window))); //Sets the up and down button actions to scrolling actions. scroll_layer_set_click_config_onto_window(s_ind_drug_info_scroll_layer,window); //Sets the select button to activate code mode. scroll_layer_set_callbacks(s_ind_drug_info_scroll_layer,(ScrollLayerCallbacks) {.click_config_provider=ind_drug_window_click_config_provider}); //Trims the scroll box to fit the contents of the text layer. See the scroll layer demo. int16_t scroll_layer_width = (layer_get_frame(window_get_root_layer(window))).size.w; int16_t scroll_layer_height = (text_layer_get_content_size(s_ind_drug_info_text_layer)).h + 4; scroll_layer_set_content_size(s_ind_drug_info_scroll_layer,GSize(scroll_layer_width,scroll_layer_height)); //Child assignment. scroll_layer_add_child(s_ind_drug_info_scroll_layer,text_layer_get_layer(s_ind_drug_info_text_layer)); layer_add_child(window_get_root_layer(window),scroll_layer_get_layer(s_ind_drug_info_scroll_layer)); } static void ind_drug_window_unload(Window *window) { strcpy(s_drug_information,""); text_layer_destroy(s_ind_drug_info_text_layer); window_destroy(s_ind_drug_window); } //Function to create the window that will display the drug information. This seemed easier than having //one callback function for each drug name, as well as multiple windows and load functions.