mate-desktop / mate-screensaver

MATE screen saver and locker
https://mate-desktop.org
GNU General Public License v2.0
48 stars 40 forks source link

mate-screensaver-preferences: Improve and cleanup time scale formatting #295

Closed cwendling closed 3 months ago

cwendling commented 3 months ago

Formatting the value of a GtkScale is actually pretty tricky, because the lower and upper values representations are used to compute the size required do draw all values. This means the representations for the lower and upper bounds have to be at least as big as any other possible value, failing that leads to wrapping and overflowing of the value representation.

This was previously partially done in time_to_string_text(), but not only wasn't it comprehensive (it only did so for whole minutes < 59), but it also meant that if one of the bounds wasn't a whole minute it didn't have the desired effect.

Fix this by extracting the code for padding the string outside of the time formatting, and pad the resulting format string whatever it is.

Also improve the padding to try and be less visible, by padding to the side where we don't want the value to align (e.g. pad on the right if we want the value left-aligned).

This is still basically a sad hack, but there doesn't seem to be a better way to do this when neither the lower nor upper bound is necessarily the largest value.


To test, verify that the time value displayed over the sliders never wrap, and is entirely visible. Note that as this unfortunately depends on the rendered width of the text we give, it's locale dependent, and there is no real perfect solution. Hopefully using EM space will be enough for every possible option, but there could be corner cases I didn't see. I tested with a few different locales, including some RTL, and it seemed fine, but understand that I don't read those so my tests for those should be taken with a grain of salt.