From f7f63f199d260c224f623bbe677af8d3ef9148d8 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Wed, 22 Jul 2026 21:44:36 -0400 Subject: [PATCH] Fix radial bar length --- src/c/neat_bar.c | 54 +++++++++++++++++++++++++++--------------------- src/c/neat_bar.h | 2 +- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/c/neat_bar.c b/src/c/neat_bar.c index b0b0079..1b7c024 100644 --- a/src/c/neat_bar.c +++ b/src/c/neat_bar.c @@ -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 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; - uint16_t width = neat_bar->main_grect.size.w; + uint16_t width = neat_bar->main_grect_visual.size.w; switch (button_index) { case BUTTON_ID_UP: @@ -145,8 +145,9 @@ static void s_main_layer_update_proc(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color); switch (s_current_neat_bar->bar_style) { case NEAT_BAR_STYLE_RADIAL: { - graphics_fill_radial(ctx, grect_inset(bounds, GEdgeInsets(-(bounds.size.w / 3))), GOvalScaleModeFitCircle, - bounds.size.w, + GRect visual = s_current_neat_bar->main_grect_visual; + graphics_fill_radial(ctx, grect_inset(bounds, GEdgeInsets(-(visual.size.w / 3))), GOvalScaleModeFitCircle, + visual.size.w, DEG_TO_TRIGANGLE(60), // ~2 o'clock DEG_TO_TRIGANGLE(120) // ~4 o'clock ); @@ -189,19 +190,19 @@ inline static void s_update_click_config_provider(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; + 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) { 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) { 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) { 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)); } } @@ -253,6 +254,13 @@ void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, uint8_t bar_style) { if (bar_style == neat_bar->bar_style) { return; } + switch (bar_style) { + case NEAT_BAR_STYLE_RADIAL: + layer_set_frame(neat_bar->main_layer, GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT)); + break; + default: + layer_set_frame(neat_bar->main_layer, neat_bar->main_grect_visual); + } neat_bar->bar_style = bar_style; layer_mark_dirty(neat_bar->main_layer); } @@ -263,8 +271,8 @@ void neat_bar_layer_set_rect_bar_floating(NeatBarLayer *neat_bar, uint16_t x_off return; } 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); + 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_visual); layer_mark_dirty(neat_bar->main_layer); } @@ -279,12 +287,12 @@ void neat_bar_layer_set_rect_bar_corner_radius(NeatBarLayer *neat_bar, uint16_t // default: ACTION_BAR_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; } - 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); + neat_bar->main_grect_visual.origin.x = PBL_DISPLAY_WIDTH - width; + neat_bar->main_grect_visual.size.w = width; + layer_set_frame(neat_bar->main_layer, neat_bar->main_grect_visual); if (neat_bar->bar_x_offset > 0) { uint16_t x = neat_bar->bar_x_offset; neat_bar->bar_x_offset = 0; // force update @@ -297,21 +305,21 @@ void neat_bar_layer_set_bar_width(NeatBarLayer *neat_bar, uint16_t width) { // default: PBL_DISPLAY_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; } - neat_bar->main_grect.size.h = height; - layer_set_frame(neat_bar->main_layer, neat_bar->main_grect); + neat_bar->main_grect_visual.size.h = height; + layer_set_frame(neat_bar->main_layer, neat_bar->main_grect_visual); layer_mark_dirty(neat_bar->main_layer); } // default: 0 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; } - neat_bar->main_grect.origin.y = y_offset; - layer_set_frame(neat_bar->main_layer, neat_bar->main_grect); + neat_bar->main_grect_visual.origin.y = y_offset; + layer_set_frame(neat_bar->main_layer, neat_bar->main_grect_visual); layer_mark_dirty(neat_bar->main_layer); s_recenter_icons(neat_bar); } @@ -368,11 +376,11 @@ void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap } 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 : (button_id == BUTTON_ID_DOWN) ? SELECT_Y + neat_bar->icons_spread - 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)); switch (button_id) { case BUTTON_ID_UP: @@ -397,7 +405,7 @@ NeatBarLayer *neat_bar_layer_create() { NeatBarLayer *neat_bar = malloc(sizeof(NeatBarLayer)); // 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->up_layer = NULL; neat_bar->down_layer = NULL; diff --git a/src/c/neat_bar.h b/src/c/neat_bar.h index e9da040..177a576 100644 --- a/src/c/neat_bar.h +++ b/src/c/neat_bar.h @@ -14,7 +14,7 @@ typedef enum { typedef struct { // layerage struct Window *window; - GRect main_grect; + GRect main_grect_visual; Layer *main_layer; BitmapLayer *up_layer; BitmapLayer *down_layer;