Fourth
This commit is contained in:
+25
-5
@@ -2,10 +2,12 @@
|
||||
#include "scrolllayer.h"
|
||||
|
||||
#include "src/c/colors.h"
|
||||
#include "src/c/settings.h"
|
||||
|
||||
static ScrollLayer *s_scroll_layer;
|
||||
static Layer *s_scroll_bar_layer;
|
||||
static GFont s_scrolllayer_font;
|
||||
static GFont s_scrolllayer_font_small;
|
||||
static GBitmap *s_background_bitmap;
|
||||
static GBitmap *s_plus_bitmap;
|
||||
static GBitmap *s_minus_bitmap;
|
||||
@@ -29,6 +31,9 @@ static int s_scroll_y;
|
||||
static int s_scroll_page;
|
||||
static scroll_items_t s_scroll_items;
|
||||
|
||||
// SETTINGS
|
||||
settings_t *app_settings;
|
||||
|
||||
|
||||
// ------------ SCROLL ------------
|
||||
static void scroll_up(ClickRecognizerRef recognizer, void *context) {
|
||||
@@ -99,11 +104,12 @@ static void click_config_provider(void *context) {
|
||||
// ------------ HELPERS ------------
|
||||
static GColor get_color_float(float val) {
|
||||
GColor color;
|
||||
int percentage = (int)(val * 100.0);
|
||||
|
||||
if (val < RED_LIMIT) {
|
||||
if (percentage < app_settings->red_limit) {
|
||||
color = RED;
|
||||
}
|
||||
else if (val < ORANGE_LIMIT) {
|
||||
else if (percentage < app_settings->orange_limit) {
|
||||
color = ORANGE;
|
||||
}
|
||||
else {
|
||||
@@ -163,9 +169,15 @@ void scroll_layer_add_items() {
|
||||
scroll_layer_add_child(s_scroll_layer, bitmap_layer_get_layer(s_scroll_items.backgrounds[i]));
|
||||
|
||||
// Add text
|
||||
int name_len = (int)strlen(s_scroll_items.items->items[i].name);
|
||||
s_scroll_items.texts[i] = text_layer_create(GRect(26, (i * ITEM_UI_HEIGHT) + 4, 124, 16));
|
||||
text_layer_set_text(s_scroll_items.texts[i], s_scroll_items.items->items[i].name);
|
||||
text_layer_set_font(s_scroll_items.texts[i], s_scrolllayer_font);
|
||||
if (name_len < 10) {
|
||||
text_layer_set_font(s_scroll_items.texts[i], s_scrolllayer_font);
|
||||
}
|
||||
else {
|
||||
text_layer_set_font(s_scroll_items.texts[i], s_scrolllayer_font_small);
|
||||
}
|
||||
text_layer_set_text_alignment(s_scroll_items.texts[i], GTextAlignmentCenter);
|
||||
text_layer_set_background_color(s_scroll_items.texts[i], GColorClear);
|
||||
text_layer_set_text_color(s_scroll_items.texts[i], WHITE);
|
||||
@@ -465,8 +477,12 @@ void scrolllayer_init(Layer *parent, Window *window) {
|
||||
s_scroll_page = 0;
|
||||
GRect bounds = SCROLLLAYER_FRAME_RECT;
|
||||
|
||||
// Load custom font
|
||||
// Load settings
|
||||
app_settings = settings_get();
|
||||
|
||||
// Load custom fonts
|
||||
s_scrolllayer_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SLKSCR_16));
|
||||
s_scrolllayer_font_small = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SLKSCR_8));
|
||||
|
||||
// Add touch areas
|
||||
item_1_plus_button = ITEM_1_PLUS_BUTTON_RECT;
|
||||
@@ -533,8 +549,12 @@ void scrolllayer_init(Layer *parent, Window *window) {
|
||||
}
|
||||
|
||||
void scrolllayer_deinit() {
|
||||
// Unload font
|
||||
// Destroy settings
|
||||
app_settings = NULL;
|
||||
|
||||
// Unload fonts
|
||||
fonts_unload_custom_font(s_scrolllayer_font);
|
||||
fonts_unload_custom_font(s_scrolllayer_font_small);
|
||||
|
||||
// Unsubscribe touch
|
||||
touch_service_unsubscribe();
|
||||
|
||||
Reference in New Issue
Block a user