TextLayer MultiColor PebbleSDK

时间:2016-06-09 14:31:38

标签: pebble-watch pebble-sdk cloudpebble

有没有办法将卵石表盘上的文字层颜色设置为多种颜色?例如,如果时间是12:00,我希望1为一种颜色,2为第二种颜色,即:为第一种颜色,依此类推。我无法在任何地方找到这些信息,而且该方法似乎只采用一个变量。

1 个答案:

答案 0 :(得分:1)

这很容易,每次都需要更改上下文颜色,例如:

  void time_update_callback(Layer *layer, GContext *ctx)
  {
  /* Get a layer rect to re-draw */
  GRect layer_bounds = layer_get_bounds(layer);
  /* Get time from variables */ 
  char h1[2];
  char h2[2];
  char m1[2];
  char m2[2];
  h1[0] = hour_text_visible[0];
  h2[0] = hour_text_visible[1];
  m1[0] = minute_text_visible[0];
  m2[0] = minute_text_visible[1];
  h1[1] = h2[1] = m1[1] = m2[1] = 0;
  /* Add y padding to GRect */
  layer_bounds.origin.y += 1;
  /* Aux copy */ 
  GRect origin = layer_bounds;
  /* Change color to Black */
  graphics_context_set_text_color(ctx, GColorBlack);
  /* Move */
  layer_bounds.origin.x += 4;
  layer_bounds.origin.y += 1;
  /* Draw assuming you have a font loaded */ 
  graphics_draw_text(ctx, h1, font, layer_bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
  /* Move again */
  layer_bounds.origin.x += 20;
  /* Draw black also */
  graphics_draw_text(ctx, h2, font, layer_bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
  /* move */
  layer_bounds.origin.x += 30;
  /* Change color to Blue */
  graphics_context_set_text_color(ctx, GColorBlue);
  /* Draw in blue */
  graphics_draw_text(ctx, m1, font, layer_bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
  /* etc */
  }