Skip to content

Commit

Permalink
Squash height of title bar to text
Browse files Browse the repository at this point in the history
Reduce the height of the title bar text (used on the headlines page)
to the height of the text contained within it. This leaves more
space for the main content (the headlines menu list).
  • Loading branch information
llewelld committed Jan 17, 2016
1 parent 64d3f57 commit a02647d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 40 deletions.
17 changes: 15 additions & 2 deletions src/layers/title_bar.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <pebble.h>
#include "layers/title_bar.h"
#include "libs/pebble-assist.h"

typedef struct TitleBarData {
#define TITLE_LAYER_PAD (8)
#define TITLE_TEXT_PAD (4)

typedef struct _TitleBarData {
TitleBarLayerUpdateProc update_proc;
GColor foreground;
GColor background;
Expand Down Expand Up @@ -43,6 +47,7 @@ TitleBarLayer * title_bar_layer_create(GRect bounds) {
text_layer_set_text_alignment(title_bar_data->text_layer, GTextAlignmentCenter);
text_layer_set_text_color(title_bar_data->text_layer, GColorBlack);
text_layer_set_background_color(title_bar_data->text_layer, GColorClear);
text_layer_set_font(title_bar_data->text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));

layer_add_child((Layer*)title_bar_layer, text_layer_get_layer(title_bar_data->text_layer));

Expand Down Expand Up @@ -105,6 +110,14 @@ int16_t title_bar_layer_get_height(TitleBarLayer * title_bar_layer) {
return layer_bounds.size.h;
}

void title_bar_layer_reduce_height(TitleBarLayer * title_bar_layer) {
TitleBarData *title_bar_data = (TitleBarData *)layer_get_data((Layer *)title_bar_layer);

GSize title_layer_size = text_layer_get_content_size(title_bar_data->text_layer);
int16_t height = title_layer_size.h + TITLE_LAYER_PAD;
title_bar_layer_set_height(title_bar_layer, height);
}

void title_bar_layer_set_colors(TitleBarLayer * title_bar_layer, GColor foreground, GColor background) {
TitleBarData *title_bar_data = (TitleBarData *)layer_get_data((Layer *)title_bar_layer);

Expand Down Expand Up @@ -159,7 +172,7 @@ void title_bar_layer_centre_text_vertically(TitleBarLayer * title_bar_layer) {
GRect text_bounds = layer_get_bounds(text_layer_get_layer(title_bar_data->text_layer));
GSize text_size = text_layer_get_content_size(title_bar_data->text_layer);

text_bounds.origin.y = (title_bar_bounds.size.h - text_size.h) / 2;
text_bounds.origin.y = (title_bar_bounds.size.h - text_size.h - TITLE_TEXT_PAD) / 2;

layer_set_frame(text_layer_get_layer(title_bar_data->text_layer), text_bounds);
}
Expand Down
1 change: 1 addition & 0 deletions src/layers/title_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TitleBarLayer * title_bar_layer_create(GRect bounds);
void title_bar_layer_destroy(TitleBarLayer * title_bar_layer);
void title_bar_layer_set_height(TitleBarLayer * title_bar_layer, int16_t height);
int16_t title_bar_layer_get_height(TitleBarLayer * title_bar_layer);
void title_bar_layer_reduce_height(TitleBarLayer * title_bar_layer);
void title_bar_layer_set_colors(TitleBarLayer * title_bar_layer, GColor foreground, GColor background);
GColor title_bar_layer_get_foreground_color(TitleBarLayer * title_bar_layer);
GColor title_bar_layer_get_background_color(TitleBarLayer * title_bar_layer);
Expand Down
2 changes: 1 addition & 1 deletion src/subscriptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void subscriptions_in_received_handler(DictionaryIterator *iter) {
if (tuple) {
strncpy(subscription->title, tuple->value->cstring, sizeof(subscription->title) - 1);
}
LOG("subscription: %d '%s'", subscription->index, subscription->title);
//LOG("subscription: %d '%s'", subscription->index, subscription->title);
subscriptions_reload_data_and_mark_dirty();
break;
}
Expand Down
9 changes: 3 additions & 6 deletions src/windows/win-headlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ static Window *window = NULL;
static MenuLayer *menu_layer = NULL;
static ProgressBarLayer *s_progress_bar_layer;
static int16_t s_title_bar_height;
#ifdef PBL_SDK_3
static TitleBarLayer *s_status_bar;
#endif

void win_headlines_init(void) {
window = window_create();
Expand Down Expand Up @@ -125,6 +123,9 @@ static void window_load(Window *window) {
// Set up the status bar if it's needed
s_status_bar = title_bar_layer_create_fullscreen(window);
title_bar_layer_set_text(s_status_bar, subscriptions_get_current()->title);

title_bar_layer_reduce_height(s_status_bar);

s_title_bar_height = title_bar_layer_get_height(s_status_bar);

#ifdef PBL_RECT
Expand All @@ -141,12 +142,8 @@ static void window_load(Window *window) {

static void window_unload(Window *window) {
menu_layer_destroy_safe(menu_layer);

#ifdef PBL_SDK_3
// Destroy the status bar if there is one
title_bar_layer_destroy(s_status_bar);
#endif

// Destroy the progress bar
progress_bar_layer_destroy(s_progress_bar_layer);
}
Expand Down
31 changes: 0 additions & 31 deletions src/windows/win-story.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,15 @@ static void window_appear(Window *window) {
}

static void window_load(Window *window) {
//window_set_background_color(window, settings()->story_font_color ? GColorBlack : GColorWhite);
//window_set_background_color(window, GColorWhite);
GRect window_bounds = layer_get_bounds(window_get_root_layer(window));

story_text_layer = text_layer_create(window_bounds);
//text_layer_set_colors(story_text_layer, GColorBlack, GColorWhite);
text_layer_set_font(story_text_layer, settings_get_story_body_font_size());
text_layer_set_text_alignment(story_text_layer, GTextAlignmentCenter);
text_layer_set_text(story_text_layer, "Loading...");


title_text_layer = text_layer_create(window_bounds);
//text_layer_set_colors(title_text_layer, GColorBlack, GColorPastelYellow);
text_layer_set_font(title_text_layer, settings_get_story_title_font_size());
text_layer_set_text_alignment(title_text_layer, GTextAlignmentCenter);
text_layer_set_text(title_text_layer, headlines_get_current()->title);
Expand Down Expand Up @@ -146,36 +142,9 @@ static void window_load(Window *window) {

scroll_layer_set_paging(scroll_layer, true);



//text_layer_set_colors(title_text_layer, settings()->story_font_color ? GColorWhite : GColorBlack, GColorPastelYellow);
//text_layer_set_font(title_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
//text_layer_set_text(title_text_layer, headlines_get_current()->title);

//scroll_layer_add_child(scroll_layer, text_layer_get_layer(title_text_layer));
//text_layer_enable_screen_text_flow_and_paging(title_text_layer, 2);

//GSize title_layer_size = text_layer_get_content_size(title_text_layer);
//title_layer_size.w = window_bounds.size.w;
//title_layer_size.h += 8;

//text_layer_set_size(title_text_layer, title_layer_size);

//GRect text_layer_bounds = window_bounds;
//text_layer_bounds.origin.y = title_layer_size.h;
//story_text_layer = text_layer_create(text_layer_bounds);
//text_layer_set_colors(story_text_layer, settings()->story_font_color ? GColorWhite : GColorBlack, GColorClear);


//GSize story_layer_size = text_layer_get_content_size(story_text_layer);
//story_layer_size.h = story_layer_size.h + 8;
//story_layer_size.h = window_bounds.size.h;
//text_layer_set_size(story_text_layer, story_layer_size);

// Set up the progress layer
progress_bar_layer = progress_bar_layer_create_fullscreen(window);
progress_bar_layer_set_pos(progress_bar_layer, title_layer_size.h);
//progress_bar_layer_set_colors(progress_bar_layer, GColorOrange, GColorWhite);
progress_bar_layer_set_progress(progress_bar_layer, 0);
scroll_layer_add_child(scroll_layer, progress_bar_layer_get_layer(progress_bar_layer));
}
Expand Down

0 comments on commit a02647d

Please # to comment.