Fix radial bar length

This commit is contained in:
2026-07-22 21:44:36 -04:00
parent 2c2f0fff94
commit f7f63f199d
2 changed files with 32 additions and 24 deletions
+31 -23
View File
@@ -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:
@@ -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); graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
switch (s_current_neat_bar->bar_style) { switch (s_current_neat_bar->bar_style) {
case NEAT_BAR_STYLE_RADIAL: { case NEAT_BAR_STYLE_RADIAL: {
graphics_fill_radial(ctx, grect_inset(bounds, GEdgeInsets(-(bounds.size.w / 3))), GOvalScaleModeFitCircle, GRect visual = s_current_neat_bar->main_grect_visual;
bounds.size.w, 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(60), // ~2 o'clock
DEG_TO_TRIGANGLE(120) // ~4 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) { 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; 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));
} }
} }
@@ -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) { if (bar_style == neat_bar->bar_style) {
return; 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; neat_bar->bar_style = bar_style;
layer_mark_dirty(neat_bar->main_layer); 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; 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_set_frame(neat_bar->main_layer, neat_bar->main_grect_visual);
layer_mark_dirty(neat_bar->main_layer); 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 // 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); layer_set_frame(neat_bar->main_layer, neat_bar->main_grect_visual);
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
@@ -297,21 +305,21 @@ 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_set_frame(neat_bar->main_layer, neat_bar->main_grect_visual);
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_set_frame(neat_bar->main_layer, neat_bar->main_grect_visual);
layer_mark_dirty(neat_bar->main_layer); layer_mark_dirty(neat_bar->main_layer);
s_recenter_icons(neat_bar); 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) { 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->main_layer, bitmap_layer_get_layer(current_bitmap_layer));
switch (button_id) { switch (button_id) {
case BUTTON_ID_UP: case BUTTON_ID_UP:
@@ -397,7 +405,7 @@ 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(s_base_grect_rect);
neat_bar->up_layer = NULL; neat_bar->up_layer = NULL;
neat_bar->down_layer = NULL; neat_bar->down_layer = NULL;
+1 -1
View File
@@ -14,7 +14,7 @@ typedef enum {
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;
BitmapLayer *up_layer; BitmapLayer *up_layer;
BitmapLayer *down_layer; BitmapLayer *down_layer;