Implement spread

This commit is contained in:
2026-07-19 13:16:54 -04:00
parent 8a04dd6c69
commit e7264a0adb
2 changed files with 18 additions and 4 deletions
+16 -3
View File
@@ -57,9 +57,10 @@ 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 y_offset = neat_bar->main_grect.origin.y; int16_t y_offset = neat_bar->main_grect.origin.y;
int8_t spread = neat_bar->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(1, UP_Y - y_offset, neat_bar->main_grect.size.w, 18)); GRect(1, UP_Y - spread - y_offset, neat_bar->main_grect.size.w, 18));
} }
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),
@@ -67,7 +68,7 @@ static void s_recenter_icons(NeatBarLayer *neat_bar) {
} }
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(1, DOWN_Y - y_offset, neat_bar->main_grect.size.w, 18)); GRect(1, DOWN_Y + spread - y_offset, neat_bar->main_grect.size.w, 18));
} }
} }
@@ -160,6 +161,14 @@ void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor backgrou
layer_mark_dirty(neat_bar->main_layer); layer_mark_dirty(neat_bar->main_layer);
} }
void neat_bar_layer_set_spread(NeatBarLayer *neat_bar, int8_t spread) {
if (spread == neat_bar->spread) {
return;
}
neat_bar->spread = spread;
s_recenter_icons(neat_bar);
}
void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap *icon) { void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap *icon) {
BitmapLayer *current_bitmap_layer; BitmapLayer *current_bitmap_layer;
uint16_t y_pos; uint16_t y_pos;
@@ -179,7 +188,10 @@ void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap
} }
if (!current_bitmap_layer) { if (!current_bitmap_layer) {
current_bitmap_layer = bitmap_layer_create(GRect(1, y_pos, neat_bar->main_grect.size.w, 18)); int16_t adjusted_y = (button_id == BUTTON_ID_UP) ? y_pos - neat_bar->spread
: (button_id == BUTTON_ID_DOWN) ? y_pos + neat_bar->spread
: y_pos;
current_bitmap_layer = bitmap_layer_create(GRect(1, adjusted_y, neat_bar->main_grect.size.w, 18));
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:
@@ -209,6 +221,7 @@ NeatBarLayer *neat_bar_layer_create() {
neat_bar->background_color = GColorBlack; neat_bar->background_color = GColorBlack;
neat_bar->corner_radius = 0; neat_bar->corner_radius = 0;
neat_bar->x_offset = 0; neat_bar->x_offset = 0;
neat_bar->spread = 0;
neat_bar->context = NULL; neat_bar->context = NULL;
layer_set_update_proc(neat_bar->main_layer, s_main_layer_update_proc); layer_set_update_proc(neat_bar->main_layer, s_main_layer_update_proc);
s_current_neat_bar = neat_bar; s_current_neat_bar = neat_bar;
+2 -1
View File
@@ -16,7 +16,7 @@ typedef struct {
GColor8 background_color; GColor8 background_color;
uint16_t corner_radius; uint16_t corner_radius;
uint16_t x_offset; uint16_t x_offset;
//int8_t spread; // positive integers push the icons further apart; negative integers pull them together int8_t spread;
//bool use_legacy_animations //bool use_legacy_animations
void *context; void *context;
} NeatBarLayer; } NeatBarLayer;
@@ -31,5 +31,6 @@ void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset);
void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset); void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset);
void neat_bar_layer_set_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius); void neat_bar_layer_set_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius);
void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor background_color); void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor background_color);
void neat_bar_layer_set_spread(NeatBarLayer *neat_bar, int8_t spread);
void neat_bar_layer_set_click_config_provider(NeatBarLayer *neat_bar, ClickConfigProvider click_config_provider); void neat_bar_layer_set_click_config_provider(NeatBarLayer *neat_bar, ClickConfigProvider click_config_provider);
void neat_bar_layer_add_to_window(NeatBarLayer *neat_bar, Window *window); void neat_bar_layer_add_to_window(NeatBarLayer *neat_bar, Window *window);