Composite

Composite #

PhpTui\Tui\Extension\Core\Widget\CompositeWidget

Render multiple widgets to the same area.

In a grid layout each widget will render to an empty buffer.

This widget enables each widget to overlay widgets on the same buffer which is useful for showing dialogues, overlaying scrollbars, floating windows, etc.

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\CompositeWidget;
use PhpTui\Tui\Extension\Core\Widget\Scrollbar\ScrollbarOrientation;
use PhpTui\Tui\Extension\Core\Widget\Scrollbar\ScrollbarState;
use PhpTui\Tui\Extension\Core\Widget\ScrollbarWidget;
use PhpTui\Tui\Text\Title;
use PhpTui\Tui\Widget\Borders;

require 'vendor/autoload.php';

$display = DisplayBuilder::default()->build();
$display->draw(
    CompositeWidget::fromWidgets(
        BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Window 1')),
        ScrollbarWidget::default()->state(new ScrollbarState(20, 5, 5)),
        ScrollbarWidget::default()
            ->state(new ScrollbarState(20, 5, 5))
            ->orientation(ScrollbarOrientation::VerticalRight),
    )
);

Parameters #

Configure the widget using the builder methods named as follows:

NameTypeDescription
widgetsWidget[] $widgets