# 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 with a scrollbox that helps managing large content area.
#
# Topic: GridLayout,FBScrollBox
#

from pyfbsdk import *
from pyfbsdk_additions import *


def PopulateLayout(mainLyt):
    x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
    y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
    w = FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
    h = FBAddRegionParam(0,FBAttachType.kFBAttachBottom,"")
    mainLyt.AddRegion("main","main", x, y, w, h)

    # create a scrollbox and set it as the main control in our tool
    scroll = FBScrollBox()
    mainLyt.SetControl("main",scroll)
    # Content property is the scrollbox's layout: create a region in it
    scroll.Content.AddRegion( "content", "content", x, y, w, h )

    lyt = GridLayout()
    # set our layout as the content of the scrollbox
    scroll.Content.SetControl("content", lyt)

    # init the scrollbox content size. We will be able to scroll on this size.
    scroll.SetContentSize(800, 800)

    # populate our grid with dummy buttons
    for i in range(7):
        for j in range(7):
            b = FBButton()
            b.Caption = "%d, %d" % (i, j)
            lyt.Add(b, i, j)


def CreateTool():
    # Tool creation will serve as the hub for all other controls
    t = CreateUniqueTool("Scrollbox Tool Example")
    t.StartSizeX = 400
    t.StartSizeY = 400
    PopulateLayout(t)
    ShowTool(t)

CreateTool()