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) {
int16_t y_offset = neat_bar->main_grect.origin.y;
int8_t spread = neat_bar->spread;
if (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) {
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) {
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);
}
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) {
BitmapLayer *current_bitmap_layer;
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) {
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));
switch (button_id) {
case BUTTON_ID_UP:
@@ -209,6 +221,7 @@ NeatBarLayer *neat_bar_layer_create() {
neat_bar->background_color = GColorBlack;
neat_bar->corner_radius = 0;
neat_bar->x_offset = 0;
neat_bar->spread = 0;
neat_bar->context = NULL;
layer_set_update_proc(neat_bar->main_layer, s_main_layer_update_proc);
s_current_neat_bar = neat_bar;