Skip to content

Commit

Permalink
Update nbgl_layoutAddTouchableBar for subtext rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Feb 27, 2024
1 parent 55680e3 commit ac955ad
Showing 1 changed file with 76 additions and 66 deletions.
142 changes: 76 additions & 66 deletions lib_nbgl/src/nbgl_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,9 @@ int nbgl_layoutAddTouchableBar(nbgl_layout_t *layout, const nbgl_layoutBar_t *ba
nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
layoutObj_t *obj;
nbgl_text_area_t *textArea;
nbgl_image_t *imageLeft = NULL, *imageRight = NULL;
nbgl_container_t *container;
color_t color = (barLayout->inactive != true) ? BLACK : LIGHT_GRAY;
color_t color = (barLayout->inactive != true) ? BLACK : LIGHT_GRAY;
int16_t usedHeight = 0;

LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTouchableBar():\n");
if (layout == NULL) {
Expand All @@ -952,12 +952,16 @@ int nbgl_layoutAddTouchableBar(nbgl_layout_t *layout, const nbgl_layoutBar_t *ba
return -1;
}

// get container children (up to 4)
// get container children (up to 4: text + left+right icons + sub text)
container->children = nbgl_containerPoolGet(4, layoutInt->layer);
container->nbChildren = 0;

container->obj.area.width = AVAILABLE_WIDTH;
container->obj.area.height = TOUCHABLE_BAR_HEIGHT;
container->obj.area.width = AVAILABLE_WIDTH;
container->obj.area.height = TOUCHABLE_BAR_HEIGHT;
if ((barLayout->iconLeft != NULL) && (barLayout->subText != NULL)) {
// Only for Stax???
container->obj.area.height -= 32;
}
container->layout = HORIZONTAL;
container->obj.alignmentMarginX = BORDER_MARGIN;
container->obj.alignment = NO_ALIGNMENT;
Expand All @@ -971,82 +975,88 @@ int nbgl_layoutAddTouchableBar(nbgl_layout_t *layout, const nbgl_layoutBar_t *ba
nbTouchableControls++;
}

// allocate main text because always present
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
textArea->textColor = color;
textArea->text = (barLayout->text != NULL) ? PIC(barLayout->text) : "";
textArea->onDrawCallback = NULL;
textArea->fontId = SMALL_BOLD_FONT;
textArea->wrapping = true;
textArea->obj.area.width = container->obj.area.width;
if (barLayout->iconLeft != NULL) {
// reduce text width accordingly
textArea->obj.area.width -= ((nbgl_icon_details_t *) PIC(barLayout->iconLeft))->width + 16;
}
if (barLayout->iconRight != NULL) {
// reduce text width accordingly
textArea->obj.area.width -= ((nbgl_icon_details_t *) PIC(barLayout->iconRight))->width;
}
textArea->obj.area.height = nbgl_getTextHeightInWidth(
textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
usedHeight = textArea->obj.area.height;
textArea->style = NO_STYLE;
textArea->obj.alignment = MID_LEFT;
textArea->textAlignment = MID_LEFT;
container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
container->nbChildren++;

// allocate left icon if present
if (barLayout->iconLeft != NULL) {
imageLeft = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
nbgl_image_t *imageLeft = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
imageLeft->foregroundColor = color;
imageLeft->buffer = PIC(barLayout->iconLeft);
imageLeft->obj.alignment = MID_LEFT;
imageLeft->obj.alignTo = (nbgl_obj_t *) NULL;
// align at the left of text
imageLeft->obj.alignment = MID_LEFT;
imageLeft->obj.alignTo = (nbgl_obj_t *) textArea;
imageLeft->obj.alignmentMarginX = 16;
container->children[container->nbChildren] = (nbgl_obj_t *) imageLeft;
container->nbChildren++;
}
if (barLayout->text != NULL) {
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
textArea->textColor = color;
textArea->text = PIC(barLayout->text);
textArea->onDrawCallback = NULL;
textArea->fontId = SMALL_BOLD_FONT;
textArea->obj.area.width = container->obj.area.width;
if (barLayout->iconLeft != NULL) {
textArea->obj.area.width -= imageLeft->buffer->width + 12;
}
if (barLayout->iconRight != NULL) {
textArea->obj.area.width -= ((nbgl_icon_details_t *) PIC(barLayout->iconRight))->width;
}
textArea->obj.area.height = container->obj.area.height;
textArea->style = NO_STYLE;
if ((barLayout->iconLeft != NULL) && (barLayout->centered != true)) {
textArea->obj.alignmentMarginX = 12;
}
if (barLayout->iconLeft != NULL) {
textArea->obj.alignTo = (nbgl_obj_t *) imageLeft;
textArea->obj.alignment = MID_RIGHT;
}
else {
textArea->obj.alignTo = (nbgl_obj_t *) NULL;
textArea->obj.alignment = NO_ALIGNMENT;
}
if (barLayout->centered != true) {
textArea->textAlignment = MID_LEFT;
}
else {
textArea->textAlignment = CENTER;

textArea->obj.alignmentMarginX = imageLeft->buffer->width + 16;

if (imageLeft->buffer->height > usedHeight) {
usedHeight = imageLeft->buffer->height;
}
textArea->wrapping = true;
container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
container->nbChildren++;
}
// allocate right icon if present
if (barLayout->iconRight != NULL) {
imageRight = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
nbgl_image_t *imageRight = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
imageRight->foregroundColor = color;
imageRight->buffer = PIC(barLayout->iconRight);
imageRight->obj.alignment = MID_RIGHT;
if (barLayout->text == NULL) {
imageRight->obj.alignTo = (nbgl_obj_t *) NULL;
}
else {
imageRight->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
}
// align at the right of text
imageRight->obj.alignment = MID_RIGHT;
imageRight->obj.alignTo = (nbgl_obj_t *) textArea;

container->children[container->nbChildren] = (nbgl_obj_t *) imageRight;
container->nbChildren++;

if (imageRight->buffer->height > usedHeight) {
usedHeight = imageRight->buffer->height;
}
}
if (barLayout->subText != NULL) {
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);

textArea->textColor = BLACK;
textArea->text = PIC(barLayout->subText);
textArea->textAlignment = MID_LEFT;
textArea->fontId = SMALL_REGULAR_FONT;
textArea->style = NO_STYLE;
textArea->wrapping = true;
textArea->obj.alignment = BOTTOM_LEFT;
textArea->obj.alignmentMarginY = BORDER_MARGIN;
textArea->obj.area.width = container->obj.area.width;
textArea->obj.area.height = nbgl_getTextHeightInWidth(
textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
nbgl_text_area_t *subTextArea
= (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);

subTextArea->textColor = color;
subTextArea->text = PIC(barLayout->subText);
subTextArea->textAlignment = MID_LEFT;
subTextArea->fontId = SMALL_REGULAR_FONT;
subTextArea->style = NO_STYLE;
subTextArea->wrapping = true;
subTextArea->obj.alignment = MID_LEFT;
subTextArea->obj.area.width = container->obj.area.width;
subTextArea->obj.area.height = nbgl_getTextHeightInWidth(subTextArea->fontId,
subTextArea->text,
subTextArea->obj.area.width,
subTextArea->wrapping);
container->children[container->nbChildren] = (nbgl_obj_t *) subTextArea;
container->nbChildren++;
container->obj.area.height += textArea->obj.area.height + 16;
container->obj.area.height += subTextArea->obj.area.height + 4;

// modify alignments to have sub-text under (icon left - text - icon right)
textArea->obj.alignmentMarginY = -(subTextArea->obj.area.height + 4) / 2;
subTextArea->obj.alignmentMarginY = (usedHeight + 4) / 2;
}

// set this new container as child of main container
Expand Down

0 comments on commit ac955ad

Please sign in to comment.