WIP: New method of spacing icons
This commit is contained in:
+30
-35
@@ -5,25 +5,24 @@
|
||||
#include <pebble.h>
|
||||
|
||||
#if PBL_DISPLAY_WIDTH >= 260 && PBL_ROUND
|
||||
const int8_t ICON_X_OFFSET = -1;
|
||||
const uint16_t UP_Y = 76;
|
||||
const uint16_t SELECT_Y = 118;
|
||||
const uint16_t DOWN_Y = 158;
|
||||
#define DEFAULT_SPREAD 30
|
||||
#define SELECT_Y 118
|
||||
#define ICON_X_OFFSET -1
|
||||
//
|
||||
#elif PBL_DISPLAY_WIDTH >= 200 && PBL_RECT
|
||||
const int8_t ICON_X_OFFSET = 0;
|
||||
const uint16_t UP_Y = 41;
|
||||
const uint16_t SELECT_Y = 102;
|
||||
const uint16_t DOWN_Y = 161;
|
||||
#define DEFAULT_SPREAD 30
|
||||
#define SELECT_Y 102
|
||||
#define ICON_X_OFFSET 0
|
||||
//
|
||||
#elif PBL_DISPLAY_WIDTH >= 180 && PBL_ROUND
|
||||
const int8_t ICON_X_OFFSET = -1;
|
||||
const uint16_t UP_Y = 49;
|
||||
const uint16_t SELECT_Y = 78;
|
||||
const uint16_t DOWN_Y = 105;
|
||||
#define DEFAULT_SPREAD 30
|
||||
#define SELECT_Y 78
|
||||
#define ICON_X_OFFSET -1
|
||||
//
|
||||
#else // all 144x168 watches
|
||||
const int8_t ICON_X_OFFSET = 0;
|
||||
const uint16_t UP_Y = 26;
|
||||
const uint16_t SELECT_Y = 72;
|
||||
const uint16_t DOWN_Y = 117;
|
||||
#define DEFAULT_SPREAD 30
|
||||
#define SELECT_Y 72
|
||||
#define ICON_X_OFFSET 0
|
||||
#endif
|
||||
|
||||
#if PBL_ROUND
|
||||
@@ -43,11 +42,11 @@ static GRect s_get_home_frame(NeatBarLayer *neat_bar, uint8_t button_index) {
|
||||
|
||||
switch (button_index) {
|
||||
case BUTTON_ID_UP:
|
||||
return GRect(ICON_X_OFFSET, UP_Y - spread - y_offset, width, 25);
|
||||
return GRect(ICON_X_OFFSET, SELECT_Y - spread - y_offset, width, 25);
|
||||
case BUTTON_ID_SELECT:
|
||||
return GRect(ICON_X_OFFSET, SELECT_Y - y_offset, width, 25);
|
||||
case BUTTON_ID_DOWN:
|
||||
return GRect(ICON_X_OFFSET, DOWN_Y + spread - y_offset, width, 25);
|
||||
return GRect(ICON_X_OFFSET, SELECT_Y + spread - y_offset, width, 25);
|
||||
default:
|
||||
return GRectZero;
|
||||
}
|
||||
@@ -171,7 +170,7 @@ static void s_recenter_icons(NeatBarLayer *neat_bar) {
|
||||
int8_t spread = neat_bar->icons_spread;
|
||||
if (neat_bar->up_layer) {
|
||||
layer_set_frame(bitmap_layer_get_layer(neat_bar->up_layer),
|
||||
GRect(ICON_X_OFFSET, UP_Y - spread - y_offset, neat_bar->main_grect.size.w, 25));
|
||||
GRect(ICON_X_OFFSET, SELECT_Y - spread - y_offset, neat_bar->main_grect.size.w, 25));
|
||||
}
|
||||
if (neat_bar->select_layer) {
|
||||
layer_set_frame(bitmap_layer_get_layer(neat_bar->select_layer),
|
||||
@@ -179,7 +178,7 @@ static void s_recenter_icons(NeatBarLayer *neat_bar) {
|
||||
}
|
||||
if (neat_bar->down_layer) {
|
||||
layer_set_frame(bitmap_layer_get_layer(neat_bar->down_layer),
|
||||
GRect(ICON_X_OFFSET, DOWN_Y + spread - y_offset, neat_bar->main_grect.size.w, 25));
|
||||
GRect(ICON_X_OFFSET, SELECT_Y + spread - y_offset, neat_bar->main_grect.size.w, 25));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +226,7 @@ void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t dura
|
||||
}
|
||||
|
||||
// default: 0
|
||||
void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset) {
|
||||
void neat_bar_layer_set_bar_floating(NeatBarLayer *neat_bar, uint16_t x_offset) {
|
||||
if (x_offset == neat_bar->bar_x_offset) {
|
||||
return;
|
||||
}
|
||||
@@ -238,7 +237,7 @@ void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset) {
|
||||
}
|
||||
|
||||
// default: ACTION_BAR_WIDTH
|
||||
void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width) {
|
||||
void neat_bar_layer_set_bar_width(NeatBarLayer *neat_bar, uint16_t width) {
|
||||
if (width == neat_bar->main_grect.size.w) {
|
||||
return;
|
||||
}
|
||||
@@ -248,7 +247,7 @@ void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width) {
|
||||
if (neat_bar->bar_x_offset > 0) {
|
||||
uint16_t x = neat_bar->bar_x_offset;
|
||||
neat_bar->bar_x_offset = 0; // force update
|
||||
neat_bar_layer_set_floating(neat_bar, x);
|
||||
neat_bar_layer_set_bar_floating(neat_bar, x);
|
||||
} else {
|
||||
layer_mark_dirty(neat_bar->main_layer);
|
||||
}
|
||||
@@ -256,7 +255,7 @@ void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width) {
|
||||
}
|
||||
|
||||
// default: PBL_DISPLAY_HEIGHT
|
||||
void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height) {
|
||||
void neat_bar_layer_set_bar_height(NeatBarLayer *neat_bar, uint16_t height) {
|
||||
if (height == neat_bar->main_grect.size.h) {
|
||||
return;
|
||||
}
|
||||
@@ -266,7 +265,7 @@ void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height) {
|
||||
}
|
||||
|
||||
// default: 0
|
||||
void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset) {
|
||||
void neat_bar_layer_set_bar_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset) {
|
||||
if (y_offset == neat_bar->main_grect.origin.y) {
|
||||
return;
|
||||
}
|
||||
@@ -277,7 +276,7 @@ void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset) {
|
||||
}
|
||||
|
||||
// default: 0
|
||||
void neat_bar_layer_set_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius) {
|
||||
void neat_bar_layer_set_bar_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius) {
|
||||
if (corner_radius == neat_bar->bar_corner_radius) {
|
||||
return;
|
||||
}
|
||||
@@ -295,7 +294,7 @@ void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor backgrou
|
||||
}
|
||||
|
||||
// default: 0
|
||||
void neat_bar_layer_set_spread(NeatBarLayer *neat_bar, int8_t spread) {
|
||||
void neat_bar_layer_set_icons_spread(NeatBarLayer *neat_bar, int8_t spread) {
|
||||
if (spread == neat_bar->icons_spread) {
|
||||
return;
|
||||
}
|
||||
@@ -306,26 +305,22 @@ void neat_bar_layer_set_spread(NeatBarLayer *neat_bar, int8_t spread) {
|
||||
// constraints: must be <=25px in height (width is only constrained to the width of the bar)
|
||||
void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap *icon) {
|
||||
BitmapLayer *current_bitmap_layer;
|
||||
uint16_t y_pos;
|
||||
|
||||
switch (button_id) {
|
||||
case BUTTON_ID_UP:
|
||||
current_bitmap_layer = neat_bar->up_layer;
|
||||
y_pos = UP_Y;
|
||||
break;
|
||||
case BUTTON_ID_DOWN:
|
||||
current_bitmap_layer = neat_bar->down_layer;
|
||||
y_pos = DOWN_Y;
|
||||
break;
|
||||
default:
|
||||
current_bitmap_layer = neat_bar->select_layer;
|
||||
y_pos = SELECT_Y;
|
||||
}
|
||||
|
||||
if (!current_bitmap_layer) {
|
||||
int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? y_pos - neat_bar->icons_spread
|
||||
: (button_id == BUTTON_ID_DOWN) ? y_pos + neat_bar->icons_spread
|
||||
: y_pos;
|
||||
int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? SELECT_Y - neat_bar->icons_spread
|
||||
: (button_id == BUTTON_ID_DOWN) ? SELECT_Y + neat_bar->icons_spread
|
||||
: SELECT_Y;
|
||||
current_bitmap_layer = bitmap_layer_create(GRect(ICON_X_OFFSET, adjusted_y, neat_bar->main_grect.size.w, 25));
|
||||
layer_add_child(neat_bar->main_layer, bitmap_layer_get_layer(current_bitmap_layer));
|
||||
switch (button_id) {
|
||||
@@ -365,7 +360,7 @@ NeatBarLayer *neat_bar_layer_create() {
|
||||
// neat_bar exclusives :D
|
||||
neat_bar->bar_corner_radius = 0;
|
||||
neat_bar->bar_x_offset = 0;
|
||||
neat_bar->icons_spread = 0;
|
||||
neat_bar->icons_spread = DEFAULT_SPREAD;
|
||||
neat_bar->animations_enabled = true;
|
||||
neat_bar->animations_move_on_y_axis = false;
|
||||
neat_bar->animations_move_distance = ANIM_DISTANCE;
|
||||
|
||||
Reference in New Issue
Block a user