WIP: radial bar background
This commit is contained in:
+23
-13
@@ -25,11 +25,11 @@
|
||||
#endif
|
||||
|
||||
#if PBL_ROUND
|
||||
#define USE_ROUND_BAR_BY_DEFAULT true
|
||||
#define DEFAULT_BAR_STYLE NEAT_BAR_STYLE_ROUND
|
||||
#define DEFAULT_ANIM_DISTANCE 4
|
||||
#define DEFAULT_ICONS_X_OFFSET -1
|
||||
#else
|
||||
#define USE_ROUND_BAR_BY_DEFAULT false
|
||||
#define DEFAULT_BAR_STYLE NEAT_BAR_STYLE_RECT
|
||||
#define DEFAULT_ANIM_DISTANCE 5
|
||||
#define DEFAULT_ICONS_X_OFFSET 1
|
||||
#endif
|
||||
@@ -141,18 +141,28 @@ static void s_select_up_handler(ClickRecognizerRef recognizer, void *context) {
|
||||
}
|
||||
|
||||
static void s_main_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
if (s_current_neat_bar->bar_use_round_style) {
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
|
||||
switch (s_current_neat_bar->bar_style) {
|
||||
case NEAT_BAR_STYLE_RADIAL: {
|
||||
graphics_fill_radial(ctx, grect_inset(bounds, GEdgeInsets(-(bounds.size.w / 3))), GOvalScaleModeFitCircle,
|
||||
bounds.size.w,
|
||||
DEG_TO_TRIGANGLE(60), // ~2 o'clock
|
||||
DEG_TO_TRIGANGLE(120) // ~4 o'clock
|
||||
);
|
||||
break;
|
||||
}
|
||||
case NEAT_BAR_STYLE_ROUND: {
|
||||
const uint32_t action_bar_circle_diameter = PBL_DISPLAY_HEIGHT * 19 / 9;
|
||||
GRect neat_bar_circle_frame = (GRect){.size = GSize(action_bar_circle_diameter, action_bar_circle_diameter)};
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
grect_align(&neat_bar_circle_frame, &bounds, GAlignLeft, false);
|
||||
graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
|
||||
const int32_t inset_thickness = MAX(ABS(neat_bar_circle_frame.size.h), ABS(neat_bar_circle_frame.size.w));
|
||||
graphics_fill_radial(ctx, neat_bar_circle_frame, GOvalScaleModeFitCircle, inset_thickness, 0, TRIG_MAX_ANGLE);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
graphics_context_set_antialiased(ctx, false);
|
||||
graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
|
||||
graphics_fill_rect(ctx, layer_get_bounds(layer), s_current_neat_bar->rect_bar_corner_radius, s_current_neat_bar->bar_x_offset > 0 ? GCornersAll : GCornersLeft);
|
||||
graphics_fill_rect(ctx, bounds, s_current_neat_bar->rect_bar_corner_radius, s_current_neat_bar->bar_x_offset > 0 ? GCornersAll : GCornersLeft);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,12 +248,12 @@ void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t dura
|
||||
neat_bar->animations_duration = duration_ms;
|
||||
}
|
||||
|
||||
// default: false (rect), true (round)
|
||||
void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, bool use_round_style) {
|
||||
if (use_round_style == neat_bar->bar_use_round_style) {
|
||||
// default: NEAT_BAR_STYLE_RECT (rect), NEAT_BAR_STYLE_ROUND (round)
|
||||
void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, uint8_t bar_style) {
|
||||
if (bar_style == neat_bar->bar_style) {
|
||||
return;
|
||||
}
|
||||
neat_bar->bar_use_round_style = use_round_style;
|
||||
neat_bar->bar_style = bar_style;
|
||||
layer_mark_dirty(neat_bar->main_layer);
|
||||
}
|
||||
|
||||
@@ -399,7 +409,7 @@ NeatBarLayer *neat_bar_layer_create() {
|
||||
neat_bar->context = NULL;
|
||||
|
||||
// neat_bar exclusives :D
|
||||
neat_bar->bar_use_round_style = USE_ROUND_BAR_BY_DEFAULT;
|
||||
neat_bar->bar_style = DEFAULT_BAR_STYLE;
|
||||
neat_bar->rect_bar_corner_radius = 0;
|
||||
neat_bar->bar_x_offset = 0;
|
||||
neat_bar->icons_spread = DEFAULT_SPREAD;
|
||||
|
||||
+8
-2
@@ -5,6 +5,12 @@
|
||||
|
||||
#include <pebble.h>
|
||||
|
||||
typedef enum {
|
||||
NEAT_BAR_STYLE_RECT = 0,
|
||||
NEAT_BAR_STYLE_ROUND = 1,
|
||||
NEAT_BAR_STYLE_RADIAL = 2,
|
||||
} NeatBarStyle;
|
||||
|
||||
typedef struct {
|
||||
// layerage
|
||||
struct Window *window;
|
||||
@@ -20,7 +26,7 @@ typedef struct {
|
||||
void *context;
|
||||
|
||||
// neat_bar exclusives :D
|
||||
bool bar_use_round_style;
|
||||
uint8_t bar_style; // 0 = rect, 1 = round, 2 = radial
|
||||
uint16_t rect_bar_corner_radius;
|
||||
uint16_t bar_x_offset;
|
||||
int8_t icons_spread;
|
||||
@@ -43,7 +49,7 @@ void neat_bar_layer_set_animations_enabled(NeatBarLayer *neat_bar, bool enabled)
|
||||
void neat_bar_layer_set_animations_move_axis(NeatBarLayer *neat_bar, bool use_y_axis);
|
||||
void neat_bar_layer_set_animations_move_distance(NeatBarLayer *neat_bar, int8_t distance);
|
||||
void neat_bar_layer_set_animations_duration(NeatBarLayer *neat_bar, uint8_t duration_ms);
|
||||
void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, bool use_round_style);
|
||||
void neat_bar_layer_set_bar_style(NeatBarLayer *neat_bar, uint8_t bar_style);
|
||||
void neat_bar_layer_set_rect_bar_floating(NeatBarLayer *neat_bar, uint16_t x_offset);
|
||||
void neat_bar_layer_set_rect_bar_corner_radius(NeatBarLayer *neat_bar, uint16_t corner_radius);
|
||||
void neat_bar_layer_set_bar_width(NeatBarLayer *neat_bar, uint16_t width);
|
||||
|
||||
Reference in New Issue
Block a user