Created
January 28, 2018 20:08
-
-
Save Helco/d2ba785e1d9d298abfaecf7e870cc5da to your computer and use it in GitHub Desktop.
backup chalk draw watchface cell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void menu_cell_chalk_draw(GContext *ctx, const Layer *layer, const char *previous, MenuItem *selected, const char *next) | |
{ | |
GRect frame = layer_get_frame(layer); | |
// Draw the selected item: | |
const char *selected_title = selected->text; | |
bool has_icon = selected->image_res_id == 0 ? false : true; | |
if (selected_title) | |
{ | |
GFont title_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); | |
GRect title_rect = GRect(0, has_icon ? (frame.size.h / 2) - 12 : (frame.size.h / 2) - 20, frame.size.w, 24); | |
graphics_draw_text_app(ctx, selected_title, title_font, title_rect, GTextOverflowModeTrailingEllipsis, | |
GTextAlignmentCenter, 0); | |
} | |
const char *selected_subtitle = selected->sub_text; | |
if (selected_subtitle) | |
{ | |
GFont subtitle_font = fonts_get_system_font(FONT_KEY_GOTHIC_18); | |
n_GSize text_size = n_graphics_text_layout_get_content_size(selected_subtitle, subtitle_font); | |
GRect subtitle_rect = GRect(0, has_icon ? (frame.size.h / 2) + 12 : (frame.size.h / 2), frame.size.w, 24); | |
graphics_draw_text_app(ctx, selected_subtitle, subtitle_font, subtitle_rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, 0); | |
} | |
GBitmap *icon = gbitmap_create_with_resource(selected->image_res_id); | |
if (icon) | |
{ | |
GSize icon_size = icon->raw_bitmap_size; | |
graphics_draw_bitmap_in_rect_app(ctx, icon, GRect((frame.size.w / 2) - (icon_size.w / 2), ((frame.size.h - icon_size.h) / 2) - 20, icon_size.w, icon_size.h)); | |
} | |
// Draw the previous: | |
ctx->text_color = GColorBlack; | |
if (previous) | |
{ | |
GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); | |
n_GSize text_size = n_graphics_text_layout_get_content_size(previous, font); | |
GRect subtitle_rect = GRect(0, 20, frame.size.w, 24); | |
graphics_draw_text_app(ctx, previous, font, subtitle_rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, 0); | |
} | |
if (next) | |
{ | |
GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); | |
n_GSize text_size = n_graphics_text_layout_get_content_size(next, font); | |
GRect subtitle_rect = GRect((frame.size.w / 2) - (text_size.w / 2) - 10, 135, frame.size.w, 24); | |
graphics_draw_text_app(ctx, next, font, subtitle_rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, 0); | |
} | |
gbitmap_destroy(icon); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment