ui: input: fixes left and right key reactions
This commit is contained in:
+25
-10
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
static void (*active_callback_backup)(w_cb_args_t *) = NULL;
|
static void (*active_callback_backup)(w_cb_args_t *) = NULL;
|
||||||
|
|
||||||
void incr_active_id(w_dialogue_t *d) {
|
static void incr_active_id(w_dialogue_t *d) {
|
||||||
w_g_el_t *active_el = NULL;
|
w_g_el_t *active_el = NULL;
|
||||||
while (true) {
|
while (true) {
|
||||||
for (int i = d->active_el->id + 1;
|
for (int i = d->active_el->id + 1;
|
||||||
@@ -29,7 +29,7 @@ void incr_active_id(w_dialogue_t *d) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void decr_active_id(w_dialogue_t *d) {
|
static void decr_active_id(w_dialogue_t *d) {
|
||||||
w_g_el_t *active_el = NULL;
|
w_g_el_t *active_el = NULL;
|
||||||
while (true) {
|
while (true) {
|
||||||
for (int i = d->active_el->id - 1; active_el == NULL && i > 0; i--) {
|
for (int i = d->active_el->id - 1; active_el == NULL && i > 0; i--) {
|
||||||
@@ -59,6 +59,20 @@ void decr_active_id(w_dialogue_t *d) {
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void case_callback(w_cb_args_t *args, w_cb_args_t *new_args) {
|
||||||
|
w_dialogue_t *d = (void *)args->element;
|
||||||
|
/* run callback function */
|
||||||
|
if (d->active_el->g_type == g_content) {
|
||||||
|
new_args->element = d->g_content;
|
||||||
|
} else {
|
||||||
|
new_args->element = d->g_action;
|
||||||
|
}
|
||||||
|
w_group_cb_default(new_args);
|
||||||
|
/* copy new result to the parental structure */
|
||||||
|
mempcpy(&(args->resp_data), &(new_args->resp_data),
|
||||||
|
sizeof(new_args->resp_data));
|
||||||
|
}
|
||||||
|
|
||||||
void w_dialogue_callback_default(w_cb_args_t *args) {
|
void w_dialogue_callback_default(w_cb_args_t *args) {
|
||||||
w_dialogue_t *d = (void *)args->element;
|
w_dialogue_t *d = (void *)args->element;
|
||||||
int32_t key = *((int32_t *)args->data);
|
int32_t key = *((int32_t *)args->data);
|
||||||
@@ -79,10 +93,18 @@ void w_dialogue_callback_default(w_cb_args_t *args) {
|
|||||||
args->resp_data.val.val.num = -2;
|
args->resp_data.val.val.num = -2;
|
||||||
break;
|
break;
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
|
if (d->active_el->type == w_input) {
|
||||||
|
case_callback(args, &new_args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
incr_active_id(d);
|
incr_active_id(d);
|
||||||
args->resp_data.code = cbrc_none;
|
args->resp_data.code = cbrc_none;
|
||||||
break;
|
break;
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
|
if (d->active_el->type == w_input) {
|
||||||
|
case_callback(args, &new_args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
decr_active_id(d);
|
decr_active_id(d);
|
||||||
args->resp_data.code = cbrc_none;
|
args->resp_data.code = cbrc_none;
|
||||||
break;
|
break;
|
||||||
@@ -129,14 +151,7 @@ void w_dialogue_callback_default(w_cb_args_t *args) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* run callback function */
|
/* run callback function */
|
||||||
if (d->active_el->g_type == g_content) {
|
case_callback(args, &new_args);
|
||||||
new_args.element = d->g_content;
|
|
||||||
} else {
|
|
||||||
new_args.element = d->g_action;
|
|
||||||
}
|
|
||||||
w_group_cb_default(&new_args);
|
|
||||||
/* copy new result to the parental structure */
|
|
||||||
mempcpy(&(args->resp_data), &(new_args.resp_data), sizeof(new_args.resp_data));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-2
@@ -34,6 +34,16 @@ bool w_input_default_key_action(w_cb_args_t *args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case KEY_RIGHT:
|
||||||
|
if (input->cur_pos > 0) {
|
||||||
|
input->cur_pos--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
if (input->value_len > input->cur_pos) {
|
||||||
|
input->cur_pos++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (input->value_len == input->max_len)
|
if (input->value_len == input->max_len)
|
||||||
break;
|
break;
|
||||||
@@ -48,7 +58,7 @@ bool w_input_default_key_action(w_cb_args_t *args) {
|
|||||||
}
|
}
|
||||||
mbstowcs(w_key, (const char *)&long_key, 2);
|
mbstowcs(w_key, (const char *)&long_key, 2);
|
||||||
if (input->cur_pos > 0) {
|
if (input->cur_pos > 0) {
|
||||||
start_pos = input->value_len - input->cur_pos;
|
start_pos = input->value_len - input->cur_pos - 1;
|
||||||
memmove(input->w_value + start_pos + 1, input->w_value + start_pos,
|
memmove(input->w_value + start_pos + 1, input->w_value + start_pos,
|
||||||
sizeof(wchar_t) * (input->value_len - start_pos));
|
sizeof(wchar_t) * (input->value_len - start_pos));
|
||||||
input->w_value[start_pos] = key;
|
input->w_value[start_pos] = key;
|
||||||
@@ -146,7 +156,7 @@ int32_t w_input_draw(w_input_t *input, int32_t active_id) {
|
|||||||
}
|
}
|
||||||
/* Uses malloc! need to invoke free() after use of output */
|
/* Uses malloc! need to invoke free() after use of output */
|
||||||
char *w_input_get_value(w_input_t *input) {
|
char *w_input_get_value(w_input_t *input) {
|
||||||
char *c_output = malloc(sizeof (wchar_t) * input->value_len);
|
char *c_output = malloc(sizeof(wchar_t) * input->value_len);
|
||||||
const wchar_t *p;
|
const wchar_t *p;
|
||||||
p = input->w_value;
|
p = input->w_value;
|
||||||
wcsrtombs(c_output, &p, input->value_len, NULL);
|
wcsrtombs(c_output, &p, input->value_len, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user