fix(layers): pass the layer instead of window
This commit is contained in:
parent
0cac476bce
commit
90c1888ba3
7 changed files with 36 additions and 37 deletions
|
|
@ -34,14 +34,12 @@ static void bar_layer_update_proc(Layer *layer, GContext *ctx) {
|
|||
GTextAlignmentRight, NULL);
|
||||
}
|
||||
|
||||
void bar_layer_init(Window *window) {
|
||||
Layer *window_layer = window_get_root_layer(window);
|
||||
GRect window_rect = layer_get_unobstructed_bounds(window_layer);
|
||||
void bar_layer_init(Layer *layer, int y) {
|
||||
GRect rect = layer_get_unobstructed_bounds(layer);
|
||||
|
||||
s_bar_layer = layer_create(GRect(BAR_PAD_W, 0, window_rect.size.w - (BAR_PAD_W * 2), 28));
|
||||
s_bar_layer = layer_create(GRect(BAR_PAD_W, y, rect.size.w - (BAR_PAD_W * 2), 28));
|
||||
layer_set_update_proc(s_bar_layer, bar_layer_update_proc);
|
||||
|
||||
layer_add_child(window_layer, s_bar_layer);
|
||||
layer_add_child(layer, s_bar_layer);
|
||||
}
|
||||
|
||||
void bar_layer_tick(void) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <pebble.h>
|
||||
|
||||
void bar_layer_init(Window *window);
|
||||
void bar_layer_init(Layer *layer, int y);
|
||||
void bar_layer_tick(void);
|
||||
void bar_layer_deinit(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "character_layer.h"
|
||||
|
||||
#include "resources_service.h"
|
||||
|
||||
#define CHARACTER_H 80
|
||||
|
|
@ -35,18 +36,17 @@ static void character_layer_update_proc(Layer *layer, GContext *ctx) {
|
|||
graphics_draw_bitmap_in_rect(ctx, bitmap, frame);
|
||||
}
|
||||
|
||||
void character_layer_init(Window *window) {
|
||||
Layer *window_root_layer = window_get_root_layer(window);
|
||||
GRect window_bounds = layer_get_unobstructed_bounds(window_root_layer);
|
||||
void character_layer_init(Layer *layer) {
|
||||
GRect rect = layer_get_unobstructed_bounds(layer);
|
||||
|
||||
s_character_layer =
|
||||
layer_create_with_data(GRect(0, window_bounds.size.h - CHARACTER_H, window_bounds.size.w, CHARACTER_H), sizeof(CharacterLayerData));
|
||||
s_character_layer = layer_create_with_data(
|
||||
GRect(0, rect.size.h - CHARACTER_H, rect.size.w, CHARACTER_H), sizeof(CharacterLayerData));
|
||||
|
||||
CharacterLayerData *layer_data = layer_get_data(s_character_layer);
|
||||
layer_data->ticks = 0;
|
||||
|
||||
layer_set_update_proc(s_character_layer, character_layer_update_proc);
|
||||
layer_add_child(window_root_layer, s_character_layer);
|
||||
layer_add_child(layer, s_character_layer);
|
||||
}
|
||||
|
||||
void character_layer_tick(void) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <pebble.h>
|
||||
|
||||
void character_layer_init(Window *window);
|
||||
void character_layer_init(Layer *layer);
|
||||
void character_layer_tick(void);
|
||||
void character_layer_deinit(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#define CLOCK_OFFSET 4
|
||||
|
||||
static Layer *s_clock_layer;
|
||||
static char s_clock_time_text[6] = "00:00";
|
||||
static char s_clock_seconds_text[3] = "00";
|
||||
|
||||
static void clock_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
// Fill a whole layer with the black color.
|
||||
|
|
@ -20,21 +22,19 @@ static void clock_layer_update_proc(Layer *layer, GContext *ctx) {
|
|||
struct tm *time = localtime(&tmp);
|
||||
|
||||
// Drawing the time and seconds.
|
||||
static char time_text[6], seconds_text[3] = "00\0";
|
||||
|
||||
GFont font_small = resources_service_get_custom_font(CustomFontKonekoToro);
|
||||
GFont font_big = resources_service_get_custom_font(CustomFontToro);
|
||||
|
||||
graphics_context_set_text_color(ctx, GColorWhite);
|
||||
|
||||
strftime(time_text, sizeof(time_text), clock_is_24h_style() ? "%H:%M" : "%I:%M", time);
|
||||
strftime(s_clock_time_text, sizeof(s_clock_time_text), clock_is_24h_style() ? "%H:%M" : "%I:%M",
|
||||
time);
|
||||
GSize time_text_size = graphics_text_layout_get_content_size(
|
||||
time_text, font_big, layer_bounds, GTextOverflowModeFill, GTextAlignmentLeft);
|
||||
s_clock_time_text, font_big, layer_bounds, GTextOverflowModeFill, GTextAlignmentLeft);
|
||||
|
||||
seconds_text[0] = seconds_text[1] = '0';
|
||||
GSize seconds_text_size = graphics_text_layout_get_content_size(
|
||||
seconds_text, font_small, layer_bounds, GTextOverflowModeFill, GTextAlignmentLeft);
|
||||
strftime(seconds_text, sizeof(seconds_text), "%S", time);
|
||||
"00", font_small, layer_bounds, GTextOverflowModeFill, GTextAlignmentLeft);
|
||||
strftime(s_clock_seconds_text, sizeof(s_clock_seconds_text), "%S", time);
|
||||
|
||||
GRect timestamp_rect =
|
||||
GRect(0, 0, time_text_size.w + seconds_text_size.w + CLOCK_SPACE, time_text_size.h);
|
||||
|
|
@ -43,24 +43,21 @@ static void clock_layer_update_proc(Layer *layer, GContext *ctx) {
|
|||
|
||||
GRect time_rect =
|
||||
GRect(timestamp_rect.origin.x, timestamp_rect.origin.y, time_text_size.w, time_text_size.h);
|
||||
graphics_draw_text(ctx, time_text, font_big, time_rect, GTextOverflowModeFill, GTextAlignmentLeft,
|
||||
NULL);
|
||||
graphics_draw_text(ctx, s_clock_time_text, font_big, time_rect, GTextOverflowModeFill,
|
||||
GTextAlignmentLeft, NULL);
|
||||
|
||||
GRect seconds_rect = GRect(0, 0, seconds_text_size.w, seconds_text_size.h);
|
||||
grect_align(&seconds_rect, ×tamp_rect, GAlignBottomRight, true);
|
||||
graphics_draw_text(ctx, seconds_text, font_small, seconds_rect, GTextOverflowModeFill,
|
||||
graphics_draw_text(ctx, s_clock_seconds_text, font_small, seconds_rect, GTextOverflowModeFill,
|
||||
GTextAlignmentLeft, NULL);
|
||||
}
|
||||
|
||||
void clock_layer_init(Window *window, GPoint position) {
|
||||
Layer *window_root_layer = window_get_root_layer(window);
|
||||
GRect window_bounds = layer_get_unobstructed_bounds(window_root_layer);
|
||||
|
||||
s_clock_layer =
|
||||
layer_create(GRect(position.x, position.y, window_bounds.size.w - position.x, CLOCK_H));
|
||||
void clock_layer_init(Layer *layer, int y) {
|
||||
GRect rect = layer_get_unobstructed_bounds(layer);
|
||||
|
||||
s_clock_layer = layer_create(GRect(0, y, rect.size.w, CLOCK_H));
|
||||
layer_set_update_proc(s_clock_layer, clock_layer_update_proc);
|
||||
layer_add_child(window_root_layer, s_clock_layer);
|
||||
layer_add_child(layer, s_clock_layer);
|
||||
}
|
||||
|
||||
void clock_layer_tick(void) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <pebble.h>
|
||||
|
||||
void clock_layer_init(Window *window, GPoint position);
|
||||
void clock_layer_init(Layer *layer, int y);
|
||||
void clock_layer_tick(void);
|
||||
void clock_layer_deinit(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,20 +7,24 @@
|
|||
static Window *s_main_window;
|
||||
|
||||
static void main_window_tick(struct tm *time, TimeUnits units) {
|
||||
character_layer_tick();
|
||||
clock_layer_tick();
|
||||
bar_layer_tick();
|
||||
clock_layer_tick();
|
||||
character_layer_tick();
|
||||
}
|
||||
|
||||
static void main_window_load(Window *window) {
|
||||
character_layer_init(s_main_window);
|
||||
clock_layer_init(s_main_window, GPoint(0, 40));
|
||||
bar_layer_init(s_main_window);
|
||||
Layer *layer = window_get_root_layer(window);
|
||||
|
||||
bar_layer_init(layer, 0);
|
||||
clock_layer_init(layer, 40);
|
||||
character_layer_init(layer);
|
||||
|
||||
tick_timer_service_subscribe(SECOND_UNIT, main_window_tick);
|
||||
}
|
||||
|
||||
static void main_window_unload(Window *window) {
|
||||
tick_timer_service_unsubscribe();
|
||||
|
||||
clock_layer_deinit();
|
||||
bar_layer_deinit();
|
||||
character_layer_deinit();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue