static void title_layer_update_proc(Layer *layer, GContext* ctx) { GRect b = layer_get_bounds(layer); TitleLayer * title_layer = (TitleLayer*)(layer_get_data(layer)); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_fill_color(ctx, COLOR_SECONDARY); graphics_fill_rect(ctx,GRect(b.origin.x,b.origin.y,b.size.w,b.size.h),0,GCornersAll); graphics_context_set_text_color(ctx,GColorWhite); // Draw the text #ifdef PBL_ROUND // Create the attributes object used for text rendering GTextAttributes *s_attributes = graphics_text_attributes_create(); // Enable text flow with an inset of 5 pixels graphics_text_attributes_enable_screen_text_flow(s_attributes, 5); graphics_draw_text(ctx, title_layer->icon, fonts_get_font(RESOURCE_ID_FONT_ICONS_16), GRect(0, 2, PEBBLE_WIDTH, 16), GTextOverflowModeFill, GTextAlignmentCenter, NULL); graphics_draw_text(ctx, title_layer->title, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(0, 16, PEBBLE_WIDTH, 18), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, s_attributes); graphics_text_attributes_destroy(s_attributes); #else graphics_draw_text(ctx, title_layer->icon, fonts_get_font(RESOURCE_ID_FONT_ICONS_16), GRect(3, 2, 16, 16), GTextOverflowModeFill, GTextAlignmentCenter, NULL); graphics_draw_text(ctx, title_layer->title, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(22, -2, PEBBLE_WIDTH - 24, 18), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); #endif }
static void layer_update_callback(Layer *layer, GContext *ctx) { SimplyUi *self = *(void **)layer_get_data(layer); const GTextAlignment text_align = PBL_IF_ROUND_ELSE((self->window.use_action_bar ? GTextAlignmentRight : GTextAlignmentCenter), GTextAlignmentLeft); GRect window_frame = { .size = layer_get_frame(scroll_layer_get_layer(self->window.scroll_layer)).size, }; GRect frame = window_frame; const SimplyStyle *style = self->ui_layer.style; GFont title_font = fonts_get_system_font(style->title_font); GFont subtitle_font = fonts_get_system_font(style->subtitle_font); GFont body_font = self->ui_layer.custom_body_font ? self->ui_layer.custom_body_font : fonts_get_system_font(style->body_font); const int16_t margin_x = 5; const int16_t margin_y = 2; const int16_t image_offset_y = 3; GRect text_frame = frame; text_frame.size.w -= 2 * margin_x; text_frame.size.h += 1000; GPoint cursor = { margin_x, margin_y }; if (self->window.use_action_bar) { text_frame.size.w -= ACTION_BAR_WIDTH + PBL_IF_ROUND_ELSE(TEXT_FLOW_INSET, 0); window_frame.size.w -= ACTION_BAR_WIDTH; } graphics_context_set_text_color(ctx, GColorBlack); const SimplyUiTextfield *title = &self->ui_layer.textfields[UiTitle]; const SimplyUiTextfield *subtitle = &self->ui_layer.textfields[UiSubtitle]; const SimplyUiTextfield *body = &self->ui_layer.textfields[UiBody]; GTextAttributes *title_attributes = graphics_text_attributes_create(); GTextAttributes *subtitle_attributes = graphics_text_attributes_create(); GTextAttributes *body_attributes = graphics_text_attributes_create(); bool has_title = is_string(title->text); bool has_subtitle = is_string(subtitle->text); bool has_body = is_string(body->text); GSize title_size, subtitle_size; GPoint title_pos, subtitle_pos, image_pos = GPointZero; GRect body_rect; SimplyImage *title_icon = simply_res_get_image( self->window.simply->res, self->ui_layer.imagefields[UiTitleIcon]); SimplyImage *subtitle_icon = simply_res_get_image( self->window.simply->res, self->ui_layer.imagefields[UiSubtitleIcon]); SimplyImage *body_image = simply_res_get_image( self->window.simply->res, self->ui_layer.imagefields[UiBodyImage]); GRect title_icon_bounds = title_icon ? gbitmap_get_bounds(title_icon->bitmap) : GRectZero; GRect subtitle_icon_bounds = subtitle_icon ? gbitmap_get_bounds(subtitle_icon->bitmap) : GRectZero; GRect body_image_bounds; if (has_title) { GRect title_frame = { cursor, text_frame.size }; if (title_icon) { title_icon_bounds.origin = title_frame.origin; title_icon_bounds.origin.y += image_offset_y; PBL_IF_RECT_ELSE({ title_frame.origin.x += title_icon_bounds.size.w; title_frame.size.w -= title_icon_bounds.size.w; }, { title_frame.origin.y += title_icon_bounds.size.h + style->title_icon_padding; }); } PBL_IF_ROUND_ELSE( enable_text_flow_and_paging(self, title_attributes, &title_frame), NOOP); title_size = graphics_text_layout_get_content_size_with_attributes( title->text, title_font, title_frame, GTextOverflowModeWordWrap, text_align, title_attributes); title_size.w = title_frame.size.w; title_pos = title_frame.origin; cursor.y = title_frame.origin.y + title_size.h + style->title_padding; }
// This is the menu item draw callback where you specify what each item should look like static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { #ifdef PBL_BW graphics_context_set_text_color(ctx, GColorBlack); #endif if (cell_index->section > NUM_SECTIONS) return; if (cell_index->row > channels[cell_index->section].num) return; chan_info* channel = &channels[cell_index->section].chans[cell_index->row]; int left_pad=0; // Title and icon #ifdef PBL_ROUND GTextAttributes *s_attributes = graphics_text_attributes_create(); // Enable text flow with an inset of 5 pixels graphics_text_attributes_enable_screen_text_flow(s_attributes, 5); MenuIndex sel = menu_layer_get_selected_index(menu_layer); if ((sel.section==cell_index->section) && (sel.row==cell_index->row)) { graphics_draw_text(ctx, channel_icon_str(channel), fonts_get_font(RESOURCE_ID_FONT_ICONS_16), GRect(4, 4, PEBBLE_WIDTH-4, 16), GTextOverflowModeFill, GTextAlignmentCenter, s_attributes); graphics_draw_text(ctx, channel->name, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(4, 14, PEBBLE_WIDTH - 4, 24), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, s_attributes); graphics_draw_text(ctx, channel->unread_msg, fonts_get_system_font(channel->unread == 0 ? FONT_KEY_GOTHIC_14 : FONT_KEY_GOTHIC_14_BOLD), GRect(4, 36, PEBBLE_WIDTH - 4 - left_pad, 14), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, s_attributes); // graphics_draw_text(ctx, channel_icon_str(channel), // fonts_get_font(RESOURCE_ID_FONT_ICONS_16), GRect(4, 4, 16, 16), // GTextOverflowModeFill, GTextAlignmentCenter, s_attributes); // // graphics_draw_text(ctx, channel->name, // fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), // GRect(24, -6, PEBBLE_WIDTH - 24, 24), GTextOverflowModeTrailingEllipsis, // GTextAlignmentLeft, s_attributes); } else { graphics_draw_text(ctx, channel->name, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(4, -6, PEBBLE_WIDTH - 4, 24), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, s_attributes); graphics_draw_text(ctx, channel->unread_msg, fonts_get_system_font(channel->unread == 0 ? FONT_KEY_GOTHIC_14 : FONT_KEY_GOTHIC_14_BOLD), GRect(4, 20, PEBBLE_WIDTH - 4 - left_pad, 14), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, s_attributes); } graphics_text_attributes_destroy(s_attributes); #else graphics_draw_text(ctx, channel_icon_str(channel), fonts_get_font(RESOURCE_ID_FONT_ICONS_16), GRect(4+left_pad, 4, 16, 16), GTextOverflowModeFill, GTextAlignmentCenter, NULL); graphics_draw_text(ctx, channel->name, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(22+left_pad, -6, PEBBLE_WIDTH - 24- left_pad, 24), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, channel->unread_msg, fonts_get_system_font(channel->unread == 0 ? FONT_KEY_GOTHIC_14 : FONT_KEY_GOTHIC_14_BOLD), GRect(4+left_pad, 20, PEBBLE_WIDTH - 8 - left_pad, 14), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); #endif }