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

Menu item text gets hidden if it is too long #4019

Closed
matejcik opened this issue Jul 10, 2024 · 14 comments · Fixed by #4226
Closed

Menu item text gets hidden if it is too long #4019

matejcik opened this issue Jul 10, 2024 · 14 comments · Fixed by #4226
Assignees
Labels
bug Something isn't working as expected

Comments

@matejcik
Copy link
Contributor

Describe the bug
problem:
image

after a local hacky fix:
image

offending code:

if area.width() > (Self::ICON_SPACE + Self::TEXT_MARGIN + width) {
//display both icon and text
text_pos = Point::new(area.top_left().x + Self::ICON_SPACE, text_pos.y);
use_text = true;
use_icon = true;
} else if area.width() > (width + Self::TEXT_MARGIN) {
use_text = true;
} else {
//if we can't fit the text, retreat to centering the icon
icon_pos = area.center();
use_icon = true;
}

Why do we even have this? ISTM we should default to showing both icon and text in all cases.

To reproduce

trezorctl btc get-address -n m/44h/0h/0h/0/0 -d
then click the menu

@matejcik matejcik added the bug Something isn't working as expected label Jul 10, 2024
@matejcik
Copy link
Contributor Author

UI tests pass with the local hack, which just unconditionally runs the first branch in the above code. This tells me that the other branches are dead code.

@obrusvit
Copy link
Contributor

obrusvit commented Jul 16, 2024

Why do we even have this? ISTM we should default to showing both icon and text in all cases.

Taken from model_t UI.

UI tests pass with the local hack, which just unconditionally runs the first branch in the above code. This tells me that the other branches are dead code.

Or rather the menu is not walked-through in UI tests?

@ibz
Copy link
Contributor

ibz commented Sep 18, 2024

Indeed, not all menus are tested.

But what is worse? I don't see a case for a menu item with no text - a menu item with incomplete text is certainly better.

So, I see 3 issues here:

  1. Is there a case against showing the text all the time? If not, maybe we should bite the bullet and just do it?
  2. What should we do if we detect that text does not fit? (can we even detect that - easily - in code?) I would argue that - if possible - we should probably just somehow crash (only in testing / emulator?) - that would make the CI pipeline fail, and would make us shorten the strings. Probably a pain, but we would do it once and know that it is done.
  3. Increasing test coverage is something we should be constantly striving for, but unrelated to this issue - so that should not hold us back from actually fixing this issue which is quite bad.

@matejcik
Copy link
Contributor Author

Is there a case against showing the text all the time? If not, maybe we should bite the bullet and just do it?

agreed, or @mmilata @obrusvit do you know of a case where we want to render icon without text?

we should probably just somehow crash (only in testing / emulator?) - that would make the CI pipeline fail, and would make us shorten the strings. Probably a pain, but we would do it once and know that it is done.

we can crash in debug mode, if detecting this is easy at run-time. i'm not sure about that, @obrusvit @mmilata can you advise?

@mmilata
Copy link
Member

mmilata commented Sep 19, 2024

do you know of a case where we want to render icon without text?

nope

we can crash in debug mode, if detecting this is easy at run-time

Seems to be easy in this particular case since we already have the widths in variables? For general case we'd probably have to extend the text renderer. Or perhaps graphics driver to detect drawing off-screen, but that sounds like it will have its own problems.

@ibz
Copy link
Contributor

ibz commented Sep 19, 2024

Seems to be easy in this particular case since we already have the widths in variables?

Right, it was a silly question from my side to start with. That's what the if in question does - detect when the text does not fit and hide the text. So it knows it does not fit.

@ibz
Copy link
Contributor

ibz commented Sep 19, 2024

On the other hand, I am thinking what is the gain of crashing if the menus are not walked-through by the tests / CI anyway.

There is a very slim chance somebody will manually get to that point while testing, and if they do, they will still notice the menu looks bad, no? Crashing at that point will just annoy somebody that is trying to do something unrelated.

So maybe the best way is to simply show the incomplete text?

@Hannsek
Copy link
Contributor

Hannsek commented Sep 19, 2024

So maybe the best way is to simply show the incomplete text?

Most probably, as on every other places.

@matejcik
Copy link
Contributor Author

On the other hand, I am thinking what is the gain of crashing if the menus are not walked-through by the tests / CI anyway.

a lot of tests actually do involve menus

the point of this is to crash if a translation causes a menu item to not render; we don't really check all languages screen by screen, so the crash will indicate that some translation string doesn't fit and we need to change it

@ibz
Copy link
Contributor

ibz commented Sep 19, 2024

a lot of tests actually do involve menus

Yes, but then shouldn't you have seen some UI tests diffs when you disabled the other branches?

@matejcik
Copy link
Contributor Author

Yes, but then shouldn't you have seen some UI tests diffs when you disabled the other branches?

i didn't run all the languages

@ibz
Copy link
Contributor

ibz commented Sep 19, 2024

OK, I'll do that then and see what happens. The way it is now is very bad, anyway.

@ibz ibz self-assigned this Sep 19, 2024
@obrusvit
Copy link
Contributor

Alternative is implementing multi-line texts. As was also desired by Figma designs. See e.g.
image

I think the combination of approaches would be the best if feasible:

  1. try to fit on one line
  2. if fails, try to fit on two lines
  3. if fails, crash in debug, show incomplete text in prod

@Hannsek
Copy link
Contributor

Hannsek commented Sep 24, 2024

@lapohoda I think we can do the multiline items, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants