You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
55 lines
1.2 KiB
#include <cstdlib> |
|
#include <cstring> |
|
|
|
#include "platform/ctr/keyboard.h" |
|
|
|
constexpr size_t MAX_TEXT_LENGTH = 255; |
|
|
|
struct vkbdEvent { |
|
const char *hintText; |
|
const char *inText; |
|
char *outText; |
|
int maxLength; |
|
}; |
|
|
|
static vkbdEvent events[16]; |
|
static int eventCount = 0; |
|
|
|
void ctr_vkbdInput(const char *hintText, const char *inText, char *outText, int maxLength) |
|
{ |
|
if (eventCount >= sizeof(events)) |
|
return; |
|
|
|
vkbdEvent &event = events[eventCount]; |
|
event.hintText = hintText; |
|
event.inText = inText; |
|
event.outText = outText; |
|
event.maxLength = maxLength; |
|
eventCount++; |
|
} |
|
|
|
void ctr_vkbdFlush() |
|
{ |
|
for (int i = 0; i < eventCount; i++) { |
|
vkbdEvent &event = events[i]; |
|
SwkbdState swkbd; |
|
|
|
char mybuf[MAX_TEXT_LENGTH + 1]; |
|
|
|
swkbdInit(&swkbd, SWKBD_TYPE_WESTERN, 2, MAX_TEXT_LENGTH); |
|
swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, 0, 0); |
|
swkbdSetInitialText(&swkbd, event.inText); |
|
swkbdSetHintText(&swkbd, event.hintText); |
|
|
|
SwkbdButton button = swkbdInputText(&swkbd, mybuf, sizeof(mybuf)); |
|
|
|
if (button == SWKBD_BUTTON_CONFIRM) { |
|
strncpy(event.outText, mybuf, event.maxLength); |
|
continue; |
|
} |
|
|
|
strncpy(event.outText, event.inText, event.maxLength); |
|
} |
|
|
|
eventCount = 0; |
|
}
|
|
|