Grid

Grid #

PhpTui\Tui\Extension\Core\Widget\GridWidget

The grid is a widget that provides either a horiztonal or vertical layout based on a series of constraints.

Widgets can be supplied to fill the cells corresponding to the resolved constraints.

Example #

Show code
<?php

declare(strict_types=1);

use PhpTui\Tui\DisplayBuilder;
use PhpTui\Tui\Extension\Core\Widget\BlockWidget;
use PhpTui\Tui\Extension\Core\Widget\GridWidget;
use PhpTui\Tui\Layout\Constraint;
use PhpTui\Tui\Text\Title;
use PhpTui\Tui\Widget\Borders;
use PhpTui\Tui\Widget\Direction;

require 'vendor/autoload.php';

$display = DisplayBuilder::default()->build();
$display->draw(
    GridWidget::default()
        ->direction(Direction::Horizontal)
        ->constraints(
            Constraint::percentage(50),
            Constraint::percentage(50),
        )
        ->widgets(
            BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Left')),
            GridWidget::default()
                ->direction(Direction::Vertical)
                ->constraints(
                    Constraint::percentage(50),
                    Constraint::percentage(50),
                )
                ->widgets(
                    BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Top Right')),
                    BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Bottom Right')),
                )
        )
);

Parameters #

Configure the widget using the builder methods named as follows:

NameTypeDescription
directionPhpTui\Tui\Widget\DirectionThe direction of the grid
widgetslist<Widget>The widgets. There should be at least as many constraints as widgets.
constraintslist<Constraint>The constraints define the widget (Direction::Horizontal) or height (Direction::Vertical) of the cells.