|
@@ -20,12 +20,11 @@ typedef struct {
|
|
|
char* text_buffer;
|
|
char* text_buffer;
|
|
|
size_t text_buffer_size;
|
|
size_t text_buffer_size;
|
|
|
bool clear_default_text;
|
|
bool clear_default_text;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
IntInputCallback callback;
|
|
IntInputCallback callback;
|
|
|
- //IntChangedCallback changed_callback;
|
|
|
|
|
void* callback_context;
|
|
void* callback_context;
|
|
|
|
|
|
|
|
- int8_t selected_row;
|
|
|
|
|
|
|
+ int8_t selected_row;
|
|
|
uint8_t selected_column;
|
|
uint8_t selected_column;
|
|
|
} IntInputModel;
|
|
} IntInputModel;
|
|
|
|
|
|
|
@@ -34,7 +33,6 @@ static const uint8_t keyboard_origin_y = 31;
|
|
|
static const uint8_t keyboard_row_count = 2;
|
|
static const uint8_t keyboard_row_count = 2;
|
|
|
static const uint8_t enter_symbol = '\r';
|
|
static const uint8_t enter_symbol = '\r';
|
|
|
static const uint8_t backspace_symbol = '\b';
|
|
static const uint8_t backspace_symbol = '\b';
|
|
|
-//static const uint8_t max_drawable_digits = 4;
|
|
|
|
|
|
|
|
|
|
static const IntInputKey keyboard_keys_row_1[] = {
|
|
static const IntInputKey keyboard_keys_row_1[] = {
|
|
|
{'0', 0, 12},
|
|
{'0', 0, 12},
|
|
@@ -106,101 +104,20 @@ static const IntInputKey* int_input_get_row(uint8_t row_index) {
|
|
|
* @param model The model
|
|
* @param model The model
|
|
|
*/
|
|
*/
|
|
|
static void int_input_draw_input(Canvas* canvas, IntInputModel* model) {
|
|
static void int_input_draw_input(Canvas* canvas, IntInputModel* model) {
|
|
|
- //const uint8_t text_x = 8;
|
|
|
|
|
- //const uint8_t text_y = 25;
|
|
|
|
|
- //const uint8_t text_y2 = 40;
|
|
|
|
|
- UNUSED(model);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const uint8_t text_x = 8;
|
|
|
|
|
+ const uint8_t text_y = 25;
|
|
|
|
|
+
|
|
|
elements_slightly_rounded_frame(canvas, 6, 14, 116, 15);
|
|
elements_slightly_rounded_frame(canvas, 6, 14, 116, 15);
|
|
|
|
|
|
|
|
- //canvas_draw_icon(canvas, 2, 19, &I_ButtonLeftSmall_3x5);
|
|
|
|
|
- //canvas_draw_icon(canvas, 123, 19, &I_ButtonRightSmall_3x5);
|
|
|
|
|
-
|
|
|
|
|
- /*for(uint8_t i = model->first_visible_byte;
|
|
|
|
|
- i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes);
|
|
|
|
|
- i++) {
|
|
|
|
|
- uint8_t byte_position = i - model->first_visible_byte;
|
|
|
|
|
-
|
|
|
|
|
- if(i == model->selected_byte) {
|
|
|
|
|
- canvas_draw_frame(canvas, text_x + byte_position * 14, text_y - 9, 15, 11);
|
|
|
|
|
- if(model->selected_row == -2) {
|
|
|
|
|
- canvas_draw_icon(
|
|
|
|
|
- canvas, text_x + 6 + byte_position * 14, text_y - 14, &I_arrow_nano_up);
|
|
|
|
|
- canvas_draw_icon(
|
|
|
|
|
- canvas, text_x + 6 + byte_position * 14, text_y + 5, &I_arrow_nano_down);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const char* text = model->text_buffer;
|
|
|
|
|
+ canvas_draw_str(canvas, text_x, text_y, text);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- if(model->selected_high_nibble) {
|
|
|
|
|
- canvas_draw_glyph(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 8 + byte_position * 14,
|
|
|
|
|
- text_y,
|
|
|
|
|
- int_input_get_nibble_text(model->bytes[i], false));
|
|
|
|
|
- canvas_draw_box(canvas, text_x + 1 + byte_position * 14, text_y - 8, 7, 9);
|
|
|
|
|
- canvas_invert_color(canvas);
|
|
|
|
|
- canvas_draw_line(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 14 + byte_position * 14,
|
|
|
|
|
- text_y - 6,
|
|
|
|
|
- text_x + 14 + byte_position * 14,
|
|
|
|
|
- text_y - 2);
|
|
|
|
|
- canvas_draw_glyph(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 2 + byte_position * 14,
|
|
|
|
|
- text_y,
|
|
|
|
|
- int_input_get_nibble_text(model->bytes[i], true));
|
|
|
|
|
- canvas_invert_color(canvas);
|
|
|
|
|
- } else {
|
|
|
|
|
- canvas_draw_box(canvas, text_x + 7 + byte_position * 14, text_y - 8, 7, 9);
|
|
|
|
|
- canvas_draw_glyph(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 2 + byte_position * 14,
|
|
|
|
|
- text_y,
|
|
|
|
|
- int_input_get_nibble_text(model->bytes[i], true));
|
|
|
|
|
- canvas_invert_color(canvas);
|
|
|
|
|
- canvas_draw_line(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + byte_position * 14,
|
|
|
|
|
- text_y - 6,
|
|
|
|
|
- text_x + byte_position * 14,
|
|
|
|
|
- text_y - 2);
|
|
|
|
|
- canvas_draw_glyph(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 8 + byte_position * 14,
|
|
|
|
|
- text_y,
|
|
|
|
|
- int_input_get_nibble_text(model->bytes[i], false));
|
|
|
|
|
- canvas_invert_color(canvas);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- if(model->first_visible_byte > 0 && i == model->first_visible_byte) {
|
|
|
|
|
- canvas_draw_icon(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 2 + byte_position * 14,
|
|
|
|
|
- text_y - 7,
|
|
|
|
|
- &I_More_data_placeholder_5x7);
|
|
|
|
|
- } else {
|
|
|
|
|
- canvas_draw_glyph(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 2 + byte_position * 14,
|
|
|
|
|
- text_y,
|
|
|
|
|
- int_input_get_nibble_text(model->bytes[i], true));
|
|
|
|
|
- }
|
|
|
|
|
- if(model->bytes_count - model->first_visible_byte > max_drawable_bytes &&
|
|
|
|
|
- i == model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes) - 1) {
|
|
|
|
|
- canvas_draw_icon(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 8 + byte_position * 14,
|
|
|
|
|
- text_y - 7,
|
|
|
|
|
- &I_More_data_placeholder_5x7);
|
|
|
|
|
- } else {
|
|
|
|
|
- canvas_draw_glyph(
|
|
|
|
|
- canvas,
|
|
|
|
|
- text_x + 8 + byte_position * 14,
|
|
|
|
|
- text_y,
|
|
|
|
|
- int_input_get_nibble_text(model->bytes[i], false));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+static void int_input_backspace_cb(IntInputModel* model) {
|
|
|
|
|
+ uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
|
|
|
|
|
+ if(text_length > 0) {
|
|
|
|
|
+ model->text_buffer[text_length - 1] = 0;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** Handle up button
|
|
/** Handle up button
|
|
@@ -254,23 +171,18 @@ static void int_input_handle_right(IntInputModel* model) {
|
|
|
static void int_input_handle_ok(IntInputModel* model) {
|
|
static void int_input_handle_ok(IntInputModel* model) {
|
|
|
char selected = int_input_get_row(model->selected_row)[model->selected_column].text;
|
|
char selected = int_input_get_row(model->selected_row)[model->selected_column].text;
|
|
|
size_t text_length = strlen(model->text_buffer);
|
|
size_t text_length = strlen(model->text_buffer);
|
|
|
-UNUSED(text_length);
|
|
|
|
|
if(selected == enter_symbol) {
|
|
if(selected == enter_symbol) {
|
|
|
- // int_input_call_input_callback(model);
|
|
|
|
|
|
|
+ model->callback(model->callback_context);
|
|
|
} else if(selected == backspace_symbol) {
|
|
} else if(selected == backspace_symbol) {
|
|
|
- //int_input_clear_selected_byte(model);
|
|
|
|
|
|
|
+ int_input_backspace_cb(model);
|
|
|
} else {
|
|
} else {
|
|
|
- if (model->clear_default_text) {
|
|
|
|
|
|
|
+ if(model->clear_default_text) {
|
|
|
text_length = 0;
|
|
text_length = 0;
|
|
|
}
|
|
}
|
|
|
- //if(text_length < (model->text_buffer_size - 1)) {
|
|
|
|
|
- //model->text_buffer[text_length] = selected;
|
|
|
|
|
- //model->text_buffer[text_length + 1] = 0;
|
|
|
|
|
- FURI_LOG_D("INT_INPUT", model->text_buffer);
|
|
|
|
|
- //FURI_LOG_D("INT_INPUT", "%u", text_length);
|
|
|
|
|
- //FURI_LOG_D("INT_INPUT", "%u", model->text_buffer_size);
|
|
|
|
|
- FURI_LOG_D("INT_INPUT", "%d", selected);
|
|
|
|
|
- //}
|
|
|
|
|
|
|
+ if(text_length < (model->text_buffer_size - 1)) {
|
|
|
|
|
+ model->text_buffer[text_length] = selected;
|
|
|
|
|
+ model->text_buffer[text_length + 1] = 0;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
model->clear_default_text = false;
|
|
model->clear_default_text = false;
|
|
|
}
|
|
}
|
|
@@ -284,16 +196,12 @@ static void int_input_view_draw_callback(Canvas* canvas, void* _model) {
|
|
|
IntInputModel* model = _model;
|
|
IntInputModel* model = _model;
|
|
|
uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
|
|
uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
|
|
|
UNUSED(text_length);
|
|
UNUSED(text_length);
|
|
|
- //uint8_t needed_string_width = canvas_width(canvas) - 8;
|
|
|
|
|
- //uint8_t start_pos = 4;
|
|
|
|
|
-
|
|
|
|
|
- //const char* text = model->text_buffer;
|
|
|
|
|
|
|
|
|
|
canvas_clear(canvas);
|
|
canvas_clear(canvas);
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
int_input_draw_input(canvas, model);
|
|
int_input_draw_input(canvas, model);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
canvas_draw_str(canvas, 2, 9, model->header);
|
|
canvas_draw_str(canvas, 2, 9, model->header);
|
|
|
canvas_set_font(canvas, FontKeyboard);
|
|
canvas_set_font(canvas, FontKeyboard);
|
|
@@ -343,9 +251,7 @@ static void int_input_view_draw_callback(Canvas* canvas, void* _model) {
|
|
|
11,
|
|
11,
|
|
|
13);
|
|
13);
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
- } else if(
|
|
|
|
|
- model->selected_row == -1 && row == 0 &&
|
|
|
|
|
- model->selected_column == column) {
|
|
|
|
|
|
|
+ } else if(model->selected_row == -1 && row == 0 && model->selected_column == column) {
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
canvas_draw_frame(
|
|
canvas_draw_frame(
|
|
|
canvas,
|
|
canvas,
|
|
@@ -380,11 +286,12 @@ static bool int_input_view_input_callback(InputEvent* event, void* context) {
|
|
|
furi_assert(int_input);
|
|
furi_assert(int_input);
|
|
|
|
|
|
|
|
bool consumed = false;
|
|
bool consumed = false;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Fetch the model
|
|
// Fetch the model
|
|
|
IntInputModel* model = view_get_model(int_input->view);
|
|
IntInputModel* model = view_get_model(int_input->view);
|
|
|
|
|
|
|
|
- if(event->type == InputTypeShort || event->type == InputTypeLong || event->type == InputTypeRepeat) {
|
|
|
|
|
|
|
+ if(event->type == InputTypeShort || event->type == InputTypeLong ||
|
|
|
|
|
+ event->type == InputTypeRepeat) {
|
|
|
consumed = true;
|
|
consumed = true;
|
|
|
switch(event->key) {
|
|
switch(event->key) {
|
|
|
case InputKeyLeft:
|
|
case InputKeyLeft:
|
|
@@ -433,7 +340,6 @@ void int_input_reset(IntInput* int_input) {
|
|
|
true);
|
|
true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
IntInput* int_input_alloc() {
|
|
IntInput* int_input_alloc() {
|
|
|
IntInput* int_input = malloc(sizeof(IntInput));
|
|
IntInput* int_input = malloc(sizeof(IntInput));
|
|
|
int_input->view = view_alloc();
|
|
int_input->view = view_alloc();
|
|
@@ -480,10 +386,5 @@ void int_input_set_result_callback(
|
|
|
|
|
|
|
|
void int_input_set_header_text(IntInput* int_input, const char* text) {
|
|
void int_input_set_header_text(IntInput* int_input, const char* text) {
|
|
|
with_view_model(
|
|
with_view_model(
|
|
|
- int_input->view,
|
|
|
|
|
- IntInputModel * model,
|
|
|
|
|
- {
|
|
|
|
|
- model->header = text;
|
|
|
|
|
- },
|
|
|
|
|
- true);
|
|
|
|
|
|
|
+ int_input->view, IntInputModel * model, { model->header = text; }, true);
|
|
|
}
|
|
}
|