28 #define BACKSPACE_KEY_INDEX 26
29 #define VALIDATE_INDEX 27
30 #define SHIFT_KEY_INDEX 28
31 #define LETTER_TO_DIGITS_OFFSET (sizeof(keysByMode[DIGITS_AND_SPECIALS]) - 29)
32 #define GET_CHAR(mode, char_idx) ((const char *) PIC(screen_keyboard_keys_by_mode[mode]))[char_idx]
50 const char *
const keysByMode[] = {
52 "abcdefghijklmnopqrstuvwxyz\b\n\r",
53 "ABCDEFGHIJKLMNOPQRSTUVWXYZ\b\n\r",
54 "0123456789 '\"`&/?!:;.,~*$=+-[](){}^<>\\_#@|%\b\n\r",
65 &C_icon_lowercase_invert,
66 &C_icon_uppercase_invert,
67 &C_icon_digits_invert,
68 &C_icon_backspace_invert,
69 &C_icon_validate_invert,
70 &C_icon_classes_invert,
91 rectArea.backgroundColor = inverted ?
WHITE :
BLACK;
92 rectArea.width = icon->width;
93 rectArea.height = icon->height;
96 rectArea.x0 = x0 + (KEYBOARD_KEY_WIDTH - icon->width) / 2;
101 static void keyboardDrawChar(
int16_t x0,
int8_t y0,
bool inverted,
const char *charPtr)
105 rectArea.backgroundColor = inverted ?
WHITE :
BLACK;
107 rectArea.height = 12;
110 rectArea.x0 = x0 + (KEYBOARD_KEY_WIDTH - rectArea.width) / 2;
121 rectArea.backgroundColor =
BLACK;
122 rectArea.x0 = keyboard->obj.area.x0;
123 rectArea.y0 = keyboard->obj.area.y0;
124 rectArea.width = keyboard->obj.area.width;
125 rectArea.height = keyboard->obj.area.height;
129 rectArea.x0 = keyboard->obj.area.x0 + 2 * KEYBOARD_KEY_WIDTH;
130 rectArea.y0 = keyboard->obj.area.y0;
131 rectArea.width = KEYBOARD_KEY_WIDTH;
132 rectArea.height = keyboard->obj.area.height;
136 rectArea.backgroundColor =
WHITE;
137 rectArea.x0 = keyboard->obj.area.x0 + KEYBOARD_KEY_WIDTH + 5;
138 rectArea.y0 = keyboard->obj.area.y0 + 6;
142 rectArea.x0 = keyboard->obj.area.x0 + 3 * KEYBOARD_KEY_WIDTH + 5;
150 const char *keys = keysByMode[keyboard->mode];
152 if (keyboard->keyMask == 0x07FFFFFF) {
156 keyboardDrawCommon(keyboard);
159 while (keyboard->keyMask & (1 << keyboard->selectedCharIndex)) {
161 keyboard->selectedCharIndex++;
164 keyboard->selectedCharIndex = 0;
170 i = keyboard->selectedCharIndex;
173 if ((keyboard->keyMask & (1 << i)) == 0) {
175 keyboardDrawIcon(keyboard->obj.area.x0 + 2 * j * KEYBOARD_KEY_WIDTH,
176 keyboard->obj.area.y0,
181 keyboardDrawChar(keyboard->obj.area.x0 + 2 * j * KEYBOARD_KEY_WIDTH,
182 keyboard->obj.area.y0,
191 if (i == keyboard->selectedCharIndex) {
196 i = (keyboard->selectedCharIndex + 26) % 27;
198 if ((keyboard->keyMask & (1 << i)) == 0) {
201 keyboard->obj.area.x0, keyboard->obj.area.y0,
false, &C_icon_backspace);
204 keyboardDrawChar(keyboard->obj.area.x0, keyboard->obj.area.y0,
false, &keys[i]);
215 if (i == (keyboard->selectedCharIndex + 26) % 27) {
226 keyboardDrawCommon(keyboard);
230 if (keyboard->mode == MODE_NONE) {
231 for (i = 0; i < 3; i++) {
232 uint8_t charIndex = (keyboard->selectedCharIndex + 2 + i) % 3;
233 keyboardDrawIcon(keyboard->obj.area.x0 + 2 * i * KEYBOARD_KEY_WIDTH,
234 keyboard->obj.area.y0,
236 modeIcons[charIndex]);
241 const char *keys = keysByMode[keyboard->mode];
245 for (i = 0; i < 3; i++) {
246 uint8_t charIndex = (keyboard->selectedCharIndex + maxLen - 1 + i) % maxLen;
247 if (keys[charIndex] ==
'\r') {
248 keyboardDrawIcon(keyboard->obj.area.x0 + 2 * i * KEYBOARD_KEY_WIDTH,
249 keyboard->obj.area.y0,
253 else if (keys[charIndex] ==
'\n') {
254 keyboardDrawIcon(keyboard->obj.area.x0 + 2 * i * KEYBOARD_KEY_WIDTH,
255 keyboard->obj.area.y0,
257 &C_icon_validate_10);
259 else if (keys[charIndex] ==
'\b') {
260 keyboardDrawIcon(keyboard->obj.area.x0 + 2 * i * KEYBOARD_KEY_WIDTH,
261 keyboard->obj.area.y0,
266 keyboardDrawChar(keyboard->obj.area.x0 + 2 * i * KEYBOARD_KEY_WIDTH,
267 keyboard->obj.area.y0,
292 if (keyboard->mode == MODE_NONE) {
296 if (keyboard->lettersOnly) {
300 nbMax = strlen(keysByMode[keyboard->mode]) - 1;
304 if (keyboard->mode == MODE_NONE) {
306 keyboard->mode = keyboard->selectedCharIndex;
308 keyboard->selectedCharIndex = 0;
311 if (keyboard->lettersOnly) {
312 if ((keyboard->selectedCharIndex < 26)
313 && ((keyboard->keyMask & (1 << keyboard->selectedCharIndex)) == 0)) {
314 const char *keys = keysByMode[keyboard->mode];
315 keyboard->callback(keys[keyboard->selectedCharIndex]);
322 char key = keysByMode[keyboard->mode][keyboard->selectedCharIndex];
325 keyboard->mode = MODE_NONE;
327 keyboard->selectedCharIndex = 0;
331 else if (key ==
'\n') {
334 else if (key ==
'\b') {
338 keyboard->callback(key);
346 if (keyboard->selectedCharIndex > 0) {
347 keyboard->selectedCharIndex--;
350 keyboard->selectedCharIndex = nbMax;
352 }
while (keyboard->keyMask & (1 << keyboard->selectedCharIndex));
356 if (keyboard->selectedCharIndex < nbMax) {
357 keyboard->selectedCharIndex++;
360 keyboard->selectedCharIndex = 0;
362 }
while (keyboard->keyMask & (1 << keyboard->selectedCharIndex));
378 if (kbd->lettersOnly) {
379 keyboardDrawLettersOnly(kbd);
382 keyboardDrawRegular(kbd);
#define LOG_DEBUG(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
void nbgl_drawIcon(nbgl_area_t *area, nbgl_transformation_t transformation, nbgl_color_map_t color_map, const nbgl_icon_details_t *icon)
Helper function to render an icon directly from its nbgl_icon_details_t structure.
nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area, const char *text, uint16_t textLen, nbgl_font_id_e fontId, color_t fontColor)
This function draws the given single-line text, with the given parameters.
void nbgl_drawRoundedRect(const nbgl_area_t *area, nbgl_radius_t radius, color_t innerColor)
This functions draws a rounded corners rectangle (without border), with the given parameters.
uint8_t nbgl_getCharWidth(nbgl_font_id_e fontId, const char *text)
return the width in pixels of the given UTF-8 character
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
Font screen low-Level driver API, to draw elementary forms.
void nbgl_frontDrawRect(const nbgl_area_t *area)
API to draw all basic graphic objects.
#define BACKSPACE_KEY_INDEX
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD type)
@ BUTTON_BOTH_PRESSED
Sent when both buttons are released.
@ BUTTON_LEFT_PRESSED
Sent when Left button is released.
@ BUTTON_RIGHT_PRESSED
Send when Right button is released.
void nbgl_objDrawKeyboard(nbgl_keyboard_t *kbd)
This function draws a keyboard object.
#define KEYBOARD_KEY_HEIGHT
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define NO_TRANSFORMATION
@ NBGL_BPP_1
1 bit per pixel
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.