Skip to content

Commit 305d7b6

Browse files
subtitle in switch is optional (nano nbgl)
(cherry picked from commit df864d3)
1 parent 1c128e5 commit 305d7b6

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

lib_nbgl/src/nbgl_layout_nanos.c

Lines changed: 24 additions & 21 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 adds the given obj to the layout
108112
*
@@ -118,10 +122,6 @@ void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
118122
layout->nbChildren++;
119123
}
120124

121-
/**********************
122-
* GLOBAL FUNCTIONS
123-
**********************/
124-
125125
/**
126126
* @brief returns a layout of the given type. The layout is reset
127127
*
@@ -689,24 +689,27 @@ int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switc
689689
textArea->obj.alignmentMarginY = 3;
690690
layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
691691

692-
// add switch description
693-
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
694-
textArea->textColor = WHITE;
695-
textArea->text = PIC(switchLayout->subText);
696-
textArea->textAlignment = CENTER;
697-
textArea->fontId = BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp;
698-
textArea->obj.area.width = AVAILABLE_WIDTH;
699-
textArea->obj.area.height = 2 * nbgl_getFontLineHeight(textArea->fontId);
700-
textArea->wrapping = true;
701-
nbLines = nbgl_getTextNbLinesInWidth(textArea->fontId, textArea->text, AVAILABLE_WIDTH, true);
702-
// if more than 2 lines on screen
703-
if (nbLines > 2) {
704-
// TODO: warning for screenshots
705-
return -1;
692+
if (switchLayout->subText != NULL) {
693+
// add switch description
694+
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
695+
textArea->textColor = WHITE;
696+
textArea->text = PIC(switchLayout->subText);
697+
textArea->textAlignment = CENTER;
698+
textArea->fontId = BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp;
699+
textArea->obj.area.width = AVAILABLE_WIDTH;
700+
textArea->obj.area.height = 2 * nbgl_getFontLineHeight(textArea->fontId);
701+
textArea->wrapping = true;
702+
nbLines
703+
= nbgl_getTextNbLinesInWidth(textArea->fontId, textArea->text, AVAILABLE_WIDTH, true);
704+
// if more than 2 lines on screen
705+
if (nbLines > 2) {
706+
// TODO: warning for screenshots
707+
return -1;
708+
}
709+
textArea->obj.alignment = CENTER;
710+
textArea->obj.alignmentMarginY = 1; // not exactly centered
711+
layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
706712
}
707-
textArea->obj.alignment = CENTER;
708-
textArea->obj.alignmentMarginY = 1; // not exactly centered
709-
layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
710713

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

0 commit comments

Comments
 (0)