Block

Block #

PhpTui\Tui\Extension\Core\Widget\BlockWidget

Container for other widgets and can provide a border, title and padding.

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\ParagraphWidget;
use PhpTui\Tui\Text\Text;
use PhpTui\Tui\Text\Title;
use PhpTui\Tui\Widget\Borders;
use PhpTui\Tui\Widget\BorderType;

require 'vendor/autoload.php';

$display = DisplayBuilder::default()->build();
$display->draw(
    BlockWidget::default()
        ->borders(Borders::ALL)
        ->titles(Title::fromString('Hello World'))
        ->borderType(BorderType::Rounded)
        ->widget(ParagraphWidget::fromText(Text::fromString('This is a block example')))
);

Parameters #

Configure the widget using the builder methods named as follows:

NameTypeDescription
bordersintBit mask which determines the border configuration, e.g. Borders::ALL
titlesarrayTitles for the block. You can have multiple titles and each title can be positioned in a different place.
borderTypePhpTui\Tui\Widget\BorderTypeType of border, e.g. BorderType::Rounded
borderStylePhpTui\Tui\Style\StyleStyle of the border.
stylePhpTui\Tui\Style\StyleStyle of the block’s inner area.
titleStylePhpTui\Tui\Style\StyleStyle of the titles.
paddingPhpTui\Tui\Extension\Core\Widget\Block\PaddingPadding to apply to the inner widget.
widgetPhpTui\Tui\Widget\Widget|nullThe inner widget.