[FL-1234] Keyboards redesign (#501)

* text input: keyboard redesign,; input: tune repeat keypress timing; archive: fix max string width when scrollbar is shown

* byte input: redesign

* byte/text input: long press back to activate backspace added

* archive: pass absolute path to app

* format sources

* better keyboard timings

Co-authored-by: SG <who.just.the.doctor@gmail.com>
This commit is contained in:
its your bedtime
2021-06-02 15:51:05 +03:00
committed by GitHub
parent 7f16c9fe5a
commit d5df0483a3
5 changed files with 96 additions and 38 deletions

View File

@@ -42,10 +42,10 @@ static const TextInputKey keyboard_keys_row_1[] = {
{'i', 64, 8},
{'o', 73, 8},
{'p', 82, 8},
{'7', 91, 8},
{'8', 100, 8},
{'9', 109, 8},
{'_', 118, 8},
{'0', 91, 8},
{'1', 100, 8},
{'2', 110, 8},
{'3', 120, 8},
};
static const TextInputKey keyboard_keys_row_2[] = {
@@ -58,10 +58,10 @@ static const TextInputKey keyboard_keys_row_2[] = {
{'j', 55, 20},
{'k', 64, 20},
{'l', 73, 20},
{'4', 82, 20},
{'5', 91, 20},
{'6', 100, 20},
{BACKSPACE_KEY, 110, 12},
{BACKSPACE_KEY, 82, 12},
{'4', 100, 20},
{'5', 110, 20},
{'6', 120, 20},
};
static const TextInputKey keyboard_keys_row_3[] = {
@@ -72,11 +72,11 @@ static const TextInputKey keyboard_keys_row_3[] = {
{'b', 37, 32},
{'n', 46, 32},
{'m', 55, 32},
{'0', 64, 32},
{'1', 73, 32},
{'2', 82, 32},
{'3', 91, 32},
{ENTER_KEY, 102, 23},
{'_', 64, 32},
{ENTER_KEY, 74, 23},
{'7', 100, 32},
{'8', 110, 32},
{'9', 120, 32},
};
static uint8_t get_row_size(uint8_t row_index) {
@@ -127,24 +127,41 @@ static const char char_to_uppercase(const char letter) {
return (letter - 0x20);
}
static void text_input_backspace_cb(TextInputModel* model) {
uint8_t text_length = strlen(model->text);
if(text_length > 0) {
model->text[text_length - 1] = 0;
}
}
static void text_input_view_draw_callback(Canvas* canvas, void* _model) {
TextInputModel* model = _model;
uint8_t text_length = strlen(model->text);
uint8_t needed_string_width = canvas_width(canvas) - 4 - 7 - 4;
uint8_t needed_string_width = canvas_width(canvas) - 8;
uint8_t start_pos = 4;
char* text = model->text;
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_str(canvas, 2, 8, model->header);
elements_slightly_rounded_frame(canvas, 1, 12, 122, 15);
elements_slightly_rounded_frame(canvas, 1, 12, 126, 15);
if(canvas_string_width(canvas, text) > needed_string_width) {
canvas_draw_str(canvas, start_pos, 22, "...");
start_pos += 6;
needed_string_width -= 8;
}
while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
text++;
}
canvas_draw_str(canvas, 4, 22, text);
canvas_draw_str(canvas, 4 + canvas_string_width(canvas, text) + 1, 22, "|");
canvas_draw_str(canvas, start_pos, 22, text);
canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 22, "|");
canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 22, "|");
canvas_set_font(canvas, FontKeyboard);
@@ -220,6 +237,9 @@ static void text_input_handle_up(TextInput* text_input) {
text_input->view, (TextInputModel * model) {
if(model->selected_row > 0) {
model->selected_row--;
if(model->selected_column > get_row_size(model->selected_row) - 5) {
model->selected_column = model->selected_column + 1;
}
}
return true;
});
@@ -230,8 +250,8 @@ static void text_input_handle_down(TextInput* text_input) {
text_input->view, (TextInputModel * model) {
if(model->selected_row < keyboard_row_count - 1) {
model->selected_row++;
if(model->selected_column > get_row_size(model->selected_row) - 1) {
model->selected_column = get_row_size(model->selected_row) - 1;
if(model->selected_column > get_row_size(model->selected_row) - 4) {
model->selected_column = model->selected_column - 1;
}
}
return true;
@@ -273,9 +293,7 @@ static void text_input_handle_ok(TextInput* text_input) {
model->callback(model->callback_context, model->text);
}
} else if(selected == BACKSPACE_KEY) {
if(text_length > 0) {
model->text[text_length - 1] = 0;
}
text_input_backspace_cb(model);
} else if(text_length < model->max_text_length) {
if(text_length == 0 && char_is_lowercase(selected)) {
selected = char_to_uppercase(selected);
@@ -319,6 +337,17 @@ static bool text_input_view_input_callback(InputEvent* event, void* context) {
}
}
if((event->type == InputTypeLong || event->type == InputTypeRepeat) &&
event->key == InputKeyBack) {
with_view_model(
text_input->view, (TextInputModel * model) {
text_input_backspace_cb(model);
return true;
});
consumed = true;
}
return consumed;
}