Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use textArea to check if strings are displayed outside allowed area #677

Merged
merged 5 commits into from
May 31, 2024

Conversation

dmorais-ledger
Copy link
Contributor

Description

This PR use textArea to check if strings are displayed outside allowed area

@codecov-commenter
Copy link

codecov-commenter commented May 30, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 60.54%. Comparing base (be085f3) to head (a92d414).

Files Patch % Lines
lib_nbgl/src/nbgl_obj.c 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #677      +/-   ##
==========================================
+ Coverage   60.47%   60.54%   +0.06%     
==========================================
  Files          12       12              
  Lines        1723     1726       +3     
==========================================
+ Hits         1042     1045       +3     
  Misses        681      681              
Flag Coverage Δ
unittests 60.54% <81.81%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -97,7 +97,7 @@ const unsigned int C_unicode_characters_count
uint16_t last_nb_lines = 0;
uint16_t last_nb_pages = 0;
bool last_bold_state = false;
void store_string_infos(char *text, uint16_t nb_lines, uint16_t nb_pages, bool bold);
bool hard_caesura = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simple line is used to detect when a hyphenation (caesura) has been forced.
That solves the problem mentioned there: https://ledgerhq.atlassian.net/wiki/spaces/FW/pages/4705091649/NBGL+improvements+suggestions#Gestion-de-la-c%C3%A9sure-sur-les-mots-trop-longs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments in code, it will be easier for next deveoppers

@@ -100,6 +100,9 @@ typedef struct {
/**********************
* VARIABLES
**********************/
#ifdef BUILD_SCREENSHOTS
extern bool verbose;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove, LOG_XXX are already used for verbose

text);
}
#ifdef BUILD_SCREENSHOTS
if (verbose)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove, LOG_XXX is already used for verbose

}
else {
rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - textWidth) / 2;
// Compute the width & number of characters displayed on first line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple code like the following one would be way simplier:
if (nbgl_getTextNbLinesInWidth(textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping) > 1) { LOG_WARN(OBJ_LOGGER, "draw_button: text [%s] is too long for button\n", text); }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here not only make it possible to inform language managers there is an issue with the string, but also make sure that no text is displayed outside of the button, like explained here.
Without the changes I made, a string too long will be displayed like this:
bug_cta

(please note that the characters were displayed not only outside the button, but also outside the front screen, on the side screen - I wonder what the result would be on a real device...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My remark also applies to width... a LOG_WARN is also enough for that... and much simpler ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check my answer here.

if (nb_lines_title > 3) {
nb_lines_title = 3;
}
area.height
Copy link
Contributor

@nroggeman-ledger nroggeman-ledger May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple code like the following one would be way simplier:
if (nbgl_getTextNbLinesInWidth(textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping) > 3) { LOG_WARN(STEP_LOGGER, "nbgl_stepDrawText: text [%s] is too long for title\n", text); }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please STOP with LOG_WARN!!

  • LOG_WARN will not make the build fail, which is necessary if a string contains an error.
  • LOG_WARN will not inform language managers there is an issue with some string(s).

It is necessary to have a kind of CI for strings and this PR will make it possible.

@dmorais-ledger dmorais-ledger merged commit 3fae7ab into master May 31, 2024
192 checks passed
@dmorais-ledger dmorais-ledger deleted the area_strings branch May 31, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants