Skip to content

1.2 DirectBoxSizer

Fireclaw edited this page Dec 29, 2020 · 3 revisions

The box sizer places all added items next to each other and aligns them. It will just stack the items next to each other and won't limit their position nor size, so it's up to you to resize the items, clip them by packing the sizer in another container like a scrolled frame or similar.

Example

from direct.gui import DirectGuiGlobals as DGG
from direct.gui.DirectButton import DirectButton
from DirectGuiExtension.DirectBoxSizer import DirectBoxSizer

myBox = DirectBoxSizer(orientation=DGG.VERTICAL)

btn1 = DirectButton(text="test 1", scale=0.1)
myBox.addItem(btn1)

btn2 = DirectButton(text="test 2", scale=0.1)
myBox.addItem(btn2)

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.

orientation: One of DirectGuiGlobals.HORIZONTAL, VERTICAL, VERTICAL_INVERTED or HORIZONTAL_INVERTED
Note: HORIZONTAL_INVERTED is not given in the default DirectGuiGlobals but can be defined as DirectGuiGlobals.HORIZONTAL_INVERTED = 'horizontal_inverted'
The orientation tells in which direction the items will be placed where horizontal and vertical will go from left to right and top to bottom respectively and the inverted ones will go from right to left and bottom to top.

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

itemAlign: Any of DirectBoxSizer.A_Center, A_Left, A_Right, A_Middle, A_Top or A_Bottom
Center, Left and Right are used for Horizontal and Middle, Top and Bottom for Vertical aligning of the given items. A Vertical and a horizontal alignment can be combined by passing them with a bitwise or '|' like DirectBoxSizer.A_Left|DirectBoxSizer.A_Top

autoUpdateFrameSize: Boolean
If set to True, the frame size of the box 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.

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