Compare commits

...

7 Commits

3 changed files with 161 additions and 31 deletions
+6 -8
View File
@@ -1,5 +1,5 @@
# neat_bar
A customizable replacement for the built-in Pebble action bar.
A more customizable replacement for the built-in Pebble action bar.
## VS Stock Action Bar
### New Features
@@ -12,14 +12,12 @@ A customizable replacement for the built-in Pebble action bar.
- Custom height
- Custom x/y positions
- Legacy Pebble SDK 2.X-style preset
- Includes corner radius, shortened height, and invert-style press animations
### Removed Features
- Anything to do with back button overrides
- Custom animations
- Fully custom animations
- Built-in move animations can still be customized
- Duration, move distance/direction, and move axis are all configurable
- Round style
- Using a rectangular bar on a round watch saves space and IMO looks way better
### Pending Features
- Match move animation distance to stock per-platform
- Match move animation duration to stock
- Allow customizing move animations
- Built-in haptics
- Legacy (background invert) animations support
- Use custom corner radius for a nice effect on round watches!
+143 -21
View File
@@ -26,54 +26,103 @@ const uint16_t SELECT_Y = 72;
const uint16_t DOWN_Y = 117;
#endif
#if PBL_ROUND
#define ANIM_DISTANCE 4
#else
#define ANIM_DISTANCE 5
#endif
static const GRect s_base_grect_rect = GRect(PBL_DISPLAY_WIDTH - ACTION_BAR_WIDTH, 0, ACTION_BAR_WIDTH, PBL_DISPLAY_HEIGHT);
static NeatBarLayer *s_current_neat_bar = NULL;
static Animation *s_animate_move(NeatBarLayer *neat_bar, uint8_t button_index, bool move_on_y_axis, int16_t distance) {
BitmapLayer *bitmap_layer = NULL;
static GRect s_get_home_frame(NeatBarLayer *neat_bar, uint8_t button_index) {
int16_t y_offset = neat_bar->main_grect.origin.y;
int8_t spread = neat_bar->spread;
uint16_t width = neat_bar->main_grect.size.w;
switch (button_index) {
case BUTTON_ID_UP:
return GRect(ICON_X_OFFSET, UP_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);
default:
return GRectZero;
}
}
// Performs a press or release animation for a single button, anchored to its
// home position. Duplicate events (press when already pressed, release when
// already released) are ignored so overlapping animations cannot accumulate
// drift.
static void s_animate_icon(NeatBarLayer *neat_bar, uint8_t button_index, bool is_press) {
BitmapLayer *bitmap_layer;
bool *pressed;
switch (button_index) {
case BUTTON_ID_UP:
bitmap_layer = neat_bar->up_layer;
pressed = &neat_bar->up_pressed;
break;
case BUTTON_ID_SELECT:
bitmap_layer = neat_bar->select_layer;
pressed = &neat_bar->select_pressed;
break;
case BUTTON_ID_DOWN:
bitmap_layer = neat_bar->down_layer;
pressed = &neat_bar->down_pressed;
break;
default:
return NULL;
return;
}
if (!bitmap_layer) {
return NULL;
if (!bitmap_layer)
return;
if (is_press) {
if (*pressed)
return;
*pressed = true;
} else {
if (!*pressed)
return;
*pressed = false;
}
// legacy animation: no icon movement, just invert the background third
if (neat_bar->animations_legacy_pressed_color) {
layer_mark_dirty(neat_bar->main_layer);
return;
}
Layer *layer = bitmap_layer_get_layer(bitmap_layer);
GRect from_frame = layer_get_frame(layer);
GRect to_frame = from_frame;
if (move_on_y_axis) {
to_frame.origin.y += distance;
GRect home = s_get_home_frame(neat_bar, button_index);
// off = home shifted by -distance (the "pressed" position)
GRect off = home;
int16_t distance = neat_bar->animations_move_distance;
if (neat_bar->animations_move_on_y_axis) {
off.origin.y -= distance;
} else {
to_frame.origin.x += distance;
off.origin.x -= distance;
}
PropertyAnimation *prop_anim = property_animation_create_layer_frame(layer, &from_frame, &to_frame);
return property_animation_get_animation(prop_anim);
GRect from = is_press ? home : off;
GRect to = is_press ? off : home;
PropertyAnimation *prop_anim = property_animation_create_layer_frame(layer, &from, &to);
Animation *anim = property_animation_get_animation(prop_anim);
animation_set_duration(anim, neat_bar->animations_duration);
animation_schedule(anim);
}
static void s_icon_down_handler(NeatBarLayer *neat_bar, uint8_t button_index) {
Animation *anim = s_animate_move(neat_bar, button_index, false, -4);
animation_set_duration(anim, 80);
animation_schedule(anim);
s_animate_icon(neat_bar, button_index, true);
}
static void s_icon_up_handler(NeatBarLayer *neat_bar, uint8_t button_index) {
Animation *anim = s_animate_move(neat_bar, button_index, false, 4);
animation_set_duration(anim, 80);
animation_schedule(anim);
s_animate_icon(neat_bar, button_index, false);
}
static void s_up_down_handler(ClickRecognizerRef recognizer, void *context) {
@@ -96,9 +145,32 @@ static void s_select_up_handler(ClickRecognizerRef recognizer, void *context) {
}
static void s_main_layer_update_proc(Layer *layer, GContext *ctx) {
NeatBarLayer *neat_bar = s_current_neat_bar;
GRect bounds = layer_get_bounds(layer);
graphics_context_set_antialiased(ctx, false);
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_fill_color(ctx, neat_bar->background_color);
graphics_fill_rect(ctx, bounds, neat_bar->corner_radius, neat_bar->x_offset > 0 ? GCornersAll : GCornersLeft);
// legacy animation: invert the background third for any pressed button
if (neat_bar->animations_legacy_pressed_color) {
int16_t third_height = bounds.size.h / 3;
uint16_t radius = neat_bar->corner_radius;
uint16_t inner_radius = radius > 0 ? radius - 1 : 0;
graphics_context_set_fill_color(ctx, *(neat_bar->animations_legacy_pressed_color));
if (neat_bar->up_pressed) {
graphics_fill_rect(ctx, GRect(1, 1, bounds.size.w - 2, third_height - 2), inner_radius,
neat_bar->x_offset > 0 ? GCornersTop : GCornerTopLeft);
}
if (neat_bar->select_pressed) {
graphics_fill_rect(ctx, GRect(1, third_height + 1, bounds.size.w - 2, third_height - 2), 0, GCornerNone);
}
if (neat_bar->down_pressed) {
graphics_fill_rect(ctx, GRect(1, third_height * 2 + 1, bounds.size.w - 2, bounds.size.h - third_height * 2 - 2), inner_radius,
neat_bar->x_offset > 0 ? GCornersBottom : GCornerBottomLeft);
}
}
}
static void s_base_click_config_provider(void *config_context) {
@@ -138,6 +210,7 @@ static void s_recenter_icons(NeatBarLayer *neat_bar) {
}
}
// match stock rectangular aesthetic (except for icon x offset)
void neat_bar_layer_set_theme_default_rect(NeatBarLayer *neat_bar) {
neat_bar_layer_set_floating(neat_bar, false);
neat_bar->main_grect = s_base_grect_rect;
@@ -146,11 +219,13 @@ void neat_bar_layer_set_theme_default_rect(NeatBarLayer *neat_bar) {
s_recenter_icons(neat_bar);
}
void neat_bar_layer_set_theme_legacy_rect(NeatBarLayer *neat_bar) {
// match SDK 2.X aesthetic
void neat_bar_layer_set_theme_legacy_rect(NeatBarLayer *neat_bar, GColor8 *pressed_color) {
neat_bar_layer_set_floating(neat_bar, false);
neat_bar->main_grect = GRect(s_base_grect_rect.origin.x, 4, s_base_grect_rect.size.w, s_base_grect_rect.size.h - 8);
layer_set_frame(neat_bar->main_layer, neat_bar->main_grect);
neat_bar_layer_set_corner_radius(neat_bar, 3);
neat_bar_layer_set_animations_type(neat_bar, pressed_color);
s_recenter_icons(neat_bar);
}
@@ -165,6 +240,30 @@ void neat_bar_layer_set_click_config_provider(NeatBarLayer *neat_bar, ClickConfi
s_update_click_config_provider(neat_bar);
}
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: false
void neat_bar_layer_set_animations_move_axis(NeatBarLayer *neat_bar, bool use_y_axis) {
if (use_y_axis == neat_bar->animations_move_on_y_axis) {
return;
}
neat_bar->animations_move_on_y_axis = use_y_axis;
}
// default: 144
void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t duration_ms) {
if (duration_ms == neat_bar->animations_duration) {
return;
}
neat_bar->animations_duration = duration_ms;
}
// default: 0
void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset) {
if (x_offset == neat_bar->x_offset) {
return;
@@ -175,6 +274,7 @@ void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset) {
layer_mark_dirty(neat_bar->main_layer);
}
// default: ACTION_BAR_WIDTH
void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width) {
if (width == neat_bar->main_grect.size.w) {
return;
@@ -192,6 +292,7 @@ void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width) {
s_recenter_icons(neat_bar);
}
// default: PBL_DISPLAY_HEIGHT
void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height) {
if (height == neat_bar->main_grect.size.h) {
return;
@@ -201,6 +302,7 @@ void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height) {
layer_mark_dirty(neat_bar->main_layer);
}
// default: 0
void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset) {
if (y_offset == neat_bar->main_grect.origin.y) {
return;
@@ -211,6 +313,7 @@ void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset) {
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;
@@ -219,6 +322,7 @@ void neat_bar_layer_set_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_ra
layer_mark_dirty(neat_bar->main_layer);
}
// default: GColorBlack
void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor background_color) {
if (gcolor_equal(background_color, neat_bar->background_color)) {
return;
@@ -227,6 +331,16 @@ void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor backgrou
layer_mark_dirty(neat_bar->main_layer);
}
// default: NULL (null disables legacy animations)
void neat_bar_layer_set_animations_type(NeatBarLayer *neat_bar, GColor8 *pressed_color) {
if (pressed_color->argb == neat_bar->animations_legacy_pressed_color->argb) {
return;
}
neat_bar->animations_legacy_pressed_color = pressed_color;
layer_mark_dirty(neat_bar->main_layer);
}
// default: 0
void neat_bar_layer_set_spread(NeatBarLayer *neat_bar, int8_t spread) {
if (spread == neat_bar->spread) {
return;
@@ -235,6 +349,7 @@ void neat_bar_layer_set_spread(NeatBarLayer *neat_bar, int8_t spread) {
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;
uint16_t y_pos;
@@ -290,6 +405,13 @@ NeatBarLayer *neat_bar_layer_create() {
neat_bar->corner_radius = 0;
neat_bar->x_offset = 0;
neat_bar->spread = 0;
neat_bar->animations_duration = 144;
neat_bar->animations_move_on_y_axis = false;
neat_bar->animations_move_distance = ANIM_DISTANCE;
neat_bar->animations_legacy_pressed_color = NULL;
neat_bar->up_pressed = false;
neat_bar->select_pressed = false;
neat_bar->down_pressed = false;
neat_bar->context = NULL;
layer_set_update_proc(neat_bar->main_layer, s_main_layer_update_proc);
s_current_neat_bar = neat_bar;
+12 -2
View File
@@ -17,14 +17,24 @@ typedef struct {
uint16_t corner_radius;
uint16_t x_offset;
int8_t spread;
//bool use_legacy_animations
uint8_t animations_duration;
bool animations_move_on_y_axis;
int8_t animations_move_distance;
GColor8 *animations_legacy_pressed_color;
bool up_pressed;
bool select_pressed;
bool down_pressed;
void *context;
} NeatBarLayer;
void neat_bar_layer_set_theme_default_rect(NeatBarLayer *neat_bar);
void neat_bar_layer_set_theme_legacy_rect(NeatBarLayer *neat_bar);
void neat_bar_layer_set_theme_legacy_rect(NeatBarLayer *neat_bar, GColor8 *pressed_color);
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_animations_move_distance(NeatBarLayer *neat_bar, int8_t distance);
void neat_bar_layer_set_animations_move_axis(NeatBarLayer *neat_bar, bool use_y_axis);
void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t duration_ms);
void neat_bar_layer_set_animations_type(NeatBarLayer *neat_bar, GColor8 *pressed_color);
void neat_bar_layer_set_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_height(NeatBarLayer *neat_bar, uint16_t height);