So I’m trying to have an input text_area with a special formatting.
Is it possible to have a text_area set with a set of accepted characters but to attach a formatter ?
So basically I want my textArea to only accept number.
But I want I want the final text to be displayed differently. ( \d\d/\d\d )
Yes but is not exactly the same @kisvegabor.
I end up writting something similar. but actually I’d be more convenient for user to have 2 separate “const char*” to deal with.
In you example for instance.
We wanted user to only insert numeric char but we have to allow “:”. Thus I might be wrong be we need to handle this “bad input” in callback. (Which is a bit late considering text_area would have already put it into his buffer).
You can’t check the rawInput versus a simple validator. You will need to unformat first.
Here what I had as callback for something similar.
void editViewButtonsEventHandler(lv_obj_t* /*obj*/, lv_event_t event) {
EditView* editView(static_cast<EditView*>(LvglUserInteraction::Pimpl::getInstance()._currentView));
if (editView) {
if (event == LV_EVENT_KEY) {
uint32_t key = *(uint32_t*)lv_event_get_data();
switch (key) {
case ':':
case '/':
case ' ':
lv_textarea_del_char(editView->_inputWidget);
break;
case LV_KEY_ESC:
editView->_result = UserInteractionInput::INPUT_CANCEL;
editView->_quit = true;
break;
case LV_KEY_ENTER: {
//need validation
bool isvalid = true;
editView->_input = lv_textarea_get_text(editView->_inputWidget);
if (editView->_inputValidator) {
if (editView->_inputFormatter) {
removeAllUnAuthChars(editView->_input);
}
isvalid = (*editView->_inputValidator)(editView->_input.c_str()); //on compare avec la valeur raw
}
if (isvalid) {
editView->_result = UserInteractionInput::INPUT_OK;
editView->_quit = true;
}
break;
}
default:
if (editView->_inputFormatter) {
editView->_input = lv_textarea_get_text(editView->_inputWidget);
removeAllUnAuthChars(editView->_input);
std::string formattedStr = (*editView->_inputFormatter)(editView->_input.c_str());
lv_textarea_set_text(editView->_inputWidget, formattedStr.c_str());
}
}
}
}
}
a preHook would be good yeah. LV_EVENT_INSERT would do the trick.
A filler would be good but might be complexe.
I would like to have it with PCRE syntaxe if that is possible.