I want to create nice-looking auto-adjusting UIList with three columns of data inside. Some of the values in columns are different in length. They are: float value, unit (usually 2-3 chars) and name of the corresponding object (could be longer, but nvm).
Here is the sample code: First, I have a collection object defined like this:
class Area(bpy.types.PropertyGroup):
id = IntProperty()
area = FloatProperty(default=0.0, description='Area measured')
atxt = StringProperty(default='0.0',description='Area converted to text and formatted')
unit = StringProperty(default='',description='Unit item choosen from UnitTypes')
name = StringProperty(default='',description='Object name which area is calculated')
Then I have a draw_item function, which is defined like this:
class AreaItemList(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
# line = ('%-12s %4s %-s' % (item.atxt,item.unit,item.name))
# layout.label(text = line)
layout.prop(item,"atxt",emboss=False,text='')
layout.prop(item,"unit",emboss=False,text='')
layout.prop(item,"name",emboss=False,text='')
elif self.layout_type in {'GRID'}:
pass
Please note the commented section: it does work, but looks ugly, and there is no align in columns because of variable char length. So, the question is: - how to make aligned columns in UIList?
It could be either by using layout.split (but it's hard to predict the split ratio, and there are three columns, and by the way - the documentation is pretty poor about this layout function), or either by using monospaced font and string formatting. How to do this? Any ideas? Look of the list for the code from the comment: http://storage3.static.itmages.com/i/16/0423/h_1461384717_4797711_d3f6576ba9.jpeg