static void main_window_load(Window *window) { // Load the custom font s_icons = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ICONS_32)); s_helvetic_bold = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_HELVETICA_BOLD_20)); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_status_bar = status_bar_layer_create(); status_bar_layer_set_separator_mode(s_status_bar, StatusBarLayerSeparatorModeNone); status_bar_layer_set_colors(s_status_bar, GColorBlack, GColorWhite); // Create MenuLayer #if defined(PBL_RECT) s_menu_layer = menu_layer_create(GRect(0, STATUS_BAR_LAYER_HEIGHT, bounds.size.w, bounds.size.h)); #elif defined(PBL_ROUND) s_menu_layer = menu_layer_create(bounds); #endif menu_layer_set_callbacks(s_menu_layer, NULL, (MenuLayerCallbacks) { .get_num_sections = (MenuLayerGetNumberOfSectionsCallback)get_num_sections_callback, .get_num_rows = (MenuLayerGetNumberOfRowsInSectionsCallback)get_num_rows_callback, .get_cell_height = (MenuLayerGetCellHeightCallback)get_cell_height_callback, .get_header_height = (MenuLayerGetHeaderHeightCallback)get_header_height_callback, .draw_row = (MenuLayerDrawRowCallback)draw_row_callback, .draw_header = (MenuLayerDrawHeaderCallback)draw_header_callback, .select_click = (MenuLayerSelectCallback)select_callback, });
void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect window_bounds = layer_get_bounds(window_layer); window_set_background_color(window, GColorBlack ); LOCAL_action_bar = action_bar_layer_create(); for ( int loop = 0; loop < N_LAYERS; loop ++ ) { local_create_layer( window_layer, &window_bounds, loop ); } action_bar_layer_add_to_window(LOCAL_action_bar, window); // then add status bar LOCAL_status_bar = status_bar_layer_create(); int16_t width = layer_get_bounds(window_layer).size.w - ACTION_BAR_WIDTH; GRect frame = GRect(0, 0, width, STATUS_BAR_LAYER_HEIGHT); layer_set_frame(status_bar_layer_get_layer(LOCAL_status_bar), frame); layer_add_child(window_layer, status_bar_layer_get_layer(LOCAL_status_bar)); // Update all main_window_reload_config(); main_window_update_elapsed( time(NULL) ); }
void create_status_bar(Window *window) { #ifdef PBL_PLATFORM_BASALT bar_layer = status_bar_layer_create(); status_bar_layer_set_colors(bar_layer, GColorCobaltBlue, GColorWhite); layer_add_child(window_get_root_layer(window), status_bar_layer_get_layer(bar_layer)); #endif }
static void initialise_ui(void) { s_window = window_create(); //#ifdef PBL_PLATFORM_APLITE // window_set_fullscreen(s_window, false); //#endif Layer *window_layer = window_get_root_layer(s_window); s_res_droid_serif_28_bold = fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD); // s_textlayer_1 #ifdef PBL_ROUND s_textlayer_1 = text_layer_create(GRect(0, 52, 180, 37)); #else s_textlayer_1 = text_layer_create(GRect(0, 32, 144, 37)); #endif text_layer_set_text(s_textlayer_1, "rss-news"); text_layer_set_text_alignment(s_textlayer_1, GTextAlignmentCenter); text_layer_set_font(s_textlayer_1, s_res_droid_serif_28_bold); layer_add_child(window_layer, (Layer *)s_textlayer_1); s_res_gothic_14 = fonts_get_system_font(FONT_KEY_GOTHIC_14); #ifdef PBL_ROUND s_textlayer_2 = text_layer_create(GRect(0, 95, 180, 27)); #else s_textlayer_2 = text_layer_create(GRect(0, 95, 144, 27)); #endif text_layer_set_text(s_textlayer_2, "Currently unavailable"); text_layer_set_text_alignment(s_textlayer_2, GTextAlignmentCenter); text_layer_set_font(s_textlayer_2, s_res_gothic_14); layer_add_child(window_layer, (Layer *)s_textlayer_2); hide_no_con_error(); #ifndef PBL_PLATFORM_APLITE #ifdef PBL_ROUND s_bitmap_layer = bitmap_layer_create(GRect(57, 92, 64, 64)); #else s_bitmap_layer = bitmap_layer_create(GRect(37, 72, 64, 64)); #endif layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer)); // Create sequence s_sequence = gbitmap_sequence_create_with_resource(RESOURCE_ID_LOADING_ANIMATION); // Create GBitmap s_bitmap = gbitmap_create_blank(gbitmap_sequence_get_bitmap_size(s_sequence), GBitmapFormat8Bit); // Begin animation app_timer_register(1, timer_handler, NULL); // Set up the status bar last to ensure it is on top of other Layers s_status_bar = status_bar_layer_create(); layer_add_child(window_layer, status_bar_layer_get_layer(s_status_bar)); #else s_textlayer_loading = text_layer_create(GRect(0, 95, 144, 27)); text_layer_set_text(s_textlayer_loading, "Loading..."); text_layer_set_text_alignment(s_textlayer_loading, GTextAlignmentCenter); text_layer_set_font(s_textlayer_loading, s_res_gothic_14); layer_add_child(window_layer, (Layer *)s_textlayer_loading); #endif }
static void initialise_ui() { s_window = window_create(); #ifndef PBL_SDK_3 window_set_fullscreen(s_window, true); #endif s_res_gothic_28 = fonts_get_system_font(FONT_KEY_GOTHIC_28); GRect bounds = layer_get_bounds((Layer *)s_window); bounds.origin.y += STATUS_BAR_LAYER_HEIGHT; bounds.size.h -= STATUS_BAR_LAYER_HEIGHT; // s_statusbar_layer s_statusbar_layer = status_bar_layer_create(); status_bar_layer_set_colors(s_statusbar_layer, GColorDarkGreen, GColorWhite); layer_add_child(window_get_root_layer(s_window), (Layer *)s_statusbar_layer); // s_destination_layer const GRect destination_bounds = GRect(bounds.origin.x, bounds.origin.y, bounds.size.w, bounds.size.h/3); s_destination_layer = text_layer_create(destination_bounds); text_layer_set_text(s_destination_layer, "?"); text_layer_set_background_color(s_destination_layer, GColorBrightGreen); text_layer_set_font(s_destination_layer, s_res_gothic_28); layer_add_child(window_get_root_layer(s_window), (Layer *)s_destination_layer); // s_distance_layer const GRect distance_bounds = GRect(bounds.size.w/3, bounds.origin.y + bounds.size.h/3, (bounds.size.w*2)/3, bounds.size.h/3); s_distance_layer = text_layer_create(distance_bounds); text_layer_set_text(s_distance_layer, "?"); text_layer_set_font(s_distance_layer, s_res_gothic_28); text_layer_set_text_alignment(s_distance_layer, GTextAlignmentRight); layer_add_child(window_get_root_layer(s_window), (Layer *)s_distance_layer); // s_distance_label_layer const GRect distance_label_bounds = GRect(0, bounds.origin.y + bounds.size.h/3, bounds.size.w/3, bounds.size.h/3); s_distance_label_layer = text_layer_create(distance_label_bounds); text_layer_set_text(s_distance_label_layer, "Dist"); layer_add_child(window_get_root_layer(s_window), (Layer *)s_distance_label_layer); // s_eta_layer const GRect eta_bounds = GRect(bounds.size.w/3, bounds.origin.y + (bounds.size.h*2)/3, (bounds.size.w*2)/3, bounds.size.h/3); s_eta_layer = text_layer_create(eta_bounds); text_layer_set_text(s_eta_layer, "?"); text_layer_set_font(s_eta_layer, s_res_gothic_28); text_layer_set_text_alignment(s_eta_layer, GTextAlignmentRight); layer_add_child(window_get_root_layer(s_window), (Layer *)s_eta_layer); // s_eta_label_layer const GRect eta_label_bounds = GRect(0, bounds.origin.y + (bounds.size.h*2)/3, bounds.size.w/3, bounds.size.h/3); s_eta_label_layer = text_layer_create(eta_label_bounds); text_layer_set_text(s_eta_label_layer, "ETA"); layer_add_child(window_get_root_layer(s_window), (Layer *)s_eta_label_layer); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); s_status_bar = status_bar_layer_create(); status_bar_layer_set_separator_mode(s_status_bar, StatusBarLayerSeparatorModeDotted); status_bar_layer_set_colors(s_status_bar, GColorClear, GColorWhite); layer_add_child(window_layer, status_bar_layer_get_layer(s_status_bar)); s_progress_bar = layer_create((GRect){ .origin = GPoint(0, STATUS_BAR_LAYER_HEIGHT - 2), .size = PROGRESS_BAR_WINDOW_SIZE });
static void initialise_ui(void) { s_window = window_create(); Layer *root_layer = window_get_root_layer(s_window); GRect bounds = layer_get_bounds(root_layer); window_set_background_color(s_window, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack)); IF_2(window_set_fullscreen(s_window, false)); #ifdef PBL_ROUND int dev_layer_left = (bounds.size.w - DEV_LAYER_WIDTH)/2; int dev_layer_top = (bounds.size.h - DEV_LAYER_HEIGHT)/2; #else int dev_layer_left = ((bounds.size.w - DEV_LAYER_WIDTH - ACTION_BAR_WIDTH)/2) + 4; int dev_layer_top = ((bounds.size.h - DEV_LAYER_HEIGHT - 14)/2) + IF_32(14, 0); #endif s_rect_above = GRect(dev_layer_left, -(DEV_LAYER_HEIGHT+2), DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT); s_rect_onscreen = GRect(dev_layer_left, dev_layer_top, DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT); s_rect_below = GRect(dev_layer_left, bounds.size.h+2, DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT); // s_devicecard_layer s_devicecard_layer = devicecard_layer_create(s_rect_onscreen); layer_add_child(root_layer, s_devicecard_layer->layer); // s_layer_spots s_layer_spots = layer_create(PBL_IF_RECT_ELSE(GRect((dev_layer_left/2)-SPOT_RADIUS, dev_layer_top, (SPOT_RADIUS*2)+1 , DEV_LAYER_HEIGHT), bounds)); layer_add_child(root_layer, (Layer *)s_layer_spots); #ifndef PBL_SDK_2 s_status_bar = status_bar_layer_create(); status_bar_layer_set_colors(s_status_bar, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack), GColorWhite); layer_add_child(root_layer, status_bar_layer_get_layer(s_status_bar)); #endif s_res_image_action_up = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_UP); s_res_image_action_set = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_SET); s_res_image_action_down = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_DOWN); // s_actionbar_main s_actionbar_main = action_bar_layer_create(); action_bar_layer_add_to_window(s_actionbar_main, s_window); action_bar_layer_set_background_color(s_actionbar_main, GColorWhite); action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_UP, s_res_image_action_up); action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_SELECT, s_res_image_action_set); action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_DOWN, s_res_image_action_down); #ifdef PBL_RECT layer_set_frame(action_bar_layer_get_layer(s_actionbar_main), GRect(bounds.size.w-20, 0, 20, bounds.size.h)); IF_3(layer_set_bounds(action_bar_layer_get_layer(s_actionbar_main), GRect(-5, 0, 30, bounds.size.h))); #endif layer_add_child(root_layer, (Layer *)s_actionbar_main); }
static void windowLoad(Window *window) { Layer *windowLayer = window_get_root_layer(window); GRect frame = layer_get_frame(windowLayer); #ifdef PBL_PLATFORM_BASALT sStatusBar = status_bar_layer_create(); layer_add_child(windowLayer, status_bar_layer_get_layer(sStatusBar)); frame.size.h -= STATUS_BAR_LAYER_HEIGHT; frame.origin.y += STATUS_BAR_LAYER_HEIGHT; #endif sScroll = scroll_layer_create(frame); layer_add_child(windowLayer, scroll_layer_get_layer(sScroll)); }
void menu_handle_init(void) { menu_window = window_create(); text_layer = text_layer_create(GRect(0, 0, 144, 20)); text_layer_set_text(text_layer, "PSI SPACER"); StatusBarLayer* sb = status_bar_layer_create(); status_bar_layer_set_colors(sb,GColorBlack, GColorYellow); layer_add_child(window_get_root_layer(menu_window), status_bar_layer_get_layer(sb)); MenuLayer* menu_layer = menu_layer_create(GRect(0,STATUS_BAR_LAYER_HEIGHT,144,168)); menu_layer_set_callbacks(menu_layer, NULL, (MenuLayerCallbacks) { .get_num_rows=menu_cb_get_num_rows, .draw_row=menu_cb_draw_row, .select_click=menu_cb_select_click, .select_long_click=menu_cb_select_long_click });
void mainWindowLoad(Window* parentWindow) { GRect b = layer_get_bounds( window_get_root_layer(parentWindow) ); s_windowSizeY = b.size.h - STATUS_BAR_LAYER_HEIGHT; s_statusBar = status_bar_layer_create(); layer_add_child(window_get_root_layer(parentWindow), status_bar_layer_get_layer(s_statusBar)); status_bar_layer_set_separator_mode(s_statusBar, StatusBarLayerSeparatorModeDotted); s_mainBackgroundLayer = layer_create( GRect(0, STATUS_BAR_LAYER_HEIGHT, b.size.w, b.size.h - STATUS_BAR_LAYER_HEIGHT) ); layer_add_child(window_get_root_layer(parentWindow), s_mainBackgroundLayer); layer_set_update_proc(s_mainBackgroundLayer, mainBackgroundUpdateProc); int dispX = (b.size.w - BOARD_SIZE_X) / 2; int dispY = dispX; #ifdef PBL_ROUND dispY = 5; #endif s_boardLayer = layer_create( GRect(dispX, dispY, BOARD_SIZE_X + 1, BOARD_SIZE_Y + 1) ); layer_add_child(s_mainBackgroundLayer, s_boardLayer); layer_set_update_proc(s_boardLayer, boardUpdateProc); layer_set_clips(s_boardLayer, true); s_mainForegroundLayer = layer_create( GRect(0, STATUS_BAR_LAYER_HEIGHT, b.size.w, b.size.h - STATUS_BAR_LAYER_HEIGHT) ); layer_add_child(window_get_root_layer(parentWindow), s_mainForegroundLayer); layer_set_update_proc(s_mainForegroundLayer, mainForegroundUpdateProc); s_wave[0] = GRect(0, b.size.h * SUB_PIXEL, b.size.w, 10); s_wave[1] = GRect(0, b.size.h * SUB_PIXEL, b.size.w, 15); s_wave[2] = GRect(0, b.size.h * SUB_PIXEL, b.size.w, 20); s_liquid = GRect(0, b.size.h * SUB_PIXEL, b.size.w, b.size.h); // TODO x2 for safety s_nWaves = 0; s_liquidEnd = s_windowSizeY * SUB_PIXEL; s_currentRun = 0; s_switch.first = GPoint(-1,-1); s_switch.second = GPoint(-1,-1); s_cursor = GPoint(0,0); s_motionCursor = GPoint(PIECE_SUB_PIXELS/2,PIECE_SUB_PIXELS/2); s_availableMove = GPoint(-1,-1); srand(time(NULL)); startGameTick(); }
.get_header_height = menu_get_header_height_callback, .draw_header = menu_draw_header_callback, .draw_row = menu_draw_row_callback, .select_click = menu_select_callback, .selection_changed = menu_selection_changed_callback, }); // Bind the menu layer's click config provider to the window for interactivity menu_layer_set_click_config_onto_window(s_menuLayer, window); layer_add_child(windowLayer, menu_layer_get_layer(s_menuLayer)); initiateScrollTimer(); #ifdef PBL_SDK_3 s_statusBar = status_bar_layer_create(); layer_add_child(windowLayer, status_bar_layer_get_layer(s_statusBar)); s_battery = layer_create(GRect(bounds.origin.x, bounds.origin.y-16, bounds.size.w, STATUS_BAR_LAYER_HEIGHT)); layer_set_update_proc(s_battery, battery_proc); layer_add_child(windowLayer, s_battery); #endif } static void nearbyStopsWindow_unload(Window *window) { menu_layer_destroy(s_menuLayer); #ifdef PBL_SDK_3 status_bar_layer_destroy(s_statusBar); layer_destroy(s_battery); #endif }
PinWindow* pin_window_create(PinWindowCallbacks callbacks, PinWindowData data) { PinWindow *pin_window = (PinWindow*)malloc(sizeof(PinWindow)); if (data.nb_digits==0) data.nb_digits = PIN_WINDOW_NUM_CELLS; if (pin_window) { pin_window->window = window_create(); pin_window->callbacks = callbacks; if (pin_window->window) { pin_window->field_selection = 0; for(int i = 0; i < data.nb_digits; i++) { pin_window->pin.digits[i] = data.init_pin->digits[i]; } // Get window parameters Layer *window_layer = window_get_root_layer(pin_window->window); GRect bounds = layer_get_bounds(window_layer); // Main TextLayer const GEdgeInsets main_text_insets = {.top = 30}; pin_window->main_text = text_layer_create(grect_inset(bounds, main_text_insets)); text_layer_set_text(pin_window->main_text, data.main_text); text_layer_set_font(pin_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(pin_window->main_text, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(pin_window->main_text)); // Separators layer const GEdgeInsets sep_text_insets = {.top = 75}; pin_window->sep_text = text_layer_create(grect_inset(bounds, sep_text_insets)); if(data.nb_digits==3) text_layer_set_text(pin_window->sep_text, " : : "); else text_layer_set_text(pin_window->sep_text, " : "); text_layer_set_font(pin_window->sep_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(pin_window->sep_text, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(pin_window->sep_text)); // Sub TextLayer const GEdgeInsets sub_text_insets = {.top = 115, .right = 5, .bottom = 10, .left = 5}; pin_window->sub_text = text_layer_create(grect_inset(bounds, sub_text_insets)); text_layer_set_text(pin_window->sub_text, data.sub_text); text_layer_set_text_alignment(pin_window->sub_text, GTextAlignmentCenter); text_layer_set_font(pin_window->sub_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); layer_add_child(window_layer, text_layer_get_layer(pin_window->sub_text)); // Create selection layer const GEdgeInsets selection_insets = GEdgeInsets( (bounds.size.h - PIN_WINDOW_SIZE.h) / 2, (bounds.size.w - (40 * data.nb_digits)) / 2); pin_window->selection = selection_layer_create(grect_inset(bounds, selection_insets), data.nb_digits); for (int i = 0; i < data.nb_digits; i++) { selection_layer_set_cell_width(pin_window->selection, i, 40); } selection_layer_set_cell_padding(pin_window->selection, 4); selection_layer_set_active_bg_color(pin_window->selection, GColorRed); selection_layer_set_inactive_bg_color(pin_window->selection, GColorDarkGray); selection_layer_set_click_config_onto_window(pin_window->selection, pin_window->window); selection_layer_set_callbacks(pin_window->selection, pin_window, (SelectionLayerCallbacks) { .get_cell_text = selection_handle_get_text, .complete = selection_handle_complete, .increment = selection_handle_inc, .decrement = selection_handle_dec, }); layer_add_child(window_get_root_layer(pin_window->window), pin_window->selection); // Create status bar pin_window->status = status_bar_layer_create(); status_bar_layer_set_colors(pin_window->status, GColorClear, GColorBlack); layer_add_child(window_layer, status_bar_layer_get_layer(pin_window->status)); return pin_window; } } APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to create PinWindow"); return NULL; } void pin_window_destroy(PinWindow *pin_window) { if (pin_window) { status_bar_layer_destroy(pin_window->status); selection_layer_destroy(pin_window->selection); text_layer_destroy(pin_window->sub_text); text_layer_destroy(pin_window->main_text); text_layer_destroy(pin_window->sep_text); free(pin_window); pin_window = NULL; return; } } void pin_window_push(PinWindow *pin_window, bool animated) { window_stack_push(pin_window->window, animated); }
void chrono_digital_window_load_handler(struct Window *window) { app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "chrono digital loads"); GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD); #ifdef PBL_SDK_3 Layer *chrono_digital_window_layer = window_get_root_layer(chrono_digital_window); chrono_status_bar_layer = status_bar_layer_create(); if (chrono_status_bar_layer == NULL) { trigger_memory_panic(__LINE__); return; } layer_add_child(chrono_digital_window_layer, status_bar_layer_get_layer(chrono_status_bar_layer)); chrono_digital_contents_layer = layer_create(GRect((SCREEN_WIDTH - DIGITAL_LAYER_WIDTH) / 2, STATUS_BAR_LAYER_HEIGHT, DIGITAL_LAYER_WIDTH, SCREEN_HEIGHT - STATUS_BAR_LAYER_HEIGHT)); if (chrono_digital_contents_layer == NULL) { trigger_memory_panic(__LINE__); return; } layer_add_child(chrono_digital_window_layer, chrono_digital_contents_layer); #else // PBL_SDK_3 // On SDK 2.0 and before, we don't create a separate contents layer; // we just use the root layer. Layer *chrono_digital_contents_layer = window_get_root_layer(chrono_digital_window); #endif // PBL_SDK_3 chrono_digital_current_layer = text_layer_create(GRect(25, LAP_HEIGHT * CHRONO_MAX_LAPS, 94, LAP_HEIGHT)); if (chrono_digital_current_layer == NULL) { trigger_memory_panic(__LINE__); return; } int i; for (i = 0; i < CHRONO_MAX_LAPS; ++i) { chrono_digital_laps_layer[i] = text_layer_create(GRect(25, LAP_HEIGHT * i, 94, LAP_HEIGHT)); if (chrono_digital_laps_layer[i] == NULL) { trigger_memory_panic(__LINE__); return; } text_layer_set_text(chrono_digital_laps_layer[i], chrono_laps_buffer[i]); text_layer_set_text_color(chrono_digital_laps_layer[i], GColorBlack); text_layer_set_text_alignment(chrono_digital_laps_layer[i], GTextAlignmentRight); text_layer_set_overflow_mode(chrono_digital_laps_layer[i], GTextOverflowModeFill); text_layer_set_font(chrono_digital_laps_layer[i], font); layer_add_child(chrono_digital_contents_layer, (Layer *)chrono_digital_laps_layer[i]); } text_layer_set_text(chrono_digital_current_layer, chrono_current_buffer); text_layer_set_text_color(chrono_digital_current_layer, GColorBlack); text_layer_set_text_alignment(chrono_digital_current_layer, GTextAlignmentRight); text_layer_set_overflow_mode(chrono_digital_current_layer, GTextOverflowModeFill); text_layer_set_font(chrono_digital_current_layer, font); layer_add_child(chrono_digital_contents_layer, (Layer *)chrono_digital_current_layer); chrono_digital_line_layer = layer_create(GRect(0, LAP_HEIGHT * CHRONO_MAX_LAPS + 1, SCREEN_WIDTH, 1)); if (chrono_digital_line_layer == NULL) { trigger_memory_panic(__LINE__); return; } layer_set_update_proc(chrono_digital_line_layer, &chrono_digital_line_layer_update_callback); layer_add_child(chrono_digital_contents_layer, (Layer *)chrono_digital_line_layer); }
TimeWindow* time_window_create(TimeWindowCallbacks callbacks, ETimeState state) { TimeWindow *time_window = (TimeWindow*)malloc(sizeof(TimeWindow)); if (time_window) { time_window->window = window_create(); time_window->callbacks = callbacks; if (time_window->window) { time_t current_time = time(NULL); struct tm* current_tm = localtime(¤t_time); time_window->field_selection = 0; time_window->state = state; time_window->time.digits[0] = current_tm->tm_hour; time_window->time.digits[1] = current_tm->tm_min; // for(int i = 0; i < TIME_WINDOW_NUM_CELLS; i++) { // time_window->time.digits[i] = 0; // } // Get window parameters Layer *window_layer = window_get_root_layer(time_window->window); GRect bounds = layer_get_bounds(window_layer); // Main TextLayer const GEdgeInsets main_text_insets = {.top = 30}; time_window->main_text = text_layer_create(grect_inset(bounds, main_text_insets)); text_layer_set_text(time_window->main_text, "Time Required"); text_layer_set_font(time_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(time_window->main_text, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(time_window->main_text)); // Sub TextLayer const GEdgeInsets sub_text_insets = {.top = 115, .right = 5, .bottom = 10, .left = 5}; time_window->sub_text = text_layer_create(grect_inset(bounds, sub_text_insets)); text_layer_set_text(time_window->sub_text, "up/down to change time"); text_layer_set_text_alignment(time_window->sub_text, GTextAlignmentCenter); text_layer_set_font(time_window->sub_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); layer_add_child(window_layer, text_layer_get_layer(time_window->sub_text)); // Create selection layer const GEdgeInsets selection_insets = GEdgeInsets( (bounds.size.h - TIME_WINDOW_SIZE.h) / 2, (bounds.size.w - TIME_WINDOW_SIZE.w) / 2); time_window->selection = selection_layer_create(grect_inset(bounds, selection_insets), TIME_WINDOW_NUM_CELLS); for (int i = 0; i < TIME_WINDOW_NUM_CELLS; i++) { selection_layer_set_cell_width(time_window->selection, i, 60); } selection_layer_set_cell_padding(time_window->selection, 6); selection_layer_set_active_bg_color(time_window->selection, GColorRed); selection_layer_set_inactive_bg_color(time_window->selection, GColorDarkGray); selection_layer_set_click_config_onto_window(time_window->selection, time_window->window); selection_layer_set_callbacks(time_window->selection, time_window, (SelectionLayerCallbacks) { .get_cell_text = selection_handle_get_text, .complete = selection_handle_complete, .increment = selection_handle_inc, .decrement = selection_handle_dec, }); layer_add_child(window_get_root_layer(time_window->window), time_window->selection); // Create status bar time_window->status = status_bar_layer_create(); status_bar_layer_set_colors(time_window->status, GColorClear, GColorBlack); layer_add_child(window_layer, status_bar_layer_get_layer(time_window->status)); return time_window; } } APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to create TimeWindow"); return NULL; }
PinWindow* pin_window_create(PinWindowCallbacks callbacks) { PinWindow *pin_window = (PinWindow*)malloc(sizeof(PinWindow)); if (pin_window) { pin_window->window = window_create(); pin_window->callbacks = callbacks; if (pin_window->window) { pin_window->field_selection = 0; for(int i = 0; i < NUM_CELLS; i++) { pin_window->pin.digits[i] = 0; } // Get window parameters Layer *window_layer = window_get_root_layer(pin_window->window); GRect bounds = layer_get_bounds(window_layer); // Main TextLayer #ifdef PBL_SDK_3 pin_window->main_text = text_layer_create(GRect(0, 30, bounds.size.w, 40)); #else pin_window->main_text = text_layer_create(GRect(0, 15, bounds.size.w, 40)); #endif text_layer_set_text(pin_window->main_text, "PIN Required"); text_layer_set_font(pin_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(pin_window->main_text, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(pin_window->main_text)); // Sub TextLayer #ifdef PBL_SDK_3 pin_window->sub_text = text_layer_create(GRect(1, 125, bounds.size.w, 40)); #else pin_window->sub_text = text_layer_create(GRect(1, 110, bounds.size.w, 40)); #endif text_layer_set_text(pin_window->sub_text, "Enter your PIN to continue"); text_layer_set_text_alignment(pin_window->sub_text, GTextAlignmentCenter); text_layer_set_font(pin_window->sub_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); layer_add_child(window_layer, text_layer_get_layer(pin_window->sub_text)); // Create selection layer #ifdef PBL_SDK_3 pin_window->selection = selection_layer_create(GRect(8, 75, 128, 34), NUM_CELLS); #else pin_window->selection = selection_layer_create(GRect(8, 60, 128, 34), NUM_CELLS); #endif for (int i = 0; i < NUM_CELLS; i++) { selection_layer_set_cell_width(pin_window->selection, i, 40); } selection_layer_set_cell_padding(pin_window->selection, 4); #ifdef PBL_COLOR selection_layer_set_active_bg_color(pin_window->selection, GColorRed); selection_layer_set_inactive_bg_color(pin_window->selection, GColorDarkGray); #endif selection_layer_set_click_config_onto_window(pin_window->selection, pin_window->window); selection_layer_set_callbacks(pin_window->selection, pin_window, (SelectionLayerCallbacks) { .get_cell_text = selection_handle_get_text, .complete = selection_handle_complete, .increment = selection_handle_inc, .decrement = selection_handle_dec, }); layer_add_child(window_get_root_layer(pin_window->window), pin_window->selection); #ifdef PBL_SDK_3 // Create status bar pin_window->status = status_bar_layer_create(); status_bar_layer_set_colors(pin_window->status, GColorClear, GColorBlack); layer_add_child(window_layer, status_bar_layer_get_layer(pin_window->status)); #endif return pin_window; }
.state = PomStateReady, }; app.mainWindow = window_create(); window_set_background_color(app.mainWindow, GColorWhite); window_set_click_config_provider(app.mainWindow, pomMainWindowClickProvider); app.workingTextLayer = text_layer_create(GRect(2, 2, windowSize.w, 50)); text_layer_set_font(app.workingTextLayer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_background_color(app.workingTextLayer, GColorClear); app.timeTextLayer = text_layer_create(GRect(4, 45, 80, 30)); text_layer_set_font(app.timeTextLayer, fonts_get_system_font(FONT_KEY_FONT_FALLBACK)); text_layer_set_background_color(app.timeTextLayer, GColorClear); app.statusBarLayer = status_bar_layer_create(); app.batteryLayer = layer_create(GRect(0, 0, 144, STATUS_BAR_LAYER_HEIGHT)); layer_set_update_proc(app.batteryLayer, pomUpdateBatteryLayer); layer_add_child(window_get_root_layer(app.mainWindow), text_layer_get_layer(app.workingTextLayer)); layer_add_child(window_get_root_layer(app.mainWindow), text_layer_get_layer(app.timeTextLayer)); #if USE_CONSOLE __console_layer = text_layer_create(GRect(0, 28, 144, 140)); text_layer_set_overflow_mode(__console_layer, GTextOverflowModeWordWrap); text_layer_set_font(__console_layer, fonts_get_system_font(FONT_KEY_FONT_FALLBACK)); layer_add_child(window_get_root_layer(app.mainWindow), text_layer_get_layer(__console_layer.layer)); #endif pomInitMenuModule(); pomInitCookiesModule();