Make float offset adjustable
This commit is contained in:
+19
-14
@@ -32,7 +32,7 @@ static void s_select_up_handler(ClickRecognizerRef recognizer, void *context) {}
|
|||||||
static void s_main_layer_update_proc(Layer *layer, GContext *ctx) {
|
static void s_main_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||||
graphics_context_set_antialiased(ctx, false);
|
graphics_context_set_antialiased(ctx, false);
|
||||||
graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
|
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->floating ? GCornersAll : GCornersLeft);
|
graphics_fill_rect(ctx, layer_get_bounds(layer), s_current_neat_bar->corner_radius, s_current_neat_bar->x_offset > 0 ? GCornersAll : GCornersLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void s_base_click_config_provider(void *config_context) {
|
static void s_base_click_config_provider(void *config_context) {
|
||||||
@@ -98,17 +98,13 @@ void neat_bar_layer_set_click_config_provider(NeatBarLayer *neat_bar, ClickConfi
|
|||||||
s_update_click_config_provider(neat_bar);
|
s_update_click_config_provider(neat_bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, bool floating) {
|
void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, uint16_t x_offset) {
|
||||||
if (floating == neat_bar->floating) {
|
if (x_offset == neat_bar->x_offset) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint16_t x = neat_bar->main_grect.origin.x;
|
neat_bar->x_offset = x_offset;
|
||||||
if (floating) {
|
neat_bar->main_grect.origin.x = PBL_DISPLAY_WIDTH - neat_bar->main_grect.size.w - x_offset;
|
||||||
x = x - 2;
|
|
||||||
}
|
|
||||||
neat_bar->main_grect = GRect(x, neat_bar->main_grect.origin.y, neat_bar->main_grect.size.w, neat_bar->main_grect.size.h);
|
|
||||||
layer_set_frame(neat_bar->main_layer, neat_bar->main_grect);
|
layer_set_frame(neat_bar->main_layer, neat_bar->main_grect);
|
||||||
neat_bar->floating = floating;
|
|
||||||
layer_mark_dirty(neat_bar->main_layer);
|
layer_mark_dirty(neat_bar->main_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,9 +115,10 @@ 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.origin.x = PBL_DISPLAY_WIDTH - width;
|
||||||
neat_bar->main_grect.size.w = width;
|
neat_bar->main_grect.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);
|
||||||
if (neat_bar->floating) {
|
if (neat_bar->x_offset > 0) {
|
||||||
neat_bar->floating = false;
|
uint16_t x = neat_bar->x_offset;
|
||||||
neat_bar_layer_set_floating(neat_bar, true);
|
neat_bar->x_offset = 0; // force update
|
||||||
|
neat_bar_layer_set_floating(neat_bar, x);
|
||||||
} else {
|
} else {
|
||||||
layer_mark_dirty(neat_bar->main_layer);
|
layer_mark_dirty(neat_bar->main_layer);
|
||||||
}
|
}
|
||||||
@@ -132,10 +129,18 @@ void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height) {
|
|||||||
if (height == neat_bar->main_grect.size.h) {
|
if (height == neat_bar->main_grect.size.h) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
neat_bar->main_grect.origin.y = (PBL_DISPLAY_HEIGHT - height) / 2;
|
|
||||||
neat_bar->main_grect.size.h = height;
|
neat_bar->main_grect.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);
|
||||||
layer_mark_dirty(neat_bar->main_layer);
|
layer_mark_dirty(neat_bar->main_layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void neat_bar_layer_set_y_offset(NeatBarLayer *neat_bar, uint16_t y_offset) {
|
||||||
|
if (y_offset == neat_bar->main_grect.origin.y) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
neat_bar->main_grect.origin.y = y_offset;
|
||||||
|
layer_set_frame(neat_bar->main_layer, neat_bar->main_grect);
|
||||||
|
layer_mark_dirty(neat_bar->main_layer);
|
||||||
s_recenter_icons(neat_bar);
|
s_recenter_icons(neat_bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +208,7 @@ NeatBarLayer *neat_bar_layer_create() {
|
|||||||
neat_bar->click_config_provider = NULL;
|
neat_bar->click_config_provider = NULL;
|
||||||
neat_bar->background_color = GColorBlack;
|
neat_bar->background_color = GColorBlack;
|
||||||
neat_bar->corner_radius = 0;
|
neat_bar->corner_radius = 0;
|
||||||
neat_bar->floating = false;
|
neat_bar->x_offset = 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;
|
||||||
|
|||||||
+3
-4
@@ -15,9 +15,7 @@ typedef struct {
|
|||||||
ClickConfigProvider click_config_provider;
|
ClickConfigProvider click_config_provider;
|
||||||
GColor8 background_color;
|
GColor8 background_color;
|
||||||
uint16_t corner_radius;
|
uint16_t corner_radius;
|
||||||
bool floating;
|
uint16_t x_offset;
|
||||||
//uint8_t top_shrinkage;
|
|
||||||
//uint8_t bottom_shrinkage;
|
|
||||||
//int8_t spread; // positive integers push the icons further apart; negative integers pull them together
|
//int8_t spread; // positive integers push the icons further apart; negative integers pull them together
|
||||||
//bool use_legacy_animations
|
//bool use_legacy_animations
|
||||||
void *context;
|
void *context;
|
||||||
@@ -29,7 +27,8 @@ void neat_bar_layer_set_theme_default_rect(NeatBarLayer *neat_bar);
|
|||||||
void neat_bar_layer_set_theme_legacy_rect(NeatBarLayer *neat_bar);
|
void neat_bar_layer_set_theme_legacy_rect(NeatBarLayer *neat_bar);
|
||||||
void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width);
|
void neat_bar_layer_set_width(NeatBarLayer *neat_bar, uint16_t width);
|
||||||
void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height);
|
void neat_bar_layer_set_height(NeatBarLayer *neat_bar, uint16_t height);
|
||||||
void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, bool floating);
|
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_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_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);
|
||||||
|
|||||||
Reference in New Issue
Block a user