-
Notifications
You must be signed in to change notification settings - Fork 7
Stack Panel
Refaltor77 edited this page Mar 29, 2026
·
2 revisions
Layout panel that automatically stacks children vertically or horizontally. Extends Panel.
use refaltor\ui\elements\StackPanel;
use refaltor\ui\helpers\OrientationHelper;
$stack = StackPanel::create("my_stack")
->setOrientation(OrientationHelper::VERTICAL);$stack->setOrientation(OrientationHelper::VERTICAL); // Top to bottom
$stack->setOrientation(OrientationHelper::HORIZONTAL); // Left to right$menu = StackPanel::create("menu")
->setOrientation(OrientationHelper::VERTICAL)
->setSize(200, 200)
->setAnchorFrom(Element::ANCHOR_CENTER)
->setAnchorTo(Element::ANCHOR_CENTER);
$menu->addChild(
Label::create("item1", "Play Game")->setSize(200, 30)->setShadow()
);
$menu->addChild(
Label::create("item2", "Settings")->setSize(200, 30)->setShadow()
);
$menu->addChild(
Label::create("item3", "Quit")->setSize(200, 30)->setShadow()
);
$root->addElement($menu);$toolbar = StackPanel::create("toolbar")
->setOrientation(OrientationHelper::HORIZONTAL)
->setCustomSize(["100%", 40])
->setAnchorFrom(Element::ANCHOR_BOTTOM_MIDDLE)
->setAnchorTo(Element::ANCHOR_BOTTOM_MIDDLE);
$toolbar->addChild(Label::create("t1", "Home")->setSize(80, 40));
$toolbar->addChild(Label::create("t2", "Inventory")->setSize(80, 40));
$toolbar->addChild(Label::create("t3", "Map")->setSize(80, 40));Children must have a defined size for stacking to work properly. Use setSize() or setCustomSize() on each child.
- Panel — Parent class (all Panel properties apply)
- OrientationHelper — Orientation constants
- Button — Commonly used with stack panels