def wrap_text(text: str, width: int) -> List[str]:
'''
Wrap the given text to the given width.
Args:
width: The maximum pixel width of each row.
text: The text to be split and returned.
Returns:
A list of the split up text and empty space if necessary.
'''
return_text = []
row_text = ''
system = bpy.context.preferences.system
dpi = 72 if system.ui_scale >= 1 else system.dpi
blf.size(0, 10, dpi)
for word in text.split():
word = f' {word}'
line_len, _ = blf.dimensions(0, row_text + word)
if line_len <= (width - 16):
row_text += word
else:
return_text.append(row_text)
row_text = word
if row_text:
return_text.append(row_text)
return return_text
def draw(self, context):
col = self.layout.column()
width = context.region.width
ui_scale = context.preferences.system.ui_scale
MSG = f"Or move your already purchased {ds_props.product} pack into this folder:"
for text in wrap_text(MSG, 0.8*(width/ui_scale)):
col.label(text=text)
I'm thinking the main issue of my attempts has been forgetting to include uiscale.
This works reportedly correctly:
I'm thinking the main issue of my attempts has been forgetting to include uiscale.