ListBox font size auto-fit on 4k screens

Started by Tarquiscani, 12 October 2018, 01:29:09

Tarquiscani

Hello, I did a search but I couldn't find anything, or maybe I didn't hang on enough.
The ListBox is the really one perfect thing I need, but I'm on a small 17'' 4k screen and the automatic fit of the text doesn't seem to work. I don't know if something is changed since this answer:
QuoteThe text size can't be changed directly in ListBox. You have to set the height of the items with setItemHeight. (The text size is internally set to 0.8 * itemHeight)
I did this so that you can easily predict the amount of visible items. If the height is 200 and you set the item height to 20 then there are 10 visible items. If you would be setting the text height then you have no idea how many items fit (since there has to be a small space between the lines).



What is a possible solution?

texus

A lot has changed since that answer.
To keep all widgets consistent, there is now a global text size that widgets use by default, instead of each widget having a slightly different text size. All widgets now do have a setTextSize function to use something other than the global value.

How are you scaling the list box? At some point you would be calling setItemHeight, I think you could just call setTextSize there as well with a value that is 0.8 times what you passed to setItemHeight.
Alternatively you can still make the text scale automatically in ListBox by calling listBox->setTextSize(0), which will result in the old behavior of the text being scaled automatically. But personally I would just call setTextSize each time you call setItemHeight, then you can choose the factor "0.8" yourself based on what text size you want and not rely on the exact number that TGUI used internally.

Tarquiscani

I completely missed setTextSize :D
Thanks a lot and sorry for the silly question