[Gambas-user] Control widths, fonts, desktop scales, strings and a bad memory

Me adamnt42 at gmail.com
Tue Sep 4 11:52:26 CEST 2018


Well, 12 working hours* later I have found an approximate solution!
1. Get the Control.Font.TextWidth(<text>) 
2. Divide that by the Len(<text>) giving a "magic" number - call it the average character width
3. Calculate a test value being ((Control.Width - Desktop.Scale) / $magic) being the number of average characters that might fit.
4. Subtract a safety margin from the test value (say 6 chars)
5. Truncate the text and add " ..."
6. Bingo! It fits!

Seems to work so far for a dozen or so fonts and font sizes I've tried. I built a little calculator while I was working through this. A 
couple of screen shots are attached.

*That 12 hours Included reading a lot of QT documentation! Talk about never use a sentence when a chapter will do.

Thanks for all the input.
b
-- 
Me <adamnt42 at gmail.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: controls 5_085.png
Type: image/png
Size: 48419 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180904/db7756c7/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: controls 5_086.png
Type: image/png
Size: 47644 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180904/db7756c7/attachment-0003.png>


More information about the User mailing list