From 1ea138f7952ac9bce054ade7add4868694a24ce2 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 20 May 2023 10:01:05 +0300 Subject: [PATCH] Port XFW keyboard to marauder instead of UART Term keyboard This implementation has not only extra symbols but a cursor feature thanks to @Willy-JL --- .../assets/KeyKeyboardSelected_10x11.png | Bin 0 -> 7210 bytes .../assets/KeyKeyboard_10x11.png | Bin 0 -> 7763 bytes .../wifi_marauder_text_input.c | 559 +++++++++++------- .../wifi_marauder_text_input.h | 31 +- 4 files changed, 358 insertions(+), 232 deletions(-) create mode 100644 applications/external/wifi_marauder_companion/assets/KeyKeyboardSelected_10x11.png create mode 100644 applications/external/wifi_marauder_companion/assets/KeyKeyboard_10x11.png diff --git a/applications/external/wifi_marauder_companion/assets/KeyKeyboardSelected_10x11.png b/applications/external/wifi_marauder_companion/assets/KeyKeyboardSelected_10x11.png new file mode 100644 index 0000000000000000000000000000000000000000..231880386a9d9e83911088c9fcd083f84a7f75bb GIT binary patch literal 7210 zcmeHMc{G&m`=?Ublaz#}DWMw1jBO@scCroG3eED&7|aYa!&oaSQQ1?BvQr3^B_u>D zRI(HaN!GGvr}BHKx3~9vzvukUd(Q9oUvtjPbKlo}U7!29KG${M=ef>=S(q8{^N8_q zaB%P&8R}xd=jxbu^9JyDl++f>!NK>$&)SZO!LlG8bQ+QD4nUZ`9smUJArm<`d^+pBC6Dvw@S z{-)=@qQ^b|b+J}=KD@%AUv=la?m*JB2h-;tO5d8_imCrneonb*>iaiOoi~|NgFw@_ z>-`^xAU-r*IlrN-```Pz{aJjIOYe6%&l?S#KG|D$Cg<#&2dHBbiv7Hj8*N; zvpssiU{m_6Dsp$aNSFHK(;jp`NzI2;_pfRP-p$Ih1Qswm1DPBQr;lPomFj({Au*WtuGPPB=1`JJ~?+kaqp}DZ~9^g`Gj^RetXd*K0SH zJ19>d_hxz4gfY4o0~P!|>%7uPfv>JPngvYNlF~X@9cNkQ$44tEW#w;Kja|N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Lk=SSlV^g#y9l$RG}YQc)x* zsUTrEWmQ#}B1)AA!x2?M2pmos1t%(kIQZWn%;{vXDzWard$kHh0HJUQ6dq3`sKQk7 z$|^8LMI{x`8w3DTLgL_n0u~ELsw%8O5%6ez8l8d#(@CaaNr1cum9)07N;q2E!bly8 zkc0m%v2e#SiJ*Zx^eCC?<@5J~HJJifF|n&`Dk!U{AmAt^MT81cMMVYqw~`G&XMmNs zim3pXLn78zR?~t8g8_-fuGT3CuqFp%LF>=~ER#mJrqSHhp{p)IRxN)mn}WxQfMsHJ zu}lC2g(Hw?I0B7Ow1y+mNN|8S2#2HLzvgv{X%EZh)foi4rr4=9zm|a@?7HzBD0n# z*?;=NasgJe01^g+BVhkYnEcOxo))aobWI($gGVt;O??U-sm*G#& zK!5)~KR~vOSwT8}y5Z6&x`A8PBTVZMP{#YRdS&a^gaPJ@ k(Oa(fF60b8WFS2`E^HCx5!~3>143{Z>6z)~A2}KPKg=ZgNB{r; literal 0 HcmV?d00001 diff --git a/applications/external/wifi_marauder_companion/assets/KeyKeyboard_10x11.png b/applications/external/wifi_marauder_companion/assets/KeyKeyboard_10x11.png new file mode 100644 index 0000000000000000000000000000000000000000..1f4c03478f68cb15c74ef99888ce4faf50e0a140 GIT binary patch literal 7763 zcmeHMcT|(hwg*8VAW}pT5e%V7OCh9?P?TPzgMbtONN-0#Ksbt`qQDF2@p$jMYrS>WdiTGRwen?V&)&b;`?vSZ`eqVoY^cr2evF-g zfq_$3N5ho90!va7!EG^n_JOLaXvtIPYQ|bLIl$M+=)P1CL*XpT|J)pSw`V*_Er$lGUV9}kPM4|w*oUQF?ll7f#pMss4lb=^o zxTHFHbLTtx?Ok4rEw7t>D(VkxZfcfTJ7sHGXLrI1f{9&ic>1nxr^!utU*9dyBa?uh zt<9U4zTNzMCU9G9(Yh;AD>cajAe{zue8xJ@Yg`6yOC0zLuJnr?{uC$hz$J!1t$O8Z z{Ij)7kNrj6`_Cz6d1P2Fte8CNzMOA6aWZ8mTM&she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_~Qeju}#nJ&>i8LJ0*VV<1iuF|n?crkS z?Oibx1l&`hIV*##42*&56i*@$0YN}uU`=1LHyotG4pj0akg%p2T0bD@J!Oy+jpmMp zLVbLEAU^UCil-w~4uio!VQ?rM4yJ2>seW!WoG;joD!L2t9Ycdi#e0(7X=I8Ua2FHj zK=Gm}gFy6g;Gh1vx*Hh$gmbuCCBuEvPh2Z#u{ihyJ4l)tr9S z0yQO4DPEp|jVAgl1Oflk-rdX7WiK289!hi}y3$pt^jYQpWlC*b1LL0-yA(K* zUETMr=w$zkCXGz`i>!a~ZFgiZoL?QGoBzc97wtb|-&3Y*85m$SD0r`3_jEOsLA&!~ z2^2h;fZc1NF(`Q$3XKQL5#$}f2n84tj6uSYU?dy|L!;3|IR`nyFHpK}R2t3=Puzu~ zgG0!490hrK3`P!v2BXkuc`yP7R{&#BI5ZdzM=2;E5d<6xPx=MI$dgR3N}S8DUhP5= zcAB9w`HZVPU`MQwU^|-~Xk(yLf;~ z-&3wbrqbv4+Y^0XQD#Js@4fF`7xLax0s{9I1r~?@9s(8TP5hp3I@b3gyc5pNkx1V? zew6EAx!J%S)>LeS-Wnmb9nWrR3qxXieCzQocselected_keyboard = (model->selected_keyboard + 1) % keyboard_count; +} + +static uint8_t get_row_size(const Keyboard* keyboard, uint8_t row_index) { uint8_t row_size = 0; - - switch(row_index + 1) { - case 1: - row_size = sizeof(keyboard_keys_row_1) / sizeof(WIFI_TextInputKey); - break; - case 2: - row_size = sizeof(keyboard_keys_row_2) / sizeof(WIFI_TextInputKey); - break; - case 3: - row_size = sizeof(keyboard_keys_row_3) / sizeof(WIFI_TextInputKey); - break; - case 4: - row_size = sizeof(keyboard_keys_row_4) / sizeof(WIFI_TextInputKey); - break; + if(keyboard == &symbol_keyboard) { + switch(row_index + 1) { + case 1: + row_size = COUNT_OF(symbol_keyboard_keys_row_1); + break; + case 2: + row_size = COUNT_OF(symbol_keyboard_keys_row_2); + break; + case 3: + row_size = COUNT_OF(symbol_keyboard_keys_row_3); + break; + default: + furi_crash(NULL); + } + } else { + switch(row_index + 1) { + case 1: + row_size = COUNT_OF(keyboard_keys_row_1); + break; + case 2: + row_size = COUNT_OF(keyboard_keys_row_2); + break; + case 3: + row_size = COUNT_OF(keyboard_keys_row_3); + break; + default: + furi_crash(NULL); + } } return row_size; } -static const WIFI_TextInputKey* get_row(uint8_t row_index) { +static const WIFI_TextInputKey* get_row(const Keyboard* keyboard, uint8_t row_index) { const WIFI_TextInputKey* row = NULL; - - switch(row_index + 1) { - case 1: - row = keyboard_keys_row_1; - break; - case 2: - row = keyboard_keys_row_2; - break; - case 3: - row = keyboard_keys_row_3; - break; - case 4: - row = keyboard_keys_row_4; - break; + if(row_index < 3) { + row = keyboard->rows[row_index]; + } else { + furi_crash(NULL); } return row; } static char get_selected_char(WIFI_TextInputModel* model) { - return get_row(model->selected_row)[model->selected_column].text; + return get_row( + keyboards[model->selected_keyboard], model->selected_row)[model->selected_column] + .text; } static bool char_is_lowercase(char letter) { @@ -165,36 +231,9 @@ static bool char_is_lowercase(char letter) { } static char char_to_uppercase(const char letter) { - switch(letter) { - case '_': + if(letter == '_') { return 0x20; - break; - case '(': - return 0x29; - break; - case '{': - return 0x7d; - break; - case '[': - return 0x5d; - break; - case '/': - return 0x5c; - break; - case ';': - return 0x3a; - break; - case '.': - return 0x2c; - break; - case '!': - return 0x3f; - break; - case '<': - return 0x3e; - break; - } - if(char_is_lowercase(letter)) { + } else if(char_is_lowercase(letter)) { return (letter - 0x20); } else { return letter; @@ -202,86 +241,96 @@ static char char_to_uppercase(const char letter) { } static void wifi_text_input_backspace_cb(WIFI_TextInputModel* 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; + if(model->clear_default_text) { + model->text_buffer[0] = 0; + model->cursor_pos = 0; + } else if(model->cursor_pos > 0) { + char* move = model->text_buffer + model->cursor_pos; + memmove(move - 1, move, strlen(move) + 1); + model->cursor_pos--; } } static void wifi_text_input_view_draw_callback(Canvas* canvas, void* _model) { WIFI_TextInputModel* 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; uint8_t needed_string_width = canvas_width(canvas) - 8; uint8_t start_pos = 4; - const char* text = model->text_buffer; + model->cursor_pos = model->cursor_pos > text_length ? text_length : model->cursor_pos; + size_t cursor_pos = model->cursor_pos; canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); - canvas_draw_str(canvas, 2, 7, model->header); - elements_slightly_rounded_frame(canvas, 1, 8, 126, 12); + canvas_draw_str(canvas, 2, 8, model->header); + elements_slightly_rounded_frame(canvas, 1, 12, 126, 15); - if(canvas_string_width(canvas, text) > needed_string_width) { - canvas_draw_str(canvas, start_pos, 17, "..."); - start_pos += 6; - needed_string_width -= 8; - } - - while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) { - text++; + char buf[model->text_buffer_size + 1]; + if(model->text_buffer) { + strlcpy(buf, model->text_buffer, sizeof(buf)); } + char* str = buf; if(model->clear_default_text) { elements_slightly_rounded_box( - canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10); + canvas, start_pos - 1, 14, canvas_string_width(canvas, str) + 2, 10); canvas_set_color(canvas, ColorWhite); } else { - canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|"); - canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|"); + char* move = str + cursor_pos; + memmove(move + 1, move, strlen(move) + 1); + str[cursor_pos] = '|'; } - canvas_draw_str(canvas, start_pos, 17, text); + + if(cursor_pos > 0 && canvas_string_width(canvas, str) > needed_string_width) { + canvas_draw_str(canvas, start_pos, 22, "..."); + start_pos += 6; + needed_string_width -= 8; + for(uint32_t off = 0; + strlen(str) && canvas_string_width(canvas, str) > needed_string_width && + off < cursor_pos; + off++) { + str++; + } + } + + if(canvas_string_width(canvas, str) > needed_string_width) { + needed_string_width -= 4; + size_t len = strlen(str); + while(len && canvas_string_width(canvas, str) > needed_string_width) { + str[len--] = '\0'; + } + strcat(str, "..."); + } + + canvas_draw_str(canvas, start_pos, 22, str); canvas_set_font(canvas, FontKeyboard); - for(uint8_t row = 0; row <= keyboard_row_count; row++) { - const uint8_t column_count = get_row_size(row); - const WIFI_TextInputKey* keys = get_row(row); + for(uint8_t row = 0; row < keyboard_row_count; row++) { + const uint8_t column_count = get_row_size(keyboards[model->selected_keyboard], row); + const WIFI_TextInputKey* keys = get_row(keyboards[model->selected_keyboard], row); for(size_t column = 0; column < column_count; column++) { + bool selected = !model->cursor_select && model->selected_row == row && + model->selected_column == column; + const Icon* icon = NULL; if(keys[column].text == ENTER_KEY) { - canvas_set_color(canvas, ColorBlack); - if(model->selected_row == row && model->selected_column == column) { - canvas_draw_icon( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - &I_KeySaveSelected_24x11); - } else { - canvas_draw_icon( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - &I_KeySave_24x11); - } + icon = selected ? &I_KeySaveSelected_24x11 : &I_KeySave_24x11; + } else if(keys[column].text == SWITCH_KEYBOARD_KEY) { + icon = selected ? &I_KeyKeyboardSelected_10x11 : &I_KeyKeyboard_10x11; } else if(keys[column].text == BACKSPACE_KEY) { - canvas_set_color(canvas, ColorBlack); - if(model->selected_row == row && model->selected_column == column) { - canvas_draw_icon( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - &I_KeyBackspaceSelected_16x9); - } else { - canvas_draw_icon( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - &I_KeyBackspace_16x9); - } + icon = selected ? &I_KeyBackspaceSelected_16x9 : &I_KeyBackspace_16x9; + } + canvas_set_color(canvas, ColorBlack); + if(icon != NULL) { + canvas_draw_icon( + canvas, + keyboard_origin_x + keys[column].x, + keyboard_origin_y + keys[column].y, + icon); } else { - if(model->selected_row == row && model->selected_column == column) { - canvas_set_color(canvas, ColorBlack); + if(selected) { canvas_draw_box( canvas, keyboard_origin_x + keys[column].x - 1, @@ -289,19 +338,25 @@ static void wifi_text_input_view_draw_callback(Canvas* canvas, void* _model) { 7, 10); canvas_set_color(canvas, ColorWhite); - } else { - canvas_set_color(canvas, ColorBlack); } - canvas_draw_glyph( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - keys[column].text); + if(model->clear_default_text || text_length == 0) { + canvas_draw_glyph( + canvas, + keyboard_origin_x + keys[column].x, + keyboard_origin_y + keys[column].y, + char_to_uppercase(keys[column].text)); + } else { + canvas_draw_glyph( + canvas, + keyboard_origin_x + keys[column].x, + keyboard_origin_y + keys[column].y, + keys[column].text); + } } } } - if(model->valadator_message_visible) { + if(model->validator_message_visible) { canvas_set_font(canvas, FontSecondary); canvas_set_color(canvas, ColorWhite); canvas_draw_box(canvas, 8, 10, 110, 48); @@ -319,37 +374,69 @@ static void UNUSED(wifi_text_input); if(model->selected_row > 0) { model->selected_row--; - if(model->selected_column > get_row_size(model->selected_row) - 6) { + if(model->selected_row == 0 && + model->selected_column > + get_row_size(keyboards[model->selected_keyboard], model->selected_row) - 6) { model->selected_column = model->selected_column + 1; } + if(model->selected_row == 1 && + model->selected_keyboard == symbol_keyboard.keyboard_index) { + if(model->selected_column > 5) + model->selected_column += 2; + else if(model->selected_column > 1) + model->selected_column += 1; + } + } else { + model->cursor_select = true; + model->clear_default_text = false; } } static void wifi_text_input_handle_down(WIFI_TextInput* wifi_text_input, WIFI_TextInputModel* model) { UNUSED(wifi_text_input); - if(model->selected_row < keyboard_row_count - 1) { + if(model->cursor_select) { + model->cursor_select = false; + } else if(model->selected_row < keyboard_row_count - 1) { model->selected_row++; - if(model->selected_column > get_row_size(model->selected_row) - 4) { + if(model->selected_row == 1 && + model->selected_column > + get_row_size(keyboards[model->selected_keyboard], model->selected_row) - 4) { model->selected_column = model->selected_column - 1; } + if(model->selected_row == 2 && + model->selected_keyboard == symbol_keyboard.keyboard_index) { + if(model->selected_column > 7) + model->selected_column -= 2; + else if(model->selected_column > 1) + model->selected_column -= 1; + } } } static void wifi_text_input_handle_left(WIFI_TextInput* wifi_text_input, WIFI_TextInputModel* model) { UNUSED(wifi_text_input); - if(model->selected_column > 0) { + if(model->cursor_select) { + if(model->cursor_pos > 0) { + model->cursor_pos = CLAMP(model->cursor_pos - 1, strlen(model->text_buffer), 0u); + } + } else if(model->selected_column > 0) { model->selected_column--; } else { - model->selected_column = get_row_size(model->selected_row) - 1; + model->selected_column = + get_row_size(keyboards[model->selected_keyboard], model->selected_row) - 1; } } static void wifi_text_input_handle_right(WIFI_TextInput* wifi_text_input, WIFI_TextInputModel* model) { UNUSED(wifi_text_input); - if(model->selected_column < get_row_size(model->selected_row) - 1) { + if(model->cursor_select) { + model->cursor_pos = CLAMP(model->cursor_pos + 1, strlen(model->text_buffer), 0u); + } else if( + model->selected_column < + get_row_size(keyboards[model->selected_keyboard], model->selected_row) - 1) { model->selected_column++; } else { model->selected_column = 0; @@ -359,35 +446,49 @@ static void static void wifi_text_input_handle_ok( WIFI_TextInput* wifi_text_input, WIFI_TextInputModel* model, - bool shift) { + InputType type) { + if(model->cursor_select) return; + bool shift = type == InputTypeLong; + bool repeat = type == InputTypeRepeat; char selected = get_selected_char(model); - uint8_t text_length = strlen(model->text_buffer); - - if(shift) { - selected = char_to_uppercase(selected); - } + size_t text_length = strlen(model->text_buffer); if(selected == ENTER_KEY) { if(model->validator_callback && (!model->validator_callback( model->text_buffer, model->validator_text, model->validator_callback_context))) { - model->valadator_message_visible = true; + model->validator_message_visible = true; furi_timer_start(wifi_text_input->timer, furi_kernel_get_tick_frequency() * 4); - } else if(model->callback != 0 && text_length > 0) { + } else if(model->callback != 0 && text_length >= model->minimum_length) { model->callback(model->callback_context); } - } else if(selected == BACKSPACE_KEY) { - wifi_text_input_backspace_cb(model); + } else if(selected == SWITCH_KEYBOARD_KEY) { + switch_keyboard(model); } else { - if(model->clear_default_text) { - text_length = 0; - } - if(text_length < (model->text_buffer_size - 1)) { - model->text_buffer[text_length] = selected; - model->text_buffer[text_length + 1] = 0; + if(selected == BACKSPACE_KEY) { + wifi_text_input_backspace_cb(model); + } else if(!repeat) { + if(model->clear_default_text) { + text_length = 0; + } + if(text_length < (model->text_buffer_size - 1)) { + if(shift != (text_length == 0)) { + selected = char_to_uppercase(selected); + } + if(model->clear_default_text) { + model->text_buffer[0] = selected; + model->text_buffer[1] = '\0'; + model->cursor_pos = 1; + } else { + char* move = model->text_buffer + model->cursor_pos; + memmove(move + 1, move, strlen(move) + 1); + model->text_buffer[model->cursor_pos] = selected; + model->cursor_pos++; + } + } } + model->clear_default_text = false; } - model->clear_default_text = false; } static bool wifi_text_input_view_input_callback(InputEvent* event, void* context) { @@ -400,8 +501,8 @@ static bool wifi_text_input_view_input_callback(InputEvent* event, void* context WIFI_TextInputModel* model = view_get_model(wifi_text_input->view); if((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) && - model->valadator_message_visible) { - model->valadator_message_visible = false; + model->validator_message_visible) { + model->validator_message_visible = false; consumed = true; } else if(event->type == InputTypeShort) { consumed = true; @@ -419,7 +520,7 @@ static bool wifi_text_input_view_input_callback(InputEvent* event, void* context wifi_text_input_handle_right(wifi_text_input, model); break; case InputKeyOk: - wifi_text_input_handle_ok(wifi_text_input, model, false); + wifi_text_input_handle_ok(wifi_text_input, model, event->type); break; default: consumed = false; @@ -441,7 +542,7 @@ static bool wifi_text_input_view_input_callback(InputEvent* event, void* context wifi_text_input_handle_right(wifi_text_input, model); break; case InputKeyOk: - wifi_text_input_handle_ok(wifi_text_input, model, true); + wifi_text_input_handle_ok(wifi_text_input, model, event->type); break; case InputKeyBack: wifi_text_input_backspace_cb(model); @@ -465,6 +566,9 @@ static bool wifi_text_input_view_input_callback(InputEvent* event, void* context case InputKeyRight: wifi_text_input_handle_right(wifi_text_input, model); break; + case InputKeyOk: + wifi_text_input_handle_ok(wifi_text_input, model, event->type); + break; case InputKeyBack: wifi_text_input_backspace_cb(model); break; @@ -487,7 +591,7 @@ void wifi_text_input_timer_callback(void* context) { with_view_model( wifi_text_input->view, WIFI_TextInputModel * model, - { model->valadator_message_visible = false; }, + { model->validator_message_visible = false; }, true); } @@ -505,7 +609,12 @@ WIFI_TextInput* wifi_text_input_alloc() { with_view_model( wifi_text_input->view, WIFI_TextInputModel * model, - { model->validator_text = furi_string_alloc(); }, + { + model->validator_text = furi_string_alloc(); + model->minimum_length = 1; + model->cursor_pos = 0; + model->cursor_select = false; + }, false); wifi_text_input_reset(wifi_text_input); @@ -537,11 +646,14 @@ void wifi_text_input_reset(WIFI_TextInput* wifi_text_input) { wifi_text_input->view, WIFI_TextInputModel * model, { - model->text_buffer_size = 0; model->header = ""; model->selected_row = 0; model->selected_column = 0; + model->selected_keyboard = 0; + model->minimum_length = 1; model->clear_default_text = false; + model->cursor_pos = 0; + model->cursor_select = false; model->text_buffer = NULL; model->text_buffer_size = 0; model->callback = NULL; @@ -549,7 +661,7 @@ void wifi_text_input_reset(WIFI_TextInput* wifi_text_input) { model->validator_callback = NULL; model->validator_callback_context = NULL; furi_string_reset(model->validator_text); - model->valadator_message_visible = false; + model->validator_message_visible = false; }, true); } @@ -575,15 +687,28 @@ void wifi_text_input_set_result_callback( model->text_buffer = text_buffer; model->text_buffer_size = text_buffer_size; model->clear_default_text = clear_default_text; + model->cursor_select = false; if(text_buffer && text_buffer[0] != '\0') { + model->cursor_pos = strlen(text_buffer); // Set focus on Save model->selected_row = 2; - model->selected_column = 8; + model->selected_column = 9; + model->selected_keyboard = 0; + } else { + model->cursor_pos = 0; } }, true); } +void wifi_text_input_set_minimum_length(WIFI_TextInput* wifi_text_input, size_t minimum_length) { + with_view_model( + wifi_text_input->view, + WIFI_TextInputModel * model, + { model->minimum_length = minimum_length; }, + true); +} + void wifi_text_input_set_validator( WIFI_TextInput* wifi_text_input, WIFI_TextInputValidatorCallback callback, diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_text_input.h b/applications/external/wifi_marauder_companion/wifi_marauder_text_input.h index b6b1f7bdf..f5efe9234 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_text_input.h +++ b/applications/external/wifi_marauder_companion/wifi_marauder_text_input.h @@ -22,27 +22,27 @@ WIFI_TextInput* wifi_text_input_alloc(); /** Deinitialize and free text input * - * @param wifi_text_input WIFI_TextInput instance + * @param text_input WIFI_TextInput instance */ -void wifi_text_input_free(WIFI_TextInput* wifi_text_input); +void wifi_text_input_free(WIFI_TextInput* text_input); /** Clean text input view Note: this function does not free memory * - * @param wifi_text_input Text input instance + * @param text_input Text input instance */ -void wifi_text_input_reset(WIFI_TextInput* wifi_text_input); +void wifi_text_input_reset(WIFI_TextInput* text_input); /** Get text input view * - * @param wifi_text_input WIFI_TextInput instance + * @param text_input WIFI_TextInput instance * * @return View instance that can be used for embedding */ -View* wifi_text_input_get_view(WIFI_TextInput* wifi_text_input); +View* wifi_text_input_get_view(WIFI_TextInput* text_input); /** Set text input result callback * - * @param wifi_text_input WIFI_TextInput instance + * @param text_input WIFI_TextInput instance * @param callback callback fn * @param callback_context callback context * @param text_buffer pointer to YOUR text buffer, that we going @@ -53,7 +53,7 @@ View* wifi_text_input_get_view(WIFI_TextInput* wifi_text_input); * event */ void wifi_text_input_set_result_callback( - WIFI_TextInput* wifi_text_input, + WIFI_TextInput* text_input, WIFI_TextInputCallback callback, void* callback_context, char* text_buffer, @@ -61,22 +61,23 @@ void wifi_text_input_set_result_callback( bool clear_default_text); void wifi_text_input_set_validator( - WIFI_TextInput* wifi_text_input, + WIFI_TextInput* text_input, WIFI_TextInputValidatorCallback callback, void* callback_context); -WIFI_TextInputValidatorCallback - wifi_text_input_get_validator_callback(WIFI_TextInput* wifi_text_input); +void wifi_text_input_set_minimum_length(WIFI_TextInput* text_input, size_t minimum_length); -void* wifi_text_input_get_validator_callback_context(WIFI_TextInput* wifi_text_input); +WIFI_TextInputValidatorCallback wifi_text_input_get_validator_callback(WIFI_TextInput* text_input); + +void* wifi_text_input_get_validator_callback_context(WIFI_TextInput* text_input); /** Set text input header text * - * @param wifi_text_input WIFI_TextInput instance + * @param text_input WIFI_TextInput instance * @param text text to be shown */ -void wifi_text_input_set_header_text(WIFI_TextInput* wifi_text_input, const char* text); +void wifi_text_input_set_header_text(WIFI_TextInput* text_input, const char* text); #ifdef __cplusplus } -#endif +#endif \ No newline at end of file