From 2e26048563bc50d7f6f9b1c309f95019693df4c1 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Mon, 20 Jul 2026 22:51:12 -0400 Subject: [PATCH] Make icons x offset configurable (default to stock value) --- README.md | 1 + src/c/neat_bar.c | 28 +++++++++++++++++----------- src/c/neat_bar.h | 2 ++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c91fd44..82ca8c3 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ - Custom bar corner radius! - Custom bar width/height! - Custom bar x/y positions! +- Custom icon x positions! ### Missing Features (unplanned) - Anything to do with back button overrides - Fully custom animations diff --git a/src/c/neat_bar.c b/src/c/neat_bar.c index 4442bd4..75cf167 100644 --- a/src/c/neat_bar.c +++ b/src/c/neat_bar.c @@ -10,22 +10,18 @@ #if PBL_DISPLAY_HEIGHT >= 260 && PBL_ROUND #define DEFAULT_SPREAD 41 #define SELECT_Y 118 -#define ICON_X_OFFSET -1 // #elif PBL_DISPLAY_HEIGHT >= 228 && PBL_RECT #define DEFAULT_SPREAD 60 #define SELECT_Y 102 -#define ICON_X_OFFSET 0 // #elif PBL_DISPLAY_HEIGHT >= 180 && PBL_ROUND #define DEFAULT_SPREAD 28 #define SELECT_Y 78 -#define ICON_X_OFFSET -1 // #else // all 144x168 watches #define DEFAULT_SPREAD 51 #define SELECT_Y 72 -#define ICON_X_OFFSET 0 #endif #if PBL_ROUND @@ -47,11 +43,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, SELECT_Y - spread - y_offset, width, 25); + return GRect(neat_bar->icons_x_offset, SELECT_Y - spread - y_offset, width, 25); case BUTTON_ID_SELECT: - return GRect(ICON_X_OFFSET, SELECT_Y - y_offset, width, 25); + return GRect(neat_bar->icons_x_offset, SELECT_Y - y_offset, width, 25); case BUTTON_ID_DOWN: - return GRect(ICON_X_OFFSET, SELECT_Y + spread - y_offset, width, 25); + return GRect(neat_bar->icons_x_offset, SELECT_Y + spread - y_offset, width, 25); default: return GRectZero; } @@ -185,15 +181,15 @@ 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, SELECT_Y - spread - y_offset, neat_bar->main_grect.size.w, 25)); + GRect(neat_bar->icons_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), - GRect(ICON_X_OFFSET, SELECT_Y - y_offset, neat_bar->main_grect.size.w, 25)); + GRect(neat_bar->icons_x_offset, SELECT_Y - y_offset, neat_bar->main_grect.size.w, 25)); } if (neat_bar->down_layer) { layer_set_frame(bitmap_layer_get_layer(neat_bar->down_layer), - GRect(ICON_X_OFFSET, SELECT_Y + spread - y_offset, neat_bar->main_grect.size.w, 25)); + GRect(neat_bar->icons_x_offset, SELECT_Y + spread - y_offset, neat_bar->main_grect.size.w, 25)); } } @@ -326,6 +322,15 @@ void neat_bar_layer_set_icons_spread(NeatBarLayer *neat_bar, int8_t spread) { s_recenter_icons(neat_bar); } +// default: -1 +void neat_bar_layer_set_icons_x_offset(NeatBarLayer *neat_bar, int8_t x_offset) { + if (x_offset == neat_bar->icons_x_offset) { + return; + } + neat_bar->icons_x_offset = x_offset; + s_recenter_icons(neat_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) { BitmapLayer *current_bitmap_layer; @@ -345,7 +350,7 @@ void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap 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)); + current_bitmap_layer = bitmap_layer_create(GRect(neat_bar->icons_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) { case BUTTON_ID_UP: @@ -386,6 +391,7 @@ NeatBarLayer *neat_bar_layer_create() { neat_bar->rect_bar_corner_radius = 0; neat_bar->bar_x_offset = 0; neat_bar->icons_spread = DEFAULT_SPREAD; + neat_bar->icons_x_offset = -1; neat_bar->animations_enabled = true; neat_bar->animations_move_on_y_axis = false; neat_bar->animations_move_distance = DEFAULT_ANIM_DISTANCE; diff --git a/src/c/neat_bar.h b/src/c/neat_bar.h index 2b7a8d7..7a28357 100644 --- a/src/c/neat_bar.h +++ b/src/c/neat_bar.h @@ -24,6 +24,7 @@ typedef struct { uint16_t rect_bar_corner_radius; uint16_t bar_x_offset; int8_t icons_spread; + int8_t icons_x_offset; bool animations_enabled; bool animations_move_on_y_axis; int8_t animations_move_distance; @@ -49,6 +50,7 @@ void neat_bar_layer_set_bar_height(NeatBarLayer *neat_bar, uint16_t height); void neat_bar_layer_set_bar_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset); void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor background_color); void neat_bar_layer_set_icons_spread(NeatBarLayer *neat_bar, int8_t spread); +void neat_bar_layer_set_icons_x_offset(NeatBarLayer *neat_bar, int8_t x_offset); void neat_bar_layer_set_icon(NeatBarLayer *layer, ButtonId button_id, GBitmap *icon); NeatBarLayer *neat_bar_layer_create(); void neat_bar_layer_destroy(NeatBarLayer *neat_bar);