diff --git a/src/c/neat_bar.c b/src/c/neat_bar.c index c5b3121..15a8af5 100644 --- a/src/c/neat_bar.c +++ b/src/c/neat_bar.c @@ -38,7 +38,7 @@ static NeatBarLayer *s_current_neat_bar = 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; + int8_t spread = neat_bar->icons_spread; uint16_t width = neat_bar->main_grect.size.w; switch (button_index) { @@ -141,7 +141,7 @@ static void s_select_up_handler(ClickRecognizerRef recognizer, void *context) { 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_fill_rect(ctx, layer_get_bounds(layer), s_current_neat_bar->corner_radius, s_current_neat_bar->x_offset > 0 ? GCornersAll : GCornersLeft); + graphics_fill_rect(ctx, layer_get_bounds(layer), s_current_neat_bar->bar_corner_radius, s_current_neat_bar->bar_x_offset > 0 ? GCornersAll : GCornersLeft); } static void s_base_click_config_provider(void *config_context) { @@ -166,7 +166,7 @@ inline static void s_update_click_config_provider(NeatBarLayer *neat_bar) { static void s_recenter_icons(NeatBarLayer *neat_bar) { int16_t y_offset = neat_bar->main_grect.origin.y; - int8_t spread = neat_bar->spread; + 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, UP_Y - spread - y_offset, neat_bar->main_grect.size.w, 25)); @@ -217,10 +217,10 @@ void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t dura // default: 0 void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset) { - if (x_offset == neat_bar->x_offset) { + if (x_offset == neat_bar->bar_x_offset) { return; } - neat_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; layer_set_frame(neat_bar->main_layer, neat_bar->main_grect); layer_mark_dirty(neat_bar->main_layer); @@ -234,9 +234,9 @@ void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width) { neat_bar->main_grect.origin.x = PBL_DISPLAY_WIDTH - width; neat_bar->main_grect.size.w = width; layer_set_frame(neat_bar->main_layer, neat_bar->main_grect); - if (neat_bar->x_offset > 0) { - uint16_t x = neat_bar->x_offset; - neat_bar->x_offset = 0; // force update + if (neat_bar->bar_x_offset > 0) { + uint16_t x = neat_bar->bar_x_offset; + neat_bar->bar_x_offset = 0; // force update neat_bar_layer_set_floating(neat_bar, x); } else { layer_mark_dirty(neat_bar->main_layer); @@ -267,10 +267,10 @@ void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset) { // default: 0 void neat_bar_layer_set_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius) { - if (corner_radius == neat_bar->corner_radius) { + if (corner_radius == neat_bar->bar_corner_radius) { return; } - neat_bar->corner_radius = corner_radius; + neat_bar->bar_corner_radius = corner_radius; layer_mark_dirty(neat_bar->main_layer); } @@ -285,10 +285,10 @@ void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor backgrou // default: 0 void neat_bar_layer_set_spread(NeatBarLayer *neat_bar, int8_t spread) { - if (spread == neat_bar->spread) { + if (spread == neat_bar->icons_spread) { return; } - neat_bar->spread = spread; + neat_bar->icons_spread = spread; s_recenter_icons(neat_bar); } @@ -312,8 +312,8 @@ void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap } if (!current_bitmap_layer) { - int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? y_pos - neat_bar->spread - : (button_id == BUTTON_ID_DOWN) ? y_pos + neat_bar->spread + int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? y_pos - neat_bar->icons_spread + : (button_id == BUTTON_ID_DOWN) ? y_pos + neat_bar->icons_spread : y_pos; 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)); @@ -338,23 +338,32 @@ void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap NeatBarLayer *neat_bar_layer_create() { NeatBarLayer *neat_bar = malloc(sizeof(NeatBarLayer)); + + // layerage neat_bar->main_grect = s_base_grect_rect; neat_bar->main_layer = layer_create(s_base_grect_rect); neat_bar->up_layer = NULL; neat_bar->down_layer = NULL; neat_bar->select_layer = NULL; + + // stock cfg/plumbing neat_bar->click_config_provider = NULL; neat_bar->background_color = GColorBlack; - neat_bar->corner_radius = 0; - neat_bar->x_offset = 0; - neat_bar->spread = 0; + neat_bar->context = NULL; + + // neat_bar exclusives :D + neat_bar->bar_corner_radius = 0; + neat_bar->bar_x_offset = 0; + neat_bar->icons_spread = 0; neat_bar->animations_move_on_y_axis = false; neat_bar->animations_move_distance = ANIM_DISTANCE; neat_bar->animations_duration = 144; + + // state tracking 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; return neat_bar; diff --git a/src/c/neat_bar.h b/src/c/neat_bar.h index 0f06cf3..8d9b552 100644 --- a/src/c/neat_bar.h +++ b/src/c/neat_bar.h @@ -6,24 +6,31 @@ #include typedef struct { + // layerage struct Window *window; GRect main_grect; Layer *main_layer; BitmapLayer *up_layer; BitmapLayer *down_layer; BitmapLayer *select_layer; + + // stock cfg/plumbing ClickConfigProvider click_config_provider; GColor8 background_color; - uint16_t corner_radius; - uint16_t x_offset; - int8_t spread; + void *context; + + // neat_bar exclusives :D + uint16_t bar_corner_radius; + uint16_t bar_x_offset; + int8_t icons_spread; bool animations_move_on_y_axis; int8_t animations_move_distance; uint8_t animations_duration; + + // state tracking bool up_pressed; bool select_pressed; bool down_pressed; - void *context; } NeatBarLayer; void neat_bar_layer_add_to_window(NeatBarLayer *neat_bar, Window *window);