refactor(layers/info): more short name

This commit is contained in:
mikhail "synzr" 2025-10-19 13:21:32 +05:00
parent 48f336a2eb
commit f32199c814
4 changed files with 41 additions and 44 deletions

View file

@ -1,37 +1,34 @@
#include "information_layer.h" #include "info_layer.h"
#include "resources_service.h" #include "resources_service.h"
#define INFO_LAYER_ICON_WIDTH 18 #define INFO_LAYER_ICON_WIDTH 18
#define INFO_LAYER_PADDING 4 #define INFO_LAYER_PADDING 4
#define INFO_LAYER_HEIGHT 24 #define INFO_LAYER_HEIGHT 24
typedef struct InformationLayerData { typedef struct InfoLayerData {
int level; int level;
int steps; int steps;
} InformationLayerData; } InfoLayerData;
static Layer *s_information_layer; static Layer *s_info_layer;
static char s_information_layer_level_text[3]; static char s_info_layer_level_text[3];
static char s_information_layer_count_text[6]; static char s_info_layer_count_text[6];
static void information_layer_update_proc(Layer *layer, GContext *ctx) { static void info_layer_update_proc(Layer *layer, GContext *ctx) {
GRect rect = layer_get_unobstructed_bounds(layer); GRect rect = layer_get_unobstructed_bounds(layer);
GFont font = resources_service_get_custom_font(CustomFontKonekoToro); GFont font = resources_service_get_custom_font(CustomFontKonekoToro);
InformationLayerData *data = layer_get_data(s_information_layer); InfoLayerData *data = layer_get_data(s_info_layer);
int content_w = INFO_LAYER_ICON_WIDTH + INFO_LAYER_PADDING; int content_w = INFO_LAYER_ICON_WIDTH + INFO_LAYER_PADDING;
snprintf(s_information_layer_level_text, sizeof(s_information_layer_level_text), "%d", snprintf(s_info_layer_level_text, sizeof(s_info_layer_level_text), "%d", data->level);
data->level);
GSize text_size = graphics_text_layout_get_content_size( GSize text_size = graphics_text_layout_get_content_size(
s_information_layer_level_text, font, rect, GTextOverflowModeFill, GTextAlignmentLeft); s_info_layer_level_text, font, rect, GTextOverflowModeFill, GTextAlignmentLeft);
content_w += text_size.w; content_w += text_size.w;
#ifdef PBL_HEALTH #ifdef PBL_HEALTH
snprintf(s_information_layer_count_text, sizeof(s_information_layer_count_text), "%d", snprintf(s_info_layer_count_text, sizeof(s_info_layer_count_text), "%d", data->steps);
data->steps); text_size = graphics_text_layout_get_content_size(s_info_layer_count_text, font, rect,
text_size = graphics_text_layout_get_content_size(s_information_layer_count_text, font, rect,
GTextOverflowModeFill, GTextAlignmentLeft); GTextOverflowModeFill, GTextAlignmentLeft);
content_w += INFO_LAYER_ICON_WIDTH + INFO_LAYER_PADDING + text_size.w; content_w += INFO_LAYER_ICON_WIDTH + INFO_LAYER_PADDING + text_size.w;
#endif #endif
@ -61,7 +58,7 @@ static void information_layer_update_proc(Layer *layer, GContext *ctx) {
GRect(content_x + INFO_LAYER_ICON_WIDTH + INFO_LAYER_PADDING, -4, text_size.w, text_size.h); GRect(content_x + INFO_LAYER_ICON_WIDTH + INFO_LAYER_PADDING, -4, text_size.w, text_size.h);
graphics_context_set_text_color(ctx, GColorBlack); graphics_context_set_text_color(ctx, GColorBlack);
graphics_draw_text(ctx, s_information_layer_level_text, font, text_rect, GTextOverflowModeFill, graphics_draw_text(ctx, s_info_layer_level_text, font, text_rect, GTextOverflowModeFill,
GTextAlignmentLeft, NULL); GTextAlignmentLeft, NULL);
#ifdef PBL_HEALTH #ifdef PBL_HEALTH
@ -75,41 +72,41 @@ static void information_layer_update_proc(Layer *layer, GContext *ctx) {
text_rect = GRect(paws_rect.origin.x + INFO_LAYER_ICON_WIDTH + INFO_LAYER_PADDING, -4, text_rect = GRect(paws_rect.origin.x + INFO_LAYER_ICON_WIDTH + INFO_LAYER_PADDING, -4,
text_size.w, text_size.h); text_size.w, text_size.h);
graphics_context_set_text_color(ctx, GColorBlack); graphics_context_set_text_color(ctx, GColorBlack);
graphics_draw_text(ctx, s_information_layer_count_text, font, text_rect, GTextOverflowModeFill, graphics_draw_text(ctx, s_info_layer_count_text, font, text_rect, GTextOverflowModeFill,
GTextAlignmentLeft, NULL); GTextAlignmentLeft, NULL);
#endif // PBL_HEALTH #endif // PBL_HEALTH
} }
static void battery_state_service_callback(BatteryChargeState charge) { static void battery_state_service_callback(BatteryChargeState charge) {
InformationLayerData *data = layer_get_data(s_information_layer); InfoLayerData *data = layer_get_data(s_info_layer);
data->level = charge.charge_percent; data->level = charge.charge_percent;
layer_mark_dirty(s_information_layer); layer_mark_dirty(s_info_layer);
} }
void information_layer_init(Layer *layer, int y) { void info_layer_init(Layer *layer, int y) {
GRect rect = layer_get_unobstructed_bounds(layer); GRect rect = layer_get_unobstructed_bounds(layer);
s_information_layer = layer_create_with_data(GRect(0, y, rect.size.w, INFO_LAYER_HEIGHT), s_info_layer = layer_create_with_data(GRect(0, y, rect.size.w, INFO_LAYER_HEIGHT),
sizeof(InformationLayerData)); sizeof(InfoLayerData));
InformationLayerData *data = layer_get_data(s_information_layer); InfoLayerData *data = layer_get_data(s_info_layer);
data->level = battery_state_service_peek().charge_percent; data->level = battery_state_service_peek().charge_percent;
data->steps = PBL_IF_HEALTH_ELSE(health_service_sum_today(HealthMetricStepCount), 0); data->steps = PBL_IF_HEALTH_ELSE(health_service_sum_today(HealthMetricStepCount), 0);
layer_set_update_proc(s_information_layer, information_layer_update_proc); layer_set_update_proc(s_info_layer, info_layer_update_proc);
layer_add_child(layer, s_information_layer); layer_add_child(layer, s_info_layer);
battery_state_service_subscribe(battery_state_service_callback); battery_state_service_subscribe(battery_state_service_callback);
} }
void information_layer_tick(void) { void info_layer_tick(void) {
#ifdef PBL_HEALTH #ifdef PBL_HEALTH
InformationLayerData *data = layer_get_data(s_information_layer); InfoLayerData *data = layer_get_data(s_info_layer);
data->steps = health_service_sum_today(HealthMetricStepCount); data->steps = health_service_sum_today(HealthMetricStepCount);
layer_mark_dirty(s_information_layer); layer_mark_dirty(s_info_layer);
#endif // PBL_HEALTH #endif // PBL_HEALTH
} }
void information_layer_deinit(void) { void info_layer_deinit(void) {
layer_destroy(s_information_layer); layer_destroy(s_info_layer);
} }

10
src/c/info_layer.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef INFO_LAYER_H_
#define INFO_LAYER_H_
#include <pebble.h>
void info_layer_init(Layer *layer, int y);
void info_layer_tick(void);
void info_layer_deinit(void);
#endif // INFO_LAYER_H_

View file

@ -1,10 +0,0 @@
#ifndef INFORMATION_LAYER_H_
#define INFORMATION_LAYER_H_
#include <pebble.h>
void information_layer_init(Layer *layer, int y);
void information_layer_tick(void);
void information_layer_deinit(void);
#endif // INFORMATION_LAYER_H_

View file

@ -2,14 +2,14 @@
#include "date_layer.h" #include "date_layer.h"
#include "character_layer.h" #include "character_layer.h"
#include "clock_layer.h" #include "clock_layer.h"
#include "information_layer.h" #include "info_layer.h"
static Window *s_main_window; static Window *s_main_window;
static void main_window_tick(struct tm *time, TimeUnits units) { static void main_window_tick(struct tm *time, TimeUnits units) {
date_layer_tick(); date_layer_tick();
clock_layer_tick(); clock_layer_tick();
information_layer_tick(); info_layer_tick();
character_layer_tick(); character_layer_tick();
} }
@ -20,7 +20,7 @@ static void main_window_load(Window *window) {
clock_layer_init(layer, 30); clock_layer_init(layer, 30);
GRect clock_layer_rect = clock_layer_get_bounds(); GRect clock_layer_rect = clock_layer_get_bounds();
information_layer_init(layer, 30 + clock_layer_rect.size.h + 4); info_layer_init(layer, 30 + clock_layer_rect.size.h + 4);
character_layer_init(layer); character_layer_init(layer);
@ -32,7 +32,7 @@ static void main_window_unload(Window *window) {
clock_layer_deinit(); clock_layer_deinit();
date_layer_deinit(); date_layer_deinit();
information_layer_deinit(); info_layer_deinit();
character_layer_deinit(); character_layer_deinit();
} }