Allow floating bars
This commit is contained in:
+21
-3
@@ -14,6 +14,8 @@ const uint16_t SELECT_Y = 90;
|
||||
const uint16_t DOWN_Y = 120;
|
||||
#endif
|
||||
|
||||
static const GRect s_base_grect = GRect(PBL_DISPLAY_WIDTH - ACTION_BAR_WIDTH, 0, ACTION_BAR_WIDTH, PBL_DISPLAY_HEIGHT);
|
||||
|
||||
static NeatBarLayer *s_current_neat_bar = NULL;
|
||||
|
||||
static void s_up_down_handler(ClickRecognizerRef recognizer, void *context) {}
|
||||
@@ -25,7 +27,7 @@ static void s_select_up_handler(ClickRecognizerRef recognizer, void *context) {}
|
||||
|
||||
static void s_main_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
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, GCornersLeft);
|
||||
graphics_fill_rect(ctx, layer_get_bounds(layer), s_current_neat_bar->corner_radius, s_current_neat_bar->floating ? GCornersAll : GCornersLeft);
|
||||
}
|
||||
|
||||
static void s_base_click_config_provider(void *config_context) {
|
||||
@@ -59,8 +61,22 @@ void neat_bar_layer_set_click_config_provider(NeatBarLayer *neat_bar, ClickConfi
|
||||
s_update_click_config_provider(neat_bar);
|
||||
}
|
||||
|
||||
void neat_bar_layer_set_floating(NeatBarLayer *neat_bar, bool floating) {
|
||||
if (floating == neat_bar->floating) {
|
||||
return;
|
||||
}
|
||||
uint16_t x = s_base_grect.origin.x;
|
||||
if (floating) {
|
||||
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(s_current_neat_bar->main_layer, s_current_neat_bar->main_grect);
|
||||
neat_bar->floating = floating;
|
||||
layer_mark_dirty(neat_bar->main_layer);
|
||||
}
|
||||
|
||||
void neat_bar_layer_set_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius) {
|
||||
if (corner_radius == 0) {
|
||||
if (corner_radius == neat_bar->corner_radius) {
|
||||
return;
|
||||
}
|
||||
neat_bar->corner_radius = corner_radius;
|
||||
@@ -115,13 +131,15 @@ void neat_bar_layer_set_icon(NeatBarLayer *neat_bar, ButtonId button_id, GBitmap
|
||||
|
||||
NeatBarLayer *neat_bar_layer_create() {
|
||||
NeatBarLayer *neat_bar = malloc(sizeof(NeatBarLayer));
|
||||
neat_bar->main_layer = layer_create(GRect(PBL_DISPLAY_WIDTH - ACTION_BAR_WIDTH, 0, ACTION_BAR_WIDTH, PBL_DISPLAY_HEIGHT)); // TODO allow custom GRect
|
||||
neat_bar->main_grect = s_base_grect;
|
||||
neat_bar->main_layer = layer_create(s_base_grect);
|
||||
neat_bar->up_layer = NULL;
|
||||
neat_bar->down_layer = NULL;
|
||||
neat_bar->select_layer = NULL;
|
||||
neat_bar->click_config_provider = NULL;
|
||||
neat_bar->background_color = GColorBlack;
|
||||
neat_bar->corner_radius = 0;
|
||||
neat_bar->floating = false;
|
||||
neat_bar->context = NULL;
|
||||
layer_set_update_proc(neat_bar->main_layer, s_main_layer_update_proc);
|
||||
s_current_neat_bar = neat_bar;
|
||||
|
||||
Reference in New Issue
Block a user