今天再来介绍一下Motionbuilder里面的Box布局
一、BoxLayout
这里主要是关于搭建出Box之后,里面的布局设置,与Script05 BoxCustomParams的并不一样
先来看一下丰满的UI效果
这里凑齐了Box内的所有Layout方法,代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Use of this software is subject to the terms of the Autodesk license agreement
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Create a tool that shows how to use a FBVBoxLayout/FBHBoxLayout to place controls dynamically on screen.
#
# Topic: FBHBoxLayout, FBVBoxLayout, FBAttachType
#
from pyfbsdk import *
from pyfbsdk_additions import *
def PopulateLayout(mainLyt):
# Create Main region frame:
x = FBAddRegionParam(5, FBAttachType.kFBAttachLeft, "")
y = FBAddRegionParam(5, FBAttachType.kFBAttachTop, "")
w = FBAddRegionParam(-5, FBAttachType.kFBAttachRight, "")
h = FBAddRegionParam(-5, FBAttachType.kFBAttachBottom, "")
main = FBVBoxLayout()
mainLyt.AddRegion("main", "main", x, y, w, h)
mainLyt.SetControl("main", main)
# create horizontal boxes packed in a vbox
hstripes = FBVBoxLayout()
# Shows how to create a FBHBoxLayout that grows from left to right
box = FBHBoxLayout(FBAttachType.kFBAttachLeft)
names = ["from ->", "left ->", "to ->", "right ->"]
for name in names:
b = FBButton()
b.Caption = name
box.Add(b, 50)
hstripes.Add(box, 35)
# Shows how to create a FBHBoxLayout that grows from right to left
box = FBHBoxLayout(FBAttachType.kFBAttachRight)
names = ["<- from", "<- right", "<- to", "<- left"]
for name in names:
b = FBButton()
b.Caption = name
box.Add(b, 50)
hstripes.Add(box, 35)
# Add a button that is center in its row using "dummy" addRelative
row = FBHBoxLayout(FBAttachType.kFBAttachLeft)
row.AddRelative(None)
b = FBButton()
b.Caption = "center"
row.Add(b, 50)
row.AddRelative(None)
hstripes.Add(row, 35)
# Shows how to add buttons that resize to take all spaces available according to ratio
names = [("1/4 of width", 0.25), ("1/2 of width", 0.5), ("1/4 of width", 0.25)]
box = FBHBoxLayout(FBAttachType.kFBAttachLeft)
for name, ratio in names:
b = FBButton()
b.Caption = name
box.AddRelative(b, ratio)
hstripes.Add(box, 35)
# add all vbox into the main layout
main.AddRelative(hstripes, 1.0)
vstripes = FBHBoxLayout()
# Shows how to create a FBVBoxLayout that grows from Top to bottom
box = FBVBoxLayout(FBAttachType.kFBAttachTop)
names = ["from ", "top", "to", "bottom"]
for name in names:
b = FBButton()
b.Caption = name
box.Add(b, 50)
vstripes.Add(box, 70)
# Shows how to create a FBVBoxLayout that grows Bottom to Top
box = FBVBoxLayout(FBAttachType.kFBAttachBottom)
names = ["from", "bottom", "to", "top"]
for name in names:
b = FBButton()
b.Caption = name
box.Add(b, 50)
vstripes.Add(box, 70)
# Add a button that is center in its column using "dummy" addRelative
row = FBVBoxLayout()
row.AddRelative(None)
b = FBButton()
b.Caption = "center"
row.Add(b, 35)
row.AddRelative(None)
vstripes.Add(row, 70)
# Shows how to add buttons that resize to take all spaces available according to ratio
names = [("1/4 of width", 0.25), ("1/2 of width", 0.5), ("1/4 of width", 0.25)]
box = FBVBoxLayout()
for name, ratio in names:
b = FBButton()
b.Caption = name
box.AddRelative(b, ratio)
vstripes.Add(box, 70)
main.AddRelative(vstripes, 1.0)
def CreateTool():
# Tool creation will serve as the hub for all other controls
t = FBCreateUniqueTool("Box Example")
PopulateLayout(t)
t.StartSizeX = 800
t.StartSizeY = 800
ShowTool(t)
CreateTool()
代码脉络清晰,decomposition and refactor!
二、结语
有问题可以留言
继续!
共勉!