TextLayer MultiColor PebbleSDK

52 Views Asked by At

Is there any way to set the textlayer color on a pebble watchface to multiple colors? For instance, if the time is 12:00 I would like the 1 to be one color, the 2 to be a second color, the : to be the first color and so on and so forth. I cannot find this information anywhere, and the method seems to only take a single variable.

1

There are 1 best solutions below

0
vgonisanz On

It is easy to do, you need to change the context color each time, In example:

  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 */
  }