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;
}
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;
}
ConnectionStatusComponent* connection_status_component_create(Layer *parent, int x, int y) {
  BitmapLayer *icon_layer = bitmap_layer_create(GRect(x, y, REASON_ICON_WIDTH, REASON_ICON_WIDTH));
  // draw the icon background over the graph
  bitmap_layer_set_compositing_mode(icon_layer, get_element_data(parent)->black ? GCompOpAssignInverted : GCompOpAssign);
  layer_set_hidden(bitmap_layer_get_layer(icon_layer), true);
  layer_add_child(parent, bitmap_layer_get_layer(icon_layer));

  FontChoice font = get_font(FONT_18_BOLD);
  TextLayer *staleness_text = text_layer_create(GRect(
    x + REASON_ICON_WIDTH + 1,
    y + (REASON_ICON_WIDTH - font.height) / 2 - font.padding_top,
    INITIAL_TEXT_SIZE,
    font.height + font.padding_top + font.padding_bottom
  ));
  text_layer_set_font(staleness_text, fonts_get_system_font(font.key));
  text_layer_set_background_color(staleness_text, element_bg(parent));
  text_layer_set_text_color(staleness_text, element_fg(parent));
  text_layer_set_text_alignment(staleness_text, GTextAlignmentLeft);
  layer_set_hidden(text_layer_get_layer(staleness_text), true);
  layer_add_child(parent, text_layer_get_layer(staleness_text));

  ConnectionStatusComponent *c = malloc(sizeof(ConnectionStatusComponent));
  c->icon_layer = icon_layer;
  c->icon_bitmap = NULL;
  c->staleness_text = staleness_text;
  return c;
}
Exemple #4
0
BatteryComponent* battery_component_create(Layer *parent, int16_t x, int16_t y, bool align_right) {
    battery_state_service_subscribe(battery_handler);

    BatteryComponent *c = malloc(sizeof(BatteryComponent));
    c->icon_layer = NULL;
    c->icon_bitmap = NULL;
    c->text_layer = NULL;

    if (get_prefs()->battery_as_number) {

        FontChoice font = get_font(BATTERY_FONT);
        c->text_layer = add_text_layer(
                            parent,
                            GRect(x, y - font.padding_top + font.padding_bottom, BATTERY_TEXT_WIDTH, font.height + font.padding_top + font.padding_bottom),
                            fonts_get_system_font(font.key),
                            element_fg(parent),
                            align_right ? GTextAlignmentRight : GTextAlignmentLeft
                        );

    } else {

        c->icon_layer = bitmap_layer_create(GRect(x, y + BATTERY_ICON_TOP_FUDGE, BATTERY_ICON_WIDTH, BATTERY_ICON_HEIGHT));
        bitmap_layer_set_compositing_mode(c->icon_layer, element_comp_op(parent));
        layer_add_child(parent, bitmap_layer_get_layer(c->icon_layer));

    }

    // XXX
    s_component = c;
    battery_handler(battery_state_service_peek());

    return c;
}
Exemple #5
0
static void draw_background_and_borders(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  if (get_element_data(layer)->black) {
    graphics_context_set_fill_color(ctx, element_bg(layer));
    graphics_fill_rect(ctx, GRect(0, 0, bounds.size.w, bounds.size.h), 0, GCornerNone);
  }
  graphics_context_set_stroke_color(ctx, element_fg(layer));
  if (get_element_data(layer)->bottom) {
    graphics_draw_line(ctx, GPoint(0, bounds.size.h - 1), GPoint(bounds.size.w - 1, bounds.size.h - 1));
  }
  if (get_element_data(layer)->right) {
    graphics_draw_line(ctx, GPoint(bounds.size.w - 1, 0), GPoint(bounds.size.w - 1, bounds.size.h - 1));
  }
}
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;
}
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;
}