Add action screen
This commit is contained in:
@@ -11,6 +11,17 @@ INCLUDE_DIRECTORIES("build/include")
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
src/main.c src/network.c src/network.h src/windows/list_window.c src/windows/list_window.h src/util.h)
|
src/main.c
|
||||||
|
src/network.c
|
||||||
|
src/network.h
|
||||||
|
src/windows/list/list_window.c
|
||||||
|
src/windows/list/list_window.h
|
||||||
|
src/windows/list/style.h
|
||||||
|
src/util.h
|
||||||
|
src/windows/action/action_window.c
|
||||||
|
src/windows/action/action_window.h
|
||||||
|
src/windows/action/style.h
|
||||||
|
src/layers/border_layer.c
|
||||||
|
src/layers/border_layer.h)
|
||||||
|
|
||||||
add_executable(hello ${SOURCE_FILES})
|
add_executable(hello ${SOURCE_FILES})
|
||||||
65
src/layers/border_layer.c
Normal file
65
src/layers/border_layer.c
Normal file
@@ -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);
|
||||||
|
}
|
||||||
33
src/layers/border_layer.h
Normal file
33
src/layers/border_layer.h
Normal file
@@ -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);
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pebble.h>
|
#include <pebble.h>
|
||||||
#include "windows/list_window.h"
|
#include "windows/list/list_window.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#include <pebble.h>
|
#include <pebble.h>
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "windows/list_window.h"
|
#include "windows/list/list_window.h"
|
||||||
|
|
||||||
#define MAX_HABIT_COUNT 50
|
#define MAX_HABIT_COUNT 50
|
||||||
static int HABIT_COUNT;
|
static int HABIT_COUNT;
|
||||||
|
|||||||
146
src/windows/action/action_window.c
Normal file
146
src/windows/action/action_window.c
Normal file
@@ -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);
|
||||||
|
}
|
||||||
24
src/windows/action/action_window.h
Normal file
24
src/windows/action/action_window.h
Normal file
@@ -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();
|
||||||
32
src/windows/action/style.h
Normal file
32
src/windows/action/style.h
Normal file
@@ -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
|
||||||
@@ -18,9 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pebble.h>
|
#include <pebble.h>
|
||||||
#include "../network.h"
|
#include "../../network.h"
|
||||||
#include "../util.h"
|
#include "../../util.h"
|
||||||
#include "list_window.h"
|
#include "list_window.h"
|
||||||
|
#include "../action/action_window.h"
|
||||||
|
#include "style.h"
|
||||||
|
|
||||||
static Window *WINDOW = 0;
|
static Window *WINDOW = 0;
|
||||||
static MenuLayer *MENU_LAYER = 0;
|
static MenuLayer *MENU_LAYER = 0;
|
||||||
@@ -99,7 +101,9 @@ static void select_click(MenuLayer *menu_layer, MenuIndex *index, void *context)
|
|||||||
{
|
{
|
||||||
int n = index->row;
|
int n = index->row;
|
||||||
int id = HABIT_IDS[n];
|
int id = HABIT_IDS[n];
|
||||||
NETWORK_request_toggle(id);
|
// NETWORK_request_toggle(id);
|
||||||
|
|
||||||
|
ACTION_WINDOW_push();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void request_list(void *context)
|
static void request_list(void *context)
|
||||||
@@ -19,17 +19,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// STYLE
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#define HIGHLIGHT_BACKGROUND_COLOR GColorFolly
|
|
||||||
#define HIGHLIGHT_FOREGROUND_COLOR GColorWhite
|
|
||||||
#define NORMAL_BACKGROUND_COLOR GColorBlack
|
|
||||||
#define NORMAL_FOREGROUND_COLOR GColorWhite
|
|
||||||
#define CELL_HEIGHT 36
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void LIST_WINDOW_push();
|
void LIST_WINDOW_push();
|
||||||
|
|
||||||
void LIST_WINDOW_destroy();
|
void LIST_WINDOW_destroy();
|
||||||
32
src/windows/list/style.h
Normal file
32
src/windows/list/style.h
Normal file
@@ -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
Block a user