Exemplo n.º 1
0
SidebarElement* sidebar_element_create(Layer *parent) {
  GRect bounds = element_get_bounds(parent);

  int trend_arrow_y = (bounds.size.h - trend_arrow_component_height()) / 2;
  int last_bg_y = (trend_arrow_y / 4 + bounds.size.h / 8) - ACTUAL_TEXT_HEIGHT_24 / 2 - PADDING_TOP_24;
  int delta_y = ((bounds.size.h + trend_arrow_y + trend_arrow_component_height()) / 4 + bounds.size.h * 3 / 8) - ACTUAL_TEXT_HEIGHT_24 / 2 - PADDING_TOP_24;

  TextLayer *last_bg_text = text_layer_create(GRect(0, last_bg_y, bounds.size.w, ACTUAL_TEXT_HEIGHT_24 + PADDING_TOP_24 + PADDING_BOTTOM_24));
  text_layer_set_font(last_bg_text, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_background_color(last_bg_text, GColorClear);
  text_layer_set_text_color(last_bg_text, element_fg(parent));
  text_layer_set_text_alignment(last_bg_text, GTextAlignmentCenter);
  layer_add_child(parent, text_layer_get_layer(last_bg_text));

  TrendArrowComponent *trend = trend_arrow_component_create(parent, (bounds.size.w - trend_arrow_component_width()) / 2, trend_arrow_y);

  TextLayer *delta_text = text_layer_create(GRect(0, delta_y, bounds.size.w, ACTUAL_TEXT_HEIGHT_24 + PADDING_TOP_24 + PADDING_BOTTOM_24));
  text_layer_set_font(delta_text, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_background_color(delta_text, GColorClear);
  text_layer_set_text_color(delta_text, element_fg(parent));
  text_layer_set_text_alignment(delta_text, GTextAlignmentCenter);
  layer_add_child(parent, text_layer_get_layer(delta_text));

  SidebarElement* el = malloc(sizeof(SidebarElement));
  el->last_bg_text = last_bg_text;
  el->trend = trend;
  el->delta_text = delta_text;
  return el;
}
SidebarElement* sidebar_element_create(Layer *parent) {
  GRect bounds = element_get_bounds(parent);
  FontChoice font = get_font(FONT_24_BOLD);

  int trend_arrow_y = (bounds.size.h - trend_arrow_component_height()) / 2;
  int last_bg_y = (trend_arrow_y / 4 + bounds.size.h / 8) - font.height / 2 - font.padding_top;
  int delta_y = ((bounds.size.h + trend_arrow_y + trend_arrow_component_height()) / 4 + bounds.size.h * 3 / 8) - font.height / 2 - font.padding_top;

  TextLayer *last_bg_text = text_layer_create(GRect(0, last_bg_y, bounds.size.w, font.height + font.padding_top + font.padding_bottom));
  text_layer_set_font(last_bg_text, fonts_get_system_font(font.key));
  text_layer_set_background_color(last_bg_text, GColorClear);
  text_layer_set_text_color(last_bg_text, element_fg(parent));
  text_layer_set_text_alignment(last_bg_text, GTextAlignmentCenter);
  layer_add_child(parent, text_layer_get_layer(last_bg_text));

  TrendArrowComponent *trend = trend_arrow_component_create(parent, (bounds.size.w - trend_arrow_component_width()) / 2, trend_arrow_y);

  TextLayer *delta_text = text_layer_create(GRect(0, delta_y, bounds.size.w, font.height + font.padding_top + font.padding_bottom));
  text_layer_set_font(delta_text, fonts_get_system_font(font.key));
  text_layer_set_background_color(delta_text, GColorClear);
  text_layer_set_text_color(delta_text, element_fg(parent));
  text_layer_set_text_alignment(delta_text, GTextAlignmentCenter);
  layer_add_child(parent, text_layer_get_layer(delta_text));

  SidebarElement* el = malloc(sizeof(SidebarElement));
  el->last_bg_text = last_bg_text;
  el->trend = trend;
  el->delta_text = delta_text;
  return el;
}
StatusBarElement* status_bar_element_create(Layer *parent) {
  GRect bounds = element_get_bounds(parent);

  int sm_text_margin = 2;
  FontChoice font = get_font(FONT_18_BOLD);

  int text_y, height;
  if (bounds.size.h <= font.height + font.padding_top + font.padding_bottom) {
    // vertically center text if there is only room for one line
    text_y = (bounds.size.h - font.height) / 2 - font.padding_top;
    height = font.height + font.padding_top + font.padding_bottom;
  } else {
    // otherwise take up all the space, with half the default padding
    text_y = -1 * font.padding_top / 2;
    height = bounds.size.h - text_y;
  }

  TextLayer *text = text_layer_create(GRect(
    sm_text_margin,
    text_y,
    bounds.size.w - sm_text_margin,
    height
  ));
  text_layer_set_text_alignment(text, GTextAlignmentLeft);
  text_layer_set_background_color(text, GColorClear);
  text_layer_set_text_color(text, element_fg(parent));

  text_layer_set_font(text, fonts_get_system_font(font.key));
  text_layer_set_overflow_mode(text, GTextOverflowModeWordWrap);
  layer_add_child(parent, text_layer_get_layer(text));

  BatteryComponent *battery = NULL;
  if (get_prefs()->battery_loc == BATTERY_LOC_STATUS_RIGHT) {
    // align the battery to the middle of the lowest line of text
    int lines = (bounds.size.h - text_y) / (font.height + font.padding_top);
    int battery_y = text_y + (font.height + font.padding_top) * (lines - 1) + font.padding_top + font.height / 2 - battery_component_height() / 2;
    // ...unless that places it too close to the bottom
    if (battery_y + battery_component_height() - battery_component_vertical_padding() > bounds.size.h - sm_text_margin) {
      battery_y = bounds.size.h - battery_component_height() + battery_component_vertical_padding() - sm_text_margin;
    }

    battery = battery_component_create(parent, bounds.size.w - battery_component_width() - sm_text_margin, battery_y, true);
  }

  StatusBarElement *el = malloc(sizeof(StatusBarElement));
  el->text = text;
  el->battery = battery;
  return el;
}
Exemplo n.º 4
0
StatusBarElement* status_bar_element_create(Layer *parent) {
  GRect bounds = element_get_bounds(parent);

  int sm_text_margin = 2;

  int y, height;
  if (bounds.size.h <= ACTUAL_TEXT_HEIGHT_18 + PADDING_TOP_18 + PADDING_BOTTOM_18) {
    // vertically center text if there is only room for one line
    y = (bounds.size.h - ACTUAL_TEXT_HEIGHT_18) / 2 - PADDING_TOP_18;
    height = ACTUAL_TEXT_HEIGHT_18 + PADDING_TOP_18 + PADDING_BOTTOM_18;
  } else {
    // otherwise take up all the space, with half the default padding
    y = -1 * PADDING_TOP_18 / 2;
    height = bounds.size.h - y;
  }
  TextLayer *text = text_layer_create(GRect(
    sm_text_margin,
    y,
    bounds.size.w - sm_text_margin,
    height
  ));
  text_layer_set_text_alignment(text, GTextAlignmentLeft);
  text_layer_set_background_color(text, GColorClear);
  text_layer_set_text_color(text, element_fg(parent));

  text_layer_set_font(text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_overflow_mode(text, GTextOverflowModeWordWrap);
  layer_add_child(parent, text_layer_get_layer(text));

  BatteryComponent *battery = NULL;
  if (get_prefs()->battery_loc == BATTERY_LOC_STATUS_RIGHT) {
    battery = battery_component_create(parent, bounds.size.w - battery_component_width() - battery_component_vertical_padding(), (bounds.size.h - battery_component_height()) / 2);
  }

  StatusBarElement *el = malloc(sizeof(StatusBarElement));
  el->text = text;
  el->battery = battery;
  return el;
}