# Copyright 2009 Autodesk, Inc.  All rights reserved.
# 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 specify attach in a FBLayout
#
# Topic: FBAttachType, FBLayout

from pyfbsdk import *
from pyfbsdk_additions import *


# Tool creation will serve as the hub for all other controls
t = CreateUniqueTool("Attach Example")

b = FBButton()
b.Caption = "But"

# Create a button that is left justify 
x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
# ... and at the top of the layout. 
y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
# its width is fixed at 40 pixels
w = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
# and its height is fixed at 40 pixels
h = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
t.AddRegion("Btn","Btn", x, y, w, h)
t.SetControl("Btn",b)

b2 = FBButton()
b2.Caption = "But2"

# Create a button that is situated to the right of the region "Btn"
x1 = FBAddRegionParam(5,FBAttachType.kFBAttachRight,"Btn")
# attach to the top of the layout
y1 = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
# its width is fixed at 40 pixels
w1 = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
# and its height is fixed at 40 pixels
h1 = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
t.AddRegion("Btn2","Btn2", x1, y1, w1, h1)
t.SetControl("Btn2",b2)

b3 = FBButton()
b3.Caption = "But3"

# Create a button that Right justify in the FBLayout. 
# since the x Region param sets the left corner of the controls
# we need to offset the attach by -45 pixels so the button is shown.
x3 = FBAddRegionParam(-45,FBAttachType.kFBAttachRight,"")
y3 = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
w3 = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
h3 = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
t.AddRegion("Btn3","Btn3", x3, y3, w3, h3)
t.SetControl("Btn3",b3)

b4 = FBButton()
b4.Caption = "But4"

# create a button that is situated at the left of region "Btn3".
# we need to offset it by -45 pixels so it doesn't overlap Btn3
x4 = FBAddRegionParam(-45,FBAttachType.kFBAttachLeft,"Btn3")
y4 = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
w4 = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
h4 = FBAddRegionParam(40,FBAttachType.kFBAttachNone,"")
t.AddRegion("Btn4","Btn4", x4, y4, w4, h4)
t.SetControl("Btn4",b4)

ShowTool(t)