Improved calculation of U.widget_unit that properly considers line
width (pixelsize) no matter what UI scale is selected.
Bug report T92770 is showing a miscalculation of U.widget_unit at 0.99X scale. At this point it is incorrect because the the truncated value of U.dpi_fac becomes zero which results in the same result as if wide lines were selected. We have similar issues just under the 2X value.
Our calculation of widget unit has always been a bit shaky, mostly because of how we calculate the width of lines - saved in pixelsize. That value doesn't change with scale's whole numbers, or even at halfs. Lines get wider at about 80% of the whole number. So if you have "Line width" set to default you get a single pixel result at 1.77X and two pixels at 1.78X.
Current code is calculating the size of U.widget_unit using a formula that is too complex and then tries to compensate for line width changes that are hard to predict. This patch simplifies the calculation and directly incorporates the current line width.
When comparing new against old, note that dpi is actually the DPI divided by pixelsize (line width). dpi_fac takes that value, multiplies by pixelsize (undoes that weirdness to give us real dpi again), then divides by 72. So although the dpi_fac calculation seems to involves line width it is not, but removing the relationship to line width. So this patch using dpi_fac instead of dpi is what is doing most of the simplifying here.
Or, if unsure, just work backwards from the desired result. At 1X scale at 72DPI widget_unit should be 20 with regular width lines, 22 with wide.