5
$\begingroup$

Is there any way to get the size of UI text, such as when using layout.label(text="message")?

I'm trying to create a simple message box popup that displays variable text, but the string is cut in the usual Blender way: "start...end". Which is really cool - its great for condensing UI controls into small spaces. But I'm just wanting to break the lines of text to fit into the box space.

There is a similar question here: Wrap text within a panel but no answers other than hard-coding the font size. And that is my primary question - how to obtain the text or font size? Or how to size the window around it?

I would really like to avoid hard-coding the glyph/text size. I'm assuming Blender does not use exactly the same font size on every display size? And there are also options for the user to set a different font for the interface. So guessing the size would break down pretty easily.

How is making a textbox usually done? Do we have to manually insert line breaks at every so many characters based on the window size? It's hard to imagine Blender implementing such a cool text condensing feature and then not including a simple one like text wrap? Maybe there is some other label() like function?

If not, has anyone managed to write your own text wrap type function that is reliable across different displays and user settings?

$\endgroup$
8
  • $\begingroup$ Possible duplicate of Wrap text within a panel $\endgroup$ Sep 27, 2019 at 14:01
  • $\begingroup$ I found that after posting. It's useful, but he's hard-coding the glyph size to 9 pixels. This seems like a really bad idea. Especially these days, where a screen twice as small can have twice as many pixels. $\endgroup$
    – Robert
    Sep 27, 2019 at 14:21
  • $\begingroup$ I understand that may not be the answer you want, but as far as I understand that is still the best solution. Also related: blender.stackexchange.com/questions/16197/… $\endgroup$ Sep 27, 2019 at 15:13
  • $\begingroup$ Apparently, 5 years ago, even tool-tips didn't auto-wrap. Glad that's over. Hopefully someone out there knows some clever way to get the size of text. Personally, I don't think hard coding the text size is reliable enough to be a solution. $\endgroup$
    – Robert
    Sep 27, 2019 at 15:20
  • $\begingroup$ In that case I would suggest editing the question to move away from the 'message box' topic and focus more closely on the 'font size' topic. I appreciate you do mention this on the first line, but I think the changing of the title and the focusing on the information you added as an edit would help. $\endgroup$ Sep 27, 2019 at 15:28

0

You must log in to answer this question.

Browse other questions tagged .