Skip to content

Commit b663c7a

Browse files
subtitle in switch is optional (nano nbgl)
(cherry picked from commit df864d3)
1 parent b360269 commit b663c7a

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

lib_nbgl/src/nbgl_layout_nanos.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ static void buttonCallback(nbgl_screen_t *screen, nbgl_buttonEvent_t buttonEvent
103103
}
104104
}
105105

106+
/**********************
107+
* GLOBAL FUNCTIONS
108+
**********************/
109+
106110
/**
107111
* @brief compute the max width of the first line of the given text fitting in maxWidth
108112
*
@@ -756,24 +760,27 @@ int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switc
756760
textArea->obj.alignmentMarginY = 3;
757761
layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
758762

759-
// add switch description
760-
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
761-
textArea->textColor = WHITE;
762-
textArea->text = PIC(switchLayout->subText);
763-
textArea->textAlignment = CENTER;
764-
textArea->fontId = BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp;
765-
textArea->obj.area.width = AVAILABLE_WIDTH;
766-
textArea->obj.area.height = 2 * nbgl_getFontLineHeight(textArea->fontId);
767-
textArea->wrapping = true;
768-
nbLines = nbgl_getTextNbLinesInWidth(textArea->fontId, textArea->text, AVAILABLE_WIDTH, true);
769-
// if more than 2 lines on screen
770-
if (nbLines > 2) {
771-
// TODO: warning for screenshots
772-
return -1;
763+
if (switchLayout->subText != NULL) {
764+
// add switch description
765+
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
766+
textArea->textColor = WHITE;
767+
textArea->text = PIC(switchLayout->subText);
768+
textArea->textAlignment = CENTER;
769+
textArea->fontId = BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp;
770+
textArea->obj.area.width = AVAILABLE_WIDTH;
771+
textArea->obj.area.height = 2 * nbgl_getFontLineHeight(textArea->fontId);
772+
textArea->wrapping = true;
773+
nbLines
774+
= nbgl_getTextNbLinesInWidth(textArea->fontId, textArea->text, AVAILABLE_WIDTH, true);
775+
// if more than 2 lines on screen
776+
if (nbLines > 2) {
777+
// TODO: warning for screenshots
778+
return -1;
779+
}
780+
textArea->obj.alignment = CENTER;
781+
textArea->obj.alignmentMarginY = 1; // not exactly centered
782+
layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
773783
}
774-
textArea->obj.alignment = CENTER;
775-
textArea->obj.alignmentMarginY = 1; // not exactly centered
776-
layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
777784

778785
button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, ((nbgl_layoutInternal_t *) layout)->layer);
779786
button->foregroundColor = BLACK;

0 commit comments

Comments
 (0)