codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.66k stars 395 forks source link

Manifestly incorrect code in stringWidth #3771

Closed ddyer0 closed 6 months ago

ddyer0 commented 6 months ago

in com.codename1.ui.Font

public int stringWidth(String str) { // this happens often for icons without text and can cost a bit more in the native platform if(str == null || str.length() == 0) { return 0; } // Its common to use a space character to create a label that takes up space but the value // of string width in this case becomes less important if(str == " ") { return 5; } return Display.impl.stringWidth(font, str); }

In some earlier universe, it might have been sensible to simply declare a space as 5 pixels...

shai-almog commented 6 months ago

You know you can physically link to the code here... If you will read the comment you will understand why this is correct.