27#define FIRST_LINE_CHAR_COUNT 10
28#define SECOND_LINE_CHAR_COUNT 9
30#if (SCREEN_WIDTH == 400)
31#define NORMAL_KEY_WIDTH 40
32#define LETTER_OFFSET_Y (((KEYBOARD_KEY_HEIGHT - 32) / 2) & 0xFFC)
33#elif (SCREEN_WIDTH == 480)
34#define NORMAL_KEY_WIDTH 48
35#define LETTER_OFFSET_Y (((KEYBOARD_KEY_HEIGHT - 36) / 2) & 0xFFC)
37#define SHIFT_KEY_WIDTH (NORMAL_KEY_WIDTH + SECOND_LINE_OFFSET)
38#define SECOND_LINE_OFFSET ((SCREEN_WIDTH - (SECOND_LINE_CHAR_COUNT * NORMAL_KEY_WIDTH)) / 2)
39#if defined(TARGET_STAX)
40#define SPACE_KEY_WIDTH 276
41#elif defined(TARGET_FLEX)
42#define SPACE_KEY_WIDTH 336
44#define SWITCH_KEY_WIDTH (SCREEN_WIDTH - SPACE_KEY_WIDTH)
45#define SPECIAL_CHARS_KEY_WIDTH (NORMAL_KEY_WIDTH * 2 + SECOND_LINE_OFFSET)
46#define BACKSPACE_KEY_WIDTH_FULL SHIFT_KEY_WIDTH
47#define BACKSPACE_KEY_WIDTH_DIGITS SPECIAL_CHARS_KEY_WIDTH
48#define BACKSPACE_KEY_WIDTH_LETTERS_ONLY (SCREEN_WIDTH - 7 * NORMAL_KEY_WIDTH)
50#define IS_KEY_MASKED(_index) (keyboard->keyMask & (1 << _index))
63static const char kbd_chars[] =
"qwertyuiopasdfghjklzxcvbnm";
64static const char kbd_chars_upper[] =
"QWERTYUIOPASDFGHJKLZXCVBNM";
66static const char kbd_specials[] =
"[]{}#%^*+=_\\|~<>$`\".,?!\'";
79 if (position->
y < KEYBOARD_KEY_HEIGHT) {
81 i = position->
x / NORMAL_KEY_WIDTH;
83 else if (position->
y < (2 * KEYBOARD_KEY_HEIGHT)) {
90 else if (position->
y < (3 * KEYBOARD_KEY_HEIGHT)) {
94 if (!keyboard->lettersOnly) {
129 else if (!keyboard->lettersOnly && (position->
y < (4 * KEYBOARD_KEY_HEIGHT))) {
147 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
148 rectArea.x0 = keyboard->obj.area.x0;
149 rectArea.y0 = keyboard->obj.area.y0;
150 rectArea.width = keyboard->obj.area.width;
151 rectArea.height = keyboard->obj.area.height;
155 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
156 rectArea.x0 = keyboard->obj.area.x0;
157 rectArea.y0 = keyboard->obj.area.y0;
158 rectArea.width = keyboard->obj.area.width;
159 rectArea.height = VERTICAL_ALIGNMENT;
161 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
163 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
166 if ((keyboard->obj.alignmentMarginY > 0) || (!keyboard->lettersOnly)) {
167 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
171 if ((keyboard->obj.alignmentMarginY > 0) && (!keyboard->lettersOnly)) {
172 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
176 rectArea.backgroundColor = keyboard->borderColor;
177 rectArea.x0 = keyboard->obj.area.x0;
178 rectArea.y0 = keyboard->obj.area.y0;
180 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
181 if (!keyboard->lettersOnly) {
182 rectArea.height += KEYBOARD_KEY_HEIGHT;
194 keyboardDrawCommonLines(keyboard);
197 rectArea.backgroundColor = keyboard->borderColor;
198 rectArea.x0 = keyboard->obj.area.x0;
199 rectArea.y0 = keyboard->obj.area.y0;
201 rectArea.height = KEYBOARD_KEY_HEIGHT;
203 for (i = 0; i < 9; i++) {
204 rectArea.x0 += NORMAL_KEY_WIDTH;
210 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
212 for (i = 10; i < 19; i++) {
213 rectArea.x0 += NORMAL_KEY_WIDTH;
218 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
219 if (!keyboard->lettersOnly) {
223 rectArea.x0 = NORMAL_KEY_WIDTH;
225 for (i = 0; i < 6; i++) {
227 rectArea.x0 += NORMAL_KEY_WIDTH;
229 if (!keyboard->lettersOnly) {
231 rectArea.x0 += NORMAL_KEY_WIDTH;
236 if (!keyboard->lettersOnly) {
237 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
250 keyboardDrawCommonLines(keyboard);
253 rectArea.backgroundColor = keyboard->borderColor;
254 rectArea.x0 = keyboard->obj.area.x0;
255 rectArea.y0 = keyboard->obj.area.y0;
257 rectArea.height = KEYBOARD_KEY_HEIGHT;
259 for (i = 0; i < 9; i++) {
260 rectArea.x0 += NORMAL_KEY_WIDTH;
266 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
268 for (i = 10; i < 19; i++) {
269 rectArea.x0 += NORMAL_KEY_WIDTH;
274 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
276 for (i = 0; i < 5; i++) {
277 rectArea.x0 += NORMAL_KEY_WIDTH;
282 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
295 keys = kbd_chars_upper;
301 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
302 rectArea.y0 = keyboard->obj.area.y0 + LETTER_OFFSET_Y;
304 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
305 rectArea.x0 = keyboard->obj.area.x0;
308 for (i = 0; i < 10; i++) {
309 rectArea.x0 = keyboard->obj.area.x0 + i * NORMAL_KEY_WIDTH;
312 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
317 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
318 for (i = 10; i < 19; i++) {
319 rectArea.x0 = keyboard->obj.area.x0 +
SECOND_LINE_OFFSET + (i - 10) * NORMAL_KEY_WIDTH;
321 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
326 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
328 if (!keyboard->lettersOnly) {
331 rectArea.height = KEYBOARD_KEY_HEIGHT;
333 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2;
339 rectArea.height = VERTICAL_ALIGNMENT;
341 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2;
345 rectArea.width = SHIFT_ICON.width;
346 rectArea.height = SHIFT_ICON.height;
348 rectArea.y0 = (keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
349 + (KEYBOARD_KEY_HEIGHT - rectArea.height) / 2)
353 rectArea.backgroundColor =
WHITE;
363 rectArea.backgroundColor =
WHITE;
370 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
371 for (i = 19; i < 26; i++) {
372 rectArea.x0 = offsetX + (i - 19) * NORMAL_KEY_WIDTH;
374 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
379 rectArea.width = BACKSPACE_ICON.width;
380 rectArea.height = BACKSPACE_ICON.height;
382 rectArea.x0 = offsetX + 7 * NORMAL_KEY_WIDTH;
383 rectArea.y0 = (keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
384 + (KEYBOARD_KEY_HEIGHT - rectArea.height) / 2)
386 if (!keyboard->lettersOnly) {
398 if (!keyboard->lettersOnly) {
400 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 3 + LETTER_OFFSET_Y;
404 SMALL_REGULAR_1BPP_FONT,
429 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
430 rectArea.y0 = keyboard->obj.area.y0 + LETTER_OFFSET_Y;
432 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
433 rectArea.x0 = keyboard->obj.area.x0;
436 for (i = 0; i < 10; i++) {
437 rectArea.x0 = keyboard->obj.area.x0 + i * NORMAL_KEY_WIDTH;
439 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
444 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
445 for (i = 10; i < 19; i++) {
446 rectArea.x0 = keyboard->obj.area.x0 + (i - 10) * NORMAL_KEY_WIDTH +
SECOND_LINE_OFFSET;
448 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
458 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
464 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
468 for (i = 19; i < 24; i++) {
471 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
476 rectArea.width = BACKSPACE_ICON.width;
477 rectArea.height = BACKSPACE_ICON.height;
480 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
481 + (((KEYBOARD_KEY_HEIGHT - rectArea.height) / 2) & 0xFFC);
487 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 3 + LETTER_OFFSET_Y;
501 keyboardDrawLetterGrid(keyboard);
504 keyboardDrawLetters(keyboard);
508 keyboardDrawDigitsGrid(keyboard);
511 keyboardDrawDigits(keyboard);
540 firstPosition->
x -= obj->area.x0;
541 firstPosition->
y -= obj->area.y0;
542 lastPosition->
x -= obj->area.x0;
543 lastPosition->
y -= obj->area.y0;
545 firstIndex = getKeyboardIndex(keyboard, firstPosition);
549 lastIndex = getKeyboardIndex(keyboard, lastPosition);
554 if (lastIndex != firstIndex) {
566 keyboard->needsRefresh =
true;
568 if ((firstIndex < 26) && ((
IS_KEY_MASKED(firstIndex)) == 0)) {
569 keyboard->callback((cur_casing !=
LOWER_CASE) ? kbd_chars_upper[firstIndex]
570 : kbd_chars[firstIndex]);
573 switch (keyboard->casing) {
595 if (firstIndex < 26) {
611 if (firstIndex < 26) {
612 keyboard->callback(kbd_specials[firstIndex]);
630 keyboard->callback(
' ');
648 while (charIndex < 26) {
649 if (index == kbd_chars[charIndex]) {
657 *x = kbd->obj.area.x0 + charIndex * NORMAL_KEY_WIDTH;
658 *y = kbd->obj.area.y0;
663 *y = kbd->obj.area.y0 + KEYBOARD_KEY_HEIGHT;
665 else if (charIndex <
sizeof(kbd_chars)) {
667 *x = kbd->obj.area.x0
670 if (!kbd->lettersOnly) {
675 *x = kbd->obj.area.x0
679 *y = kbd->obj.area.y0 + 2 * KEYBOARD_KEY_HEIGHT;
694 kbd->obj.touchMask = (1 <<
TOUCHED);
696 kbd->needsRefresh =
false;
703 touch_exclude_borders(0);
#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.
uint8_t nbgl_getCharWidth(nbgl_font_id_e fontId, const char *text)
return the width in pixels of the given UTF-8 character
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text (can be multiline)
Font screen low-Level driver API, to draw elementary forms.
void nbgl_frontDrawHorizontalLine(const nbgl_area_t *area, uint8_t mask, color_t lineColor)
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)
keyboardCase_t
Letters casing in which to open/set the keyboard.
@ LOCKED_UPPER_CASE
locked upper case mode
@ LOWER_CASE
lower case mode
@ UPPER_CASE
upper case mode for one character
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD type)
#define DIGITS_SWITCH_KEY_INDEX
@ MODE_SPECIAL
extended special characters mode
@ MODE_DIGITS
digits and some special characters mode
@ MODE_LETTERS
letters mode
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
#define SPECIAL_KEYS_INDEX
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
#define BACKSPACE_KEY_WIDTH_LETTERS_ONLY
void nbgl_keyboardTouchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
function to be called when the keyboard object is touched
#define BACKSPACE_KEY_WIDTH_DIGITS
bool nbgl_keyboardGetPosition(nbgl_keyboard_t *kbd, char index, uint16_t *x, uint16_t *y)
This function gets the position (top-left corner) of the key at the given index. (to be used for Test...
#define SECOND_LINE_OFFSET
void nbgl_objDrawKeyboard(nbgl_keyboard_t *kbd)
This function draws a keyboard object.
#define SPECIAL_CHARS_KEY_WIDTH
#define FIRST_LINE_CHAR_COUNT
#define BACKSPACE_KEY_WIDTH_FULL
#define SECOND_LINE_CHAR_COUNT
#define IS_KEY_MASKED(_index)
bool nbgl_touchGetTouchedPosition(nbgl_obj_t *obj, nbgl_touchStatePosition_t **firstPos, nbgl_touchStatePosition_t **lastPos)
@ POST_REFRESH_FORCE_POWER_ON
Force screen power on after refresh.
nbgl_touchType_t
The different types of Touchscreen events.
#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.
@ BLACK_AND_WHITE_REFRESH
to be used for pure B&W area, when contrast is important
@ FULL_COLOR_REFRESH
to be used for normal refresh
The low level Touchscreen event, coming from driver.
int16_t y
vertical position of the touch (or for a RELEASED the last touched point)
int16_t x
horizontal position of the touch (or for a RELEASED the last touched point)