mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-28 04:46:57 -04:00
[WIP] - Implement set methods
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
+4
-4
@@ -14,17 +14,17 @@ void clay_register_callbacks(const ClayCallbacks *callbacks, void *context);
|
||||
|
||||
bool clay_remove(const char *key);
|
||||
|
||||
bool clay_set_bool(const char *key, bool value);
|
||||
bool clay_set_bool(const char *key, bool *value);
|
||||
|
||||
bool clay_set_data(const char *key, const void *data, size_t n);
|
||||
bool clay_set_data(const char *key, const void *value, size_t size);
|
||||
|
||||
bool clay_set_int(const char *key, int value);
|
||||
bool clay_set_int(const char *key, int *value);
|
||||
|
||||
bool clay_set_string(const char *key, const char *value);
|
||||
|
||||
bool clay_get_bool(const char *key, bool *value_out);
|
||||
|
||||
bool clay_get_data(const char *key, void *value_out, size_t n);
|
||||
bool clay_get_data(const char *key, void *value_out, size_t size);
|
||||
|
||||
bool clay_get_int(const char *key, int *value_out);
|
||||
|
||||
|
||||
+1
-1
@@ -88,6 +88,6 @@
|
||||
"watchify": "^3.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@keegan-stoneware/simple-app-message": "^1.0.0"
|
||||
"@keegan-stoneware/simple-app-message": "^1.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,3 +80,19 @@ bool clay_get_string(const char *key, char *value_out, size_t size) {
|
||||
bool clay_get_data(const char *key, void *value_out, size_t size) {
|
||||
return prv_read(key, value_out, size);
|
||||
}
|
||||
|
||||
bool clay_set_int(const char *key, int *value) {
|
||||
return prv_write(key, value, sizeof(value));
|
||||
}
|
||||
|
||||
bool clay_set_bool(const char *key, bool *value) {
|
||||
return prv_write(key, value, sizeof(value));
|
||||
}
|
||||
|
||||
bool clay_set_data(const char *key, const void *value, size_t size) {
|
||||
return prv_write(key, value, size);
|
||||
}
|
||||
|
||||
bool clay_set_string(const char *key, const char *value) {
|
||||
return prv_write(key, value, strlen(value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user