目标
- [x] 总结Blender面板布局
总结
Blender面板中界面组件是通过UILayout进行组织的. 其主要属性如下:
- row() 定义横向子布局.
- column() 定义竖向子布局.
- split() 按比例拆分行
- column_flow() 定义多列的竖向子布局(根据列,计算行数, 然后按逐列摆放组件)
- box() 定义有外框的竖向子布局
- menu_pie() 饼状菜单
- operator() 放置调用操作器的按钮
- prop() 展示RNA,并把它放在布局中
- label() 显示标签
- separator() 分隔元素
代码示例
class SimplePanel(bpy.types.Panel):bl_space_type = 'VIEW_3D'bl_region_type = "TOOLS"bl_category = "Test"bl_label = "测试工具"bl_context = "objectmode"def draw(self, context):# Store reference to context.scenescn = context.scene# Store reference to self.layoutlay = self.layout# Create boxbox = lay.column_flow(2)box.operator("object.simple_operator", text="Print #1")box.prop(scn, 'encouraging_message')box.operator("object.simple_operator", text="Print #1")box.prop(scn, 'encouraging_message')box.operator("object.simple_operator", text="Print #1")# Create another boxbox = lay.box()# Create a row within itrow = box.row()# We can jam a few things on the same rowrow.operator("object.simple_operator", text="Print #2")row.prop(scn, 'encouraging_message')# Create yet another boxbox = lay.box()# Create a row just for a labelrow = box.row()row.label('There is a split row below me!')# Create a split row within itrow = box.row()splitrow = row.split(percentage=0.2)# Store references to each column of the split rowleft_col = splitrow.column()right_col = splitrow.column()left_col.operator("object.simple_operator", text="Print #3")right_col.prop(scn, 'encouraging_message')# Throw a separator in for white space...lay.separator()# We can create columns within rows...row = lay.row()col = row.column()col.prop(scn, 'my_int_prop')col.prop(scn, 'my_int_prop')col.prop(scn, 'my_int_prop')col = row.column()col.prop(scn, 'my_float_prop')col.label("I'm in the middle of a column")col.prop(scn, 'my_float_prop')# Throw a few separators in...lay.separator()lay.separator()lay.separator()# Same as above but with boxes...row = lay.row()box = row.box()box.prop(scn, 'my_int_prop')box.label("I'm in the box, bottom left.")box = row.box()box.prop(scn, 'my_bool_prop')box.operator("object.simple_operator", text="Print #4")@classmethoddef register(cls):print("Register class: %s" % cls.bl_label)@classmethoddef unregister(cls):print('Unregister class: %s' % cls.bl_label)