Example #1
0
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
}
Example #2
0
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,
  });
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
  });
Example #5
0
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);
}
Example #6
0
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
  });
Example #7
0
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);
}
Example #8
0
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(&current_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;
}
Example #9
0
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;
    }