22#include "os_io_seph_cmd.h"
23#include "os_io_seph_ux.h"
25#include "os_helpers.h"
30#if defined(TARGET_FLEX) || defined(TARGET_APEX)
31#define USE_PARTIAL_BUTTONS 1
37#ifdef USE_PARTIAL_BUTTONS
43#ifndef USE_PARTIAL_BUTTONS
58#if defined(TARGET_STAX)
59#define TEXT_ENTRY_NORMAL_HEIGHT 64
60#define TEXT_ENTRY_COMPACT_HEIGHT 64
61#define BOTTOM_NORMAL_MARGIN 24
62#define BOTTOM_CONFIRM_MARGIN 24
63#define BOTTOM_COMPACT_MARGIN 24
64#define TOP_NORMAL_MARGIN 20
65#define TOP_CONFIRM_MARGIN 20
66#define TOP_COMPACT_MARGIN 20
67#define TITLE_ENTRY_MARGIN_Y 4
68#define TEXT_ENTRY_FONT LARGE_MEDIUM_1BPP_FONT
70#define NUMBER_TEXT_SPACE 8
71#define NUMBER_WIDTH 56
72#define DELETE_ICON C_Close_32px
73#elif defined(TARGET_FLEX)
74#define TEXT_ENTRY_NORMAL_HEIGHT 72
75#define TEXT_ENTRY_COMPACT_HEIGHT 56
76#define BOTTOM_NORMAL_MARGIN 24
77#define BOTTOM_CONFIRM_MARGIN 24
78#define BOTTOM_COMPACT_MARGIN 12
79#define TOP_NORMAL_MARGIN 20
80#define TOP_CONFIRM_MARGIN 20
81#define TOP_COMPACT_MARGIN 12
82#define TITLE_ENTRY_MARGIN_Y 4
83#define TEXT_ENTRY_FONT LARGE_MEDIUM_1BPP_FONT
85#define NUMBER_TEXT_SPACE 8
86#define NUMBER_WIDTH 56
87#define DELETE_ICON C_Close_40px
88#elif defined(TARGET_APEX)
89#define TEXT_ENTRY_NORMAL_HEIGHT 40
90#define TEXT_ENTRY_COMPACT_HEIGHT 40
91#define BOTTOM_NORMAL_MARGIN 20
92#define BOTTOM_CONFIRM_MARGIN 16
93#define BOTTOM_COMPACT_MARGIN 8
94#define TOP_NORMAL_MARGIN 20
95#define TOP_CONFIRM_MARGIN 12
96#define TOP_COMPACT_MARGIN 8
97#define TITLE_ENTRY_MARGIN_Y 4
98#define TEXT_ENTRY_FONT SMALL_BOLD_FONT
100#define NUMBER_TEXT_SPACE 4
101#define NUMBER_WIDTH 32
102#define DELETE_ICON C_Close_Tiny_24px
105#ifdef USE_PARTIAL_BUTTONS
106#if defined(TARGET_FLEX)
107#define LEFT_HALF_ICON C_left_half_64px
108#define SUGGESTION_CONTAINER_HEIGHT 92
109#elif defined(TARGET_APEX)
110#define LEFT_HALF_ICON C_half_disc_left_40px_1bpp
111#define SUGGESTION_CONTAINER_HEIGHT 56
116#define SUGGESTION_BUTTONS_SIDE_MARGIN BORDER_MARGIN
117#if defined(TARGET_APEX)
118#define LINE_THICKNESS 1
119#define LINE_COLOR BLACK
121#define LINE_THICKNESS 2
122#define LINE_COLOR LIGHT_GRAY
137static nbgl_button_t *choiceButtons[NB_MAX_SUGGESTION_BUTTONS];
138static char numText[5];
139static uint8_t nbActiveButtons;
140#ifdef USE_PARTIAL_BUTTONS
152 uint8_t currentLeftButtonIndex)
154 bool needRefresh =
false;
159 && (currentLeftButtonIndex
160 < (uint32_t) (nbActiveButtons - NB_MAX_VISIBLE_SUGGESTION_BUTTONS))) {
163 currentLeftButtonIndex += NB_MAX_VISIBLE_SUGGESTION_BUTTONS;
165 = (
nbgl_obj_t *) choiceButtons[currentLeftButtonIndex];
167 for (i = 1; i < NB_MAX_VISIBLE_SUGGESTION_BUTTONS; i++) {
168 if (currentLeftButtonIndex < (uint32_t) (nbActiveButtons - i)) {
170 = (
nbgl_obj_t *) choiceButtons[currentLeftButtonIndex + i];
176 page = currentLeftButtonIndex / NB_MAX_VISIBLE_SUGGESTION_BUTTONS;
180 && (currentLeftButtonIndex > (NB_MAX_VISIBLE_SUGGESTION_BUTTONS - 1))) {
183 currentLeftButtonIndex -= NB_MAX_VISIBLE_SUGGESTION_BUTTONS;
184 for (i = 0; i < NB_MAX_VISIBLE_SUGGESTION_BUTTONS; i++) {
186 = (
nbgl_obj_t *) choiceButtons[currentLeftButtonIndex + i];
188 page = currentLeftButtonIndex / NB_MAX_VISIBLE_SUGGESTION_BUTTONS;
206#ifndef USE_PARTIAL_BUTTONS
228 indicator->activePage = page;
230#ifdef USE_PARTIAL_BUTTONS
232 if (currentLeftButtonIndex > 0) {
233 container->children[LEFT_HALF_INDEX] = (
nbgl_obj_t *) partialButtonImages[0];
236 container->children[LEFT_HALF_INDEX] = NULL;
239 if (currentLeftButtonIndex < (nbActiveButtons - NB_MAX_VISIBLE_SUGGESTION_BUTTONS)) {
240 container->children[RIGHT_HALF_INDEX] = (
nbgl_obj_t *) partialButtonImages[1];
243 container->children[RIGHT_HALF_INDEX] = NULL;
258 if ((container->nbChildren < 2) || (container->children[1]->type !=
CONTAINER)) {
265 && (nbActiveButtons > NB_MAX_VISIBLE_SUGGESTION_BUTTONS)) {
267 while (i < (uint32_t) nbActiveButtons) {
275 if (i < (uint32_t) nbActiveButtons) {
276 if (updateSuggestionButtons(suggestionsContainer, eventType, i)) {
277 os_io_seph_cmd_piezo_play_tune(TUNE_TAP_CASUAL);
299 uint16_t textEntryHeight = (compactMode ? TEXT_ENTRY_COMPACT_HEIGHT : TEXT_ENTRY_NORMAL_HEIGHT);
300 bool withCross = ((text != NULL) && (strlen(text) > 0));
304 mainContainer->nbChildren = 2;
307 mainContainer->obj.alignment =
CENTER;
312 textArea->textColor =
BLACK;
313 textArea->text = title;
314 textArea->textAlignment =
CENTER;
315 textArea->fontId = SMALL_REGULAR_FONT;
316 textArea->wrapping =
true;
320 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
321 mainContainer->children[0] = (
nbgl_obj_t *) textArea;
322 mainContainer->obj.area.height = textArea->obj.area.height + TITLE_ENTRY_MARGIN_Y;
327 container->nbChildren = 4;
335 textArea->textColor =
BLACK;
336 snprintf(numText,
sizeof(numText),
"%d.", number);
337 textArea->text = numText;
338 textArea->textAlignment =
CENTER;
339 textArea->fontId = TEXT_ENTRY_FONT;
340 textArea->obj.area.width = NUMBER_WIDTH;
349 textArea->textColor =
BLACK;
350 textArea->text = text;
352 textArea->fontId = TEXT_ENTRY_FONT;
353 textArea->obj.area.width =
AVAILABLE_WIDTH - DELETE_ICON.width - NUMBER_TEXT_SPACE;
355 textArea->obj.alignmentMarginX = NUMBER_TEXT_SPACE;
356 textArea->obj.alignTo = container->children[0];
358 textArea->obj.area.width -= textArea->obj.alignmentMarginX + NUMBER_WIDTH;
364 textArea->autoHideLongLine =
true;
367 container->obj.area.height = textEntryHeight;
371 image->buffer = &DELETE_ICON;
373 image->foregroundColor = withCross ?
BLACK :
WHITE;
379 image->obj.alignTo = container->children[
TEXT_INDEX];
380 image->obj.alignmentMarginX = NUMBER_TEXT_SPACE;
381 image->obj.touchMask = (1 <<
TOUCHED);
398 mainContainer->children[1] = (
nbgl_obj_t *) container;
399 mainContainer->obj.area.height += container->obj.area.height;
401 return mainContainer;
405 uint8_t nbUsedButtons,
406 const char **buttonTexts,
407 int firstButtonToken,
413 nbActiveButtons = nbUsedButtons;
415 suggestionsContainer->layout =
VERTICAL;
416 suggestionsContainer->obj.area.width = SCREEN_WIDTH;
417#ifndef USE_PARTIAL_BUTTONS
419 suggestionsContainer->obj.area.height = 2 * SMALL_BUTTON_HEIGHT +
INTERNAL_MARGIN + 28;
422 suggestionsContainer->obj.area.height = SUGGESTION_CONTAINER_HEIGHT;
425 suggestionsContainer->children
429 suggestionsContainer->obj.alignmentMarginY = BOTTOM_NORMAL_MARGIN;
435 for (
int i = 0; i < NB_MAX_SUGGESTION_BUTTONS; i++) {
437 layoutInt, (
nbgl_obj_t *) choiceButtons[i], firstButtonToken + i, tuneId);
442 choiceButtons[i]->innerColor =
BLACK;
443 choiceButtons[i]->borderColor =
BLACK;
444 choiceButtons[i]->foregroundColor =
WHITE;
445 choiceButtons[i]->obj.area.width
447 choiceButtons[i]->obj.area.height = SMALL_BUTTON_HEIGHT;
448 choiceButtons[i]->radius = SMALL_BUTTON_RADIUS_INDEX;
449 choiceButtons[i]->fontId = SMALL_BOLD_1BPP_FONT;
450 choiceButtons[i]->text = buttonTexts[i];
451 choiceButtons[i]->obj.touchMask = (1 <<
TOUCHED);
454 if (i <
MIN(NB_MAX_VISIBLE_SUGGESTION_BUTTONS, nbActiveButtons)) {
463 indicator->activePage = 0;
464 indicator->nbPages = (nbActiveButtons + NB_MAX_VISIBLE_SUGGESTION_BUTTONS - 1)
465 / NB_MAX_VISIBLE_SUGGESTION_BUTTONS;
466 indicator->obj.area.width
467 = (indicator->nbPages < 3) ? STEPPER_2_PAGES_WIDTH : STEPPER_N_PAGES_WIDTH;
471#ifdef USE_PARTIAL_BUTTONS
475 partialButtonImages[0]->buffer = &LEFT_HALF_ICON;
476 partialButtonImages[0]->obj.alignment =
TOP_LEFT;
477 partialButtonImages[0]->foregroundColor =
BLACK;
479 partialButtonImages[1]->buffer = &LEFT_HALF_ICON;
480 partialButtonImages[1]->obj.alignment =
TOP_RIGHT;
481 partialButtonImages[1]->foregroundColor =
BLACK;
483 updateSuggestionButtons(suggestionsContainer, 0, 0);
486 return suggestionsContainer;
506 button->obj.alignmentMarginY = compactMode ? BOTTOM_COMPACT_MARGIN : BOTTOM_CONFIRM_MARGIN;
508 button->foregroundColor =
WHITE;
510 button->innerColor =
BLACK;
511 button->borderColor =
BLACK;
512 button->obj.touchMask = (1 <<
TOUCHED);
519 button->text = PIC(text);
520 button->fontId = SMALL_BOLD_1BPP_FONT;
523 button->radius = BUTTON_RADIUS;
545 if (layout == NULL) {
555 keyboard->obj.area.width = SCREEN_WIDTH;
556 keyboard->obj.area.height = 3 * KEYBOARD_KEY_HEIGHT;
558 keyboard->obj.area.height += KEYBOARD_KEY_HEIGHT;
561 keyboard->obj.alignmentMarginY = 56;
565 keyboard->callback = PIC(kbdInfo->
callback);
567 keyboard->mode = kbdInfo->
mode;
568 keyboard->keyMask = kbdInfo->
keyMask;
569 keyboard->casing = kbdInfo->
casing;
579 = keyboard->obj.area.height + keyboard->obj.alignmentMarginY;
618 if (layout == NULL) {
625 if ((keyboard == NULL) || (keyboard->obj.type !=
KEYBOARD)) {
628 keyboard->keyMask = keyMask;
630 keyboard->casing = casing;
651 if (layout == NULL) {
658 if ((keyboard == NULL) || (keyboard->obj.type !=
KEYBOARD)) {
661 if (keyboard->needsRefresh) {
662 keyboard->needsRefresh =
false;
696 uint8_t enteredTextIndex = (layoutInt->
container->nbChildren == 2) ? 0 : 1;
697 bool compactMode = ((layoutInt->
container->children[enteredTextIndex + 1] != NULL)
698 && (layoutInt->
container->children[enteredTextIndex + 1]->type ==
BUTTON)
699 && (layoutInt->
container->nbChildren == 3));
702 if (layout == NULL) {
708 container = addTextEntry(layoutInt, NULL, text, numbered, number, token, compactMode);
713 if (layoutInt->
container->children[enteredTextIndex + 1] != NULL) {
714 if (layoutInt->
container->children[enteredTextIndex + 1]->type ==
BUTTON) {
717 container->obj.alignmentMarginY
718 -= (button->obj.area.height + button->obj.alignmentMarginY
719 + (compactMode ? TOP_COMPACT_MARGIN : TOP_NORMAL_MARGIN))
725 container->obj.alignmentMarginY
726 -= (suggestionContainer->obj.area.height + suggestionContainer->obj.alignmentMarginY
727 + (compactMode ? TOP_COMPACT_MARGIN : TOP_NORMAL_MARGIN))
733 if (layoutInt->
container->nbChildren == 3) {
734 container->obj.alignmentMarginY += layoutInt->
container->children[0]->area.height / 2;
764 uint8_t enteredTextIndex = (layoutInt->
container->nbChildren == 2) ? 0 : 1;
767 if (layout == NULL) {
774 if ((container == NULL) || (container->obj.type !=
CONTAINER)) {
778 if ((textArea == NULL) || (textArea->obj.type !=
TEXT_AREA)) {
781 textArea->text = text;
790 snprintf(numText,
sizeof(numText),
"%d.", number);
791 textArea->text = numText;
820 uint8_t enteredTextIndex = (layoutInt->
container->nbChildren == 2) ? 0 : 1;
821 bool compactMode = (layoutInt->
container->nbChildren == 3);
824 if (layout == NULL) {
828 button = addConfirmationButton(layoutInt, active, text, token, tuneId, compactMode);
831 if (layoutInt->
container->children[enteredTextIndex] != NULL) {
833 ->obj.alignmentMarginY
834 -= (button->obj.area.height + button->obj.alignmentMarginY
835 + (compactMode ? TOP_COMPACT_MARGIN : TOP_NORMAL_MARGIN))
860 uint8_t enteredTextIndex = (layoutInt->
container->nbChildren == 2) ? 0 : 1;
865 if (layout == NULL) {
871 if ((button == NULL) || (button->obj.type !=
BUTTON)) {
877 button->innerColor =
BLACK;
878 button->borderColor =
BLACK;
879 button->obj.touchMask = (1 <<
TOUCHED);
905 if (layout == NULL) {
909 textEntryContainer = addTextEntry(layoutInt,
922 = addSuggestionButtons(layoutInt,
937 textEntryContainer->obj.alignmentMarginY
938 -= (suggestionsContainer->obj.area.height + suggestionsContainer->obj.alignmentMarginY
948 (content->
title != NULL));
951 textEntryContainer->obj.alignmentMarginY
952 -= (button->obj.area.height + button->obj.alignmentMarginY
953 + ((content->
title != NULL) ? TOP_COMPACT_MARGIN : TOP_CONFIRM_MARGIN))
956 return layoutInt->
container->obj.area.height;
977 if (layout == NULL) {
988 snprintf(numText,
sizeof(numText),
"%d.", content->
number);
994 textArea->text = content->
text;
999 if ((textArea->text != NULL) && (strlen(textArea->text) > 0)) {
1000 if (image->foregroundColor ==
WHITE) {
1001 image->foregroundColor =
BLACK;
1006 if (image->foregroundColor ==
BLACK) {
1007 image->foregroundColor =
WHITE;
1019 for (
int i = 0; i < NB_MAX_SUGGESTION_BUTTONS; i++) {
1022 if (i <
MIN(NB_MAX_VISIBLE_SUGGESTION_BUTTONS, nbActiveButtons)) {
1030 suggestionsContainer->forceClean =
true;
1035 indicator->nbPages = (nbActiveButtons + NB_MAX_VISIBLE_SUGGESTION_BUTTONS - 1)
1036 / NB_MAX_VISIBLE_SUGGESTION_BUTTONS;
1037 indicator->activePage = 0;
1038 updateSuggestionButtons(suggestionsContainer, 0, 0);
1045 if ((button == NULL) || (button->obj.type !=
BUTTON)) {
1051 button->innerColor =
BLACK;
1052 button->borderColor =
BLACK;
1053 button->obj.touchMask = (1 <<
TOUCHED);
#define LOG_DEBUG(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
uint16_t nbgl_getSingleLineTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text until the first or \0 is encountered
uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId)
return the height in pixels of the font with the given font ID
uint16_t nbgl_getTextHeightInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
return the height of the given multiline text, with the given font.
Font screen low-Level driver API, to draw elementary forms.
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the main container
layoutObj_t * layoutAddCallbackObj(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj, uint8_t token, tune_index_e tuneId)
void * nbgl_layout_t
type shared externally
@ KEYBOARD_WITH_BUTTON
text entry area + confirmation button
@ KEYBOARD_WITH_SUGGESTIONS
text entry area + suggestion buttons
Internal functions/constants of NBGL layout layer.
@ SWIPE_USAGE_SUGGESTIONS
#define KEYBOARD_FOOTER_TYPE
int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask, bool updateCasing, keyboardCase_t casing)
Updates an existing keyboard on bottom of the screen, with the given configuration.
int nbgl_layoutAddKeyboard(nbgl_layout_t *layout, const nbgl_layoutKbd_t *kbdInfo)
Creates a keyboard on bottom of the screen, with the given configuration.
bool keyboardSwipeCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
int nbgl_layoutAddKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardContent_t *content)
Adds an area containing a potential title, a text entry and either confirmation or suggestion buttons...
int nbgl_layoutAddEnteredText(nbgl_layout_t *layout, bool numbered, uint8_t number, const char *text, bool grayedOut, int offsetY, int token)
Adds a "text entry" area under the previously entered object. This area can be preceded (beginning of...
int nbgl_layoutUpdateConfirmationButton(nbgl_layout_t *layout, uint8_t index, bool active, const char *text)
Updates an existing black full width confirmation button on top of the previously added keyboard.
int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout, uint8_t index, bool numbered, uint8_t number, const char *text, bool grayedOut)
Updates an existing "text entry" area, created with nbgl_layoutAddEnteredText()
#define SUGGESTION_BUTTONS_SIDE_MARGIN
int nbgl_layoutUpdateKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardContent_t *content)
Updates an area containing a potential title, a text entry and either confirmation or suggestion butt...
int nbgl_layoutAddConfirmationButton(nbgl_layout_t *layout, bool active, const char *text, int token, tune_index_e tuneId)
Adds a black full width confirmation button on top of the previously added keyboard.
bool nbgl_layoutKeyboardNeedsRefresh(nbgl_layout_t *layout, uint8_t index)
function called to know whether the keyboard has been redrawn and needs a refresh
API to draw all basic graphic objects.
struct PACKED__ nbgl_line_s nbgl_line_t
struct to represent a vertical or horizontal line
struct PACKED__ nbgl_navigation_bar_s nbgl_page_indicator_t
struct to represent a navigation bar (PAGE_INDICATOR type) There can be up to 5 page indicators,...
struct PACKED__ nbgl_text_area_s nbgl_text_area_t
struct to represent a text area (TEXT_AREA type)
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
nbgl_obj_t ** nbgl_containerPoolGet(uint8_t nbObjs, uint8_t layer)
Gets a new container from the pool, with the given number of obj pointers.
keyboardCase_t
Letters casing in which to open/set the keyboard.
nbgl_obj_t * nbgl_objPoolGet(nbgl_obj_type_t type, uint8_t layer)
Gets a new graphic object from the pool, with the given type. The type field of the object is set.
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD type)
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
This functions refreshes the actual screen on display with what has changed since the last refresh,...
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
int nbgl_objPoolGetArray(nbgl_obj_type_t type, uint8_t nbObjs, uint8_t layer, nbgl_obj_t **objArray)
Gets nbObjects new graphic object from the pool, with the given type, for the given layer (screen)....
struct PACKED__ nbgl_button_s nbgl_button_t
struct to represent a button (BUTTON type) that can contain a text and/or an icon
#define INACTIVE_TEXT_COLOR
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
@ CURRENT_INDICATOR
only current page dash is black
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
nbgl_touchType_t
The different types of Touchscreen events.
@ VERTICAL
from top to bottom
@ HORIZONTAL
from left to right
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
@ BUTTON
Rounded rectangle button with icon and/or text.
@ PAGE_INDICATOR
horizontal bar to indicate position within pages
@ LINE
Vertical or Horizontal line.
@ CONTAINER
Empty container.
@ TEXT_AREA
Area to contain text line(s)
#define NO_TRANSFORMATION
@ FULL_COLOR_PARTIAL_REFRESH
to be used for small partial refresh (radio buttons, switches)
Structure containing all information about the current layout.
nbgl_container_t * footerContainer
container used to store footer (buttons, nav....)
uint8_t layer
layer in screen stack
nbgl_swipe_usage_t swipeUsage
nbgl_container_t * container
nbgl_layoutFooterType_t footerType
type of footer
nbgl_obj_t ** children
children for main screen
This structure contains info to build a keyboard with nbgl_layoutAddKeyboard()
bool lettersOnly
if true, only display letter keys and Backspace
keyboardCallback_t callback
function called when an active key is pressed
keyboardMode_t mode
keyboard mode to start with
keyboardCase_t casing
keyboard casing mode (lower, upper once or upper locked)
This structure contains info to build a keyboard content (controls that are linked to keyboard)
uint8_t number
if numbered is true, number used to build 'number.' text
const char * text
already entered text
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
nbgl_layoutKeyboardContentType_t type
type of content
nbgl_layoutSuggestionButtons_t suggestionButtons
nbgl_layoutConfirmationButton_t confirmationButton
used if type is KEYBOARD_WITH_SUGGESTIONS
const char * title
centered title explaining the screen
bool numbered
if set to true, the text is preceded on the left by 'number.'