Compare commits

..

6 Commits

3 changed files with 88 additions and 47 deletions
+9 -3
View File
@@ -4,12 +4,13 @@
## VS Stock Action Bar ## VS Stock Action Bar
### New Features ### New Features
- Floating mode! - Floating mode!
- Rectangular/round backgrounds on all 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/icon x/y offsets! - Custom bar/icon x/y offsets!
- Toggle-able bar AA!
### Missing Features (unplanned) ### Missing Features (unplanned)
- Anything to do with back button overrides - Anything to do with back button overrides
- Fully custom animations - Fully custom animations
@@ -17,7 +18,12 @@
- Duration, move distance/direction, and move axis are all configurable - Duration, move distance/direction, and move axis are all configurable
- They can also be disabled - They can also be disabled
### Pending Features ### Pending Features
- Optional AA on bar corners
- Legacy (background invert) animations support - Legacy (background invert) animations support
- Customizable round bar size - Customizable round bar size
- Legacy and default theme setters - 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
+65 -39
View File
@@ -25,11 +25,11 @@
#endif #endif
#if PBL_ROUND #if PBL_ROUND
#define USE_ROUND_BAR_BY_DEFAULT true #define DEFAULT_BAR_STYLE NEAT_BAR_STYLE_ROUND
#define DEFAULT_ANIM_DISTANCE 4 #define DEFAULT_ANIM_DISTANCE 4
#define DEFAULT_ICONS_X_OFFSET -1 #define DEFAULT_ICONS_X_OFFSET -1
#else #else
#define USE_ROUND_BAR_BY_DEFAULT false #define DEFAULT_BAR_STYLE NEAT_BAR_STYLE_RECT
#define DEFAULT_ANIM_DISTANCE 5 #define DEFAULT_ANIM_DISTANCE 5
#define DEFAULT_ICONS_X_OFFSET 1 #define DEFAULT_ICONS_X_OFFSET 1
#endif #endif
@@ -39,9 +39,9 @@ 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 total_y_offset = neat_bar->main_grect.origin.y - neat_bar->icons_y_offset; int16_t total_y_offset = neat_bar->main_grect_visual.origin.y - neat_bar->icons_y_offset;
int8_t spread = neat_bar->icons_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:
@@ -141,18 +141,27 @@ 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) {
if (s_current_neat_bar->bar_use_round_style) { graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
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; 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 neat_bar_circle_frame = (GRect){.size = GSize(action_bar_circle_diameter, action_bar_circle_diameter)};
GRect bounds = layer_get_bounds(layer); grect_align(&neat_bar_circle_frame, &s_current_neat_bar->main_grect_visual, GAlignLeft, false);
grect_align(&neat_bar_circle_frame, &bounds, GAlignLeft, false);
graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
const int32_t inset_thickness = MAX(ABS(neat_bar_circle_frame.size.h), ABS(neat_bar_circle_frame.size.w)); 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); graphics_fill_radial(ctx, neat_bar_circle_frame, GOvalScaleModeFitCircle, inset_thickness, 0, TRIG_MAX_ANGLE);
} else { break;
graphics_context_set_antialiased(ctx, false); }
graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color); default:
graphics_fill_rect(ctx, layer_get_bounds(layer), s_current_neat_bar->rect_bar_corner_radius, s_current_neat_bar->bar_x_offset > 0 ? GCornersAll : GCornersLeft); 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);
} }
} }
@@ -179,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 total_y_offset = neat_bar->main_grect.origin.y - neat_bar->icons_y_offset; layer_set_frame(neat_bar->icon_parent_layer, neat_bar->main_grect_visual);
int16_t total_y_offset = neat_bar->main_grect_visual.origin.y - neat_bar->icons_y_offset;
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(neat_bar->icons_x_offset, SELECT_Y - spread - total_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(neat_bar->icons_x_offset, SELECT_Y - total_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(neat_bar->icons_x_offset, SELECT_Y + spread - total_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));
} }
} }
@@ -238,12 +248,24 @@ 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: false (rect), true (round) // default: NEAT_BAR_STYLE_RECT (rect), NEAT_BAR_STYLE_ROUND (round)
void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, bool use_round_style) { void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, uint8_t bar_style) {
if (use_round_style == neat_bar->bar_use_round_style) { if (bar_style == neat_bar->bar_style) {
return; return;
} }
neat_bar->bar_use_round_style = use_round_style; neat_bar->bar_style = bar_style;
layer_mark_dirty(neat_bar->main_layer);
}
// 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); layer_mark_dirty(neat_bar->main_layer);
} }
@@ -253,9 +275,9 @@ void neat_bar_layer_set_rect_bar_floating(NeatBarLayer *neat_bar, uint16_t x_off
return; return;
} }
neat_bar->bar_x_offset = x_offset; neat_bar->bar_x_offset = x_offset;
neat_bar->main_grect.origin.x = PBL_DISPLAY_WIDTH - neat_bar->main_grect.size.w - x_offset; neat_bar->main_grect_visual.origin.x = PBL_DISPLAY_WIDTH - neat_bar->main_grect_visual.size.w - x_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);
} }
// default: 0 // default: 0
@@ -269,12 +291,11 @@ void neat_bar_layer_set_rect_bar_corner_radius(NeatBarLayer *neat_bar, uint16_t
// default: ACTION_BAR_WIDTH // default: ACTION_BAR_WIDTH
void neat_bar_layer_set_bar_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->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
@@ -287,21 +308,19 @@ void neat_bar_layer_set_bar_width(NeatBarLayer *neat_bar, uint16_t width) {
// default: PBL_DISPLAY_HEIGHT // default: PBL_DISPLAY_HEIGHT
void neat_bar_layer_set_bar_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_bar_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);
} }
@@ -358,12 +377,12 @@ void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap
} }
if (!current_bitmap_layer) { if (!current_bitmap_layer) {
int16_t total_y_offset = neat_bar->main_grect.origin.y - neat_bar->icons_y_offset; int16_t total_y_offset = neat_bar->main_grect_visual.origin.y - neat_bar->icons_y_offset;
int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? SELECT_Y - neat_bar->icons_spread - total_y_offset int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? SELECT_Y - neat_bar->icons_spread - total_y_offset
: (button_id == BUTTON_ID_DOWN) ? SELECT_Y + neat_bar->icons_spread - total_y_offset : (button_id == BUTTON_ID_DOWN) ? SELECT_Y + neat_bar->icons_spread - total_y_offset
: SELECT_Y - total_y_offset; : SELECT_Y - total_y_offset;
current_bitmap_layer = bitmap_layer_create(GRect(neat_bar->icons_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_visual.size.w, 25));
layer_add_child(neat_bar->main_layer, bitmap_layer_get_layer(current_bitmap_layer)); 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;
@@ -387,8 +406,10 @@ NeatBarLayer *neat_bar_layer_create() {
NeatBarLayer *neat_bar = malloc(sizeof(NeatBarLayer)); NeatBarLayer *neat_bar = malloc(sizeof(NeatBarLayer));
// layerage // layerage
neat_bar->main_grect = s_base_grect_rect; neat_bar->main_grect_visual = s_base_grect_rect;
neat_bar->main_layer = layer_create(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;
@@ -399,9 +420,14 @@ NeatBarLayer *neat_bar_layer_create() {
neat_bar->context = NULL; neat_bar->context = NULL;
// neat_bar exclusives :D // neat_bar exclusives :D
neat_bar->bar_use_round_style = USE_ROUND_BAR_BY_DEFAULT; neat_bar->bar_style = DEFAULT_BAR_STYLE;
neat_bar->rect_bar_corner_radius = 0; #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->bar_x_offset = 0;
neat_bar->rect_bar_corner_radius = 0;
neat_bar->icons_spread = DEFAULT_SPREAD; neat_bar->icons_spread = DEFAULT_SPREAD;
neat_bar->icons_x_offset = DEFAULT_ICONS_X_OFFSET; neat_bar->icons_x_offset = DEFAULT_ICONS_X_OFFSET;
neat_bar->icons_y_offset = 0; neat_bar->icons_y_offset = 0;
+14 -5
View File
@@ -5,11 +5,18 @@
#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 // 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;
@@ -20,9 +27,10 @@ typedef struct {
void *context; void *context;
// neat_bar exclusives :D // neat_bar exclusives :D
bool bar_use_round_style; uint8_t bar_style;
uint16_t rect_bar_corner_radius; bool bar_enable_aa;
uint16_t bar_x_offset; uint8_t bar_x_offset;
uint8_t rect_bar_corner_radius;
int8_t icons_spread; int8_t icons_spread;
int8_t icons_x_offset; int8_t icons_x_offset;
int8_t icons_y_offset; int8_t icons_y_offset;
@@ -43,7 +51,8 @@ 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_bar_style(NeatBarLayer *neat_bar, bool use_round_style); void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, uint8_t bar_style);
void neat_bar_layer_set_bar_aa(NeatBarLayer *neat_bar, bool enable_aa);
void neat_bar_layer_set_rect_bar_floating(NeatBarLayer *neat_bar, uint16_t x_offset); void neat_bar_layer_set_rect_bar_floating(NeatBarLayer *neat_bar, uint16_t x_offset);
void neat_bar_layer_set_rect_bar_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius); void neat_bar_layer_set_rect_bar_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_width(NeatBarLayer *neat_bar, uint16_t width);