Fix uneven multiline text spacing.

This commit is contained in:
2018-08-03 17:02:27 +02:00
parent cefaa27640
commit e6dfebbfd7

View File

@@ -51,21 +51,21 @@ def viewport_size():
def draw_text_center(text, x, y):
dim = blf.dimensions(font_id, text)
cx = x - dim[0]/2
cy = y - dim[1]/2
cx = x - int(dim[0]/2)
cy = y - int(dim[1]/2)
blf.position(font_id, cx, cy, 0)
blf.draw(font_id, text)
def draw_text_multiline(text, x, y):
space = 8
ui_scale = bpy.context.user_preferences.system.ui_scale
height = int(blf.dimensions(font_id, "Dummy Text")[1])
space = int(8 * ui_scale)
for line in text.split('\n'):
dim = blf.dimensions(font_id, line)
y -= dim[1]
blf.position(font_id, x, y, 0)
blf.position(font_id, x, y - height, 0)
blf.draw(font_id, line)
y -= space
y -= height + space
def draw_rect(x, y, w, h, color):
import gpu