5

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?

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
Robert
  • 1,265
  • 1
  • 13
  • 29
  • 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. – Robert Sep 27 '19 at 14:21
  • I understand that may not be the answer you want, but as far as I understand that is still the best solution. Also related: https://blender.stackexchange.com/questions/16197/ui-text-box-with-multiple-lines – Ray Mairlot Sep 27 '19 at 15:13
  • 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. – Robert Sep 27 '19 at 15:20
  • 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. – Ray Mairlot Sep 27 '19 at 15:28
  • I can do that. I used that title because I assumed most add-on developers would want a decent message box setup to show the user variable-width text messages. I was wondering how it is usually done. But there are other answers that would work for me. For example, if someone knows how to auto-size the window itself, the text could be roughly broken up with a function, then the window sized to fit around it. – Robert Sep 27 '19 at 15:36
  • That's true, it's just important to focus the question on what you're actually asking. If you want the general answers on how to create a message box, then I think this is a duplicate, if you want more specific answers on font size, then focus on that. – Ray Mairlot Sep 27 '19 at 15:45
  • A solution to that post would have likely resolved my problem. If that makes it a duplicate, then it is. But it doesn't look like there actually is a solution. Or at least not an easy or obvious one. It seems strange to leave this type of feature out, given how dynamic and flexible Blender's UI system is at adapting to resizing. I guess it's something that isn't needed all that often. I might try to find the source code that deals with tool-tips to see if I can figure out anything useful. – Robert Sep 27 '19 at 21:59

0 Answers0