[WIP] - Implement set methods

This commit is contained in:
Keegan
2016-11-21 10:54:51 -08:00
parent df3965ccac
commit ae5cc21abb
5 changed files with 88 additions and 16 deletions
+61 -5
View File
@@ -4,13 +4,20 @@
#define CLAY_INBOX_SIZE (64)
#define CHAR_SIZE (10)
#define ARRAY_SIZE (3)
#define INT_DEFAULT (0xff0000)
#define CHAR_DEFAULT ("default")
#define BOOL_DEFAULT (false)
static Window *s_window;
static int s_background_color = 0xff0000;
static char s_label_char_value[CHAR_SIZE] = "initial";
static bool s_label_bool_value = false;
static int s_background_color = INT_DEFAULT;
static char s_label_char_value[CHAR_SIZE] = CHAR_DEFAULT;
static bool s_label_bool_value = BOOL_DEFAULT;
static bool s_label_array_value_raw[ARRAY_SIZE] = {true, false, true};
static char s_label_array_value[ARRAY_SIZE + 1] = {'0', '0', '0'};
static TextLayer *s_label_char;
static TextLayer *s_label_bool;
static TextLayer *s_label_array;
static void prv_update_display(Layer *layer, GContext *ctx) {
graphics_context_set_fill_color(ctx, GColorFromHEX(s_background_color));
@@ -18,6 +25,14 @@ static void prv_update_display(Layer *layer, GContext *ctx) {
text_layer_set_text(s_label_char, s_label_char_value);
text_layer_set_text(s_label_bool, s_label_bool_value ? "true" : "false");
for (int i = 0; i < ARRAY_SIZE; ++i) {
if (s_label_array_value_raw[i]) {
s_label_array_value[i] = '1';
}
}
text_layer_set_text(s_label_array, s_label_array_value);
}
static void prv_clay_updated_handler(void *context) {
@@ -30,9 +45,43 @@ static void prv_clay_updated_handler(void *context) {
static void prv_window_unload(Window *window) {
layer_destroy(text_layer_get_layer(s_label_char));
layer_destroy(text_layer_get_layer(s_label_bool));
layer_destroy(text_layer_get_layer(s_label_array));
window_destroy(window);
}
static void prv_select_click_handler(ClickRecognizerRef recognizer, void *context) {
s_background_color = 0x00ff00;
clay_set_int("test_int", &s_background_color);
s_label_bool_value = true;
clay_set_bool("test_bool", &s_label_bool_value);
strcpy(s_label_char_value, "internal");
clay_set_string("test_char", s_label_char_value);
layer_mark_dirty(window_get_root_layer(s_window));
}
static void prv_up_click_handler(ClickRecognizerRef recognizer, void *context) {
s_background_color = INT_DEFAULT;
clay_set_int("test_int", &s_background_color);
s_label_bool_value = BOOL_DEFAULT;
clay_set_bool("test_bool", &s_label_bool_value);
strcpy(s_label_char_value, CHAR_DEFAULT);
clay_set_string("test_char", s_label_char_value);
layer_mark_dirty(window_get_root_layer(s_window));
}
static void prv_click_config_provider(void *context) {
window_single_click_subscribe(BUTTON_ID_SELECT, prv_select_click_handler);
window_single_click_subscribe(BUTTON_ID_UP, prv_up_click_handler);
}
static void prv_window_load(Window *window) {
Layer *window_layer = window_get_root_layer(s_window);
@@ -40,16 +89,21 @@ static void prv_window_load(Window *window) {
GRect bounds = layer_get_bounds(window_layer);
s_label_char = text_layer_create(GRect(0, bounds.size.h/4, bounds.size.w, 30));
s_label_char = text_layer_create(GRect(0, bounds.size.h / 4, bounds.size.w, 30));
text_layer_set_text_alignment(s_label_char, GTextAlignmentCenter);
text_layer_set_background_color(s_label_char, GColorClear);
layer_add_child(window_layer, text_layer_get_layer(s_label_char));
s_label_bool = text_layer_create(GRect(0, bounds.size.h/2, bounds.size.w, 30));
s_label_bool = text_layer_create(GRect(0, bounds.size.h / 2, bounds.size.w, 30));
text_layer_set_text_alignment(s_label_bool, GTextAlignmentCenter);
text_layer_set_background_color(s_label_bool, GColorClear);
layer_add_child(window_layer, text_layer_get_layer(s_label_bool));
s_label_array = text_layer_create(GRect(0, 3 * (bounds.size.h / 4), bounds.size.w, 30));
text_layer_set_text_alignment(s_label_array, GTextAlignmentCenter);
text_layer_set_background_color(s_label_array, GColorClear);
layer_add_child(window_layer, text_layer_get_layer(s_label_array));
prv_clay_updated_handler(NULL);
}
@@ -68,6 +122,8 @@ static void prv_init(void) {
.unload = prv_window_unload,
});
window_set_click_config_provider(s_window, prv_click_config_provider);
window_stack_push(s_window, true);
}
+6 -6
View File
@@ -20,12 +20,12 @@ var clay = new Clay({
type: 'toggle',
messageKey: 'test_bool'
},
// {
// label: 'raw',
// type: 'checkboxgroup',
// messageKey: 'test_raw',
// options: ['one', 'two', 'three']
// },
{
label: 'array',
type: 'checkboxgroup',
messageKey: 'test_array',
options: ['one', 'two', 'three']
},
{
type: 'submit',
defaultValue: 'submit'