Skip to content

1.3 DirectGridSizer

Fireclaw edited this page Dec 29, 2020 · 3 revisions

Using the grid sizer, you can place multiple elements in a grid layout. Means all elements are placed at a specific position within the grid and the rows and columns will scale up to the largest element that they contain.

Example

from direct.gui.DirectButton import DirectButton
from DirectGuiExtension.DirectGridSizer import DirectGridSizer

gridSizer = DirectGridSizer(numRows=2, numColumns=3, autoUpdateFrameSize=True, itemMargin=[0.01, 0.01, 0.01, 0.01])

btnA = DirectButton(text="A", scale=0.1)
btnB = DirectButton(text="B", scale=0.1)
btnC = DirectButton(text="C", scale=0.1)
btnD = DirectButton(text="D", scale=0.1)

gridSizer.addItem(btnA, 0,0)
gridSizer.addItem(btnB, 0,1)
gridSizer.addItem(btnC, 0,2)
gridSizer.addItem(btnD, 1,1)

Options

items: List of DirectItemContainer
This list contains all items that are added to the container. If you plan to add items by this parameter, you should also reparent them to the box sizer. The list will also be updated and elements reparented if they are passed by the addItem command.

itemMargin: Tuple of 4 or LVecBase4f
The margine controls the space between the items inside the grid sizer.

numRows: integer
The number of rows that are created for the grid

numColumns: integer
The number of columns that are created for the grid

autoUpdateFrameSize: Boolean
If set to True, the frame size of the grid sizer will be updated to the maximum extend of all the items it contains. If set to False, the sizer will keep the frameSize it was initially set to.

Note: If you plan to pack this element into a DirectAutoSizer, you should set this to False.

boxAlign: any of TextNode.ALeft, ARight, ACenter
Used to set the align of elements within a cell

Functions

addItem(widget):
Add another widget to the box sizer

removeItem(widget):
Removes the given widget from the box sizer. Returns 1 if the item was successfully removed, 0 otherwise.

Clone this wiki locally