parent
c07d86512a
commit
67131602d0
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "border_layer.h"
|
||||||
|
|
||||||
|
struct BorderLayer* get_data(const struct Layer *layer)
|
||||||
|
{
|
||||||
|
struct BorderLayer **data_region = layer_get_data(layer);
|
||||||
|
struct BorderLayer *border = *data_region;
|
||||||
|
return border;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_update(struct Layer *layer, GContext *context)
|
||||||
|
{
|
||||||
|
struct BorderLayer *border = get_data(layer);
|
||||||
|
struct GRect bounds = layer_get_bounds(layer);
|
||||||
|
struct GRect rect = {
|
||||||
|
.origin = bounds.origin,
|
||||||
|
.size.h = bounds.size.h,
|
||||||
|
.size.w = border->width
|
||||||
|
};
|
||||||
|
graphics_context_set_fill_color(context, border->color);
|
||||||
|
graphics_fill_rect(context, rect, 0, GCornerNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct Layer* create_layer(struct BorderLayer *border,
|
||||||
|
struct GRect frame)
|
||||||
|
{
|
||||||
|
size_t data_region_size = sizeof(struct BorderLayer *);
|
||||||
|
struct Layer *layer = layer_create_with_data(frame, data_region_size);
|
||||||
|
layer_set_update_proc(layer, on_update);
|
||||||
|
|
||||||
|
struct BorderLayer **data_region = layer_get_data(layer);
|
||||||
|
*data_region = border;
|
||||||
|
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BORDER_LAYER_init(struct BorderLayer *border, struct GRect frame)
|
||||||
|
{
|
||||||
|
border->raw_layer = create_layer(border, frame);
|
||||||
|
border->color = GColorWhite;
|
||||||
|
border->width = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BORDER_LAYER_destroy(struct BorderLayer *border)
|
||||||
|
{
|
||||||
|
layer_destroy(border->raw_layer);
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pebble.h>
|
||||||
|
|
||||||
|
struct BorderLayer
|
||||||
|
{
|
||||||
|
int16_t width;
|
||||||
|
GColor color;
|
||||||
|
Layer *raw_layer;
|
||||||
|
};
|
||||||
|
|
||||||
|
void BORDER_LAYER_init(struct BorderLayer *border, struct GRect frame);
|
||||||
|
|
||||||
|
void BORDER_LAYER_destroy(struct BorderLayer *border);
|
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pebble.h>
|
||||||
|
#include "action_window.h"
|
||||||
|
#include "style.h"
|
||||||
|
#include "../../layers/border_layer.h"
|
||||||
|
#include "../../util.h"
|
||||||
|
|
||||||
|
static struct Window *WINDOW = 0;
|
||||||
|
static struct MenuLayer *MENU_LAYER = 0;
|
||||||
|
static struct BorderLayer *BORDER_LAYER = 0;
|
||||||
|
|
||||||
|
char *ACTIONS[] = { " Check", " View stats"};
|
||||||
|
|
||||||
|
// DRAWING
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void draw_left_border(GContext *ctx, const Layer *cell_layer)
|
||||||
|
{
|
||||||
|
GRect bounds = layer_get_bounds(cell_layer);
|
||||||
|
GRect rect = GRect(bounds.origin.x, bounds.origin.y, 5, bounds.size.h);
|
||||||
|
graphics_context_set_fill_color(ctx, GColorFolly);
|
||||||
|
graphics_fill_rect(ctx, rect, 0, GCornerNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// MENU LAYER CALLBACKS
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static uint16_t get_num_rows(MenuLayer *menu_layer,
|
||||||
|
uint16_t section_index,
|
||||||
|
void *context)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_row(GContext *ctx,
|
||||||
|
const Layer *cell_layer,
|
||||||
|
MenuIndex *cell_index,
|
||||||
|
void *extra)
|
||||||
|
{
|
||||||
|
int n = cell_index->row;
|
||||||
|
menu_cell_basic_draw(ctx, cell_layer, ACTIONS[n], NULL, NULL);
|
||||||
|
draw_left_border(ctx, cell_layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int16_t get_cell_height(struct MenuLayer *menu_layer,
|
||||||
|
MenuIndex *cell_index,
|
||||||
|
void *context)
|
||||||
|
{
|
||||||
|
return CELL_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_click(MenuLayer *menu_layer, MenuIndex *index, void *context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// WINDOWS HANDLERS
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void add_menu_layer(Window *window,
|
||||||
|
Layer *root_layer,
|
||||||
|
GRect bounds)
|
||||||
|
{
|
||||||
|
MenuLayerCallbacks callbacks = {
|
||||||
|
.get_num_rows = get_num_rows,
|
||||||
|
.draw_row = draw_row,
|
||||||
|
.get_cell_height = get_cell_height,
|
||||||
|
.select_click = select_click,
|
||||||
|
};
|
||||||
|
|
||||||
|
MENU_LAYER = menu_layer_create(bounds);
|
||||||
|
menu_layer_set_click_config_onto_window(MENU_LAYER, window);
|
||||||
|
menu_layer_set_callbacks(MENU_LAYER, NULL, callbacks);
|
||||||
|
menu_layer_set_highlight_colors(MENU_LAYER, HIGHLIGHT_BACKGROUND_COLOR,
|
||||||
|
HIGHLIGHT_FOREGROUND_COLOR);
|
||||||
|
menu_layer_set_normal_colors(MENU_LAYER, NORMAL_BACKGROUND_COLOR,
|
||||||
|
NORMAL_FOREGROUND_COLOR);
|
||||||
|
|
||||||
|
layer_add_child(root_layer, menu_layer_get_layer(MENU_LAYER));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int add_border_layer(Window *window, Layer *root_layer, GRect frame)
|
||||||
|
{
|
||||||
|
int rval = 0;
|
||||||
|
|
||||||
|
BORDER_LAYER = (struct BorderLayer*) malloc(sizeof(struct BorderLayer));
|
||||||
|
abort_if(!BORDER_LAYER, "could not allocate BORDER_LAYER");
|
||||||
|
|
||||||
|
BORDER_LAYER_init(BORDER_LAYER, frame);
|
||||||
|
BORDER_LAYER->color = GColorFolly;
|
||||||
|
|
||||||
|
layer_add_child(root_layer, BORDER_LAYER->raw_layer);
|
||||||
|
|
||||||
|
CLEANUP:
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_load(Window *window)
|
||||||
|
{
|
||||||
|
Layer *root_layer = window_get_root_layer(window);
|
||||||
|
GRect bounds = layer_get_bounds(root_layer);
|
||||||
|
add_menu_layer(window, root_layer, bounds);
|
||||||
|
add_border_layer(window, root_layer, bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_unload(Window *window)
|
||||||
|
{
|
||||||
|
menu_layer_destroy(MENU_LAYER);
|
||||||
|
free(BORDER_LAYER);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void ACTION_WINDOW_push()
|
||||||
|
{
|
||||||
|
WindowHandlers handlers = {
|
||||||
|
.load = on_load,
|
||||||
|
.unload = on_unload
|
||||||
|
};
|
||||||
|
|
||||||
|
WINDOW = window_create();
|
||||||
|
window_set_window_handlers(WINDOW, handlers);
|
||||||
|
window_stack_push(WINDOW, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ACTION_WINDOW_destroy()
|
||||||
|
{
|
||||||
|
window_destroy(WINDOW);
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void ACTION_WINDOW_push();
|
||||||
|
|
||||||
|
void ACTION_WINDOW_destroy();
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pebble.h>
|
||||||
|
|
||||||
|
#define HIGHLIGHT_BACKGROUND_COLOR GColorBlack
|
||||||
|
|
||||||
|
#define HIGHLIGHT_FOREGROUND_COLOR GColorWhite
|
||||||
|
|
||||||
|
#define NORMAL_BACKGROUND_COLOR GColorBlack
|
||||||
|
|
||||||
|
#define NORMAL_FOREGROUND_COLOR GColorDarkGray
|
||||||
|
|
||||||
|
#define CELL_HEIGHT 36
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pebble.h>
|
||||||
|
|
||||||
|
#define HIGHLIGHT_BACKGROUND_COLOR GColorFolly
|
||||||
|
|
||||||
|
#define HIGHLIGHT_FOREGROUND_COLOR GColorWhite
|
||||||
|
|
||||||
|
#define NORMAL_BACKGROUND_COLOR GColorWhite
|
||||||
|
|
||||||
|
#define NORMAL_FOREGROUND_COLOR GColorBlack
|
||||||
|
|
||||||
|
#define CELL_HEIGHT 36
|
Reference in new issue