Compare commits

...

21 Commits

Author SHA1 Message Date
RandyTheSilly a68f5e49cb Update roadmap 2026-07-23 00:11:48 -04:00
RandyTheSilly 55c3d658b6 Fix icons not recentering with floating mode 2026-07-22 23:44:56 -04:00
RandyTheSilly 465f059ddc Fix icon alignment on custom rect bars 2026-07-22 23:26:29 -04:00
RandyTheSilly a357067441 Make bar AA optional 2026-07-22 23:15:42 -04:00
RandyTheSilly 4a7487fa10 Fix icon positions on radial bar 2026-07-22 22:59:58 -04:00
RandyTheSilly f7f63f199d Fix radial bar length 2026-07-22 21:44:36 -04:00
RandyTheSilly 2c2f0fff94 WIP: radial bar background 2026-07-22 20:49:58 -04:00
RandyTheSilly 2a909727c0 Do not set background color for b&w watch icons 2026-07-21 21:54:53 -04:00
RandyTheSilly ba80a2972a Update roadmap 2026-07-21 00:48:19 -04:00
RandyTheSilly 1f07cf7563 Specify background color for b&w watches 2026-07-20 23:39:35 -04:00
RandyTheSilly 28c50819ad Make icons y offset configurable 2026-07-20 23:18:31 -04:00
RandyTheSilly 682b824488 Update rect default icon x offset to match stock 2026-07-20 23:01:17 -04:00
RandyTheSilly 9c20d38612 Revert to platform-dependent defaults for icons x offset 2026-07-20 22:57:56 -04:00
RandyTheSilly 2e26048563 Make icons x offset configurable (default to stock value) 2026-07-20 22:51:12 -04:00
RandyTheSilly 937cc08ac8 Use round bg by default on round watches 2026-07-20 22:46:03 -04:00
RandyTheSilly 93a3d568aa Allow drawing round bar background (currently mimics stock) 2026-07-20 22:42:44 -04:00
RandyTheSilly 8cd1dbd11a Define based on height, not width 2026-07-20 21:52:23 -04:00
RandyTheSilly 62fd6aa756 Set default spread for all platforms 2026-07-20 21:43:48 -04:00
RandyTheSilly 0e61a4bf79 WIP: New method of spacing icons 2026-07-20 21:27:17 -04:00
RandyTheSilly 7155e2f4f0 Allow disabling animations 2026-07-20 20:28:58 -04:00
RandyTheSilly 70004c432d Improve organization of NeatBarLayer struct 2026-07-20 20:19:40 -04:00
3 changed files with 237 additions and 120 deletions
+20 -13
View File
@@ -1,23 +1,30 @@
# neat_bar # neat_bar
A more customizable replacement for the built-in Pebble action bar. `neat_bar` is a (mostly) drop-in replacement for the stock Pebble action bar that adds a bunch of customizability.
## VS Stock Action Bar ## VS Stock Action Bar
### New Features ### New Features
- Floating mode - Floating mode!
- Rectangular mode on round watches - Rectangular/round/radial backgrounds on all watches!
- Adjustable spread (distance between icons) - Adjustable spread (distance between icons)!
- Increased max icon size (unlimited width; 25px height) - Increased max icon size (unlimited width; 25px height)!
- Custom bar corner radius - Custom bar corner radius!
- Custom bar width/height - Custom bar width/height!
- Custom bar x/y positions - Custom bar/icon x/y offsets!
### Removed Features - Toggle-able bar AA!
### Missing Features (unplanned)
- Anything to do with back button overrides - Anything to do with back button overrides
- Fully custom animations - Fully custom animations
- Built-in animations can still be customized - Built-in animations can still be customized
- Duration, move distance/direction, and move axis are all configurable - Duration, move distance/direction, and move axis are all configurable
- Round style - They can also be disabled
- Using a rectangular bar on a round watch saves space and IMO looks way better
- Use custom corner radius for a nice effect on round watches!
### Pending Features ### Pending Features
- Allow disabling bar background
- Legacy (background invert) animations support - Legacy (background invert) animations support
- Y offset for all icons - Customizable round bar size
- Customizable radial bar length
- Make floating work on radial bar
- Disable ability to set floating/reset floating for round bar
- Separate select icon x offset (especially useful for the radial bar)
- Theme presets!
- Default
- Legacy
+181 -95
View File
@@ -4,32 +4,34 @@
#include "neat_bar.h" #include "neat_bar.h"
#include <pebble.h> #include <pebble.h>
#if PBL_DISPLAY_WIDTH >= 260 && PBL_ROUND #define MAX(a, b) (((a) > (b)) ? (a) : (b))
const int8_t ICON_X_OFFSET = -1; #define ABS(a) (((a) < 0) ? -(a) : (a))
const uint16_t UP_Y = 76;
const uint16_t SELECT_Y = 118; #if PBL_DISPLAY_HEIGHT >= 260 && PBL_ROUND
const uint16_t DOWN_Y = 158; #define DEFAULT_SPREAD 41
#elif PBL_DISPLAY_WIDTH >= 200 && PBL_RECT #define SELECT_Y 118
const int8_t ICON_X_OFFSET = 0; //
const uint16_t UP_Y = 41; #elif PBL_DISPLAY_HEIGHT >= 228 && PBL_RECT
const uint16_t SELECT_Y = 102; #define DEFAULT_SPREAD 60
const uint16_t DOWN_Y = 161; #define SELECT_Y 102
#elif PBL_DISPLAY_WIDTH >= 180 && PBL_ROUND //
const int8_t ICON_X_OFFSET = -1; #elif PBL_DISPLAY_HEIGHT >= 180 && PBL_ROUND
const uint16_t UP_Y = 49; #define DEFAULT_SPREAD 28
const uint16_t SELECT_Y = 78; #define SELECT_Y 78
const uint16_t DOWN_Y = 105; //
#else // all 144x168 watches #else // all 144x168 watches
const int8_t ICON_X_OFFSET = 0; #define DEFAULT_SPREAD 51
const uint16_t UP_Y = 26; #define SELECT_Y 72
const uint16_t SELECT_Y = 72;
const uint16_t DOWN_Y = 117;
#endif #endif
#if PBL_ROUND #if PBL_ROUND
#define ANIM_DISTANCE 4 #define DEFAULT_BAR_STYLE NEAT_BAR_STYLE_ROUND
#define DEFAULT_ANIM_DISTANCE 4
#define DEFAULT_ICONS_X_OFFSET -1
#else #else
#define ANIM_DISTANCE 5 #define DEFAULT_BAR_STYLE NEAT_BAR_STYLE_RECT
#define DEFAULT_ANIM_DISTANCE 5
#define DEFAULT_ICONS_X_OFFSET 1
#endif #endif
static const GRect s_base_grect_rect = GRect(PBL_DISPLAY_WIDTH - ACTION_BAR_WIDTH, 0, ACTION_BAR_WIDTH, PBL_DISPLAY_HEIGHT); static const GRect s_base_grect_rect = GRect(PBL_DISPLAY_WIDTH - ACTION_BAR_WIDTH, 0, ACTION_BAR_WIDTH, PBL_DISPLAY_HEIGHT);
@@ -37,17 +39,17 @@ static const GRect s_base_grect_rect = GRect(PBL_DISPLAY_WIDTH - ACTION_BAR_WIDT
static NeatBarLayer *s_current_neat_bar = NULL; static NeatBarLayer *s_current_neat_bar = NULL;
static GRect s_get_home_frame(NeatBarLayer *neat_bar, uint8_t button_index) { static GRect s_get_home_frame(NeatBarLayer *neat_bar, uint8_t button_index) {
int16_t y_offset = neat_bar->main_grect.origin.y; int16_t total_y_offset = neat_bar->main_grect_visual.origin.y - neat_bar->icons_y_offset;
int8_t spread = neat_bar->spread; int8_t spread = neat_bar->icons_spread;
uint16_t width = neat_bar->main_grect.size.w; uint16_t width = neat_bar->main_grect_visual.size.w;
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(neat_bar->icons_x_offset, SELECT_Y - spread - total_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(neat_bar->icons_x_offset, SELECT_Y - total_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(neat_bar->icons_x_offset, SELECT_Y + spread - total_y_offset, width, 25);
default: default:
return GRectZero; return GRectZero;
} }
@@ -139,20 +141,41 @@ static void s_select_up_handler(ClickRecognizerRef recognizer, void *context) {
} }
static void s_main_layer_update_proc(Layer *layer, GContext *ctx) { static void s_main_layer_update_proc(Layer *layer, GContext *ctx) {
graphics_context_set_antialiased(ctx, false);
graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color); graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
graphics_fill_rect(ctx, layer_get_bounds(layer), s_current_neat_bar->corner_radius, s_current_neat_bar->x_offset > 0 ? GCornersAll : GCornersLeft); graphics_context_set_antialiased(ctx, s_current_neat_bar->bar_enable_aa);
switch (s_current_neat_bar->bar_style) {
case NEAT_BAR_STYLE_RADIAL: {
graphics_fill_radial(ctx, grect_inset(layer_get_bounds(layer), GEdgeInsets(-1)), GOvalScaleModeFitCircle,
s_current_neat_bar->main_grect_visual.size.w,
DEG_TO_TRIGANGLE(60), // ~2 o'clock
DEG_TO_TRIGANGLE(120) // ~4 o'clock
);
break;
}
case NEAT_BAR_STYLE_ROUND: {
const uint32_t action_bar_circle_diameter = PBL_DISPLAY_HEIGHT * 19 / 9;
GRect neat_bar_circle_frame = (GRect){.size = GSize(action_bar_circle_diameter, action_bar_circle_diameter)};
grect_align(&neat_bar_circle_frame, &s_current_neat_bar->main_grect_visual, GAlignLeft, false);
const int32_t inset_thickness = MAX(ABS(neat_bar_circle_frame.size.h), ABS(neat_bar_circle_frame.size.w));
graphics_fill_radial(ctx, neat_bar_circle_frame, GOvalScaleModeFitCircle, inset_thickness, 0, TRIG_MAX_ANGLE);
break;
}
default:
graphics_fill_rect(ctx, s_current_neat_bar->main_grect_visual, s_current_neat_bar->rect_bar_corner_radius, s_current_neat_bar->bar_x_offset > 0 ? GCornersAll : GCornersLeft);
}
} }
static void s_base_click_config_provider(void *config_context) { static void s_base_click_config_provider(void *config_context) {
NeatBarLayer *neat_bar = config_context; NeatBarLayer *neat_bar = config_context;
void *context = neat_bar->context ? neat_bar->context : neat_bar; void *context = neat_bar->context ? neat_bar->context : neat_bar;
window_raw_click_subscribe(BUTTON_ID_UP, s_up_down_handler, s_up_up_handler, neat_bar); if (neat_bar->animations_enabled) {
window_raw_click_subscribe(BUTTON_ID_DOWN, s_down_down_handler, s_down_up_handler, neat_bar); window_raw_click_subscribe(BUTTON_ID_UP, s_up_down_handler, s_up_up_handler, neat_bar);
window_raw_click_subscribe(BUTTON_ID_SELECT, s_select_down_handler, s_select_up_handler, neat_bar); window_raw_click_subscribe(BUTTON_ID_DOWN, s_down_down_handler, s_down_up_handler, neat_bar);
window_set_click_context(BUTTON_ID_UP, context); window_raw_click_subscribe(BUTTON_ID_SELECT, s_select_down_handler, s_select_up_handler, neat_bar);
window_set_click_context(BUTTON_ID_DOWN, context); window_set_click_context(BUTTON_ID_UP, context);
window_set_click_context(BUTTON_ID_SELECT, context); window_set_click_context(BUTTON_ID_DOWN, context);
window_set_click_context(BUTTON_ID_SELECT, context);
}
if (neat_bar->click_config_provider) { if (neat_bar->click_config_provider) {
neat_bar->click_config_provider(context); neat_bar->click_config_provider(context);
} }
@@ -165,19 +188,20 @@ inline static void s_update_click_config_provider(NeatBarLayer *neat_bar) {
} }
static void s_recenter_icons(NeatBarLayer *neat_bar) { static void s_recenter_icons(NeatBarLayer *neat_bar) {
int16_t y_offset = neat_bar->main_grect.origin.y; layer_set_frame(neat_bar->icon_parent_layer, neat_bar->main_grect_visual);
int8_t spread = neat_bar->spread; int16_t total_y_offset = neat_bar->main_grect_visual.origin.y - neat_bar->icons_y_offset;
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(neat_bar->icons_x_offset, SELECT_Y - spread - total_y_offset, neat_bar->main_grect_visual.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),
GRect(ICON_X_OFFSET, SELECT_Y - y_offset, neat_bar->main_grect.size.w, 25)); GRect(neat_bar->icons_x_offset, SELECT_Y - total_y_offset, neat_bar->main_grect_visual.size.w, 25));
} }
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(neat_bar->icons_x_offset, SELECT_Y + spread - total_y_offset, neat_bar->main_grect_visual.size.w, 25));
} }
} }
@@ -192,11 +216,12 @@ void neat_bar_layer_set_click_config_provider(NeatBarLayer *neat_bar, ClickConfi
s_update_click_config_provider(neat_bar); s_update_click_config_provider(neat_bar);
} }
void neat_bar_layer_set_animations_move_distance(NeatBarLayer *neat_bar, int8_t distance) { // default: true
if (distance == neat_bar->animations_move_distance) { void neat_bar_layer_set_animations_enabled(NeatBarLayer *neat_bar, bool enabled) {
if (enabled == neat_bar->animations_enabled) {
return; return;
} }
neat_bar->animations_move_distance = distance; neat_bar->animations_enabled = enabled;
} }
// default: false // default: false
@@ -207,6 +232,14 @@ void neat_bar_layer_set_animations_move_axis(NeatBarLayer *neat_bar, bool use_y_
neat_bar->animations_move_on_y_axis = use_y_axis; neat_bar->animations_move_on_y_axis = use_y_axis;
} }
// default: 5 (rect), 4 (round)
void neat_bar_layer_set_animations_move_distance(NeatBarLayer *neat_bar, int8_t distance) {
if (distance == neat_bar->animations_move_distance) {
return;
}
neat_bar->animations_move_distance = distance;
}
// default: 144 // default: 144
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) {
if (duration_ms == neat_bar->animations_duration) { if (duration_ms == neat_bar->animations_duration) {
@@ -215,29 +248,58 @@ void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t dura
neat_bar->animations_duration = duration_ms; neat_bar->animations_duration = duration_ms;
} }
// default: 0 // default: NEAT_BAR_STYLE_RECT (rect), NEAT_BAR_STYLE_ROUND (round)
void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset) { void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, uint8_t bar_style) {
if (x_offset == neat_bar->x_offset) { if (bar_style == neat_bar->bar_style) {
return; return;
} }
neat_bar->x_offset = x_offset; neat_bar->bar_style = bar_style;
neat_bar->main_grect.origin.x = PBL_DISPLAY_WIDTH - neat_bar->main_grect.size.w - x_offset; layer_mark_dirty(neat_bar->main_layer);
layer_set_frame(neat_bar->main_layer, neat_bar->main_grect); }
// default: true (color); always false on b&w watches
void neat_bar_layer_set_bar_aa(NeatBarLayer *neat_bar, bool enable_aa) {
#if PBL_BW
return;
#endif
if (enable_aa == neat_bar->bar_enable_aa) {
return;
}
neat_bar->bar_enable_aa = enable_aa;
layer_mark_dirty(neat_bar->main_layer);
}
// default: 0
void neat_bar_layer_set_rect_bar_floating(NeatBarLayer *neat_bar, uint16_t x_offset) {
if (x_offset == neat_bar->bar_x_offset) {
return;
}
neat_bar->bar_x_offset = x_offset;
neat_bar->main_grect_visual.origin.x = PBL_DISPLAY_WIDTH - neat_bar->main_grect_visual.size.w - x_offset;
layer_mark_dirty(neat_bar->main_layer);
s_recenter_icons(neat_bar);
}
// default: 0
void neat_bar_layer_set_rect_bar_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius) {
if (corner_radius == neat_bar->rect_bar_corner_radius) {
return;
}
neat_bar->rect_bar_corner_radius = corner_radius;
layer_mark_dirty(neat_bar->main_layer); layer_mark_dirty(neat_bar->main_layer);
} }
// 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_visual.size.w) {
return; return;
} }
neat_bar->main_grect.origin.x = PBL_DISPLAY_WIDTH - width; neat_bar->main_grect_visual.origin.x = PBL_DISPLAY_WIDTH - width;
neat_bar->main_grect.size.w = width; neat_bar->main_grect_visual.size.w = width;
layer_set_frame(neat_bar->main_layer, neat_bar->main_grect); if (neat_bar->bar_x_offset > 0) {
if (neat_bar->x_offset > 0) { uint16_t x = neat_bar->bar_x_offset;
uint16_t x = neat_bar->x_offset; neat_bar->bar_x_offset = 0; // force update
neat_bar->x_offset = 0; // force update neat_bar_layer_set_rect_bar_floating(neat_bar, x);
neat_bar_layer_set_floating(neat_bar, x);
} else { } else {
layer_mark_dirty(neat_bar->main_layer); layer_mark_dirty(neat_bar->main_layer);
} }
@@ -245,35 +307,24 @@ 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_visual.size.h) {
return; return;
} }
neat_bar->main_grect.size.h = height; neat_bar->main_grect_visual.size.h = height;
layer_set_frame(neat_bar->main_layer, neat_bar->main_grect);
layer_mark_dirty(neat_bar->main_layer); layer_mark_dirty(neat_bar->main_layer);
} }
// 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_visual.origin.y) {
return; return;
} }
neat_bar->main_grect.origin.y = y_offset; neat_bar->main_grect_visual.origin.y = y_offset;
layer_set_frame(neat_bar->main_layer, neat_bar->main_grect);
layer_mark_dirty(neat_bar->main_layer); layer_mark_dirty(neat_bar->main_layer);
s_recenter_icons(neat_bar); s_recenter_icons(neat_bar);
} }
// default: 0
void neat_bar_layer_set_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius) {
if (corner_radius == neat_bar->corner_radius) {
return;
}
neat_bar->corner_radius = corner_radius;
layer_mark_dirty(neat_bar->main_layer);
}
// default: GColorBlack // default: GColorBlack
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) {
if (gcolor_equal(background_color, neat_bar->background_color)) { if (gcolor_equal(background_color, neat_bar->background_color)) {
@@ -283,40 +334,55 @@ void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor backgrou
layer_mark_dirty(neat_bar->main_layer); layer_mark_dirty(neat_bar->main_layer);
} }
// default: 0 // default: DEFAULT_SPREAD
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->spread) { if (spread == neat_bar->icons_spread) {
return; return;
} }
neat_bar->spread = spread; neat_bar->icons_spread = spread;
s_recenter_icons(neat_bar);
}
// default: 1 (rect), -1 (round)
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);
}
// default: 0
void neat_bar_layer_set_icons_y_offset(NeatBarLayer *neat_bar, int8_t y_offset) {
if (y_offset == neat_bar->icons_y_offset) {
return;
}
neat_bar->icons_y_offset = y_offset;
s_recenter_icons(neat_bar); s_recenter_icons(neat_bar);
} }
// 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->spread int16_t total_y_offset = neat_bar->main_grect_visual.origin.y - neat_bar->icons_y_offset;
: (button_id == BUTTON_ID_DOWN) ? y_pos + neat_bar->spread int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? SELECT_Y - neat_bar->icons_spread - total_y_offset
: y_pos; : (button_id == BUTTON_ID_DOWN) ? SELECT_Y + neat_bar->icons_spread - total_y_offset
current_bitmap_layer = bitmap_layer_create(GRect(ICON_X_OFFSET, adjusted_y, neat_bar->main_grect.size.w, 25)); : SELECT_Y - total_y_offset;
layer_add_child(neat_bar->main_layer, bitmap_layer_get_layer(current_bitmap_layer)); current_bitmap_layer = bitmap_layer_create(GRect(neat_bar->icons_x_offset, adjusted_y, neat_bar->main_grect_visual.size.w, 25));
layer_add_child(neat_bar->icon_parent_layer, bitmap_layer_get_layer(current_bitmap_layer));
switch (button_id) { switch (button_id) {
case BUTTON_ID_UP: case BUTTON_ID_UP:
neat_bar->up_layer = current_bitmap_layer; neat_bar->up_layer = current_bitmap_layer;
@@ -338,23 +404,43 @@ void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap
NeatBarLayer *neat_bar_layer_create() { NeatBarLayer *neat_bar_layer_create() {
NeatBarLayer *neat_bar = malloc(sizeof(NeatBarLayer)); NeatBarLayer *neat_bar = malloc(sizeof(NeatBarLayer));
neat_bar->main_grect = s_base_grect_rect;
neat_bar->main_layer = layer_create(s_base_grect_rect); // layerage
neat_bar->main_grect_visual = s_base_grect_rect;
neat_bar->main_layer = layer_create(GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT)); // GRect covers entire screen - needed for radial support
neat_bar->icon_parent_layer = layer_create(neat_bar->main_grect_visual);
layer_add_child(neat_bar->main_layer, neat_bar->icon_parent_layer);
neat_bar->up_layer = NULL; neat_bar->up_layer = NULL;
neat_bar->down_layer = NULL; neat_bar->down_layer = NULL;
neat_bar->select_layer = NULL; neat_bar->select_layer = NULL;
// stock cfg/plumbing
neat_bar->click_config_provider = NULL; neat_bar->click_config_provider = NULL;
neat_bar->background_color = GColorBlack; neat_bar->background_color = GColorBlack;
neat_bar->corner_radius = 0; neat_bar->context = NULL;
neat_bar->x_offset = 0;
neat_bar->spread = 0; // neat_bar exclusives :D
neat_bar->bar_style = DEFAULT_BAR_STYLE;
#if PBL_BW
neat_bar->bar_enable_aa = false;
#else
neat_bar->bar_enable_aa = true;
#endif
neat_bar->bar_x_offset = 0;
neat_bar->rect_bar_corner_radius = 0;
neat_bar->icons_spread = DEFAULT_SPREAD;
neat_bar->icons_x_offset = DEFAULT_ICONS_X_OFFSET;
neat_bar->icons_y_offset = 0;
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 = DEFAULT_ANIM_DISTANCE;
neat_bar->animations_duration = 144; neat_bar->animations_duration = 144;
// state tracking
neat_bar->up_pressed = false; neat_bar->up_pressed = false;
neat_bar->select_pressed = false; neat_bar->select_pressed = false;
neat_bar->down_pressed = false; neat_bar->down_pressed = false;
neat_bar->context = NULL;
layer_set_update_proc(neat_bar->main_layer, s_main_layer_update_proc); layer_set_update_proc(neat_bar->main_layer, s_main_layer_update_proc);
s_current_neat_bar = neat_bar; s_current_neat_bar = neat_bar;
return neat_bar; return neat_bar;
+36 -12
View File
@@ -5,39 +5,63 @@
#include <pebble.h> #include <pebble.h>
typedef enum {
NEAT_BAR_STYLE_RECT = 0,
NEAT_BAR_STYLE_ROUND = 1,
NEAT_BAR_STYLE_RADIAL = 2,
} NeatBarStyle;
typedef struct { typedef struct {
// layerage
struct Window *window; struct Window *window;
GRect main_grect; GRect main_grect_visual;
Layer *main_layer; Layer *main_layer;
Layer *icon_parent_layer;
BitmapLayer *up_layer; BitmapLayer *up_layer;
BitmapLayer *down_layer; BitmapLayer *down_layer;
BitmapLayer *select_layer; BitmapLayer *select_layer;
// stock cfg/plumbing
ClickConfigProvider click_config_provider; ClickConfigProvider click_config_provider;
GColor8 background_color; GColor8 background_color;
uint16_t corner_radius; void *context;
uint16_t x_offset;
int8_t spread; // neat_bar exclusives :D
uint8_t bar_style;
bool bar_enable_aa;
uint8_t bar_x_offset;
uint8_t rect_bar_corner_radius;
int8_t icons_spread;
int8_t icons_x_offset;
int8_t icons_y_offset;
bool animations_enabled;
bool animations_move_on_y_axis; bool animations_move_on_y_axis;
int8_t animations_move_distance; int8_t animations_move_distance;
uint8_t animations_duration; uint8_t animations_duration;
// state tracking
bool up_pressed; bool up_pressed;
bool select_pressed; bool select_pressed;
bool down_pressed; bool down_pressed;
void *context;
} NeatBarLayer; } NeatBarLayer;
void neat_bar_layer_add_to_window(NeatBarLayer *neat_bar, Window *window); void neat_bar_layer_add_to_window(NeatBarLayer *neat_bar, Window *window);
void neat_bar_layer_set_click_config_provider(NeatBarLayer *neat_bar, ClickConfigProvider click_config_provider); void neat_bar_layer_set_click_config_provider(NeatBarLayer *neat_bar, ClickConfigProvider click_config_provider);
void neat_bar_layer_set_animations_move_distance(NeatBarLayer *neat_bar, int8_t distance); 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_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_style(NeatBarLayer *neat_bar, uint8_t bar_style);
void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width); void neat_bar_layer_set_bar_aa(NeatBarLayer *neat_bar, bool enable_aa);
void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height); void neat_bar_layer_set_rect_bar_floating(NeatBarLayer *neat_bar, uint16_t x_offset);
void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset); void neat_bar_layer_set_rect_bar_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius);
void neat_bar_layer_set_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius); void neat_bar_layer_set_bar_width(NeatBarLayer *neat_bar, uint16_t width);
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_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_icons_x_offset(NeatBarLayer *neat_bar, int8_t x_offset);
void neat_bar_layer_set_icons_y_offset(NeatBarLayer *neat_bar, int8_t y_offset);
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);