MotionBuilder Python Script16 - UI_GridLayout

自我检讨

还是托更了,前两天专注于新家打扫,之后又重新接到了一些耗时的任务,不知不觉竟然将近5天没有更新,还是没有把小事做好!自我检讨!

今天我们来看一下Motion中的GridLayout

一、GridLayout

网格布局,将控件以表格形式布局

我们先来看一下UI效果


GridLayout

这里的控件都用Button来代替,大家可以尝试用之前文章中的控件来摆一摆!代码如下:

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,"")
    mainLyt.AddRegion("main","main", x, y, w, h)

    grid = FBGridLayout()

    grid.SetRowRatio(0, 3.0)

    # Add buttons in the first row
    for i in range(7):
        b = FBButton()
        b.Caption = "0," + str(i)
        grid.Add(b,0,i)
        
    # add buttons in the first column
    for i in range(7):
        b = FBButton()
        b.Caption = str(i) + ",0"
        grid.Add(b,i,0)
    
    b = FBButton()
    b.Caption = "0,1"
    grid.Add(b,0,1)    
        
    b = FBButton()
    b.Caption = "1,3"
    # specify button width: this will make the rows and columns grow to accomodate this big button
    grid.Add(b,1,3, width = 200)
        
    # set the height of the row 2
    grid.SetRowHeight(2, 50)
    
    b = FBButton()
    b.Caption = "2,2"
    # specify the width and height of a button
    grid.Add(b,2,2,width = 45, height = 25)
    
    # set the spacing between col3 and col4
    grid.SetColSpacing(3, 50)
    
    b = FBButton()
    b.Caption = "2,3"
    # specify that the button will be "right justified" in the column (attachX relates to horizontal position)
    grid.Add(b,2,3,attachX = FBAttachType.kFBAttachRight, width = 25, height = 20, attachY = FBAttachType.kFBAttachBottom)

    b = FBButton()
    b.Caption = "3,1"
    # specify the height of the button
    grid.Add(b,3,1, height = 200)


    b = FBButton()
    b.Caption = "3,2"
    # specify that the button will be attach to the bottom of the row (attachY relates to vertical position)
    grid.Add(b,3,2,attachY = FBAttachType.kFBAttachBottom, height = 25)
    
    b = FBButton()
    b.Caption = "3,6,3,6"
    # this button will span from row 3 to row 6 and from col 3 to col 6.
    grid.AddRange(b,3,6, 3, 6)

    mainLyt.SetControl("main",grid)

def CreateTool():    
    # Tool creation will serve as the hub for all other controls
    t = FBCreateUniqueTool("Grid Example")
    PopulateLayout(t)
    # Button creation
    t.StartSizeX = 800
    t.StartSizeY = 800
    ShowTool(t)
CreateTool()

decomposition and refactor!

二、结语

做任何事情都要坚持!

尤其是小事,一屋不扫何以扫天下!

有什么问题可以留言!

共勉!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容