mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Port TextInput to ASCII event API
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "text_input_i.h"
|
||||
#include "text_input.h"
|
||||
#include <gui/elements.h>
|
||||
#include <assets_icons.h>
|
||||
#include <furi.h>
|
||||
@@ -495,7 +495,7 @@ static void text_input_handle_ok(TextInput* text_input, TextInputModel* model, I
|
||||
}
|
||||
}
|
||||
|
||||
bool text_input_view_input_callback(InputEvent* event, void* context) {
|
||||
static bool text_input_view_input_callback(InputEvent* event, void* context) {
|
||||
TextInput* text_input = context;
|
||||
furi_assert(text_input);
|
||||
|
||||
@@ -588,6 +588,73 @@ bool text_input_view_input_callback(InputEvent* event, void* context) {
|
||||
return consumed;
|
||||
}
|
||||
|
||||
static bool text_input_view_ascii_callback(AsciiEvent* event, void* context) {
|
||||
TextInput* text_input = context;
|
||||
furi_assert(text_input);
|
||||
|
||||
switch(event->value) {
|
||||
case AsciiValueDC3: // Right
|
||||
case AsciiValueDC4: // Left
|
||||
with_view_model(
|
||||
text_input->view,
|
||||
TextInputModel * model,
|
||||
{
|
||||
model->cursor_select = true;
|
||||
model->clear_default_text = false;
|
||||
model->selected_row = 0;
|
||||
if(event->value == AsciiValueDC3) {
|
||||
model->cursor_pos =
|
||||
CLAMP(model->cursor_pos + 1, strlen(model->text_buffer), 0u);
|
||||
} else {
|
||||
model->cursor_pos =
|
||||
CLAMP(model->cursor_pos - 1, strlen(model->text_buffer), 0u);
|
||||
}
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
case _AsciiValueSOH: // Ctrl A
|
||||
with_view_model(
|
||||
text_input->view,
|
||||
TextInputModel * model,
|
||||
{ model->clear_default_text = !model->clear_default_text; },
|
||||
true);
|
||||
return true;
|
||||
default: // Look in keyboards
|
||||
for(size_t k = 0; k < keyboard_count; k++) {
|
||||
const Keyboard* keyboard = keyboards[k];
|
||||
for(size_t r = 0; r < keyboard_row_count; r++) {
|
||||
const TextInputKey* row = get_row(keyboard, r);
|
||||
uint8_t size = get_row_size(keyboard, r);
|
||||
for(size_t key = 0; key < size; key++) {
|
||||
char lower = row[key].text;
|
||||
char upper = char_to_uppercase(lower);
|
||||
if(event->value == lower || event->value == upper) {
|
||||
with_view_model(
|
||||
text_input->view,
|
||||
TextInputModel * model,
|
||||
{
|
||||
model->cursor_select = false;
|
||||
model->selected_keyboard = k;
|
||||
model->selected_row = r;
|
||||
model->selected_column = key;
|
||||
bool shift =
|
||||
(event->value == upper) !=
|
||||
(model->clear_default_text || strlen(model->text_buffer) == 0);
|
||||
text_input_handle_ok(
|
||||
text_input, model, shift ? InputTypeLong : InputTypeShort);
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void text_input_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
TextInput* text_input = context;
|
||||
@@ -633,6 +700,7 @@ TextInput* text_input_alloc() {
|
||||
view_allocate_model(text_input->view, ViewModelTypeLocking, sizeof(TextInputModel));
|
||||
view_set_draw_callback(text_input->view, text_input_view_draw_callback);
|
||||
view_set_input_callback(text_input->view, text_input_view_input_callback);
|
||||
view_set_ascii_callback(text_input->view, text_input_view_ascii_callback);
|
||||
|
||||
text_input->timer = furi_timer_alloc(text_input_timer_callback, FuriTimerTypeOnce, text_input);
|
||||
|
||||
@@ -816,52 +884,3 @@ void text_input_set_header_text(TextInput* text_input, const char* text) {
|
||||
with_view_model(
|
||||
text_input->view, TextInputModel * model, { model->header = text; }, true);
|
||||
}
|
||||
|
||||
bool text_input_insert_character(TextInput* text_input, char chr) {
|
||||
if(chr == 0x1b) { // Arrow escape code = Select input row
|
||||
with_view_model(
|
||||
text_input->view,
|
||||
TextInputModel * model,
|
||||
{
|
||||
model->cursor_select = true;
|
||||
model->clear_default_text = false;
|
||||
model->selected_row = 0;
|
||||
},
|
||||
true);
|
||||
return false; // Don't consume so CLI gives arrow input
|
||||
}
|
||||
if(chr == 0x01) { // Ctrl A = Select all text
|
||||
with_view_model(
|
||||
text_input->view, TextInputModel * model, { model->clear_default_text = true; }, true);
|
||||
return true;
|
||||
}
|
||||
for(size_t k = 0; k < keyboard_count; k++) {
|
||||
const Keyboard* keyboard = keyboards[k];
|
||||
for(size_t r = 0; r < keyboard_row_count; r++) {
|
||||
const TextInputKey* row = get_row(keyboard, r);
|
||||
uint8_t size = get_row_size(keyboard, r);
|
||||
for(size_t key = 0; key < size; key++) {
|
||||
char lower = row[key].text;
|
||||
char upper = char_to_uppercase(lower);
|
||||
if(chr == lower || chr == upper) {
|
||||
with_view_model(
|
||||
text_input->view,
|
||||
TextInputModel * model,
|
||||
{
|
||||
model->cursor_select = false;
|
||||
model->selected_keyboard = k;
|
||||
model->selected_row = r;
|
||||
model->selected_column = key;
|
||||
bool shift = (chr == upper) != (model->clear_default_text ||
|
||||
strlen(model->text_buffer) == 0);
|
||||
text_input_handle_ok(
|
||||
text_input, model, shift ? InputTypeLong : InputTypeShort);
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -89,8 +89,6 @@ void* text_input_get_validator_callback_context(TextInput* text_input);
|
||||
*/
|
||||
void text_input_set_header_text(TextInput* text_input, const char* text);
|
||||
|
||||
bool text_input_insert_character(TextInput* text_input, char c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "text_input.h"
|
||||
|
||||
bool text_input_view_input_callback(InputEvent* event, void* context);
|
||||
@@ -3319,7 +3319,6 @@ Function,+,text_input_free,void,TextInput*
|
||||
Function,+,text_input_get_validator_callback,TextInputValidatorCallback,TextInput*
|
||||
Function,+,text_input_get_validator_callback_context,void*,TextInput*
|
||||
Function,+,text_input_get_view,View*,TextInput*
|
||||
Function,+,text_input_insert_character,_Bool,"TextInput*, char"
|
||||
Function,+,text_input_reset,void,TextInput*
|
||||
Function,+,text_input_set_header_text,void,"TextInput*, const char*"
|
||||
Function,+,text_input_set_minimum_length,void,"TextInput*, size_t"
|
||||
|
||||
|
Reference in New Issue
Block a user