WIP: New method of spacing icons

This commit is contained in:
2026-07-20 21:27:17 -04:00
parent 7155e2f4f0
commit 0e61a4bf79
2 changed files with 36 additions and 41 deletions
+30 -35
View File
@@ -5,25 +5,24 @@
#include <pebble.h> #include <pebble.h>
#if PBL_DISPLAY_WIDTH >= 260 && PBL_ROUND #if PBL_DISPLAY_WIDTH >= 260 && PBL_ROUND
const int8_t ICON_X_OFFSET = -1; #define DEFAULT_SPREAD 30
const uint16_t UP_Y = 76; #define SELECT_Y 118
const uint16_t SELECT_Y = 118; #define ICON_X_OFFSET -1
const uint16_t DOWN_Y = 158; //
#elif PBL_DISPLAY_WIDTH >= 200 && PBL_RECT #elif PBL_DISPLAY_WIDTH >= 200 && PBL_RECT
const int8_t ICON_X_OFFSET = 0; #define DEFAULT_SPREAD 30
const uint16_t UP_Y = 41; #define SELECT_Y 102
const uint16_t SELECT_Y = 102; #define ICON_X_OFFSET 0
const uint16_t DOWN_Y = 161; //
#elif PBL_DISPLAY_WIDTH >= 180 && PBL_ROUND #elif PBL_DISPLAY_WIDTH >= 180 && PBL_ROUND
const int8_t ICON_X_OFFSET = -1; #define DEFAULT_SPREAD 30
const uint16_t UP_Y = 49; #define SELECT_Y 78
const uint16_t SELECT_Y = 78; #define ICON_X_OFFSET -1
const uint16_t DOWN_Y = 105; //
#else // all 144x168 watches #else // all 144x168 watches
const int8_t ICON_X_OFFSET = 0; #define DEFAULT_SPREAD 30
const uint16_t UP_Y = 26; #define SELECT_Y 72
const uint16_t SELECT_Y = 72; #define ICON_X_OFFSET 0
const uint16_t DOWN_Y = 117;
#endif #endif
#if PBL_ROUND #if PBL_ROUND
@@ -43,11 +42,11 @@ static GRect s_get_home_frame(NeatBarLayer *neat_bar, uint8_t button_index) {
switch (button_index) { switch (button_index) {
case BUTTON_ID_UP: 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: case BUTTON_ID_SELECT:
return GRect(ICON_X_OFFSET, SELECT_Y - y_offset, width, 25); return GRect(ICON_X_OFFSET, SELECT_Y - y_offset, width, 25);
case BUTTON_ID_DOWN: 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: default:
return GRectZero; return GRectZero;
} }
@@ -171,7 +170,7 @@ static void s_recenter_icons(NeatBarLayer *neat_bar) {
int8_t spread = neat_bar->icons_spread; int8_t spread = neat_bar->icons_spread;
if (neat_bar->up_layer) { if (neat_bar->up_layer) {
layer_set_frame(bitmap_layer_get_layer(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) { if (neat_bar->select_layer) {
layer_set_frame(bitmap_layer_get_layer(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) { if (neat_bar->down_layer) {
layer_set_frame(bitmap_layer_get_layer(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 // 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) { if (x_offset == neat_bar->bar_x_offset) {
return; return;
} }
@@ -238,7 +237,7 @@ void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset) {
} }
// default: ACTION_BAR_WIDTH // 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) { if (width == neat_bar->main_grect.size.w) {
return; return;
} }
@@ -248,7 +247,7 @@ void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width) {
if (neat_bar->bar_x_offset > 0) { if (neat_bar->bar_x_offset > 0) {
uint16_t x = neat_bar->bar_x_offset; uint16_t x = neat_bar->bar_x_offset;
neat_bar->bar_x_offset = 0; // force update 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 { } else {
layer_mark_dirty(neat_bar->main_layer); 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 // 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) { if (height == neat_bar->main_grect.size.h) {
return; return;
} }
@@ -266,7 +265,7 @@ void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height) {
} }
// default: 0 // 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) { if (y_offset == neat_bar->main_grect.origin.y) {
return; return;
} }
@@ -277,7 +276,7 @@ void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset) {
} }
// default: 0 // 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) { if (corner_radius == neat_bar->bar_corner_radius) {
return; return;
} }
@@ -295,7 +294,7 @@ void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor backgrou
} }
// default: 0 // 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) { if (spread == neat_bar->icons_spread) {
return; 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) // 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) { void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap *icon) {
BitmapLayer *current_bitmap_layer; BitmapLayer *current_bitmap_layer;
uint16_t y_pos;
switch (button_id) { switch (button_id) {
case BUTTON_ID_UP: case BUTTON_ID_UP:
current_bitmap_layer = neat_bar->up_layer; current_bitmap_layer = neat_bar->up_layer;
y_pos = UP_Y;
break; break;
case BUTTON_ID_DOWN: case BUTTON_ID_DOWN:
current_bitmap_layer = neat_bar->down_layer; current_bitmap_layer = neat_bar->down_layer;
y_pos = DOWN_Y;
break; break;
default: default:
current_bitmap_layer = neat_bar->select_layer; current_bitmap_layer = neat_bar->select_layer;
y_pos = SELECT_Y;
} }
if (!current_bitmap_layer) { if (!current_bitmap_layer) {
int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? y_pos - neat_bar->icons_spread int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? SELECT_Y - neat_bar->icons_spread
: (button_id == BUTTON_ID_DOWN) ? y_pos + neat_bar->icons_spread : (button_id == BUTTON_ID_DOWN) ? SELECT_Y + neat_bar->icons_spread
: y_pos; : SELECT_Y;
current_bitmap_layer = bitmap_layer_create(GRect(ICON_X_OFFSET, adjusted_y, neat_bar->main_grect.size.w, 25)); 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)); layer_add_child(neat_bar->main_layer, bitmap_layer_get_layer(current_bitmap_layer));
switch (button_id) { switch (button_id) {
@@ -365,7 +360,7 @@ NeatBarLayer *neat_bar_layer_create() {
// neat_bar exclusives :D // neat_bar exclusives :D
neat_bar->bar_corner_radius = 0; neat_bar->bar_corner_radius = 0;
neat_bar->bar_x_offset = 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_enabled = true;
neat_bar->animations_move_on_y_axis = false; neat_bar->animations_move_on_y_axis = false;
neat_bar->animations_move_distance = ANIM_DISTANCE; neat_bar->animations_move_distance = ANIM_DISTANCE;
+6 -6
View File
@@ -40,13 +40,13 @@ void neat_bar_layer_set_animations_enabled(NeatBarLayer *neat_bar, bool enabled)
void neat_bar_layer_set_animations_move_axis(NeatBarLayer *neat_bar, bool use_y_axis); void neat_bar_layer_set_animations_move_axis(NeatBarLayer *neat_bar, bool use_y_axis);
void neat_bar_layer_set_animations_move_distance(NeatBarLayer *neat_bar, int8_t distance); void neat_bar_layer_set_animations_move_distance(NeatBarLayer *neat_bar, int8_t distance);
void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t duration_ms); void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t duration_ms);
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);
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);
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);
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);
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);
void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor background_color); void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor background_color);
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);
void neat_bar_layer_set_icon(NeatBarLayer *layer, ButtonId button_id, GBitmap *icon); void neat_bar_layer_set_icon(NeatBarLayer *layer, ButtonId button_id, GBitmap *icon);
NeatBarLayer *neat_bar_layer_create(); NeatBarLayer *neat_bar_layer_create();
void neat_bar_layer_destroy(NeatBarLayer *neat_bar); void neat_bar_layer_destroy(NeatBarLayer *neat_bar);