Solved Scaling text without squashing it horizontally
-
I need to scale text in my project, but I don't like the way it looks when it's scaled horizontally without being scaled down vertically too.
For example, HISE deals with the line under "30 Divisions of the Octave" like this:
Whereas I'd want it to look more like this:
Is there a way to do achieve this?
-
@cynthasiser If it's in a label change the height of the label. If it's in a paint routine change the height of the area.
-
@d-healey that doesn't change the scaling though? it only changes how much of the text is visible:
(the example is in a label)
-
@cynthasiser Post a snippet
-
@d-healey I'm not sure what the snippet would show? It's standard HISE behaviour (at least on my computer) that text boxes try to scale text horizontally but not vertically.
-
@cynthasiser I see the issue. If changing the font size doesn't help you'll need to draw it in a panel instead of using a label.
-
You get the same horizontal squishing behaviour even in a panel though:
Updating the font size would work, but I'd have to somehow know exactly how many pixels the text would take up to know if I needed to scale it down.
e.g.
If I had a text box that's 200 pixels wide and the sentence "the quick brown fox jumped over the lazy dog" in Arial at 20pt size. Let's pretend this sentence would take up 220 pixels of screen space. I'd want to write a for loop that keeps decreasing the font size until the sentence was less than 200 pixels wide.But how would I check the "pixel width" of a given text string in a given font?
-
@cynthasiser said in Scaling text without squashing it horizontally:
But how would I check the "pixel width" of a given text string in a given font?
g.getStringWidth()
-
@d-healey ah that's great news, I'll give it a go! thank you!
-
Yep, that's perfect, thanks!
-
-
@cynthasiser is it possible to make the text add … at the end of the string when the text is too long? Rather than changing size
-
@mmprod Yes, I think if you use drawFittedText it does this
Edit, yup that's it
HiseSnippet 831.3ocsUstSaCCE1tPPztwzPZO.Q7qvDppEJ2DZZL5kQ0nP0RGh+gbcbZsHwtJ1AnZhGk8Nt2fsiiaokQEWpzhpR74l8WOmuywsSjTlRISP3BcFNfgvu0wenP2uZeBWfZVCgemSKhRyRbspNZ3.hRwBPX7Be0n.meQT1yu+7QjHhfxlnBgNWxorS3wb8DssO7a7nnFj.VGd7TdW4vlTonpLRlB3YAmRnAD5UjdrSIF2x4fNln5ivezoKoaIBMLbmM6tWXoJat8lc6VInBno6t6u+9gaWlr8V6RoH7R0C3ZYhulnYJXSORFLzuu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