Skip to content

Commit

Permalink
fix(ui): Fixed 2 characters being skipped from input screen
Browse files Browse the repository at this point in the history
  • Loading branch information
amanCypherock committed Oct 12, 2023
1 parent a844e8b commit 669c2fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions common/interfaces/user_interface/ui_input_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void ui_input_text(const char *input_list,
data->current_text[0] = input_list[data->current_index];
data->current_display_index = 0;
data->current_text[1] = '\0';
data->max_input_size = max_input_size - 1;
data->max_input_size = max_input_size;
strncpy(data->entered_text, "", 1);
data->data_type = data_type;
strncpy(data->password_text, "", 1);
Expand Down Expand Up @@ -338,9 +338,10 @@ static void character_event_handler(lv_obj_t *character,
// average width of a pixel
char first_char_current_text = data->current_text[0];
if (get_entered_text_px_width() + 10 <= 98 &&
strnlen(data->entered_text, MAX_ARRAY_SIZE) <= data->max_input_size) {
(strnlen(data->entered_text, MAX_ARRAY_SIZE) + 1) <=
data->max_input_size) {
if (data->data_type == DATA_TYPE_PIN &&
strnlen(data->entered_text, MAX_ARRAY_SIZE) < MAX_PIN_SIZE) {
(strnlen(data->entered_text, MAX_ARRAY_SIZE) + 1) <= MAX_PIN_SIZE) {
strncat(data->entered_text, &first_char_current_text, 1);
strncat(data->password_text, "*", 2);
lv_label_set_text(lv_obj_get_child(obj->text_entered, NULL),
Expand All @@ -363,7 +364,7 @@ static void character_event_handler(lv_obj_t *character,
data->entered_text);
}
hide_unhide_ok();
} else if (strnlen(data->entered_text, MAX_ARRAY_SIZE) <=
} else if ((strnlen(data->entered_text, MAX_ARRAY_SIZE) + 1) <=
data->max_input_size) {
if (data->data_type != DATA_TYPE_PIN) {
strncat(data->entered_text, &first_char_current_text, 1);
Expand Down Expand Up @@ -549,7 +550,7 @@ static void next_btn_event_handler(lv_obj_t *next_btn, const lv_event_t event) {
* therefore we must copy data from here into the buffer which the
* application can access */
ui_fill_text(
data->entered_text, data->input_text_ptr, data->max_input_size);
data->entered_text, data->input_text_ptr, data->max_input_size + 1);
ui_set_text_input_event(data->input_text_ptr);
input_text_destructor();
break;
Expand Down
6 changes: 4 additions & 2 deletions common/interfaces/user_interface/ui_input_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ struct Input_Text_Object {
* @param initial_heading Input heading text
* @param min_input_size Mininum input text size
* @param data_type data type PASSWORD, PASSPHRASE or TEXT
* @param max_input_size Maximum input text size
* @param max_input_size Maximum input text size(this is text limit not buffer
* size, buffer size should be greater than this to accomodate max text)
*/
void ui_input_text(const char *input_list,
char *input_text_ptr,
Expand All @@ -101,7 +102,8 @@ void ui_input_text(const char *input_list,
* @param initial_heading Input heading text
* @param min_input_size Mininum input text size
* @param data_type data type PASSWORD, PASSPHRASE or TEXT
* @param max_input_size Maximum input text size
* @param max_input_size Maximum input text size(this is text limit not buffer
* size, buffer size should be greater than this to accomodate max text)
*
* @return
* @retval
Expand Down

0 comments on commit 669c2fd

Please sign in to comment.