LGiki / gnome-shell-extension-simple-system-monitor

🖥️ Show current CPU usage, memory usage and net speed on panel
https://extensions.gnome.org/extension/4506/simple-system-monitor/
GNU General Public License v2.0
48 stars 14 forks source link

Padding issue whn up/down is 0 #14

Closed enebo closed 1 year ago

enebo commented 1 year ago

I had not noticed but this extension does whitespace pad (my original report assumed it wasn't). When up or down are 0 the padding disappears and all the text to the left shifts over while it is 0 but then is padded regularly again once it is >0.

LGiki commented 1 year ago

Thank you for reporting this issue.

Do you use a monospaced font? When using a monospaced font, the text should not shift left and right because each character has the same width. If you use a non-monospaced font, the width of different characters is not fixed, which can cause the text to shift.

For example, when I use the Ubuntu Mono font, the displayed width remains constant regardless of the usage rate or internet speed.

Screenshot from 2023-07-05 19-25-20 Screenshot from 2023-07-05 19-25-45

In fact, when formatting text, this extension uses padStart() to pad values (i.e. the %4d you mentioned). See lines 267 and 275 of the code.

https://github.com/LGiki/gnome-shell-extension-simple-system-monitor/blob/acc9f5c475a93d1627e541f01eb7b9c91f821ba2/src/extension.js#L246-L277

If you are using a monospaced font and experiencing character shifting, please tell me more details as it will be helpful for me.

enebo commented 1 year ago

@LGiki lol. sorry I did not get your comment auto-appended to this tab so once I realized what I was seeing with padding I changed the title and description.

I feel like there may be a special case for 0 for up and down bytes which is not padded? Otherwise the left space padding is fine. I am on a fresh FC install and it appears to be monospaced.

enebo commented 1 year ago

amount.toFixed(digits).toString().padStart(4)

Is there ever a case where the string wiht padStart(4) will just return itself? When I see 0 B/s | 0 B/s there is no padding for those two. It is difficult to try and screenshot because it only happens occasionally and only for a very short time.

enebo commented 1 year ago

Ok for whatever reason it defaulted to sans 14. This is pretty amazing because it truly looked monospaced but I suppose most of the numbers are. Sorry for the noise.

Not sure how the default is chosen though? It is a brand new install and that shows sans 14 in your config menu. I guess that comes from some other location by default?

LGiki commented 1 year ago

The default Sans 14 font comes from src/schemas/org.gnome.shell.extensions.simple-system-monitor.gschema.xml

https://github.com/LGiki/gnome-shell-extension-simple-system-monitor/blob/acc9f5c475a93d1627e541f01eb7b9c91f821ba2/src/schemas/org.gnome.shell.extensions.simple-system-monitor.gschema.xml#L79-L88

Due to the fact that the monospaced fonts installed on different computers vary, I am unable to make a pre-selection for users. Therefore, the choice of font is left to the user. Therefore, I set the default font to Sans 14.

In addition, I can actually set the font to monospace, which in CSS represents a fixed-width font (the gnome extension uses CSS to control its style). But most distros' default monospace font looks ugly, just like the image below. Therefore, I decided to set it to Sans 14 and remind users to use a monospaced font in the extension's page and settings window.

Screenshot from 2023-07-07 09-29-20

enebo commented 1 year ago

@LGiki thanks for the explanation. Fonts are subjective and supporting multiple distros is no doubt hard so I understand.