Scaling font size for text nodes

is there a way to easily change the size of a text node without changing the font’s text size?
i know that changing the scale of the node will change the size, however that comes with a few problems, that being that the actual size versus the listed size is not the same.
it also makes using a function like gui.get_text_metrics_from_node very hard to use, as it also uses the unscaled text size.
this makes creating UI layouts that depend on the size of text hard (example, a text button that scales its text if it’s too large, perhaps due to localization differences)

is there something i am missing, or is it more or less a necessary evil?

A text node, like any gui node, has a size and you should be able to use gui.set_size() to change the size of the node.

But I guess that is not what you are asking for? The other options is to scale the node, or change to a different font on the node.

1 Like

you should be able to use gui.set_size() to change the size of the node.

changing the size of a text node doesn’t do anything to the text node unless you enable line breaking, since the text node will happily overflow

The other options is to scale the node

a problem with scaling is that it makes the text look blurry or pixelated (depending on the scaling mode used). i know there are workarounds to this.

change to a different font on the node.

making a separate font file for every possible size is tedious, and is not applicable to dynamically scalable UIs.
by size i refer to the size of the text on screen

Isn’t this what you are looking to do? Just change the size of the node without changing the font. If so then I think gui.set_size() should work.

i want the text node to be visibly larger, the size of the node has nothing to do with that
the only 2 ways to do that that i know of are creating more font files (unreasonable to make 30+ for each possible size, for each font) or increasing the scale (isn’t factored into the node’s size or get text size function, making using those a mess) - both methods are flawed in their own manner and i want to know if there’s a better way that i’m missing

Then why not make a font with a large size and the scale the node down to whatever size you want?

Surely this depends on the font? If you use a distance field font you should be able to scale it without impacting the look.

Ah okay, I had your question backwards. Britzl’s suggestion of using a distance field font is a good one. They are built for scaling. Think SVG vs PNG, vector image vs raster image. Jhonny’s suggestion is also good. Scaling is usually better done with a large base image.

…Additionally, if you want the true size of the node after scaling, simply multiply the base size by the scaling factor. No matter what, scaling graphics has its tradeoffs.

2 Likes